You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Bhuvan Rawal <bh...@gmail.com> on 2016/09/06 17:48:44 UTC

Isolation in case of Single Partition Writes and Batching with LWT

Hi,

We are working to solve on a multi threaded distributed design which in
which a thread reads current state from Cassandra (Single partition ~ 20
Rows), does some computation and saves it back in. But it needs to be
ensured that in between reading and writing by that thread any other thread
should not have saved any operation on that partition.

We have thought of a solution for the same - *having a write_time column*
in the schema and making it static. Every time the thread picks up a job
read will be performed with LOCAL_QUORUM. While writing into Cassandra
batch will contain a LWT (IF write_time is read time) otherwise read will
be performed and computation will be done again and so on. This will ensure
that while saving partition is in a state it was read from.

In order to avoid race condition we need to ensure couple of things:

1. While saving data in a batch with a single partition (*Rows may be
Updates, Deletes, Inserts)* are they Isolated per replica node. (Not
necessarily on a cluster as a whole). Is there a possibility of client
reading partial rows?

2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this case could
there a chance of inconsistency in this case (When LWT is being used in
batches).

3. Is it possible to use multiple LWT in a single Batch? In general how
does LWT performs with Batch and is Paxos acted on before batch execution?

Can someone help us with this?

Thanks & Regards,
Bhuvan

Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Benedict Elliott Smith <be...@apache.org>.
Yes, each partition modified by a batch has its modifications applied
altogether, atomically (at the node level).

On Friday, 9 September 2016, Bhuvan Rawal <bh...@gmail.com> wrote:

> As per this
> <https://docs.datastax.com/en/cql/3.3/cql/cql_reference/batch_r.html> doc
> conditional batches can contain queries only belonging to that partition.
> On trying it in 3.6 I got this exception as expected:
> InvalidRequest: Error from server: code=2200 [Invalid query]
> message="Batch with conditions cannot span multiple partitions"
>
> On trying single partition batch with multiple LWT statements cassandra
> accepted them at times and rejected the complete batch statement based on
> the other LWT. I mean in the below batch
> BEGIN BATCH
> Statement 1 IF SOME CONDITION;
> Statement 2 IF SOME CONDITION2;
> Statement 3;
> APPLY BATCH;
>
> LWT of Either of Statement 1/2 was being observed of batch to be
> successful or fail and as per this doc
> <https://docs.datastax.com/en/cql/3.3/cql/cql_reference/batch_r.html> "If
> one statement in a batch is a conditional update, the conditional logic
> must return true, or the entire batch fails." Thats what must be
> essentially happening and therefore having more than one lwt may not make a
> lot of sence.
>
> One query still remains though, can single partition batch considered to
> be isolated per replica. Say if there are 5 rows in a partition and we are
> updating all using lwt the clients should read either all of them old or
> all of them during batch update.
>
> Will be glad if someone can  clarify the above doubt.
>
>
>
> On Tue, Sep 6, 2016 at 11:18 PM, Bhuvan Rawal <bhu1rawal@gmail.com
> <javascript:_e(%7B%7D,'cvml','bhu1rawal@gmail.com');>> wrote:
>
>> Hi,
>>
>> We are working to solve on a multi threaded distributed design which in
>> which a thread reads current state from Cassandra (Single partition ~ 20
>> Rows), does some computation and saves it back in. But it needs to be
>> ensured that in between reading and writing by that thread any other thread
>> should not have saved any operation on that partition.
>>
>> We have thought of a solution for the same - *having a write_time column*
>> in the schema and making it static. Every time the thread picks up a job
>> read will be performed with LOCAL_QUORUM. While writing into Cassandra
>> batch will contain a LWT (IF write_time is read time) otherwise read will
>> be performed and computation will be done again and so on. This will ensure
>> that while saving partition is in a state it was read from.
>>
>> In order to avoid race condition we need to ensure couple of things:
>>
>> 1. While saving data in a batch with a single partition (*Rows may be
>> Updates, Deletes, Inserts)* are they Isolated per replica node. (Not
>> necessarily on a cluster as a whole). Is there a possibility of client
>> reading partial rows?
>>
>> 2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this case
>> could there a chance of inconsistency in this case (When LWT is being used
>> in batches).
>>
>> 3. Is it possible to use multiple LWT in a single Batch? In general how
>> does LWT performs with Batch and is Paxos acted on before batch execution?
>>
>> Can someone help us with this?
>>
>> Thanks & Regards,
>> Bhuvan
>>
>>
>

Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Bhuvan Rawal <bh...@gmail.com>.
As per this
<https://docs.datastax.com/en/cql/3.3/cql/cql_reference/batch_r.html> doc
conditional batches can contain queries only belonging to that partition.
On trying it in 3.6 I got this exception as expected:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Batch
with conditions cannot span multiple partitions"

On trying single partition batch with multiple LWT statements cassandra
accepted them at times and rejected the complete batch statement based on
the other LWT. I mean in the below batch
BEGIN BATCH
Statement 1 IF SOME CONDITION;
Statement 2 IF SOME CONDITION2;
Statement 3;
APPLY BATCH;

