You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Jay Svc <ja...@gmail.com> on 2013/02/01 19:51:19 UTC

conditional update or insert

Hi All,

On each row I have a column which maintains the timestamp like
"lastUpdated" etc.

While inserting such row I want to make sure that the row should be only
updated if the lastUpdated is older than the new one I am inserting.

One way to do this is -

Read the record first check the timestamp if newer is latest then update.

Since I have higher volume of read and writes load. This additional read
will add to it.

Any alternative to achieve this?

Thanks,
Jay

Re: conditional update or insert

Posted by aaron morton <aa...@thelastpickle.com>.
> Any alternative to achieve this?
Nothing server side. 
i.e. you cannot do Update foo set bar='baz' where timestamp < new_timestamp

You can monkey around with the timestamps a little though. 
Cassandra will return you the column value with the highest (internal cassandra) time stamp. Now days most clients set this to microseconds since the unix epoch, and CQL client lets the server set it. 

You could use your application time stamp (which I normally call sequence to avoid confusion) as the cassandra column timestamp. If you application writes with our of order sequences, cassandra will always return the values with the highest sequence as it will also be the cassandra timestamp.

Hope that helps. 

-----------------
Aaron Morton
Freelance Cassandra Developer
New Zealand

@aaronmorton
http://www.thelastpickle.com

On 2/02/2013, at 7:51 AM, Jay Svc <ja...@gmail.com> wrote:

> Hi All,
> 
> On each row I have a column which maintains the timestamp like "lastUpdated" etc. 
> 
> While inserting such row I want to make sure that the row should be only updated if the lastUpdated is older than the new one I am inserting.
> 
> One way to do this is - 
> 
> Read the record first check the timestamp if newer is latest then update.
> 
> Since I have higher volume of read and writes load. This additional read will add to it.  
> 
> Any alternative to achieve this?
> 
> Thanks,
> Jay