You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Alvin UW <al...@gmail.com> on 2010/12/10 21:49:40 UTC

Consistency question caused by Read_all and Write_one

Hello,


I got a consistency problem in Cassandra.

Given a column family with a record:    Id   Name
                                                        1    David

There are three backups for this column family.

Assume there are two write operation happens issued by the same application
by this order: write_one("1", "Dan") ; write_one("1", "Ken").
What will Read_all("1") get?

Assume the above two write operations happens exactly the same time in two
applications,
Again what will Read_all("1") get?

Thanks.

Alvin

Re: Consistency question caused by Read_all and Write_one

Posted by Tyler Hobbs <ty...@riptano.com>.
Could you give more details on what you're trying to do?  This sounds like a
case where a UUID will give you what you need without needing to lock.

- Tyler

On Tue, Dec 14, 2010 at 10:24 AM, Alvin UW <al...@gmail.com> wrote:

> Thanks.
> It is very helpful.
>
> I think I'd like to write to the same column.
>
> Would you please give me more details about your last sentence? For
> example, why can't I use locking mechanism inside of cassandra?
>
> Thanks.
> Alvin
>
> 2010/12/13 Aaron Morton <aa...@thelastpickle.com>
>
> In your example is a little unclear.
>>
>>  If you are writing to a single row and creating columns with user names.
>> Then when you read all the columns for row 1 you will get columns called Dan
>> and Ken.
>>
>> If you are writing to the same column, let's say called user, then *if*
>> they are send with the same time stamp the greater value when compared by
>> bytes will be used. Ken in this case.
>>
>> If you app has sections that are highly concurrent try to design them
>> away, or use a locking mechanism outside of casandra, or use another DB.
>>
>> Hope that helps.
>> Aaron
>>
>>
>> On 14/12/2010, at 7:11 AM, Alvin UW <al...@gmail.com> wrote:
>>
>> Yes, the same timestamp
>>
>> 2010/12/10 Ryan King < <ry...@twitter.com>
>>
>>> On Fri, Dec 10, 2010 at 12:49 PM, Alvin UW < <al...@gmail.com>
>>> alvinuw@gmail.com> wrote:
>>> > Hello,
>>> >
>>> >
>>> > I got a consistency problem in Cassandra.
>>> >
>>> > Given a column family with a record:    Id   Name
>>> >                                                         1    David
>>> >
>>> > There are three backups for this column family.
>>> >
>>> > Assume there are two write operation happens issued by the same
>>> application
>>> > by this order: write_one("1", "Dan") ; write_one("1", "Ken").
>>> > What will Read_all("1") get?
>>> >
>>> > Assume the above two write operations happens exactly the same time in
>>> two
>>> > applications,
>>> > Again what will Read_all("1") get?
>>>
>>> By "exactly the same" do you mean "with the same timestamp"?
>>>
>>> -ryan
>>>
>>
>>
>

Re: Consistency question caused by Read_all and Write_one

Posted by Alvin UW <al...@gmail.com>.
Thanks.
It is very helpful.

I think I'd like to write to the same column.

Would you please give me more details about your last sentence? For example,
why can't I use locking mechanism inside of cassandra?

Thanks.
Alvin

2010/12/13 Aaron Morton <aa...@thelastpickle.com>

> In your example is a little unclear.
>
>  If you are writing to a single row and creating columns with user names.
> Then when you read all the columns for row 1 you will get columns called Dan
> and Ken.
>
> If you are writing to the same column, let's say called user, then *if*
> they are send with the same time stamp the greater value when compared by
> bytes will be used. Ken in this case.
>
> If you app has sections that are highly concurrent try to design them away,
> or use a locking mechanism outside of casandra, or use another DB.
>
> Hope that helps.
> Aaron
>
>
> On 14/12/2010, at 7:11 AM, Alvin UW <al...@gmail.com> wrote:
>
> Yes, the same timestamp
>
> 2010/12/10 Ryan King < <ry...@twitter.com>
>
>> On Fri, Dec 10, 2010 at 12:49 PM, Alvin UW < <al...@gmail.com>
>> alvinuw@gmail.com> wrote:
>> > Hello,
>> >
>> >
>> > I got a consistency problem in Cassandra.
>> >
>> > Given a column family with a record:    Id   Name
>> >                                                         1    David
>> >
>> > There are three backups for this column family.
>> >
>> > Assume there are two write operation happens issued by the same
>> application
>> > by this order: write_one("1", "Dan") ; write_one("1", "Ken").
>> > What will Read_all("1") get?
>> >
>> > Assume the above two write operations happens exactly the same time in
>> two
>> > applications,
>> > Again what will Read_all("1") get?
>>
>> By "exactly the same" do you mean "with the same timestamp"?
>>
>> -ryan
>>
>
>