LWT of Either of Statement 1/2 was being observed of batch to be successful
or fail and as per this doc
<https://docs.datastax.com/en/cql/3.3/cql/cql_reference/batch_r.html> "If
one statement in a batch is a conditional update, the conditional logic
must return true, or the entire batch fails." Thats what must be
essentially happening and therefore having more than one lwt may not make a
lot of sence.

One query still remains though, can single partition batch considered to be
isolated per replica. Say if there are 5 rows in a partition and we are
updating all using lwt the clients should read either all of them old or
all of them during batch update.

Will be glad if someone can  clarify the above doubt.



On Tue, Sep 6, 2016 at 11:18 PM, Bhuvan Rawal <bh...@gmail.com> wrote:

> Hi,
>
> We are working to solve on a multi threaded distributed design which in
> which a thread reads current state from Cassandra (Single partition ~ 20
> Rows), does some computation and saves it back in. But it needs to be
> ensured that in between reading and writing by that thread any other thread
> should not have saved any operation on that partition.
>
> We have thought of a solution for the same - *having a write_time column*
> in the schema and making it static. Every time the thread picks up a job
> read will be performed with LOCAL_QUORUM. While writing into Cassandra
> batch will contain a LWT (IF write_time is read time) otherwise read will
> be performed and computation will be done again and so on. This will ensure
> that while saving partition is in a state it was read from.
>
> In order to avoid race condition we need to ensure couple of things:
>
> 1. While saving data in a batch with a single partition (*Rows may be
> Updates, Deletes, Inserts)* are they Isolated per replica node. (Not
> necessarily on a cluster as a whole). Is there a possibility of client
> reading partial rows?
>
> 2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this case could
> there a chance of inconsistency in this case (When LWT is being used in
> batches).
>
> 3. Is it possible to use multiple LWT in a single Batch? In general how
> does LWT performs with Batch and is Paxos acted on before batch execution?
>
> Can someone help us with this?
>
> Thanks & Regards,
> Bhuvan
>
>

Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Jonathan Haddad <jo...@jonhaddad.com>.
It's due to the fact that DataStax hired a bunch of people to write high
quality docs over the last several years that have been linked to from all
over the internet since the company started publishing them.  Rankings are
computed by a number of things, one of them being inbound links.

I'm not sure why you're using Google, there's a perfectly acceptable Apache
project for you to use (nutch). Simply edit the source to rank *apache.org
sites highest, or remote DataStax altogether and you'll be good to go!



On Mon, Sep 12, 2016 at 6:15 AM Mark Thomas <ma...@apache.org> wrote:

