HBase Thrift接口C++客戶端


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.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 或之前的版本,用戶根據Hbase.thrift文件生成客戶端thrift接口代碼實現。

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

接口實現

目前已封裝實現的接口如下:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM