1.启动脚本
$HIVE_HOME/bin/hive --service hivemetastore --> $HIVE_HOME/bin/ ext/metastore.sh --> 可以看到入口类org.apache.hadoop.hive.metastore.HiveMetaStore
2.入口类
(1) cli.parse 解析参数
(2) LogUtils.initHiveLog4j 设置日志,创建hiveConf
(3)startMetaStore启动服务
(4)初始化thrift为TBinaryProtocol
(5) 创建HMSHandler basehandler -->通过newRetryingHMSHandler 初始化basehandler
3.HMSHandler初始化
(1) 通过hive.metastore.rawstore.impl 获取加载的加载元数据的 对象类 ( 该类继承RawStore, 操作数据库)
(2) 通过hive.metastore.init.hooks 获取初始化类,用来额外的初始化HMSHandler
(3) 通过hive.metastore.alter.impl 获取HiveAlterHandler (通过此handler 进行sql 中的alter操作)
(4)createDefaultDB()创建 默认的DB 表 —> 创建默认的角色admin 和 public -->添加admin的用户
(5)通过hive.metastore.pre.event.listeners 获取预处理的监听。此类会实现onEvent方法,在一些thrift接口调用前调用(比如与role 和 授权的一些接口)
(6)通过hive.metastore.event.listeners 获取监听类。(通过实现onCreateTable onDropTbale 等等 来实现一些sql操作后触发的action
(7) 通过hive.metastore.end.function.listeners 获取函数监听 (在sql 函数调用的时候hook)
(8) 通过handler 创建Processor
(9) 通过TThreadPoolServer 创建server 并serve 启动服务
4.metastore 的调用
public HiveMetaPoolFactory(String metastoreUris, String jdoUrl, String jdoUser,
String jdoPassword, String jdoDriverName) {
this.metastoreUris = metastoreUris;
this.jdoUrl = jdoUrl;
this.jdoUser = jdoUser;
this.jdoPassword = jdoPassword;
this.jdoDriverName = jdoDriverName;
Configuration conf = new Configuration();
if(StringUtils.isNotEmpty(metastoreUris)) {//uris 的访问方式
conf.set("hive.metastore.uris", metastoreUris);
} else {
conf.set("javax.jdo.option.ConnectionURL", jdoUrl);//jdbc的访问方式
conf.set("javax.jdo.option.ConnectionUserName", jdoUser);
conf.set("javax.jdo.option.ConnectionPassword", jdoPassword);
conf.set("javax.jdo.option.ConnectionDriverName", jdoDriverName);
}
hConf = new HiveConf(conf, HiveConf.class);
}
@Override
public Object makeObject() throws Exception {
HiveMetaStoreClient hmsc = new HiveMetaStoreClient(hConf);//创建客户端
return hmsc;
}
本文详细介绍了Hive Metastore的启动流程,包括启动脚本、入口类解析、参数配置、服务启动过程及元数据操作类加载等关键步骤,并探讨了metastore的调用方式及Thrift接口实现。
238

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