> On 12/09/2016 13:57, Ryan Svihla wrote:
> > It was just the first place google turned up, I made an answer late in
> the evening trying to help someone out on my own free time.
>
> Thanks for the background Ryan. That is really useful.
>
> Googling for "CQL" and the first Apache hosted result (for me anyway) is
> the 6th entry. 7th if you count the 'featured snippet' as position 1.
>
> Interestingly, the results for "Cassandra" are much better.
>
> SEO is not my area of expertise at all. Does anyone here have some
> suggestions as to what could be done to improve our ranking for "CQL"
> (and any similar search terms)?
>
> Mark
>
>
> >
> > Regards,
> >
> > Ryan Svihla
> >
> >> On Sep 12, 2016, at 6:34 AM, Mark Thomas <ma...@apache.org> wrote:
> >>
> >>> On 11/09/2016 23:07, Ryan Svihla wrote:
> >>> 1. A batch with updates to a single partition turns into a single
> >>> mutation so partition writes aren't possible (so may as well use
> >>> Unlogged batches)
> >>> 2. Yes, so use local_serial or serial reads and all updates you want to
> >>> honor LWT need to be LWT as well, this way everything is buying into
> the
> >>> same protocol and behaving accordingly.
> >>> 3. LWT works with batch (has to be same partition).
> >>> https://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html if
> >>> condition doesn't fire none of the batch will (same partition will mean
> >>> it'll be the same mutation anyway so there really isn't any magic
> going on).
> >>
> >> Is there a good reason for linking to the 3rd party docs rather than the
> >> official docs in this case? I can't see one at the moment.
> >>
> >> The official docs appear to be:
> >>
> >> http://cassandra.apache.org/doc/latest/cql/dml.html#batch
> >>
> >> It might not matter in this particular instance but it looks as if there
> >> is a little more to the syntax than the 3rd party docs suggest (even if
> >> you switch to the latest version of those 3rd party docs).
> >>
> >> Generally, if you are going to point to docs, please point to the
> >> official Apache Cassandra docs unless there is a very good reason not
> >> to. (And if the good reason is that there’s a deficiency in the Apache
> >> Cassandra docs, please make it known on the list or in a Jira so someone
> >> can write what’s missing)
> >>
> >> Mark
> >>
> >>
> >>> Your biggest issue with such a design will be contention (as it would
> >>> with an rdbms with say row locking), as by intent you're making all
> >>> reads and writes block until any pending ones are complete. I'm sure
> >>> there are a couple things I forgot but this is the standard wisdom.
> >>>
> >>> Regards,
> >>>
> >>> Ryan Svihla
> >>>
> >>> On Sep 11, 2016, at 3:49 PM, Jens Rantil <jens.rantil@tink.se
> >>> <ma...@tink.se>> wrote:
> >>>
> >>>> Hi,
> >>>>
> >>>> This might be off-topic, but you could always use Zookeeper locking
> >>>> and/or Apache Kafka topic keys for doing things like this.
> >>>>
> >>>> Cheers,
> >>>> Jens
> >>>>
> >>>> On Tuesday, September 6, 2016, Bhuvan Rawal <bhu1rawal@gmail.com
> >>>> <ma...@gmail.com>> wrote:
> >>>>
> >>>>    Hi,
> >>>>
> >>>>    We are working to solve on a multi threaded distributed design
> >>>>    which in which a thread reads current state from Cassandra (Single
> >>>>    partition ~ 20 Rows), does some computation and saves it back in.
> >>>>    But it needs to be ensured that in between reading and writing by
> >>>>    that thread any other thread should not have saved any operation
> >>>>    on that partition.
> >>>>
> >>>>    We have thought of a solution for the same - *having a write_time
> >>>>    column* in the schema and making it static. Every time the thread
> >>>>    picks up a job read will be performed with LOCAL_QUORUM. While
> >>>>    writing into Cassandra batch will contain a LWT (IF write_time is
> >>>>    read time) otherwise read will be performed and computation will
> >>>>    be done again and so on. This will ensure that while saving
> >>>>    partition is in a state it was read from.
> >>>>
> >>>>    In order to avoid race condition we need to ensure couple of
> things:
> >>>>
> >>>>    1. While saving data in a batch with a single partition (*Rows may
> >>>>    be Updates, Deletes, Inserts)* are they Isolated per replica node.
> >>>>    (Not necessarily on a cluster as a whole). Is there a possibility
> >>>>    of client reading partial rows?
> >>>>
> >>>>    2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this
> >>>>    case could there a chance of inconsistency in this case (When LWT
> >>>>    is being used in batches).
> >>>>
> >>>>    3. Is it possible to use multiple LWT in a single Batch? In
> >>>>    general how does LWT performs with Batch and is Paxos acted on
> >>>>    before batch execution?
> >>>>
> >>>>    Can someone help us with this?
> >>>>
> >>>>    Thanks & Regards,
> >>>>    Bhuvan
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> Jens Rantil
> >>>> Backend engineer
> >>>> Tink AB
> >>>>
> >>>> Email: jens.rantil@tink.se <ma...@tink.se>
> >>>> Phone: +46 708 84 18 32
> >>>> Web: www.tink.se <http://www.tink.se/>
> >>>>
> >>>> Facebook <https://www.facebook.com/#!/tink.se> Linkedin
> >>>> <
> http://www.linkedin.com/company/2735919?trk=vsrp_companies_res_photo&trkInfo=VSRPsearchId%3A1057023381369207406670%2CVSRPtargetId%3A2735919%2CVSRPcmpt%3Aprimary>
> Twitter
> >>>> <https://twitter.com/tink>
> >>
>
>

Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Mark Thomas <ma...@apache.org>.
On 12/09/2016 13:57, Ryan Svihla wrote:
> It was just the first place google turned up, I made an answer late in the evening trying to help someone out on my own free time. 

Thanks for the background Ryan. That is really useful.

Googling for "CQL" and the first Apache hosted result (for me anyway) is
the 6th entry. 7th if you count the 'featured snippet' as position 1.

Interestingly, the results for "Cassandra" are much better.

SEO is not my area of expertise at all. Does anyone here have some
suggestions as to what could be done to improve our ranking for "CQL"
(and any similar search terms)?

Mark


