Running Cassandra on Windows: first attempt

Yesterday I was reading up on some resources on Apache Cassandra for the .Net devs. I decided to try it out.

A little problem on Windows

I found one potential stumbling block, which is in order to talk to Cassandra I will need to build a ’˜proxy class' to handle the de/serialization for me. Cassandra uses a protocol called Thrift. So I will need a proxy class that can serialize my objects to something that fits into the Thrift protocol. This can be done by using the Thrift executable. One little catch: currently there isn't a version built for Windows.

Side note: What is Thrift and does it really not run on Windows?

I was slightly unsure if Thrift was a separate executable that needs to be run on the server and acts as a mediator between my .Net app and Cassandra. But soon I found out it is just a protocol that Cassandra make use of.

As you see below, Cassandra is running on Windows and binding Thrift successfully to localhost.

image

The Thrift executable, however, is a code generator of some sort that produce a language specific proxy class/driver/client/interface code that handles the communication between our app and cassandra. This is the bit that currently not available in Windows.

Solution: Generated Cassandra interface

There's already a generated Cassandra interface for C# on Google Code, however using it feels pretty clunky as shown here:

System.Text.Encoding utf8Encoding = System.Text.Encoding.UTF8; 
long timeStamp = DateTime.Now.Millisecond; 

ColumnPath nameColumnPath = new ColumnPath()  
	{  
		Column_family = "Posts",  
		Column = utf8Encoding.GetBytes("name") 
	}; 

//Insert the data into the column 'name' 
client.insert("Blog", 
	"first-blog-post", 
	nameColumnPath, 
	utf8Encoding.GetBytes("Ronald Widha"), 
	timeStamp, 
	ConsistencyLevel.ONE); 

A cleaner solution: FluentCassandra

Alternatively, one could use FluentCassandra. This eliminates the need of using the generated Cassandra interface (which may become obsolete should the a new version of Cassandra is released and using a newer version of Thrift protocol), or even the need to run Thrift executable.

I haven't looked at the implementation of FluentCassandra yet, so I don't know how easy it would be to support future versions of the Thrift protocol.

The same code above could then be re-implemented like the following:

var family = db.GetColumnFamily<UTF8Type, UTF8Type>("Posts");

dynamic post = family.CreateRecord(key: "first-blog-post");

// create post details
dynamic postDetails = post.CreateSuperColumn();
postDetails.name = "Ronald Widha";

db.Attach(post);
db.SaveChanges();

I got the sample code working using Apache Cassandra 0.6.2 and FluentCassandra 2010-06-22.

*All code shown here are modified from Nick Berardi's example posted in coderjournal.