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]

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

被折叠的 条评论
为什么被折叠?