> 
> Regards,
> 
> Ryan Svihla
> 
>> On Sep 12, 2016, at 6:34 AM, Mark Thomas <ma...@apache.org> wrote:
>>
>>> On 11/09/2016 23:07, Ryan Svihla wrote:
>>> 1. A batch with updates to a single partition turns into a single
>>> mutation so partition writes aren't possible (so may as well use
>>> Unlogged batches)
>>> 2. Yes, so use local_serial or serial reads and all updates you want to
>>> honor LWT need to be LWT as well, this way everything is buying into the
>>> same protocol and behaving accordingly. 
>>> 3. LWT works with batch (has to be same partition).
>>> https://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html if
>>> condition doesn't fire none of the batch will (same partition will mean
>>> it'll be the same mutation anyway so there really isn't any magic going on).
>>
>> Is there a good reason for linking to the 3rd party docs rather than the
>> official docs in this case? I can't see one at the moment.
>>
>> The official docs appear to be:
>>
>> http://cassandra.apache.org/doc/latest/cql/dml.html#batch
>>
>> It might not matter in this particular instance but it looks as if there
>> is a little more to the syntax than the 3rd party docs suggest (even if
>> you switch to the latest version of those 3rd party docs).
>>
>> Generally, if you are going to point to docs, please point to the
>> official Apache Cassandra docs unless there is a very good reason not
>> to. (And if the good reason is that there\u2019s a deficiency in the Apache
>> Cassandra docs, please make it known on the list or in a Jira so someone
>> can write what\u2019s missing)
>>
>> Mark
>>
>>
>>> Your biggest issue with such a design will be contention (as it would
>>> with an rdbms with say row locking), as by intent you're making all
>>> reads and writes block until any pending ones are complete. I'm sure
>>> there are a couple things I forgot but this is the standard wisdom. 
>>>
>>> Regards,
>>>
>>> Ryan Svihla
>>>
>>> On Sep 11, 2016, at 3:49 PM, Jens Rantil <jens.rantil@tink.se
>>> <ma...@tink.se>> wrote:
>>>
>>>> Hi,
>>>>
>>>> This might be off-topic, but you could always use Zookeeper locking
>>>> and/or Apache Kafka topic keys for doing things like this.
>>>>
>>>> Cheers,
>>>> Jens
>>>>
>>>> On Tuesday, September 6, 2016, Bhuvan Rawal <bhu1rawal@gmail.com
>>>> <ma...@gmail.com>> wrote:
>>>>
>>>>    Hi,
>>>>
>>>>    We are working to solve on a multi threaded distributed design
>>>>    which in which a thread reads current state from Cassandra (Single
>>>>    partition ~ 20 Rows), does some computation and saves it back in.
>>>>    But it needs to be ensured that in between reading and writing by
>>>>    that thread any other thread should not have saved any operation
>>>>    on that partition.
>>>>
>>>>    We have thought of a solution for the same - *having a write_time
>>>>    column* in the schema and making it static. Every time the thread
>>>>    picks up a job read will be performed with LOCAL_QUORUM. While
>>>>    writing into Cassandra batch will contain a LWT (IF write_time is
>>>>    read time) otherwise read will be performed and computation will
>>>>    be done again and so on. This will ensure that while saving
>>>>    partition is in a state it was read from.
>>>>
>>>>    In order to avoid race condition we need to ensure couple of things:
>>>>
>>>>    1. While saving data in a batch with a single partition (*Rows may
>>>>    be Updates, Deletes, Inserts)* are they Isolated per replica node.
>>>>    (Not necessarily on a cluster as a whole). Is there a possibility
>>>>    of client reading partial rows?
>>>>
>>>>    2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this
>>>>    case could there a chance of inconsistency in this case (When LWT
>>>>    is being used in batches).
>>>>
>>>>    3. Is it possible to use multiple LWT in a single Batch? In
>>>>    general how does LWT performs with Batch and is Paxos acted on
>>>>    before batch execution?
>>>>
>>>>    Can someone help us with this?
>>>>
>>>>    Thanks & Regards,
>>>>    Bhuvan
>>>>
>>>>
>>>>
>>>> -- 
>>>> Jens Rantil
>>>> Backend engineer
>>>> Tink AB
>>>>
>>>> Email: jens.rantil@tink.se <ma...@tink.se>
>>>> Phone: +46 708 84 18 32
>>>> Web: www.tink.se <http://www.tink.se/>
>>>>
>>>> Facebook <https://www.facebook.com/#!/tink.se> Linkedin
>>>> <http://www.linkedin.com/company/2735919?trk=vsrp_companies_res_photo&trkInfo=VSRPsearchId%3A1057023381369207406670%2CVSRPtargetId%3A2735919%2CVSRPcmpt%3Aprimary> Twitter
>>>> <https://twitter.com/tink>
>>


Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Ryan Svihla <rs...@foundev.pro>.
It was just the first place google turned up, I made an answer late in the evening trying to help someone out on my own free time. 

Regards,

Ryan Svihla

