1
votes

In Cassandra, if I update different columns concurrently in one row, will there be any write conflicts?

For example I have a table

CREATE TABLE foo (k text, a text, b text, PRIMARY KEY (k))

One thread in my code updates column a

INSERT INTO foo (k, a) VALUES ('hello', 'foo')

while the other thread updates column b

INSERT INTO foo (k, b) VALUES ('hello', 'bar').

When running concurrently, it is possible that the two queries arrive at the server at the same time.

Could I always expect the same result as I update the two columns in one CQL?

INSERT INTO foo(k, a, b) VALUES ('hello', 'foo', 'bar')

Will there be any write conflicts? Is each insertion atomic?


As Tom mentioned in his reply that in Cassandra, all the operations are column-based. Then each column should have a timestamp. In such a case, the above scenario will not bring any trouble given one thread will only update column a while the other only update column b. Is my understanding correct?

Thank you!

1

1 Answers

1
votes

Write conflicts are resolved by having each server track the time of the write. If they arrive at the exact same time (with ms accuracy) Cassandra will pick one based on an algorithm (not sure about the details, I would assume it involves node UUIDs).

So write conflicts are not something you need to worry about. Reducing those two queries into the single one will do the right thing.

Of course it is very important that your servers are synchronized with their times, or funny things may happen.