You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by kannan chandrasekaran <ck...@yahoo.com> on 2010/10/16 03:16:44 UTC

Preventing an update of a CF row

Hi All,

I have a query regarding the insert operation. The insert operation by default  
inserts an new row or updates an existing row. Is it possible to prevent an 
update but allow only inserts automatically  ( especially when multiple clients 
are writing to cassandra)?  I was wondering if there is any flag in cassandra 
that will validate this for me automatically ( something like unique key 
constraint) ? If not, is it non-trivial to implement this ? Any suggestions 
would be helpful.

Thanks
Kannan


      

Re: Preventing an update of a CF row

Posted by Peter Schuller <pe...@infidyne.com>.
> I have a query regarding the insert operation. The insert operation by
> default  inserts an new row or updates an existing row. Is it possible to
> prevent an update but allow only inserts automatically  ( especially when
> multiple clients are writing to cassandra)?  I was wondering if there is any
> flag in cassandra that will validate this for me automatically ( something
> like unique key constraint) ? If not, is it non-trivial to implement this ?
> Any suggestions would be helpful.

There is no way to do this now, and I believe it is non-trivial to
implement. You're saying you want the insert to fail if corresponding
data already exists; but this is non-trivial to do in a distributed
system.

As for suggested work-arounds, that would depend on what you're trying
to do. Could you explain a bit about what the situation is in your
application and what it is trying to do that you want this behavior
for?

-- 
/ Peter Schuller

Re: Preventing an update of a CF row

Posted by Peter Schuller <pe...@infidyne.com>.
> Always specify some constant value for timestamp. Only 1st insertion with that
> timestamp will succeed. Others will be ignored, because will be considered
> duplicates by cassandra.

Just be aware that this limits you in several ways in terms of your
data model. For examle, if you ever need to remove a value and then
re-write it, you have to up the timestamp on your inserts in order for
it to be re-inserted. Same thing if you sometimes need to actually
overwrite said value in some different context than the concurrent
writer case you're trying to solve.

-- 
/ Peter Schuller

RE: Preventing an update of a CF row

Posted by Viktor Jevdokimov <Vi...@adform.com>.
Reverse timestamp.

-----Original Message-----
From: Sylvain Lebresne [mailto:sylvain@yakaz.com] 
Sent: Tuesday, October 19, 2010 10:44 AM
To: user@cassandra.apache.org
Subject: Re: Preventing an update of a CF row

> Always specify some constant value for timestamp. Only 1st insertion with that
> timestamp will succeed. Others will be ignored, because will be considered
> duplicates by cassandra.

Well, that's not entirely true. When cassandra 'resolves' two columns
having the
same timestamp, it will compare the values to decide which one to keep
(and it'll
keep the one column whose value is greater for bytes comparison).
Concretely, if you insert Column('foo', 'b', 0) and then Column('foo',
'bar', 0), then
you'll end up with the second column, even though the timestamps are the same
because 'bar' > 'b'.
So constant timestamps doesn't work for preventing updates of a given column.

--
Sylvain



Re: Preventing an update of a CF row

Posted by Sylvain Lebresne <sy...@yakaz.com>.
> Always specify some constant value for timestamp. Only 1st insertion with that
> timestamp will succeed. Others will be ignored, because will be considered
> duplicates by cassandra.

Well, that's not entirely true. When cassandra 'resolves' two columns
having the
same timestamp, it will compare the values to decide which one to keep
(and it'll
keep the one column whose value is greater for bytes comparison).
Concretely, if you insert Column('foo', 'b', 0) and then Column('foo',
'bar', 0), then
you'll end up with the second column, even though the timestamps are the same
because 'bar' > 'b'.
So constant timestamps doesn't work for preventing updates of a given column.

--
Sylvain

RE: Preventing an update of a CF row

Posted by Viktor Jevdokimov <Vi...@adform.com>.
Nice and simple!

-----Original Message-----
From: Oleg Anastasyev [mailto:oleganas@gmail.com] 
Sent: Tuesday, October 19, 2010 9:00 AM
To: user@cassandra.apache.org
Subject: Re: Preventing an update of a CF row

kannan chandrasekaran <ckannanck <at> yahoo.com> writes:

> Hi All,I have a query regarding the insert operation. The insert operation by
default  inserts an new row or updates an existing row. Is it possible to
prevent an update but allow only inserts automatically  ( especially when
multiple clients are writing to cassandra)?  I was wondering if there is any
flag in cassandra that will validate this for me automatically ( something like
unique key constraint) ? If not, is it non-trivial to implement this ? Any
suggestions would be helpful.ThanksKannan

Always specify some constant value for timestamp. Only 1st insertion with that
timestamp will succeed. Others will be ignored, because will be considered
duplicates by cassandra.



Re: Preventing an update of a CF row

Posted by Oleg Anastasyev <ol...@gmail.com>.
kannan chandrasekaran <ckannanck <at> yahoo.com> writes:

> Hi All,I have a query regarding the insert operation. The insert operation by
default  inserts an new row or updates an existing row. Is it possible to
prevent an update but allow only inserts automatically  ( especially when
multiple clients are writing to cassandra)?  I was wondering if there is any
flag in cassandra that will validate this for me automatically ( something like
unique key constraint) ? If not, is it non-trivial to implement this ? Any
suggestions would be helpful.ThanksKannan

Always specify some constant value for timestamp. Only 1st insertion with that
timestamp will succeed. Others will be ignored, because will be considered
duplicates by cassandra.