> On Sep 12, 2016, at 6:34 AM, Mark Thomas <ma...@apache.org> wrote:
> 
>> On 11/09/2016 23:07, Ryan Svihla wrote:
>> 1. A batch with updates to a single partition turns into a single
>> mutation so partition writes aren't possible (so may as well use
>> Unlogged batches)
>> 2. Yes, so use local_serial or serial reads and all updates you want to
>> honor LWT need to be LWT as well, this way everything is buying into the
>> same protocol and behaving accordingly. 
>> 3. LWT works with batch (has to be same partition).
>> https://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html if
>> condition doesn't fire none of the batch will (same partition will mean
>> it'll be the same mutation anyway so there really isn't any magic going on).
> 
> Is there a good reason for linking to the 3rd party docs rather than the
> official docs in this case? I can't see one at the moment.
> 
> The official docs appear to be:
> 
> http://cassandra.apache.org/doc/latest/cql/dml.html#batch
> 
> It might not matter in this particular instance but it looks as if there
> is a little more to the syntax than the 3rd party docs suggest (even if
> you switch to the latest version of those 3rd party docs).
> 
> Generally, if you are going to point to docs, please point to the
> official Apache Cassandra docs unless there is a very good reason not
> to. (And if the good reason is that there’s a deficiency in the Apache
> Cassandra docs, please make it known on the list or in a Jira so someone
> can write what’s missing)
> 
> Mark
> 
> 
>> Your biggest issue with such a design will be contention (as it would
>> with an rdbms with say row locking), as by intent you're making all
>> reads and writes block until any pending ones are complete. I'm sure
>> there are a couple things I forgot but this is the standard wisdom. 
>> 
>> Regards,
>> 
>> Ryan Svihla
>> 
>> On Sep 11, 2016, at 3:49 PM, Jens Rantil <jens.rantil@tink.se
>> <ma...@tink.se>> wrote:
>> 
>>> Hi,
>>> 
>>> This might be off-topic, but you could always use Zookeeper locking
>>> and/or Apache Kafka topic keys for doing things like this.
>>> 
>>> Cheers,
>>> Jens
>>> 
>>> On Tuesday, September 6, 2016, Bhuvan Rawal <bhu1rawal@gmail.com
>>> <ma...@gmail.com>> wrote:
>>> 
>>>    Hi,
>>> 
>>>    We are working to solve on a multi threaded distributed design
>>>    which in which a thread reads current state from Cassandra (Single
>>>    partition ~ 20 Rows), does some computation and saves it back in.
>>>    But it needs to be ensured that in between reading and writing by
>>>    that thread any other thread should not have saved any operation
>>>    on that partition.
>>> 
>>>    We have thought of a solution for the same - *having a write_time
>>>    column* in the schema and making it static. Every time the thread
>>>    picks up a job read will be performed with LOCAL_QUORUM. While
>>>    writing into Cassandra batch will contain a LWT (IF write_time is
>>>    read time) otherwise read will be performed and computation will
>>>    be done again and so on. This will ensure that while saving
>>>    partition is in a state it was read from.
>>> 
>>>    In order to avoid race condition we need to ensure couple of things:
>>> 
>>>    1. While saving data in a batch with a single partition (*Rows may
>>>    be Updates, Deletes, Inserts)* are they Isolated per replica node.
>>>    (Not necessarily on a cluster as a whole). Is there a possibility
>>>    of client reading partial rows?
>>> 
>>>    2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this
>>>    case could there a chance of inconsistency in this case (When LWT
>>>    is being used in batches).
>>> 
>>>    3. Is it possible to use multiple LWT in a single Batch? In
>>>    general how does LWT performs with Batch and is Paxos acted on
>>>    before batch execution?
>>> 
>>>    Can someone help us with this?
>>> 
>>>    Thanks & Regards,
>>>    Bhuvan
>>> 
>>> 
>>> 
>>> -- 
>>> Jens Rantil
>>> Backend engineer
>>> Tink AB
>>> 
>>> Email: jens.rantil@tink.se <ma...@tink.se>
>>> Phone: +46 708 84 18 32
>>> Web: www.tink.se <http://www.tink.se/>
>>> 
>>> Facebook <https://www.facebook.com/#!/tink.se> Linkedin
>>> <http://www.linkedin.com/company/2735919?trk=vsrp_companies_res_photo&trkInfo=VSRPsearchId%3A1057023381369207406670%2CVSRPtargetId%3A2735919%2CVSRPcmpt%3Aprimary> Twitter
>>> <https://twitter.com/tink>
> 

Re: External linking Was: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Benedict Elliott Smith <be...@apache.org>.
Again: *dev list*.

"Please Note: These requirements apply to Apache projects: that is, to
*individual
committer and PMC behaviors* and actions within the context of
collaboratively building software products at The Apache Software
Foundation. By definition here, "Apache project" means the collaborative
activity of *building a software release* called an "Apache product" here
at the ASF."

My emphasis.  This document expressly limits its applicability, both in
terms of individuals and activities.  *Neither* of these scopes apply here,
so you have no basis for your actions.

It is, in my view, shameful to try to strong arm a community to your will
without even reading the rules you think you are applying beyond a cursory
glance to check they confirm your prior held beliefs.

Again, and now with *your own* justification, I ask you to stop.





On 13 September 2016 at 11:35, Mark Thomas <ma...@apache.org> wrote:

> On 12/09/2016 19:22, Jim Ancona wrote:
> > Mark,
> >
> > Is there some official Apache policy on which sites it's appropriate to
> > link to on an Apache mailing list? If so, could you please post a link
> > to it so we can all understand the rules. Or is this your personal
> > opinion on what you'd like to see here?
> >
> > Thanks!
>
> The relevant policy quote from [1] is "... Apache projects are required
> to govern themselves independently of undue commercial influence." which
> is expanded on in [2].
>
> One of the elements of [2] is that perception is important. If a project
> is not independent of commercial influence, or there is a perception
> that that is the case, then that is an issue.
>
> In the majority of cases, external links are fine. If the project docs
> don't cover something, more depth is required than is available in the
> docs, a different perspective on the same topic is better suited to the
> problem at hand, etc. are all fine.
>
> It is links that can give the impression that the official Apache
> Cassandra docs are hosted by an external entity that are a concern. Such
> links increase the risk that the perception is created/re-enforced that
> the entity that hosts the external site has some special status within
> the project and that falls foul of the 'no undue commercial influence'
> requirement.
>
> Mark
>
>
> [1] http://www.apache.org/foundation/how-it-works.html
> [2] http://community.apache.org/projectIndependence.html
>
>

External linking Was: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Mark Thomas <ma...@apache.org>.
On 12/09/2016 19:22, Jim Ancona wrote:
> Mark,
> 
> Is there some official Apache policy on which sites it's appropriate to
> link to on an Apache mailing list? If so, could you please post a link
> to it so we can all understand the rules. Or is this your personal
> opinion on what you'd like to see here?
> 
> Thanks!

The relevant policy quote from [1] is "... Apache projects are required
to govern themselves independently of undue commercial influence." which
is expanded on in [2].

One of the elements of [2] is that perception is important. If a project
is not independent of commercial influence, or there is a perception
that that is the case, then that is an issue.

In the majority of cases, external links are fine. If the project docs
don't cover something, more depth is required than is available in the
docs, a different perspective on the same topic is better suited to the
problem at hand, etc. are all fine.

It is links that can give the impression that the official Apache
Cassandra docs are hosted by an external entity that are a concern. Such
links increase the risk that the perception is created/re-enforced that
the entity that hosts the external site has some special status within
the project and that falls foul of the 'no undue commercial influence'
requirement.

Mark


[1] http://www.apache.org/foundation/how-it-works.html
[2] http://community.apache.org/projectIndependence.html


Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Jim Ancona <ji...@anconafamily.com>.
Mark,

Is there some official Apache policy on which sites it's appropriate to
link to on an Apache mailing list? If so, could you please post a link to
it so we can all understand the rules. Or is this your personal opinion on
what you'd like to see here?

Thanks!

On Mon, Sep 12, 2016 at 7:34 AM, Mark Thomas <ma...@apache.org> wrote:

> On 11/09/2016 23:07, Ryan Svihla wrote:
> > 1. A batch with updates to a single partition turns into a single
> > mutation so partition writes aren't possible (so may as well use
> > Unlogged batches)
> > 2. Yes, so use local_serial or serial reads and all updates you want to
> > honor LWT need to be LWT as well, this way everything is buying into the
> > same protocol and behaving accordingly.
> > 3. LWT works with batch (has to be same partition).
> > https://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html if
> > condition doesn't fire none of the batch will (same partition will mean
> > it'll be the same mutation anyway so there really isn't any magic going
> on).
>
> Is there a good reason for linking to the 3rd party docs rather than the
> official docs in this case? I can't see one at the moment.
>
> The official docs appear to be:
>
> http://cassandra.apache.org/doc/latest/cql/dml.html#batch
>
> It might not matter in this particular instance but it looks as if there
> is a little more to the syntax than the 3rd party docs suggest (even if
> you switch to the latest version of those 3rd party docs).
>
> Generally, if you are going to point to docs, please point to the
> official Apache Cassandra docs unless there is a very good reason not
> to. (And if the good reason is that there’s a deficiency in the Apache
> Cassandra docs, please make it known on the list or in a Jira so someone
> can write what’s missing)
>
> Mark
>
>
> > Your biggest issue with such a design will be contention (as it would
> > with an rdbms with say row locking), as by intent you're making all
> > reads and writes block until any pending ones are complete. I'm sure
> > there are a couple things I forgot but this is the standard wisdom.
> >
> > Regards,
> >
> > Ryan Svihla
> >
> > On Sep 11, 2016, at 3:49 PM, Jens Rantil <jens.rantil@tink.se
> > <ma...@tink.se>> wrote:
> >
> >> Hi,
> >>
> >> This might be off-topic, but you could always use Zookeeper locking
> >> and/or Apache Kafka topic keys for doing things like this.
> >>
> >> Cheers,
> >> Jens
> >>
> >> On Tuesday, September 6, 2016, Bhuvan Rawal <bhu1rawal@gmail.com
> >> <ma...@gmail.com>> wrote:
> >>
> >>     Hi,
> >>
> >>     We are working to solve on a multi threaded distributed design
> >>     which in which a thread reads current state from Cassandra (Single
> >>     partition ~ 20 Rows), does some computation and saves it back in.
> >>     But it needs to be ensured that in between reading and writing by
> >>     that thread any other thread should not have saved any operation
> >>     on that partition.
> >>
> >>     We have thought of a solution for the same - *having a write_time
> >>     column* in the schema and making it static. Every time the thread
> >>     picks up a job read will be performed with LOCAL_QUORUM. While
> >>     writing into Cassandra batch will contain a LWT (IF write_time is
> >>     read time) otherwise read will be performed and computation will
> >>     be done again and so on. This will ensure that while saving
> >>     partition is in a state it was read from.
> >>
> >>     In order to avoid race condition we need to ensure couple of things:
> >>
> >>     1. While saving data in a batch with a single partition (*Rows may
> >>     be Updates, Deletes, Inserts)* are they Isolated per replica node.
> >>     (Not necessarily on a cluster as a whole). Is there a possibility
> >>     of client reading partial rows?
> >>
> >>     2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this
> >>     case could there a chance of inconsistency in this case (When LWT
> >>     is being used in batches).
> >>
> >>     3. Is it possible to use multiple LWT in a single Batch? In
> >>     general how does LWT performs with Batch and is Paxos acted on
> >>     before batch execution?
> >>
> >>     Can someone help us with this?
> >>
> >>     Thanks & Regards,
> >>     Bhuvan
> >>
> >>
> >>
> >> --
> >> Jens Rantil
> >> Backend engineer
> >> Tink AB
> >>
> >> Email: jens.rantil@tink.se <ma...@tink.se>
> >> Phone: +46 708 84 18 32
> >> Web: www.tink.se <http://www.tink.se/>
> >>
> >> Facebook <https://www.facebook.com/#!/tink.se> Linkedin
> >> <http://www.linkedin.com/company/2735919?trk=vsrp_
> companies_res_photo&trkInfo=VSRPsearchId%3A1057023381369207406670%
> 2CVSRPtargetId%3A2735919%2CVSRPcmpt%3Aprimary> Twitter
> >> <https://twitter.com/tink>
> >>
>
>

Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Mark Thomas <ma...@apache.org>.
On 11/09/2016 23:07, Ryan Svihla wrote:
> 1. A batch with updates to a single partition turns into a single
> mutation so partition writes aren't possible (so may as well use
> Unlogged batches)
> 2. Yes, so use local_serial or serial reads and all updates you want to
> honor LWT need to be LWT as well, this way everything is buying into the
> same protocol and behaving accordingly. 
> 3. LWT works with batch (has to be same partition).
> https://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html if
> condition doesn't fire none of the batch will (same partition will mean
> it'll be the same mutation anyway so there really isn't any magic going on).

