I have a table cassandra1:
CREATE TABLE Policy.table1 ( name VARCHAR , date TIMESTAMP , version_num INT, PRIMARY KEY ( name )) WITH caching = 'all'
I need to implement optimistic locking on a tis table. When we read a row from table1, we remember its version_num. And when we want to update this line, we compare the current value and the version_num value that we remembered. We also need to increment version_num for each update.
Problems:
We cannot put version_num in where, this will create an error: Bad Request: Non PRIMARY KEY version_num found in where where:
update table where name = 'abc' and version = 3
We cannot set version_num as part of the primary key because we need to update its value
- If we index version_num, this will not help update operators, the same exception will be thrown
- The only way I can see is to get the current value of version_num Java, and if the expected and actual values โโof version_num are the same, than update. The problem is that in this case we do not have the atomic operation of checking the value of version_num and updating the string.
Do you see any solution to this problem?
source share