Cassandra row level locking support with DataStax driver

安稳与你 提交于 2019-12-04 06:50:58
  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.

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.

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.

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