Wednesday 23 May 2012

Cassandra Rescue Guide

You see, things can
go worse...
If you're using Cassandra to store your data, I guess you do it because they are a lot! In that case you wouldn't risk losing them because something went wrong... This post is a short rescue guide for Cassandra going a bit further from how to backup and restore your data (read this). This post is mostly concerned with more extreme situations where you restart your server to find out that your precious keyspace is not there!!! Don't panic! As you see in the picture (left) things can go much worse...

 

 Before it happens

In order to avoid loss of data, it's good to keep a copy of your schema generation code somewhere. You can create it from within cqlsh (CQL Shell) or using the Cassandra Client (cassandra-cli). Export your KS generation code in a file and keep it under lock and key. For example, using cli, create a file called schema_export and add in it the following lines:
use MyKeyspace;
show schema;

where of course you have to replace MyKeyspace by the name of your keyspace. If you have multiple keyspaces, create one such file for every keyspace. then run this cassandra script and save the output in another file:

cassandra-cli < schema_export > my.schema


When it happens

  1. Stop the server
  2. Apply an rm -rf /var/lib/cassandra/data/system
  3. Start the server
  4. Load the schema: cassandra-cli < my.schema
  5. Restart Cassandra
  6. Connect with cassandra-cli or cqlsh - your data must be there!
That's all folks. Stay tuned for more!

Coming Soon

I'm preparing a text on what happens behind the scenes in Cassandra. How things work and all one needs to know in order to configure and optimize the Cassandra server with respect to the hardware specifications of the hosting machine.

No comments:

Post a Comment