Cassandra row level locking support with DataStax driver
Asked Answered
H

3

6

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

Historiated answered 26/8, 2013 at 14:29 Comment(1)
Is this a duplicate of this question?Accipitrine
A
3
  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.

Accipitrine answered 31/8, 2013 at 10:29 Comment(0)
T
3

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.

Toilsome answered 7/11, 2014 at 3:10 Comment(1)
what "cross partition insert" means?Malia
K
0

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.

Kimkimball answered 26/8, 2013 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.