简体   繁体   中英

How to achieve row level locking in cassandra

I have a Cassandra cluster setup like Node N1, Node N2 and Node N3

I have a user table, I need to write create a row level locking for it across the nodes in the cluster, So could you please guide me by answering the following questions?

1) What is the maximum level of locking possible in Cassandra?
2) What is lightweight transaction? How much it is possible to achieve row level locking?
3) Is there an alternate way to achieve the row level locking in Cassandra?

  1. None, but you might stretch it to say column level.
  2. It uses paxos for consensus and can perform conditional updates. It doesnt do locking. It will either succeed or not if another update occurred, if it doesnt succeed you can try again. If it does succeed everything in "transaction" (poor naming) will apply. However, theres still no isolation within it and if multiple columns in row are updated you may read between them being applied. details here
  3. Design data model so you dont need locking.

There is no transactions in cassandra, there is no locking. There is however light weight transactions. They're not great, the performance is worse and there are alot of tradeoffs.

Depending on what the use case is for this lock you could do: INSERT INTO User (userID, email) VALUES ('MyGuid', 'user@example.com') IF NOT EXISTS;

If the query returns an error/failure you would have to handle that, it won't just fail if someone inserts before you. A failure also might mean that 1 of your nodes did get the write but not all of them. LWT don't roll back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM