You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Blair Zajac <bl...@orcaware.com> on 2013/06/25 05:23:57 UTC

How to do a CAS UPDATE on single column CF?

How does one do an atomic update in a column family with a single column?

I have a this CF

   CREATE TABLE schema_migrations (
     version TEXT PRIMARY KEY,
   ) WITH COMPACTION = {'class': 'LeveledCompactionStrategy'};

that records which database migrations have been applied.  I want to do 
a CAS UPDATE to add a dummy lock token to prevent multiple migrations 
from running, but these three attempts fail (using the Python cql client):


 >>> cursor.execute("UPDATE schema_migrations SET version = 'locked' 
WHERE version = 'locked' IF NOT EXISTS")
cql.apivalues.ProgrammingError: Bad Request: PRIMARY KEY part version 
found in SET part


 >>> cursor.execute("UPDATE schema_migrations SET WHERE version = 
'locked' IF NOT EXISTS")
cql.apivalues.ProgrammingError: Bad Request: line 1:29 no viable 
alternative at input 'WHERE'



 >>> cursor.execute("INSERT INTO schema_migrations (version) VALUES 
('locked') IF NOT EXISTS")
cql.apivalues.ProgrammingError: Bad Request: line 1:58 missing EOF at 'IF'

Thanks,
Blair

Re: How to do a CAS UPDATE on single column CF?

Posted by Andrew Cobley <a....@dundee.ac.uk>.
According to Jonathan Ellis talk at Cassandra 13 it does use Paxos:

http://www.youtube.com/watch?v=PcUpPR4nSr4&list=PLqcm6qE9lgKJzVvwHprow9h7KMpb5hcUU

http://www.slideshare.net/jbellis/cassandra-summit-2013-keynote

Andy

On 1 Jul 2013, at 19:40, Francisco Andrades Grassi <bi...@gmail.com>> wrote:

http://en.wikipedia.org/wiki/Compare-and-swap

I believe C* uses Paxos for CAS but not completely sure?

--
Francisco Andrades Grassi
www.bigjocker.com<http://www.bigjocker.com/>
@bigjocker

On Jul 1, 2013, at 1:49 PM, "Hiller, Dean" <De...@nrel.gov>> wrote:

What does CAS stand for? And is that the row locking feature like hbase's
setAndReadWinner that you give the previous val and next val and your next
val is returned if you won otherwise the current result is returned and
you know some other node won?



The University of Dundee is a registered Scottish Charity, No: SC015096

Re: How to do a CAS UPDATE on single column CF?

Posted by Francisco Andrades Grassi <bi...@gmail.com>.
http://en.wikipedia.org/wiki/Compare-and-swap

I believe C* uses Paxos for CAS but not completely sure?

--
Francisco Andrades Grassi
www.bigjocker.com
@bigjocker

On Jul 1, 2013, at 1:49 PM, "Hiller, Dean" <De...@nrel.gov> wrote:

> What does CAS stand for? And is that the row locking feature like hbase's
> setAndReadWinner that you give the previous val and next val and your next
> val is returned if you won otherwise the current result is returned and
> you know some other node won?
> 
> Thanks,
> Dean
> 
> On 7/1/13 12:09 PM, "Blair Zajac" <bl...@orcaware.com> wrote:
> 
>> Thanks!
>> 
>> On 7/1/13 1:41 AM, Sylvain Lebresne wrote:
>>> You're right, there is currently no way to do this since 1) insert
>>> can't have a
>>> IF currently and 2) update can't update such table.
>>> 
>>> We'll fix that: https://issues.apache.org/jira/browse/CASSANDRA-5715
>>> 
>>> --
>>> Sylvain
>>> 
>>> 
>>> On Sat, Jun 29, 2013 at 9:51 PM, Blair Zajac <blair@orcaware.com
>>> <ma...@orcaware.com>> wrote:
>>> 
>>>    On 6/24/13 8:23 PM, Blair Zajac wrote:
>>> 
>>>        How does one do an atomic update in a column family with a
>>> single column?
>>> 
>>>        I have a this CF
>>> 
>>>        CREATE TABLE schema_migrations (
>>>        version TEXT PRIMARY KEY,
>>>        ) WITH COMPACTION = {'class': 'LeveledCompactionStrategy'};
>>> 
>>> 
>>>    Anyone?  Should I raise this on the developer mailing list or open
>>> a ticket?
>>> 
>>>    Blair
> 


Re: How to do a CAS UPDATE on single column CF?

Posted by "Hiller, Dean" <De...@nrel.gov>.
What does CAS stand for? And is that the row locking feature like hbase's
setAndReadWinner that you give the previous val and next val and your next
val is returned if you won otherwise the current result is returned and
you know some other node won?

Thanks,
Dean

On 7/1/13 12:09 PM, "Blair Zajac" <bl...@orcaware.com> wrote:

>Thanks!
>
>On 7/1/13 1:41 AM, Sylvain Lebresne wrote:
>> You're right, there is currently no way to do this since 1) insert
>>can't have a
>> IF currently and 2) update can't update such table.
>>
>> We'll fix that: https://issues.apache.org/jira/browse/CASSANDRA-5715
>>
>> --
>> Sylvain
>>
>>
>> On Sat, Jun 29, 2013 at 9:51 PM, Blair Zajac <blair@orcaware.com
>> <ma...@orcaware.com>> wrote:
>>
>>     On 6/24/13 8:23 PM, Blair Zajac wrote:
>>
>>         How does one do an atomic update in a column family with a
>>single column?
>>
>>         I have a this CF
>>
>>         CREATE TABLE schema_migrations (
>>         version TEXT PRIMARY KEY,
>>         ) WITH COMPACTION = {'class': 'LeveledCompactionStrategy'};
>>
>>
>>     Anyone?  Should I raise this on the developer mailing list or open
>>a ticket?
>>
>>     Blair


Re: How to do a CAS UPDATE on single column CF?

Posted by Blair Zajac <bl...@orcaware.com>.
Thanks!

On 7/1/13 1:41 AM, Sylvain Lebresne wrote:
> You're right, there is currently no way to do this since 1) insert can't have a
> IF currently and 2) update can't update such table.
>
> We'll fix that: https://issues.apache.org/jira/browse/CASSANDRA-5715
>
> --
> Sylvain
>
>
> On Sat, Jun 29, 2013 at 9:51 PM, Blair Zajac <blair@orcaware.com
> <ma...@orcaware.com>> wrote:
>
>     On 6/24/13 8:23 PM, Blair Zajac wrote:
>
>         How does one do an atomic update in a column family with a single column?
>
>         I have a this CF
>
>         CREATE TABLE schema_migrations (
>         version TEXT PRIMARY KEY,
>         ) WITH COMPACTION = {'class': 'LeveledCompactionStrategy'};
>
>
>     Anyone?  Should I raise this on the developer mailing list or open a ticket?
>
>     Blair

Re: How to do a CAS UPDATE on single column CF?

Posted by Sylvain Lebresne <sy...@datastax.com>.
You're right, there is currently no way to do this since 1) insert can't
have a IF currently and 2) update can't update such table.

We'll fix that: https://issues.apache.org/jira/browse/CASSANDRA-5715

--
Sylvain


On Sat, Jun 29, 2013 at 9:51 PM, Blair Zajac <bl...@orcaware.com> wrote:

> On 6/24/13 8:23 PM, Blair Zajac wrote:
>
>> How does one do an atomic update in a column family with a single column?
>>
>> I have a this CF
>>
>> CREATE TABLE schema_migrations (
>> version TEXT PRIMARY KEY,
>> ) WITH COMPACTION = {'class': 'LeveledCompactionStrategy'};
>>
>
> Anyone?  Should I raise this on the developer mailing list or open a
> ticket?
>
> Blair
>

Re: How to do a CAS UPDATE on single column CF?

Posted by Blair Zajac <bl...@orcaware.com>.
On 6/24/13 8:23 PM, Blair Zajac wrote:
> How does one do an atomic update in a column family with a single column?
>
> I have a this CF
>
> CREATE TABLE schema_migrations (
> version TEXT PRIMARY KEY,
> ) WITH COMPACTION = {'class': 'LeveledCompactionStrategy'};

Anyone?  Should I raise this on the developer mailing list or open a ticket?

Blair

Re: How to do a CAS UPDATE on single column CF?

Posted by Blair Zajac <bl...@orcaware.com>.
On 06/24/2013 08:35 PM, Arthur Zubarev wrote:
> On 06/24/2013 11:23 PM, Blair Zajac wrote:
>> CAS UPDATE
> Since when C* has IF NOT EXISTS in DML part of CQL?

It's new in 2.0.

https://issues.apache.org/jira/browse/CASSANDRA-5062
https://github.com/riptano/cassandra-dtest/blob/master/cql_tests.py#L3044

Blair


Re: How to do a CAS UPDATE on single column CF?

Posted by Arthur Zubarev <ar...@aol.com>.
On 06/24/2013 11:23 PM, Blair Zajac wrote:
> CAS UPDATE
Since when C* has IF NOT EXISTS in DML part of CQL?

-- 

Regards,

Arthur