libQtCassandra 0.5.22 fixing a bug in the QCassandraLock implementation

WARNING: This implementation of an inter-process, inter-computer lock works with Cassandra only if you know that you are directly dealing with a single Cassandra node at a time. The Cassandra C++ driver (probably all the drivers) makes use of a set of threads to connect to several Cassandra nodes and if the load of the current thread/node pair becomes too large, it will automatically switch to another thread/node pair. This means your messages may not be received in the order you sent them to the database cluster. As a result, the lock mechanism described below will not function as expected. On our end, we now use snaplock instead.

I got a problem with one website which somehow could not be updated anymore. Each time I tried, it would come back with broken pages (pages that are marked as being updated but clearly nothing working on those pages.)

It took me some time to realize that the QCassandraLock was the culprit. Since I have been using this lock for over two years without any problems, I was rather surprised to get such a problem!

The libQtCassandra lock worked really well even in versions prior to 0.5.22, but there was one case that was not properly handled: the case where the process that started creating the lock crashes or is killed before it can delete the "entering::<lock-name>" row from the lock table. When that happens, that key stays in the database forever preventing further locking.

I changed the behavior by adding one line of code so the "entering:<lock-name>" row gets deleted after a few seconds if the process quits before it drops the row. This way, the lock will not stop working and the existing functionality is exactly the same (i.e. we do not need to have the "entering::<lock-name>" row available for any longer than the time it takes to obtain the lock. It was getting dropped before we returned from the function anyway.)

If you are using the QCassandraLock class, you want to upgrade to this version to make sure you do not run in a similar problem.

Download: libQtCassandra version 0.5.22 sources

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly