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 参数我们是知道的,是解决这个问题的关键。