Reputation: 1750
I have a Cassandra Cluster which will be used by multiple clients. I have a table(let's call it 'Counter')in my keyspace which I'm using to store the count of the number of entries in other tables.
Whenever a new entry has to be inserted in some table, first the 'Counter' table will be queried to find out the number of entries already inside that table and then it will be incremented after a new row has been added to the table.
Since, there are multiple clients, how can I ensure that 2 clients simultaneously don't try to read/write on the 'Counter' table.
My Cluster is on 3.11.2.
Upvotes: 0
Views: 226
Reputation: 16420
You can use counters and increment on a new entry: https://docs.datastax.com/en/cql/3.3/cql/cql_using/useCounters.html
Or light weight transactions. If the value is applied you know no one else read/written in that time - if they have you just retry. https://docs.datastax.com/en/cassandra/3.0/cassandra/dml/dmlLtwtTransactions.html
Might be good to write some kind of job that can be run that scans and counts the entries and compares to current value. Inconsistencies between your 2 tables are possible if a node crashes in-between the increment and the new entry inserted.
Upvotes: 3