MetaStore Thrift

本文分析了Hive MetaStore如何使用Thrift协议进行远程通信,详细阐述了MetaStoreClient的创建过程,包括RetryingMetaStoreClient和SessionHiveMetaStoreClient的使用。Thrift作为一个RPC框架,实现了C/S模式,通过代码生成工具生成服务端和客户端代码,支持跨语言通信。Thrift的Transport层提供网络读写抽象,Protocol层定义数据传输格式,而Processor处理数据的读写。HiveMetaStore服务端通过ThriftHiveMetaStore创建,客户端需配置hive.metastore.uri进行远程连接。
摘要由CSDN通过智能技术生成

Hive MetaStore整体代码分析
  远程metastore服务端和客户端之间使用Thrift协议通信。IMetaStoreClient接口定义了Metastore的thrift api,该接口中定义了操作元数据的各种方法。Hive中IMetaStoreClient的实现类是HiveMetaStoreClient。

Hive.getMSC() ➔ createMetaStoreClient()
  ↳ RetryingMetaStoreClient.getProxy()//动态代理类创建代理对象
  ↳RetryingMetaStoreClient.RetryingMetaStoreClient()
  ↳MetaStoreUtils.newInstance()//反射实例化对象
  ↳SessionHiveMetaStoreClient.SessionHiveMetaStoreClient()
  ↳HiveMetaStoreClient.HiveMetaStoreClient()
  ↳HiveMetaStoreClient.open()

 1   public HiveMetaStoreClient(HiveConf conf, HiveMetaHookLoader hookLoader)
 2     throws MetaException {
   
 3 
 4     this.hookLoader = hookLoader;
 5     if (conf == null) {
   
 6       conf = new HiveConf(HiveMetaStoreClient.class);
 7     }
 8     this.conf = conf;
 9     filterHook = loadFilterHooks();
10    //根据hive-site.xml中的hive.metastore.uris配置,如果配置该参数,则认为是远程连接,否则为本地连接
11     String msUri = conf.getVar(HiveConf.ConfVars.METASTOREURIS);
12     localMetaStore = HiveConfUtil.isEmbeddedMetaStore(msUri);
13     if (localMetaStore) {
   
      //本地连接直接连接HiveMetaStore
16       client = HiveMetaStore.newRetryingHMSHandler("hive client", conf, true);
17       isConnected = true;
18       snapshotActiveConf();
19       return;
20     }
21 
22     //获取配置中的重试次数及timeout时间
23     retries = HiveConf.getIntVar(conf, HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES);
24     retryDelaySeconds = conf.getTimeVar(
25         ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY, TimeUnit.SECONDS);
26 
27     //拼接metastore uri
28     if (conf.getVar(HiveConf.ConfVars.METASTOREURIS) != null) {
   
29       String metastoreUrisString[] = conf.getVar(
30           HiveConf.ConfVars.METASTOREURIS).split(",");
31       metastoreUris = new URI[metastoreUrisString.length];
32       
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值