Cassandra Jump Start For The Windows Developer

Recently I have been exploring the NoSQL options for .NET and specifically a database called Cassandra. In case you haven’t heard of Cassandra before, it is a decentralized, fault-tolerant, elastic database designed by Facebook for high availability. As Wikipedia describes it:

Cassandra is an open source distributed database management system. It is an Apache Software Foundation top-level project, as of February 17, 2010, designed to handle very large amounts of data spread out across many commodity servers while providing a highly available service with no single point of failure. It is a NoSQL solution that was initially developed by Facebook and powers their Inbox Search feature. Jeff Hammerbacher, who led the Facebook Data team at the time, has described Cassandra as a BigTable data model running on an Amazon Dynamo-like infrastructure.

I bet you have used data that has been served by Cassandra and not even realized it, here are some prominent users of Cassandra:

Facebook

Digg

Twitter

Reddit

Sounds interesting or at least worth a look, right? Well I thought so, however during my journey of getting the database setup I have come to realize there is almost no documentation on installation for Linux, and even less for Windows. So I am going to provide you with a jump start to installing Cassandra on your machine. I am doing this so you don’t have to spend days jumping around the web, going down false paths, and pulling your hair out like I did, all so you can get on to what you really care about … development.

First Things First

The first thing you need to understand about Cassandra is that it is developed in Java. So you can run it on any machine that supports Java 6 or better. So before you go any farther make sure you Java JRE is updated to the latest version.

The next thing you need is a copy of Cassandra. Which can be found here. My setup is going to be based off of the latest stable release.

Running From Windows

As I said before you can run from an operating system that Java has a runtime for. So the first and probably most obvious one for a Windows developer, is running Cassandra on Windows. To install Cassandra on windows just follow these steps:

Extract Cassandra to a directory of your choice (I used c:\development\cassandra)

Set the following environment variables

JAVA_HOME (To the directory where you install the JRE, this should not be the bin directory)

CASSANDRA_HOME (To the directory you extracted the files to in step 1)

Modify your Cassandra config file as you like and don’t forget to update the directory locations from a UNIX like path to something on your windows directory (in my example the config file is located at c:\development\cassandra\conf\storage-conf.xml)

Open cmd and run the cassandra.bat file (in my example the batch file is located at c:\development\cassandra\bin\cassandra.bat)

cd c:\development\cassandra\bin\
.\cassandra.bat

You can verify that Cassandra is running, by trying to connect to the server. To do this open a new cmd and run the cassandra-cli.bat file from the bin directory.

This is easy to get running, but there is some manual process that you have to go through each time to get the server running. In the future when you want to start up the Cassandra database for development, just repeat Step 4.

Running From A Linux Virtual Machine

The other way, to run Cassandra is through a Virtual Machine running Linux. This setup is just as easy as the Windows setup as long as you have some experience with Linux. I am going to start the install steps assuming that you have already installed Ubuntu Server. This way the process is generic if you want to run the server on an physical or virtual machine.

NOTE: You must replace the key value ‘F758CE318D77295D’ with the key value you received in your error message.

Now is the big moment to install Cassandra.

sudo apt-get install cassandra

Now just restart your machine, to do it from the command line run the following:

sudo reboot

Unlike Windows to startup this Cassandara database so that you can start using it for development, you just need to boot up the physical or virtual machine and it should be ready for development.

The Thrifty Way To Connect

Thrift is a protocol also developed by Facebook to create agnostic interfaces for all the common languages based off a simple configuration file. The Thrift team describes their mission as:

Thrift is a software project spanning a variety of programming languages and use cases. Our goal is to make reliable, performant communication and data serialization across languages as efficient and seamless as possible.

As I found out there wasn’t any good way to build the thrift executable in Windows, which is another reason the Linux VM came in handy. The thrift executable is needed to generate the protocol interface for Cassandra. You can read how to build the thrift executable here for your operating system.

After you have the executable you need to run it against the Cassandra interface definition. I am not going to go much into depth with this, because this part of the process is pretty well documented on the internet, but here is the command I ran to create the generated Cassandra interface for C#.

thrift -gen csharp cassandra.thrift

I am not going to leave you high and dry, I have already generated the Cassandra Thrift interfaces for the following languages for you: