Cassandra row level locking support with DataStax driver

ⅰ亾dé卋堺 提交于 2019-12-06 00:56:11

问题


Cassandra row level locking support while accessing same row by cocurrent users

we are in design phase of our shooping cart application considering Cassandra as Inventory database. now requirment is that if multiple users access same product row in Inventory DB at same time. for example :- Product table : productID productQuantitiy 1000 1 If first user selects product '1000' and add product quantity as '1' in shopping cart, other users accessing the same product should not be able to select this product until it gets free by first user (updated product quantity as 0). so does cassandra provide row level locking support for this kind of scenario


回答1:


  1. Locking is a complicated problem for distributed systems. It also usually leads to slow operations.

  2. Cassandra 2.0 will introduce a form of lightweight transactions.

  3. Also in 2.0 there will be support for CAS operations. Basically this would allow you to simulate row level locks (update the row iif condition)

  4. While I'm not sure I understand completely the problem you are trying to solve, I think what you are looking for is consistent counters. These have been supported for a while.




回答2:


Reviving this old thread with some updated info now that LWT's are available in c*

History

Implementing locks in Cassandra has been considered and decided against. You can see the history, conversation, and ultimate resolution in this Jira --

https://issues.apache.org/jira/browse/CASSANDRA-5062.

To summarize, 1) there are some external options that allow to do some locking over cassandra (i.e. hector and others) but these are suboptimal solutions. 2) Rather than implementing c* locks (which imply zookeeper integration + introducing a single point of failure) it was decided to build cassandra's own implementation of Paxos which has been exposed as Lightweight transactions available since C* 2.0 and currently in DSE.

Example

In this video you can watch how a major bank is using LWT in C*

https://www.youtube.com/watch?v=-sD3x8-tuDU&list=PLqcm6qE9lgKJkxYZUOIykswDndrOItnn2

Key points to note

1) LWTs are, by definition, slower than regular insert/update statements in Cassandra and are designed to be used for a minority of use cases. 1% of your workload.

2) LWTs only work inside a partition. Cross partition inserts will not block LWTs.




回答3:


Cassandra has support to multiple users, but no lock any row to it, actually it uses the timestamp to sincronize what is lastest update and then share to another nodes.



来源:https://stackoverflow.com/questions/18446555/cassandra-row-level-locking-support-with-datastax-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!