Is there a good reason for linking to the 3rd party docs rather than the
official docs in this case? I can't see one at the moment.

The official docs appear to be:

http://cassandra.apache.org/doc/latest/cql/dml.html#batch

It might not matter in this particular instance but it looks as if there
is a little more to the syntax than the 3rd party docs suggest (even if
you switch to the latest version of those 3rd party docs).

Generally, if you are going to point to docs, please point to the
official Apache Cassandra docs unless there is a very good reason not
to. (And if the good reason is that there\u2019s a deficiency in the Apache
Cassandra docs, please make it known on the list or in a Jira so someone
can write what\u2019s missing)

Mark


> Your biggest issue with such a design will be contention (as it would
> with an rdbms with say row locking), as by intent you're making all
> reads and writes block until any pending ones are complete. I'm sure
> there are a couple things I forgot but this is the standard wisdom. 
> 
> Regards,
> 
> Ryan Svihla
> 
> On Sep 11, 2016, at 3:49 PM, Jens Rantil <jens.rantil@tink.se
> <ma...@tink.se>> wrote:
> 
>> Hi,
>>
>> This might be off-topic, but you could always use Zookeeper locking
>> and/or Apache Kafka topic keys for doing things like this.
>>
>> Cheers,
>> Jens
>>
>> On Tuesday, September 6, 2016, Bhuvan Rawal <bhu1rawal@gmail.com
>> <ma...@gmail.com>> wrote:
>>
>>     Hi,
>>
>>     We are working to solve on a multi threaded distributed design
>>     which in which a thread reads current state from Cassandra (Single
>>     partition ~ 20 Rows), does some computation and saves it back in.
>>     But it needs to be ensured that in between reading and writing by
>>     that thread any other thread should not have saved any operation
>>     on that partition.
>>
>>     We have thought of a solution for the same - *having a write_time
>>     column* in the schema and making it static. Every time the thread
>>     picks up a job read will be performed with LOCAL_QUORUM. While
>>     writing into Cassandra batch will contain a LWT (IF write_time is
>>     read time) otherwise read will be performed and computation will
>>     be done again and so on. This will ensure that while saving
>>     partition is in a state it was read from.
>>
>>     In order to avoid race condition we need to ensure couple of things:
>>
>>     1. While saving data in a batch with a single partition (*Rows may
>>     be Updates, Deletes, Inserts)* are they Isolated per replica node.
>>     (Not necessarily on a cluster as a whole). Is there a possibility
>>     of client reading partial rows?
>>
>>     2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this
>>     case could there a chance of inconsistency in this case (When LWT
>>     is being used in batches).
>>
>>     3. Is it possible to use multiple LWT in a single Batch? In
>>     general how does LWT performs with Batch and is Paxos acted on
>>     before batch execution?
>>
>>     Can someone help us with this?
>>
>>     Thanks & Regards,
>>     Bhuvan
>>
>>
>>
>> -- 
>> Jens Rantil
>> Backend engineer
>> Tink AB
>>
>> Email: jens.rantil@tink.se <ma...@tink.se>
>> Phone: +46 708 84 18 32
>> Web: www.tink.se <http://www.tink.se/>
>>
>> Facebook <https://www.facebook.com/#!/tink.se> Linkedin
>> <http://www.linkedin.com/company/2735919?trk=vsrp_companies_res_photo&trkInfo=VSRPsearchId%3A1057023381369207406670%2CVSRPtargetId%3A2735919%2CVSRPcmpt%3Aprimary> Twitter
>> <https://twitter.com/tink>
>>


Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Ryan Svihla <rs...@foundev.pro>.
1. A batch with updates to a single partition turns into a single mutation so partition writes aren't possible (so may as well use Unlogged batches)
2. Yes, so use local_serial or serial reads and all updates you want to honor LWT need to be LWT as well, this way everything is buying into the same protocol and behaving accordingly. 
3. LWT works with batch (has to be same partition). https://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html if condition doesn't fire none of the batch will (same partition will mean it'll be the same mutation anyway so there really isn't any magic going on).

