8

Is there anyway to synchronise client using cassandra built in functions?

I need to perform some operations and those operations need to be synchronized with all other clients (mutual exclusion).

In RDBMS I can lock entire table or prepare special table for synchronization purposes and use SELECT ... FOR UPDATE on it.

Can I achive this with Cassandra without any third party apps? If not what's the best way to do that? Preferable languages are Java and Python.

Daimon
  • 3,703
  • 2
  • 28
  • 30

4 Answers4

8

Its not possible to lock an entire (or a subset of a) column familiy without third party libraries like Apache ZooKeeper.

I would probably start looking at Domic Williams cages before start rolling my own distributed locking mechanism

Schildmeijer
  • 20,702
  • 12
  • 62
  • 79
  • 1
    I don't need to lock column family. SELECT FOR UPDATE equivalent would be the best. I'll check ZooKeeper – Daimon Jan 17 '11 at 21:19
  • 3
    It's also pretty likely that you could avoid the need for this at all by adjusting your data model. Perhaps that would make another good SO question? – Tyler Hobbs Jan 18 '11 at 06:35
  • 2
    No, I need distributed processing architecture and Cassandra as data storage. I need sync some operations to prevent same data being processed by more than one machine. – Daimon Jan 18 '11 at 22:58
2

Because C* provides row level atomicity why not use Lamport's Bakery Algorithm. I found an incomplete page on C* wiki too.

https://github.com/jakedouglas/cassandra_lock

Raedwald
  • 46,613
  • 43
  • 151
  • 237
Praveen
  • 375
  • 1
  • 5
  • 18
2

If you are updating one row in a column family, it is atomic. But it won't work like select for update. You should probably revisit your data model with more denormalization in mind, so that you won't need to worry about synchronization.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Pranab
  • 663
  • 5
  • 10
0

I was also looking way to make syncronization with cassandra, but as far as I know it does not provide mechanisms to implement mutexes.

However, memcached has atomic cas (check and set) operation, which can be used to implement mutex. It has also python and java clients.

So you could use memcached to implement mutexes for syncronization and does read/write data with quorum consistency level in cassandra to make sure that latest write is always returned on when reading.

Has anyone experience about implementing mutex with memcached?

Mikael Lepistö
  • 18,909
  • 3
  • 68
  • 70
  • This might be a bit unstable if some mutex is flushed or memcached server crash which will release lock too early. However I'm not sure how probable is that when locking is done just for few seconds at maximum. Stability depends a lot of application, how mutexes are used. – Mikael Lepistö Mar 19 '11 at 21:31