卡桑德拉乐观锁定
我有一个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子句中找到的非PRIMARY KEY 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其中name =’abc’如果version_num = 4;我将收到一行[applied]列.此行包含布尔值:true = update成功,false =在其他情况下. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |