Cassandra schemas require synchronization

As I got a 3 node Cassandra system, I can test in an environment that is much more realistic than my one local node. As I tried writing a new test, I got an error saying that a table wasn't ready. Looking at how the Cassandra-CLI does it, I now understand why it waits after creating a table. It actually synchronizes the schema on all the available nodes in your current ring. If the schema differs on any one node, then the CLI waits and tries again.

The fact is that you can run any number of Create, Update, and Drop functions in a raw as you'd like (as long as they are not against the same context/table--so if you create a context you have to wait to create tables in that context [unless you created the tables at the same time] but you could create 10 contexts in a raw without waiting.) Once you want to use the corresponding context or table, you have to wait for these order to be complete.

The wait is very simple, you have to call the describe_schema_versions() function and wait for the function to return one version for all the nodes. If you get more than one, then some nodes were not yet updated and you need to wait and try again until it is correct.

In libQtCassandra this is done with the new QCassandra::synchronizeSchemaVersions() function. The function takes one argument which is the number of seconds to wait for the synchronization to complete. If the function times out before the schema versions are synchronized, then the function throws an std::runtime_error() exception.


This simple (non-working) example shows how after a context or table create order you want to synchronize the schema versions before using that context or table.

Note that the function is likely to take seconds, even on a small ring of nodes. It is to be expected. By default the timeout is set at 60 seconds (1 minute.) On systems with a large number of nodes, that may not be enough.

Also, if you are programming an application, you may want to consider creating your contexts and tables using some form of backend tool rather than the front end because the front end will otherwise block your viewers whenever you create a context or table!

Syndicate content

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

Contact Us Directly