Dear all,

We are considering using Cassandra for storing gathered data in Zabbix (see https://support.zabbix.com/browse/ZBXNEXT-844 for more details). Because Zabbix is written in C, we are considering using Thrift API in C, too.

However, we are running into problems trying to get even the basic code work. Consider the attached source code. This is essentially a rewrite of the first part of the C++ example given at http://wiki.apache.org/cassandra/ThriftExamples#C.2B-.2B- . If we run it under strace, we see that it hangs on the call to recv() when setting keyspace:

$ strace -s 64 ./test
...
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(9160), sin_addr=inet_addr("127.0.0.1")}, 16) = 0 send(3, "\0\0\0/\200\1\0\1\0\0\0\fset_keyspace\0\0\0\0\v\0\1\0\0\0\vmy_keyspace\0", 47, 0) = 47
recv(3, ^C <unfinished ...>

If we run the C++ example, it passes this step successfully. Does anybody know where the problem is? We are using Thrift 0.6.1 and Cassandra 0.8.1.

Also, what is the current state of Thrift API in C? Can it be considered stable? Has anybody used it successfully? Any examples?

Thanks,
Aleksandrs
#include <stdio.h>

#include <thrift.h>
#include <transport/thrift_socket.h>
#include <transport/thrift_framed_transport.h>
#include <protocol/thrift_protocol.h>
#include <protocol/thrift_binary_protocol.h>

#include "cassandra.h"

int main()
{
	ThriftSocket		*tsocket;
	ThriftTransport		*transport;
	ThriftBinaryProtocol	*protocol2;
	ThriftProtocol		*protocol;
	CassandraClient		*client;

	g_type_init();

	tsocket = g_object_new(THRIFT_TYPE_SOCKET, "hostname", "localhost", "port", 9160, NULL);
	transport = g_object_new(THRIFT_TYPE_FRAMED_TRANSPORT, "transport", THRIFT_TRANSPORT(tsocket), NULL);
	protocol2 = g_object_new(THRIFT_TYPE_BINARY_PROTOCOL, "transport", transport, NULL);
	protocol = THRIFT_PROTOCOL(protocol2);
	client = g_object_new(TYPE_CASSANDRA_CLIENT, "input_protocol", protocol, "output_protocol", protocol, NULL);

	thrift_framed_transport_open(transport, NULL);
	cassandra_client_set_keyspace(CASSANDRA_IF(client), "my_keyspace", NULL, NULL); // hangs here on recv()
	thrift_framed_transport_close(transport, NULL);

	g_object_unref(client);
	g_object_unref(protocol2);
	g_object_unref(transport);
	g_object_unref(tsocket);

	return 0;
}

Reply via email to