hbase-thrift項目是對HBase Thrift介面的封裝,屏蔽底層的細節,使使用者可以方便地通過HBase Thrift介面訪問HBase叢集,同時基於此對C++用戶端讀寫的效率進行了簡單的測試。該項目目前基於的是HBase thrift介面,至於HBase 0.94版本中的HBase thrift2介面,後續再考慮進一步的支援。
前提條件
1)下載,解壓,安裝 thrift-0.8.0。
wget https://dist.apache.org/repos/dist/release/thrift/0.8.0/thrift-0.8.0.tar.gztar zxvf thrift-0.8.0.tar.gzsudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-develcd thrift-0.8.0./configuremakesudo make install
2)下載,解壓 hbase-0.92.1 或之前的版本,使用者根據Hbase.thrift檔案產生用戶端thrift介面代碼實現。
wget http://www.fayea.com/apache-mirror/hbase/hbase-0.92.1/hbase-0.92.1.tar.gztar zxvf hbase-0.92.1.tar.gz
介面實現
目前已封裝實現的介面如下:
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)運行thrift命令,產生C++模組的用戶端代碼:
thrift --gen cpp [hbase-root]/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
2)執行make產生二進位程式:
make demo
make perf
3)執行二進位程式:
./demo <host> <port>
./testput <host> <port> <key_len> <val_len> <list_num>
./testget <host> <port> <key_len> <val_len> <list_num> <block_cache_flag>
暫時更新這些內容,感興趣的,詳見:https://github.com/ypf412/hbase-thrift