Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Cassandra, if I run a query that increments a counter, then selects from that counter is that atomic?

If I run a query that increments a counter, then selects from that counter is that atomic?

I am wanting to generate smaller (integer) numbers using Cassandra.

The usage will likely be generating fewer than 1000 Ids/day, but definitely needs to be non-conflicting, and would prefer minimal chance of waste (unused blocks of numbers).


I've considered the following option(s)

  1. I know I can do conditional read+update until I get a successful result.
  2. Similar to #1, but updating with a block of 10 or 100, then using that block to issue new ids in a separate service.
  3. Using a separate service altogether (sql backed?) for this purpose.

I'm also using UUIDs for records on creation, I'm only wanting to use the sequential numbers for records that are publicly published, and will be part of a URL.

like image 662
Tracker1 Avatar asked Mar 05 '15 23:03

Tracker1


1 Answers

The update operation is atomic, however you don't get the updated value back as an output from the operation. Update/Select combination is definitely not atomic. Any other process can increment/decrement counter value in between of your update and select calls, therefore making your results unpredictable. Here is a good description of how counters work: http://www.datastax.com/dev/blog/whats-new-in-cassandra-2-1-a-better-implementation-of-counters. Try to use some synchronization layer in front of Cassandra to accomplish atomicity of this operation. Astyanax is one of the examples.

like image 137
Roman Tumaykin Avatar answered Sep 22 '22 10:09

Roman Tumaykin