Using the libhbase Library
libhbase is a JNI-based, thread-safe C library that implements a native HBase client. You can use libhbase to build applications that access HBase.
For examples on how to use the APIs, see the sample source file.
This page contains the following topics:
Install libhbase on the nodes from which you will build and run the application.
Complete the following steps to install libhbase from a repository:
- Configure the repository to point to http://package.mapr.com/releases/ecosystem-4.x/<operating system>
- Based on your operating system, run one of the following
commands to install the package:
- On Red Hat /Centos:
yum install mapr-libhbase
- On SUSE:
zypper install mapr-libhbase
On Ubuntu: apt-get install mapr-libhbase
- On Red Hat /Centos:
Once the installation completes, the libhbase installation includes the following directories under /opt/mapr/libhbase/libhbase-<version>:
/ +---bin/ +---conf/ +---include/ | +--hbase/ +---lib/ | +---native/ +---src +---examples/ | +---async/ +---test/ +---native/ +---common/
includefolder contains the headers required to build applications and the
lib/nativedirectory contains shared libraries.
To upgrade to a more recent version of libhbase:
- Install the new version.
- Re-configure the application environment to refer to the new libraries.
Building Applications with libhbase
libhbase should be installed on the each node that builds the application.
Note the following items when you build applications with libhbase:
- The headers required to build applications are located under /opt/mapr/libhbase/libhbase-<version>/include.
- libhbase shared library is located in the following directory: /opt/mapr/libhbase/libhbase-<version>/lib/native
- Since libhbase uses JNI, you must also link your application against libjvm. In general, the libjvm library is located within the JDK/JRE installation directory.
For example, the following command builds the hello_hbase application with the hello_hbase.c source code:
gcc -o hello_hbase hello_hbase.c -I/opt/mapr/libhbase/libhbase-0.98.7/include -L/opt/mapr/libhbase/libhbase-0.98.7/lib/native -lhbase -L/usr/lib/jvm/java-7-sun/jre/lib/amd64/server -ljvm
Configuring the Application Environment
Complete the following steps to configure the node from which you run the application:
Verify that libhbase is installed on the node.
Verify that both the libhbase and libjvm shared libraries are in the application’s library search path. The libhbase shared library is located under /opt/mapr/libhbase/libhbase-<version>/lib/native. In general, the libjvm library is located within the JDK/JRE installation directory.
Specify any JARs required by the application with one of the following environment variables: CLASSPATH or HBASE_LIB_DIR.
- Specify custom JVM options, such as -Xmx, using the environment variable LIBHBASE_OPTS.
Running a libhbase Performance Test
libhbase 0.98.7 includes a performance test that supports sequential/random gets and puts. In libhbase 0.98.9, the performance test utility also includes support for Zipfian, support for uniform random key generation, and it test for scans. You can run the test using this shell script.