Re: Consistency question caused by Read_all and Write_one

Posted by Aaron Morton <aa...@thelastpickle.com>.
In your example is a little unclear.

 If you are writing to a single row and creating columns with user names. Then when you read all the columns for row 1 you will get columns called Dan and Ken.

If you are writing to the same column, let's say called user, then *if* they are send with the same time stamp the greater value when compared by bytes will be used. Ken in this case.

If you app has sections that are highly concurrent try to design them away, or use a locking mechanism outside of casandra, or use another DB.

Hope that helps.
Aaron


On 14/12/2010, at 7:11 AM, Alvin UW <al...@gmail.com> wrote:

> Yes, the same timestamp
> 
> 2010/12/10 Ryan King <ry...@twitter.com>
> On Fri, Dec 10, 2010 at 12:49 PM, Alvin UW <al...@gmail.com> wrote:
> > Hello,
> >
> >
> > I got a consistency problem in Cassandra.
> >
> > Given a column family with a record:    Id   Name
> >                                                         1    David
> >
> > There are three backups for this column family.
> >
> > Assume there are two write operation happens issued by the same application
> > by this order: write_one("1", "Dan") ; write_one("1", "Ken").
> > What will Read_all("1") get?
> >
> > Assume the above two write operations happens exactly the same time in two
> > applications,
> > Again what will Read_all("1") get?
> 
> By "exactly the same" do you mean "with the same timestamp"?
> 
> -ryan
> 

Re: Consistency question caused by Read_all and Write_one

Posted by Alvin UW <al...@gmail.com>.
Yes, the same timestamp

2010/12/10 Ryan King <ry...@twitter.com>

> On Fri, Dec 10, 2010 at 12:49 PM, Alvin UW <al...@gmail.com> wrote:
> > Hello,
> >
> >
> > I got a consistency problem in Cassandra.
> >
> > Given a column family with a record:    Id   Name
> >                                                         1    David
> >
> > There are three backups for this column family.
> >
> > Assume there are two write operation happens issued by the same
> application
> > by this order: write_one("1", "Dan") ; write_one("1", "Ken").
> > What will Read_all("1") get?
> >
> > Assume the above two write operations happens exactly the same time in
> two
> > applications,
> > Again what will Read_all("1") get?
>
> By "exactly the same" do you mean "with the same timestamp"?
>
> -ryan
>

Re: Consistency question caused by Read_all and Write_one

Posted by Ryan King <ry...@twitter.com>.
On Fri, Dec 10, 2010 at 12:49 PM, Alvin UW <al...@gmail.com> wrote:
> Hello,
>
>
> I got a consistency problem in Cassandra.
>
> Given a column family with a record:    Id   Name
>                                                         1    David
>
> There are three backups for this column family.
>
> Assume there are two write operation happens issued by the same application
> by this order: write_one("1", "Dan") ; write_one("1", "Ken").
> What will Read_all("1") get?
>
> Assume the above two write operations happens exactly the same time in two
> applications,
> Again what will Read_all("1") get?

By "exactly the same" do you mean "with the same timestamp"?

-ryan

Re: Consistency question caused by Read_all and Write_one

Posted by Peter Schuller <pe...@infidyne.com>.
> Assume there are two write operation happens issued by the same application
> by this order: write_one("1", "Dan") ; write_one("1", "Ken").
> What will Read_all("1") get?

Assuming read_all means reading at consistency level ALL, it sees the
latest value ("Ken").

> Assume the above two write operations happens exactly the same time in two
> applications,
> Again what will Read_all("1") get?

If they happen exactly at the same time, in the sense that the
timestamps (micro second) end up being exactly equal, IIRC the
tie-breaker is the value (I think the greater value wins). But note
that this is likely not a problem; if it is you probably already have
an issue with races anyway. Unless you have some very very strict
synchronization going on between your clients, it will be essentially
equivalent to an outside observer whether two clients wrote two values
with timestamps of almost the same microseconds, or wrote two values
with timestamps that are exactly equal. In both cases you're
effectively racing and you'll see afterwards who won. If you require
otherwise you probably require synchronization, regardless of what
Cassandra does in terms of tie breaking with identical timestamps (if
you have such strict ordering requirements then by what means do you
allocate the timestamps in a guaranteed-in-order way? you're probably
not).

-- 
/ Peter Schuller