Your biggest issue with such a design will be contention (as it would with an rdbms with say row locking), as by intent you're making all reads and writes block until any pending ones are complete. I'm sure there are a couple things I forgot but this is the standard wisdom. 

Regards,

Ryan Svihla

> On Sep 11, 2016, at 3:49 PM, Jens Rantil <je...@tink.se> wrote:
> 
> Hi,
> 
> This might be off-topic, but you could always use Zookeeper locking and/or Apache Kafka topic keys for doing things like this.
> 
> Cheers,
> Jens
> 
>> On Tuesday, September 6, 2016, Bhuvan Rawal <bh...@gmail.com> wrote:
>> Hi,
>> 
>> We are working to solve on a multi threaded distributed design which in which a thread reads current state from Cassandra (Single partition ~ 20 Rows), does some computation and saves it back in. But it needs to be ensured that in between reading and writing by that thread any other thread should not have saved any operation on that partition.
>> 
>> We have thought of a solution for the same - having a write_time column in the schema and making it static. Every time the thread picks up a job read will be performed with LOCAL_QUORUM. While writing into Cassandra batch will contain a LWT (IF write_time is read time) otherwise read will be performed and computation will be done again and so on. This will ensure that while saving partition is in a state it was read from.
>> 
>> In order to avoid race condition we need to ensure couple of things:
>> 
>> 1. While saving data in a batch with a single partition (Rows may be Updates, Deletes, Inserts) are they Isolated per replica node. (Not necessarily on a cluster as a whole). Is there a possibility of client reading partial rows?
>> 
>> 2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this case could there a chance of inconsistency in this case (When LWT is being used in batches).
>> 
>> 3. Is it possible to use multiple LWT in a single Batch? In general how does LWT performs with Batch and is Paxos acted on before batch execution?
>> 
>> Can someone help us with this?
>> 
>> Thanks & Regards,
>> Bhuvan
> 
> 
> -- 
> Jens Rantil
> Backend engineer
> Tink AB
> 
> Email: jens.rantil@tink.se
> Phone: +46 708 84 18 32
> Web: www.tink.se
> 
> Facebook Linkedin Twitter
> 

Re: Isolation in case of Single Partition Writes and Batching with LWT

Posted by Jens Rantil <je...@tink.se>.
Hi,

This might be off-topic, but you could always use Zookeeper locking and/or
Apache Kafka topic keys for doing things like this.

Cheers,
Jens

On Tuesday, September 6, 2016, Bhuvan Rawal <bh...@gmail.com> wrote:

> Hi,
>
> We are working to solve on a multi threaded distributed design which in
> which a thread reads current state from Cassandra (Single partition ~ 20
> Rows), does some computation and saves it back in. But it needs to be
> ensured that in between reading and writing by that thread any other thread
> should not have saved any operation on that partition.
>
> We have thought of a solution for the same - *having a write_time column*
> in the schema and making it static. Every time the thread picks up a job
> read will be performed with LOCAL_QUORUM. While writing into Cassandra
> batch will contain a LWT (IF write_time is read time) otherwise read will
> be performed and computation will be done again and so on. This will ensure
> that while saving partition is in a state it was read from.
>
> In order to avoid race condition we need to ensure couple of things:
>
> 1. While saving data in a batch with a single partition (*Rows may be
> Updates, Deletes, Inserts)* are they Isolated per replica node. (Not
> necessarily on a cluster as a whole). Is there a possibility of client
> reading partial rows?
>
> 2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this case could
> there a chance of inconsistency in this case (When LWT is being used in
> batches).
>
> 3. Is it possible to use multiple LWT in a single Batch? In general how
> does LWT performs with Batch and is Paxos acted on before batch execution?
>
> Can someone help us with this?
>
> Thanks & Regards,
> Bhuvan
>
>

-- 
Jens Rantil
Backend engineer
Tink AB

Email: jens.rantil@tink.se
Phone: +46 708 84 18 32
Web: www.tink.se

Facebook <https://www.facebook.com/#!/tink.se> Linkedin
<http://www.linkedin.com/company/2735919?trk=vsrp_companies_res_photo&trkInfo=VSRPsearchId%3A1057023381369207406670%2CVSRPtargetId%3A2735919%2CVSRPcmpt%3Aprimary>
 Twitter <https://twitter.com/tink>