HBase Thrift接口C++客戶端
hbase-thrift項(xiàng)目是對(duì)HBase Thrift接口的封裝,屏蔽底層的細(xì)節(jié),使用戶可以方便地通過(guò)HBase Thrift接口訪問(wèn)HBase集群,同時(shí)基于此對(duì)C++客戶端讀寫的效率進(jìn)行了簡(jiǎn)單的測(cè)試。該項(xiàng)目目前基于的是HBase thrift接口,至于HBase 0.94版本中的HBase thrift2接口,后續(xù)再考慮進(jìn)一步的支持。
前提條件
1)下載,解壓,安裝 thrift-0.8.0。
wget https://dist.apache.org/repos/dist/release/thrift/0.8.0/thrift-0.8.0.tar.gz tar zxvf thrift-0.8.0.tar.gz sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel cd thrift-0.8.0 ./configure make sudo make install
2)下載,解壓 hbase-0.92.1 或之前的版本,用戶根據(jù)Hbase.thrift文件生成客戶端thrift接口代碼實(shí)現(xiàn)。
wget http://www.fayea.com/apache-mirror/hbase/hbase-0.92.1/hbase-0.92.1.tar.gz tar zxvf hbase-0.92.1.tar.gz
接口實(shí)現(xiàn)
目前已封裝實(shí)現(xiàn)的接口如下:
class HbCli { public: // Constructor and Destructor HbCli(const char *server, const char *port); ~HbCli(); // Util Functions bool connect(); bool disconnect(); bool reconnect(); inline bool isconnect(); // HBase DDL Functions bool createTable(const std::string table, const ColVec &columns); bool deleteTable(const std::string table); bool tableExists(const std::string table); // HBase DML Functions bool putRow(const std::string table, const std::string row, const std::string column, const std::string value); bool putRowWithColumns(const std::string table, const std::string row, const StrMap columns); bool putRows(const std::string table, const RowMap rows); bool getRow(const std::string table, const std::string row, ResVec &rowResult); bool getRowWithColumns(const std::string table, const std::string row, const StrVec columns, ResVec &rowResult); bool getRows(const std::string table, const StrVec rows, ResVec &rowResult); bool getRowsWithColumns(const std::string table, const StrVec rows, const StrVec columns, ResVec &rowResult); bool delRow(const std::string table, const std::string row); bool delRowWithColumn(const std::string table, const std::string row, const std::string column); bool delRowWithColumns(const std::string table, const std::string row, const StrVec columns); bool scan(const std::string table, const std::string startRow, StrVec columns, ResVec &values); bool scanWithStop(const std::string table, const std::string startRow, const std::string stopRow, StrVec columns, ResVec &values); // HBase Util Functions void printRow(const ResVec &rowResult); private: boost::shared_ptr<TTransport> socket; boost::shared_ptr<TTransport> transport; boost::shared_ptr<TProtocol> protocol; HbaseClient client; bool _is_connected; };
編譯安裝
1)運(yùn)行thrift命令,生成C++模塊的客戶端代碼:
thrift --gen cpp [hbase-root]/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
2)執(zhí)行make生成二進(jìn)制程序:
make demo
make perf
3)執(zhí)行二進(jìn)制程序:
./demo <host> <port>
./testput <host> <port> <key_len> <val_len> <list_num>
./testget <host> <port> <key_len> <val_len> <list_num> <block_cache_flag>
./testput <host> <port> <key_len> <val_len> <list_num>
./testget <host> <port> <key_len> <val_len> <list_num> <block_cache_flag>
暫時(shí)更新這些內(nèi)容,感興趣的,詳見(jiàn):https://github.com/ypf412/hbase-thrift
posted on 2012-08-28 13:08 大圓那些事 閱讀(11521) 評(píng)論(0) 收藏 舉報(bào)
浙公網(wǎng)安備 33010602011771號(hào)