On 02/24/2014 09:24 PM, [email protected] wrote:
Thanks Michael, I will take a look at LWT for the future but
unfortunately we are using Cassandra 1.2 ( I should have stated that,
sorry). Are there any recommendations for 1.2, or do you just have to
deal with him the race condition and possible duplicate data.

I think you would need to try to perform a best effort read before write in your application. I guess it depends on the amount of traffic for the table. Even then, there is a small race window in that turnaround time. A nasty alternative would be a distributed lock manager, or you could upgrade to 2.0, if that's possible, which would be easier than messing around with locking. Someone may correct me, if there are better alternatives. I simple example attached.

Michael
cqlsh> CREATE KEYSPACE users WITH replication = { 'class' : 'SimpleStrategy', 
'replication_factor' : 1 };
cqlsh> CREATE TABLE users.user ( uid text PRIMARY KEY, tid timeuuid, email 
set<text> );
cqlsh> 
cqlsh> SELECT * from users.user ; INSERT INTO users.user ( uid, tid, email ) 
VALUES ( 'bob', now(), {'[email protected]'} );

(0 rows)

cqlsh> SELECT * from users.user ; INSERT INTO users.user ( uid, tid, email ) 
VALUES ( 'bob', now(), {'[email protected]'} );

 uid | email           | tid
-----+-----------------+--------------------------------------
 bob | {'[email protected]'} | 7cad2110-9dd6-11e3-a25b-75998baadb41

(1 rows)

cqlsh> SELECT * from users.user ; INSERT INTO users.user ( uid, tid, email ) 
VALUES ( 'bob', now(), {'[email protected]'} );

 uid | email           | tid
-----+-----------------+--------------------------------------
 bob | {'[email protected]'} | 7d177ba0-9dd6-11e3-a25b-75998baadb41

(1 rows)

cqlsh>
cqlsh> SELECT * from users.user ; INSERT INTO users.user ( uid, tid, email ) 
VALUES ( 'bob', now(), {'[email protected]'} );

 uid | email           | tid
-----+-----------------+--------------------------------------
 bob | {'[email protected]'} | 7de35720-9dd6-11e3-a25b-75998baadb41

(1 rows)

cqlsh> SELECT * from users.user ;

 uid | email                | tid
-----+----------------------+--------------------------------------
 bob | {'[email protected]'} | 8fa89880-9dd6-11e3-a25b-75998baadb41

(1 rows)

cqlsh> 
cqlsh> INSERT INTO users.user ( uid, tid, email ) VALUES ( 'bob', now(), 
{'[email protected]'} ) IF NOT EXISTS;
 [applied] | uid | email                | tid
-----------+-----+----------------------+--------------------------------------
     False | bob | {'[email protected]'} | 8fa89880-9dd6-11e3-a25b-75998baadb41

cqlsh>

Reply via email to