Search code examples
cassandrapaxosconsensus

Cassandra's lightweight transactions & Paxos consensus algorithm


I have a very particular question regarding Paxos algorithm, which is implemented in Cassandra's lightweight transactions:

What happens if two nodes issue the same proposal at the same time? Do them both get '[applied]: true' ?

For example, consider this table:

ids:
+-------------------+---------------+
| id_name (varchar) | next_id (int) |
+-------------------+---------------+
| person_id         |             1 |
+-------------------+---------------+

And this query:

UPDATE ids
SET next_id = 2
WHERE id_name = 'person_id'
IF next_id = 1

If I execute this query, I get as a response:

[{[applied]: True}]

If I execute it again, which then it won't be accepted since next_id != 1, I get:

[{[applied]: False, next_id: 2}]

My question is - what happens if I execute this query from two nodes in parallel. Is there a chance that they both get accepted?

(My use case is described in this stackoverflow question)


Solution

  • It's not possible that both queries would be executed concurrently. For each query a proposal is created that will be used to reach consensus based on paxos. This will happen based on the timestamp associated with the proposal where an identical timestamp will still make on of the two proposals fail.