【Java】HBase_thrift/thrift2_使用指南

Thrift server简介

Thrift server是HBase中的一种服务,主要用于对多语言API的支持。基于Apache Thrift(多语言支持的通讯框架)开发,目前有两种版本thriftthrift2git

thrift2是当时为了适应新的Java API,提出来的。因为种种缘由,thrift2没有完美兼容并替代thrift,全部就留下了两个版本。github

Thrift 和 Thrift2 的区别

  • 接口设计上Thrift2要比Thrfit更优雅,或者说和如今的API更贴近。好比二者的get接口:
// Thrift2 的get接口,传入TGet(对应Java API种的Get类)
    // 用过Java API的同窗看起来应该会更亲切
    TResult get(
         /** the table to get from */
        1: required binary table,
        /** the TGet to fetch */
        2: required TGet tget
    ) throws (1: TIOError io)
// Thrift 的get接口,没有TGet这些包装,比较裸
    list<TCell> get(
        /** name of table */
        1:Text tableName,
        /** row key */
        2:Text row,
        /** column name */ 
        3:Text column, 
        /** Get attributes */
        4:map<Text, Text> attributes
    ) throws (1:IOError io)
  • Thrift2没有DDL方面的接口,因此如今Hue仍是用Thrift的接口。若是你只想读写数据,建议用Thrift2。

Thrift server原理

Thrfit其实就是个代理,你的请求发到Thrift server上后,server经过Java API再帮你访问HBase。
Thrift_server
Thrift实现类是org.apache.hadoop.hbase.thrift.ThriftServer,thrift2的实现类是org.apache.hadoop.hbase.thrift2.ThriftServer。它们访问HBase使用的也是普通的HBase client API,因此当你的请求到达Thrift server后,它经过client API去帮你定位数据,而后读取数据。这么来看,Thrift Server比较灵活,你能够部署在客户机上,也能够独立部署一个thrift集群。apache

阅读原文请点击框架

相关文章
相关标签/搜索