Ambari Hive 无法正常查询的解决

1.今天遇到一个错误,在连接到hive之后,无法执行任何命令。

$ beeline -u "jdbc:hive2://hostname.domain.cn:10000/default;principal=hive/_HOST@domain.com;"
Connecting to jdbc:hive2://hostname.domain.cn:10000/default;principal=hive/_HOST@domain.com;
Connected to: Apache Hive (version release-1.2.1-EDH-1.1.2)
Driver: Hive JDBC (version release-1.2.1-EDH-1.1.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version release-1.2.1-EDH-1.1.2 by Apache Hive
0: jdbc:hive2://hostname.domain.cn:10000> show databases;

返回错误如下

Error: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.Hadoop.hive.ql.exec.DDLTask. MetaException
(message:For direct MetaStore DB connections, we don't support retries at the client level.) (state=08S01,code=1)

2. 百度这个错误,很多文档都提及是字符集的问题,需要保证mysql的字符集是latin1.

mysql>  show variables like '%collation_%';
+----------------------+-------------------+
| Variable_name        | Value            |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database  | latin1_swedish_ci |
| collation_server    | latin1_swedish_ci |
+----------------------+-------------------+

3. 如果字符集不是latin1,需要手动执行(本次问题,不是这个,我的字符集,原本就是latin1)

mysql>use hive
mysql>alter database hive character set latin1;

4. 后来尝试重启一下hive,结果,metastore竟然启动失败。查看日志,说创建表失败。这个hive已经运行一段时间了,一直没有问题。对应的表也都是存在的,没有道理重建的。

Ambari Hive 无法正常查询的解决

5.日志输出如下:

Traceback (most recent call last):
  File "/var/lib/ambari-agent/cache/common-services/HIVE/0.12.0.2.0/package/scripts/hive_metastore.py", line 259, in <module>
    HiveMetastore().execute()
  File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 280, in execute
    method(env)
  File "/var/lib/ambari-agent/cache/common-services/HIVE/0.12.0.2.0/package/scripts/hive_metastore.py", line 59, in start
    self.configure(env)
  File "/var/lib/ambari-agent/cache/common-services/HIVE/0.12.0.2.0/package/scripts/hive_metastore.py", line 73, in configure
    hive(name = 'metastore')
  File "/usr/lib/python2.6/site-packages/ambari_commons/os_family_impl.py", line 89, in thunk
    return fn(*args, **kwargs)
  File "/var/lib/ambari-agent/cache/common-services/HIVE/0.12.0.2.0/package/scripts/hive.py", line 320, in hive
    user = params.hive_user
  File "/usr/lib/python2.6/site-packages/resource_management/core/base.py", line 155, in __init__
    self.env.run()
  File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 160, in run
    self.run_action(resource, action)
  File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 124, in run_action
    provider_action()
  File "/usr/lib/python2.6/site-packages/resource_management/core/providers/system.py", line 273, in action_run
    tries=self.resource.tries, try_sleep=self.resource.try_sleep)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 71, in inner
    result = function(command, **kwargs)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 93, in checked_call
    tries=tries, try_sleep=try_sleep)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 141, in _call_wrapper
    result = _call(command, **kwargs_copy)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 294, in _call
    raise Fail(err_msg)
resource_management.core.exceptions.Fail: Execution of 'export HIVE_CONF_DIR=/usr/hdp/current/hive-metastore/conf/conf.server ; /usr/hdp/current/hive-metastore/bin/schematool -initSchema -dbType mysql -userName hive -passWord [PROTECTED] -verbose' returned 1. Metastore connection URL:    jdbc:mysql://hostname.mysql.cn/hivemeta
Metastore Connection Driver :    com.mysql.jdbc.Driver
Metastore connection User:    hive
Starting metastore schema initialization to 1.2.0
Initialization script hive-schema-1.2.0.mysql.sql
Connecting to jdbc:mysql://hostname.mysql.cn/hivemeta
Connected to: MySQL (version 5.1.73)
Driver: MySQL Connector Java (version mysql-connector-java-5.1.40 ( Revision: 402933ef52cad9aa82624e80acbea46e3a701ce6 ))
Transaction isolation: TRANSACTION_READ_COMMITTED
0: jdbc:mysql://hostname.mysql.cn/hivem> !autocommit on
Autocommit status: true
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40101 SET @OLD_CHARACTER_SET_C
LIENT=@@CHARACTER_SET_CLIENT */
No rows affected (0.003 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40101 SET @OLD_CHARACTER_SET_R
ESULTS=@@CHARACTER_SET_RESULTS */
No rows affected (0 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40101 SET @OLD_COLLATION_CONNE
CTION=@@COLLATION_CONNECTION */
No rows affected (0 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40101 SET NAMES utf8 */
No rows affected (0 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40103 SET @OLD_TIME_ZONE=@@TIM
E_ZONE */
No rows affected (0.002 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40103 SET TIME_ZONE='+00:00' *
/
No rows affected (0 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40014 SET @OLD_UNIQUE_CHECKS=@
@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */
No rows affected (0 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40014 SET @OLD_FOREIGN_KEY_CHE
CKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */
No rows affected (0.001 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40101 SET @OLD_SQL_MODE=@@SQL_
MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */
No rows affected (0 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40111 SET @OLD_SQL_NOTES=@@SQL
_NOTES, SQL_NOTES=0 */
No rows affected (0.001 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40101 SET @saved_cs_client   
 = @@character_set_client */
No rows affected (0 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> /*!40101 SET character_set_client
 = utf8 */
No rows affected (0.001 seconds)
0: jdbc:mysql://hostname.mysql.cn/hivem> CREATE TABLE IF NOT EXISTS `BUCKE
TING_COLS` ( `SD_ID` bigint(20) NOT NULL, `BUCKET_COL_NAME` varchar(256) CHARACT
ER SET latin1 COLLATE latin1_bin DEFAULT NULL, `INTEGER_IDX` int(11) NOT NULL, P
RIMARY KEY (`SD_ID`,`INTEGER_IDX`), KEY `BUCKETING_COLS_N49` (`SD_ID`), CONSTRAI
NT `BUCKETING_COLS_FK1` FOREIGN KEY (`SD_ID`) REFERENCES `SDS` (`SD_ID`) ) ENGIN
E=InnoDB DEFAULT CHARSET=latin1
Error: Can't create table 'hivemeta.bucketing_cols' (errno: 121) (state=HY000,code=1005)
Closing: 0: jdbc:mysql://hostname.mysql.cn/hivemeta
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
    at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:270)
    at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:243)
    at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:473)
    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.io.IOException: Schema script failed, errorcode 2
    at org.apache.hive.beeline.HiveSchemaTool.runBeeLine(HiveSchemaTool.java:358)
    at org.apache.hive.beeline.HiveSchemaTool.runBeeLine(HiveSchemaTool.java:326)
    at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:266)
    ... 8 more
*** schemaTool failed ***

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4c3268b482d75bf59785473161196634.html