Connecting to Cassandra 0.7 in .NET

984 Views Asked by At

I am having a lot of trouble trying to upgrade my existing library from Cassandra 0.6 to 0.7 beta1. I had originally thought it was a order of operations issue, so I decided to break it down to the basics.

Here is the basic setup that I will be suing

TTransport framedTransport = new TFramedTransport(new TSocket("localhost", 9160));
TTransport socketTransport = new TSocket("localhost", 9160);
TProtocol framedProtocol = new TBinaryProtocol(framedTransport);
TProtocol socketProtocol = new TBinaryProtocol(socketTransport);

Then I have tried to vary the setup of the client in the following ways switching the input and output protocols:

var client = new Cassandra.Client(framedProtocol, framedProtocol); // all framed
var client = new Cassandra.Client(socketProtocol, socketProtocol); // all socket
var client = new Cassandra.Client(framedProtocol, socketProtocol); // in: framed out: socket
var client = new Cassandra.Client(socketProtocol, framedProtocol); // in: socket out: framed

Then I execute the following program which uses the default Cassandra configuration that comes from the download and I am doing a simple request such as a count which I expect it to return zero since no data was inserted.

framedTransport.Open();
socketTransport.Open();
Console.WriteLine("Start");

client.set_keyspace("Keyspace1");

var key = System.Text.Encoding.ASCII.GetBytes("MyKey");
var columns = new List<byte[]>(new[] { System.Text.Encoding.ASCII.GetBytes("MyColumn") });
var column_parent = new ColumnParent {
    Column_family = "Standard1"
};
var predicate = new SlicePredicate {
    Column_names = columns
};
client.get_count(key, column_parent, predicate, ConsistencyLevel.ALL);

Console.WriteLine("Done");
Console.Read();

Each of the 4 different setups I provided above fail to execute. A couple of them just lock up and others throw an exception. So basically I am stuck trying to get a connection to work with the new Cassandra 0.7 with the .NET framework.

Here are the types of problems I found with each:

  • all framed: locks up on set_keyspace
  • all socket: throws Invalid method name: 'set_keyspace' on set_keyspace
  • in: framed out: socket: locks up on set_keyspace
  • in: socket out: framed: locks up on set_keyspace

I am 99% sure it has to do with something I am doing at the Thrift layer of Cassandra since I can't get this simple application to work. But if you want to browser my 0.7 branch you can find it here:

http://github.com/managedfusion/fluentcassandra/tree/0.7

2

There are 2 best solutions below

5
On BEST ANSWER

I didn't update the environment variables in Windows to point to the new location of 0.7. So it was essentially running the stable version instead of the beta version. After I updated thee environment variable to point to the new location everything started working again.

1
On

Probably the C# thrift framed-mode code is buggy, because all that changed on the server side was making framed the default mode instead of unframed. You can switch it back in cassandra.yaml as a workaround.

(It's slightly insane to specify different protocols on the in/out sides of the connection. No other Thrift languages I know do that. If you dig into the code generation that is another thing to potentially fix.)