我有一个cassandra table1:
CREATE TABLE Policy.table1 (
name VARCHAR ,
date TIMESTAMP ,
version_num INT,
PRIMARY KEY (
name
)) WITH caching = 'all'
-- and memtable_flush_period_in_ms = 7200 ;
;
我需要在tis表上实现乐观锁定。当我们从table1中读取一行时,我们会记住它的version_num。当我们要更新此行时,我们将比较当前的version_num值和我们记住的值。同样,我们需要在每次更新时增加version_num。
问题:
我们不能将version_num放入where子句中,这将产生一个错误:错误的请求:在where子句中找到非主键version_num:
update table where name = 'abc' and version = 3
我们无法将version_num设置为主键的一部分,因为我们需要更新其值
您看到这个问题的解决方案了吗?
在那里找到了解决方案:Cassandra 2.0,轻量级交易http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_ltwt_transaction_c.html
如果我执行查询:
update table1 set version_num = 5 where name = 'abc' if version_num = 4;
我将收到带有[applied]
列的行。该行包含布尔值:true
=更新成功,false
=在其他情况下。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句