1

I have two questions regarding the LightWeight Transcation in cassandra,

1) What level of locking (Row? Column? Table? level locking) will be provided for the following two queries?

i) INSERT INTO user (user_id, user_name, user_phone, timestamp) VALUES(1,'uma', 9003934069, 4331312423232) IF EXISTS;
ii)  UPDATE user SET user_name = 'harry' where user_id=1 IF timestamp=4331312423232;

2) If LWT is providing the locking mechanism, why do we need to have SERIAL consistency to be set in READ? I mean If any conditional update is on going why do we need SERIAL consistency on above that?

It would be really Great, If someone could respond for this.

Thanks, Harry

Harry
  • 3,072
  • 6
  • 43
  • 100

1 Answers1

2

Cassandra does not provide lock mechanism, IF NOT EXISTS is a Lightweight Transaction.

To get linearizable consistency we need route all requests through a single master. In a fully distributed system like cassandra, it is less obvious.

Cassandra achieve linearizable consistency using paxos protocol.

The Paxos consensus protocol allows a distributed system to agree on proposals with a quorum-based algorithm, with no masters required and without the problems of two-phase commit. There are four phases to Paxos: prepare/promise, read/results, propose/accept and commit/ack

Cassandra is making four round trips between a node proposing a lightweight transaction and any needed replicas in the cluster to ensure proper execution so performance is affected.

Lightweight Transactions

That sounds like a high cost—perhaps too high. That's why Cassandra can throw timeout exception. Consequently, reserve lightweight transactions for those situations where they are absolutely necessary

Source : http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_ltwt_transaction_c.html https://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0

Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53
  • Can you explain what LWT will provide then? Where we need to use it? – Harry Nov 24 '17 at 06:06
  • LWT offers a way to ensure a transaction isolation level similar to the serializable level offered by RDBMS’s. – Ashraful Islam Nov 24 '17 at 06:09
  • Lets say T1 from Node 1 tries to update row 1, in the same time T2 from Node 2 tries to update the same row 1, How LWT will prevent it? – Harry Nov 24 '17 at 06:11
  • Two users attempting to create a unique user account in the same cluster could overwrite each other’s work with neither user knowing about it, in such case strong consistency is needed – Ashraful Islam Nov 24 '17 at 06:11
  • 1
    One of the transaction t1 or t2 will fail – Ashraful Islam Nov 24 '17 at 06:12
  • Awesome, using the response like below right, cqlsh:qnapvm> UPDATE vmserver SET vm_name = 'vmnamev3' where vm_id = 2 IF timestamp = 111111112; [applied] | timestamp -----------+----------- False | 111111113 – Harry Nov 24 '17 at 06:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159729/discussion-between-harry-and-ashraful-islam). – Harry Nov 24 '17 at 06:13