hive metastore日志中报错:
Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:444)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:672)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:616)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
at org.apache.hadoop.hive.metastore.MetaStoreUtils.newInstance(MetaStoreUtils.java:1449)
at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.<init>(RetryingMetaStoreClient.java:63)
at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.getProxy(RetryingMetaStoreClient.java:73)
at org.apache.hadoop.hive.ql.metadata.Hive.createMetaStoreClient(Hive.java:2661)
at org.apache.hadoop.hive.ql.metadata.Hive.getMSC(Hive.java:2680)
at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:425)
... 8 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.hadoop.hive.metastore.MetaStoreUtils.newInstance(MetaStoreUtils.java:1447)
... 13 more
Caused by: MetaException(message:Metastore contains multiple versions)
at org.apache.hadoop.hive.metastore.ObjectStore.getMSchemaVersion(ObjectStore.java:6643)
at org.apache.hadoop.hive.metastore.ObjectStore.getMetaStoreSchemaVersion(ObjectStore.java:6605)
at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:6564)
at org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:6552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:98)
at com.sun.proxy.$Proxy5.verifySchema(Unknown Source)
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMS(HiveMetaStore.java:539)
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB(HiveMetaStore.java:587)
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.init(HiveMetaStore.java:429)
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.<init>(RetryingHMSHandler.java:66)
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.getProxy(RetryingHMSHandler.java:72)
at org.apache.hadoop.hive.metastore.HiveMetaStore.newRetryingHMSHandler(HiveMetaStore.java:5554)
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.<init>(HiveMetaStoreClient.java:178)
at org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient.<init>(SessionHiveMetaStoreClient.java:73)
因为hive metastore存储在mysql中,所以登录mysql,use hive所使用的DB,然后 查询下VERSION表
mysql> select * from VERSION;
+--------+----------------+------------------+
| VER_ID | SCHEMA_VERSION | VERSION_COMMENT |
+--------+----------------+------------------+
| 1 | 0.14.0 | Set by MetaStore |
+--------+----------------+—————————+
| 16 | 0.14.0 | Set by MetaStore |
+--------+----------------+—————————+
问题已经通过删除多余的版本记录解决,
保留第一条记录,其他记录全部删除
delete from VERSION where VER_ID=16;
或者
delete from VERSION where VER_ID !=1;
出现这类异常问题原因,hive 是不支持并发的,估计不小心启动多个hive,也可能是网络问题,反正很诡异;
网上有些解决方法,为了避免这种问题再次出现,请在hive客户端开启以下配置项:
<property>
<name>hive.metastore.schema.verification</name>
<value>true</value>
</property>
开启该选项后,重启hive客户端和MetaStore Server。
hive.metastore.schema.verification:
强制metastore的schema一致性,开启的话会校验在metastore中存储的信息的版本和hive的jar包中的版本一致性,并且关闭自动schema迁移,用户必须手动的升级hive并且迁移schema,关闭的话只会在版本不一致时给出警告,默认是false不开启;
但是以上方法为证明可以解决这个问题,而且我的环境下存在多版本hive客户端,如果设置为True可能会影响hive客户端提交任务,为采用这个方式。
网上查到有锁表lock tables VERSION read;的命令,但是退出终端或者重启mysql就会失效,无法使用
开始尝试想让这个VERSION表只读,但是没有好的方法。
mysql没有对单一表进行查询权限及其他所有表进行所有权限设置。
mysql设置只能针对没一个表逐一设置下权限,这样的风险太大不建议线上hive表操作。
hive表有53个,想对VERSION设置只读,那就需要删除现有hive用户权限,对VERSION表设置select权限,其他52个表一个个设置GRANT ALL权限,这可是生产环境,不建议这么操作。
现在想到解决方法:
写个shell定时去删除VERSION表中VER_ID 不等于1的数据,这个方法就比较难维护,时间长就忘记了。
其实这样的情况很少出现,一次删除多余的数据,也是可以的,有时候不要较真。
这个问题是hive版本的bug在新版本中不存在,我在测试环境hive1.1.0,建立多条数据也没有问题
脚本:
cat check_hive.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin
#用户和密码
DBUSER="hive"
DBPW="123456789"
DATE=`date +%Y%m%d%H%m%S`
OUTFILE=/tmp/check_hive.log
#读取第二行,因为第一行是count(*)
st=$(/usr/bin/mysql -u$DBUSER -p$DBPW -e 'select count(*) from hive.VERSION;'|sed -n '2p')
echo "$st"
#判断下如何是一行显示正常,不是一行就删除VER_ID不等于1的
if [ "$st" == 1 ]
then
echo "$DATE hive.VERSION count = 1" >> $OUTFILE
else
/usr/bin/mysql -u$DBUSER -p$DBPW -e 'delete from hive.VERSION where VER_ID !=1;' && echo "$DATE hive.VERSION count != 1 , delete table data!" >> $OUTFILE
fi
查看数据
mysql> select * from VERSION;
+--------+----------------+------------------+
| VER_ID | SCHEMA_VERSION | VERSION_COMMENT |
+--------+----------------+------------------+
| 1 | 0.14.0 | Set by MetaStore |
+--------+----------------+------------------+
参考命令:
use hive;
锁表
lock tables VERSION read;
解锁表
mysql>unlock tables;
LOCK TABLES为当前线程锁定表。 UNLOCK TABLES释放被当前线程持有的任何锁。当线程发出另外一个LOCK TABLES时,或当服务器的连接被关闭时,当前线程锁定的所有表会自动被解锁。
insert into VERSION values('1.1.0','Hive release version 1.1.0');
查看是否有锁表
SHOW PROCESSLIST;
查看锁
mysql> show global status like "table_locks%";
查看表级锁的征用情况
mysql> show status like 'table%';
mysql> show grants for 'hive'@'%';
show grants for hive;
插入数据
insert into VERSION values(2,'1.1.0','Hive release version 1.1.0');
删除数据
delete from VERSION where VER_ID=2;
删除权限
revoke ALL PRIVILEGES ON `hive`.* TO 'hive'@'%'
设置权限
grant select ON hive.VERSION TO 'hive'@'%';
刷新授权
flush privileges ;
hive库中表
mysql> show tables;
+---------------------------+
| Tables_in_hive |
+---------------------------+
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
| COMPACTION_QUEUE |
| COMPLETED_TXN_COMPONENTS |
| DATABASE_PARAMS |
| DBS |
| DB_PRIVS |
| DELEGATION_TOKENS |
| DELETEME1480404975708 |
| FUNCS |
| FUNC_RU |
| GLOBAL_PRIVS |
| HIVE_LOCKS |
| IDXS |
| INDEX_PARAMS |
| MASTER_KEYS |
| NEXT_COMPACTION_QUEUE_ID |
| NEXT_LOCK_ID |
| NEXT_TXN_ID |
| NUCLEUS_TABLES |
| PARTITIONS |
| PARTITION_EVENTS |
| PARTITION_KEYS |
| PARTITION_KEY_VALS |
| PARTITION_PARAMS |
| PART_COL_PRIVS |
| PART_COL_STATS |
| PART_PRIVS |
| ROLES |
| ROLE_MAP |
| SDS |
| SD_PARAMS |
| SEQUENCE_TABLE |
| SERDES |
| SERDE_PARAMS |
| SKEWED_COL_NAMES |
| SKEWED_COL_VALUE_LOC_MAP |
| SKEWED_STRING_LIST |
| SKEWED_STRING_LIST_VALUES |
| SKEWED_VALUES |
| SORT_COLS |
| TABLE_PARAMS |
| TAB_COL_STATS |
| TBLS |
| TBL_COL_PRIVS |
| TBL_PRIVS |
| TXNS |
| TXN_COMPONENTS |
| TYPES |
| TYPE_FIELDS |
| VERSION |
+---------------------------+