【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

閱讀原文請點擊框架

相關文章
相關標籤/搜索