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

posted on   大圆那些事  阅读(11498)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2011-08-28 分布式文件系统KFS源码阅读与分析(二):MetaServer元数据持久化

导航

< 2012年8月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示