A preface
After the project has Cassandra as an alternative environment, it is beginning to consider developing with C + +. According to the data, the current Cassandra C + + interface, there are mainly thrift and libcassandra two kinds, the official website is:
Thrift:https://github.com/packaged/cassandrathrift
libcassandra:http://datastax.github.io/cpp-driver/
Thrift API for two-C + +
We started with the thrift interface, after all, thrift provides the same interface for multiple languages. Cassandra installation, compilation thrift interface is also simple, as a novice I took one or two hours to fix, see:
"Cassandra C + + driver": http://blog.chinaunix.net/uid-12023855-id-3431018.html
But in the development, but encountered a very troublesome trouble, that is, "exception:default texception." [Expected 4 or 0 byte int (1)]"
In the search for this blog: "About Cassandra and thrift on the int/text/varint on the ambiguous", because you cannot change the table's clolumn type from int to text or varint, you can only discard thrift.
Privately think, Cassandra to type matching requirements are very strict, and the provided thrift interface is text-based type, is not the Cassandra official does not really value this way?
Of course, if the type of column in the environment can be changed to text, or you are familiar with Thrift Province, you can continue on this road.
Three Libcassandra compile and install
Next, focus on Libcassandra, the following steps in the installation of the CentOS build:
- Install dependent packages
sudo yum install automake cmake gcc-c++ git libtool openssl-devel
- Compiling and installing LIBUV
Download the latest source installation package Libuv-1.x.zip from GitHub (https://github.com/libuv/libuv/tree/v1.x):
Unzip Libuv-1.x.zip
CD libuv-1.x
Sh./autogem.sh
./configure
sudo make install
- Modify the link library directory
The default installation directory for LIBUV (and other compiled libraries) is/usr/local/lib and is not within the system's default search scope. There are two ways to modify, one is to set the system environment parameter Ld_library_path, the other is to modify the configuration file/etc/ld.so.conf, here the second type.
sudo echo "/usr/local/mysql/lib" >>/etc/ld.so.conf
sudo ldconfig
- Compiling and installing Cpp-driver
Download the latest source installation package Cpp-driver-master.zip from GitHub (https://github.com/datastax/cpp-driver):
Unzip Cpp-driver-master.zip
CD Cpp-driver-master
CMake.
Make
- Generated header files and shared library files in this directory, it is best to copy to the/usr/local/corresponding directory:
CP./libcassandra*/usr/local/lib
CP./include/cassandra.h/usr/local/include/
Four Development Time considerations
Libcassandra APIs are provided in the form of a standard C structure and function, rather than a C + + form of classes and methods. However, compared with the thrift form of the interface, Libcassandra API and Java API more similar, development can refer to the Java API to find the corresponding function, and then follow the CASSANDRA.H instructions to transform.
Most of the structures used by Libcassandra, with the exception of a few, must be freed after use, and therefore must be taken seriously to avoid memory leaks.
This is consistent with the Java API, where the parameters are strictly matched to the column type at bind and get and do not allow implicit type conversions (such as Int32 and Int64), and it is important to pay attention.
Write so much first, and the sample code will be up later.
Some experience in C/D + + development Cassandra