HiveServer2 启动时 datanucleus.schema.autoCreateTables 不生效的问题

HiveServer2 启动时出 "Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"问题

java 复制代码
Required table missing : "FUNCS" in Catalog "" Schema "". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"
org.datanucleus.store.rdbms.exceptions.MissingTableException: Required table missing : "FUNCS" in Catalog "" Schema "". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"
	at org.datanucleus.store.rdbms.table.AbstractTable.exists(AbstractTable.java:606)
	at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.performTablesValidation(RDBMSStoreManager.java:3385)
	at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.run(RDBMSStoreManager.java:2896)
	at org.datanucleus.store.rdbms.AbstractSchemaTransaction.execute(AbstractSchemaTransaction.java:119)
	at org.datanucleus.store.rdbms.RDBMSStoreManager.manageClasses(RDBMSStoreManager.java:1627)
	at org.datanucleus.store.rdbms.RDBMSStoreManager.getDatastoreClass(RDBMSStoreManager.java:672)
	at org.datanucleus.store.rdbms.query.RDBMSQueryUtils.getStatementForCandidates(RDBMSQueryUtils.java:425)
	at org.datanucleus.store.rdbms.query.JDOQLQuery.compileQueryFull(JDOQLQuery.java:865)
	at org.datanucleus.store.rdbms.query.JDOQLQuery.compileInternal(JDOQLQuery.java:347)
	at org.datanucleus.store.query.Query.executeQuery(Query.java:1816)
	at org.datanucleus.store.query.Query.executeWithArray(Query.java:1744)
	at org.datanucleus.api.jdo.JDOQuery.executeInternal(JDOQuery.java:368)
	at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:228)
	at org.apache.hadoop.hive.metastore.ObjectStore.getAllFunctions(ObjectStore.java:9429)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:97)
	at com.sun.proxy.$Proxy118.getAllFunctions(Unknown Source)
	at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.get_all_functions(HiveMetaStore.java:7113)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invokeInternal(RetryingHMSHandler.java:147)
	at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invoke(RetryingHMSHandler.java:108)
	at com.sun.proxy.$Proxy120.get_all_functions(Unknown Source)
	at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.getAllFunctions(HiveMetaStoreClient.java:2861)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.invoke(RetryingMetaStoreClient.java:212)
	at com.sun.proxy.$Proxy122.getAllFunctions(Unknown Source)
	at org.apache.hadoop.hive.ql.metadata.Hive.getAllFunctions(Hive.java:4610)
	at org.apache.hadoop.hive.ql.metadata.Hive.reloadFunctions(Hive.java:291)
	at org.apache.hadoop.hive.ql.metadata.Hive.registerAllFunctionsOnce(Hive.java:274)
	at org.apache.hadoop.hive.ql.metadata.Hive.<init>(Hive.java:442)
	at org.apache.hadoop.hive.ql.metadata.Hive.create(Hive.java:382)
	at org.apache.hadoop.hive.ql.metadata.Hive.getInternal(Hive.java:362)
	at org.apache.hadoop.hive.ql.metadata.Hive.get(Hive.java:331)
	at 

出现这个问题就是需要将 datanucleus.schema.autoCreateAll 配置设置为 true。

但是明明我们已经将 HiveConf 的 datanucleus.schema.autoCreateAll 参数设置为 true 了,为什么还是会出现这个问题呢?

留意日志可以发现这一行:

[INFO] (org.apache.hadoop.hive.metastore.HiveMetaStoreClient:346) [main] - Mestastore configuration datanucleus.schema.autoCreateAll changed from true to false

原来是将配置改成了 false。

研究相关的逻辑发现,原来是初始化时如果两个配置不同就会出现这个问题,那为什么配置会不同呢?

追踪一下可以发现 HiveMaterializedViewRegistry 在初始化时会新建一个 HiveConf,而不是我们传入的 HiveConf:

解决办法

HiveConf 在初始化时,将会添加设置的 hivemetastoreSiteUrl HiveConf 资源,而 hivemetastoreSiteUrl 需要通过调用HiveConf#setHivemetastoreSiteUrl 方法设置,该方法是个静态的公共方法,可以在任何地方调用。

注意:设置的 HiveConf 需要配置 hive.metastore.schema.verification = false 以及 datanucleus.schema.autoCreateAll = true 参数,因为如果没有设置 hive.metastore.schema.verification 参数的话,hive.metastore.schema.verification 的默认值为 true,而在初始化时,如果检测 hive.metastore.schema.verification 为 true 那么就会将 datanucleus.schema.autoCreateAll 参数设置为 false,datanucleus.schema.autoCreateAll 参数我们是知道的,是解决这个问题的关键。

相关推荐
zskj_qcxjqr7 小时前
七彩喜艾灸机器人:当千年中医智慧遇上现代科技
大数据·人工智能·科技·机器人
洛克大航海11 小时前
Ubuntu安装Hbase
大数据·linux·数据库·ubuntu·hbase
GIOTTO情11 小时前
媒介宣发的技术革命:Infoseek如何用AI重构企业传播全链路
大数据·人工智能·重构
ApacheSeaTunnel12 小时前
新兴数据湖仓手册·从分层架构到数据湖仓架构(2025):数据仓库分层的概念与设计
大数据·数据仓库·开源·数据湖·dataops·白鲸开源·底层技术
落雪财神意12 小时前
股指10月想法
大数据·人工智能·金融·区块链·期股
柳贯一(逆流河版)12 小时前
ElasticSearch 实战:全文检索与数据聚合分析的完整指南
大数据·elasticsearch·全文检索
白鲸开源13 小时前
最佳实践:基于Apache SeaTunnel从MySQL同步到PostgreSQL
大数据·mysql·postgresql
QYResearch13 小时前
2025年全球移动变电站市场占有率及行业竞争格局分析报告
大数据
字节跳动数据平台13 小时前
为何底层数据湖决定了 AI Agent 的上限?
大数据
QYResearch13 小时前
自主机器人扫雪机行业现状与分析
大数据