HBase Thrift介面C++用戶端

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.