记录一次Hive中遇到的问题

今天在测试MapJoin对优化作用的提升的时候,使用普通用户mapan在命令行hive-cli里跑一段的MapJoin得到测试HQL,发现报如下错误,学会看报错日志是非常好的解决问题的方法,通过看日志能够解决大部分常见的的问题。关键日志如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
2020-03-26 20:42:36,065 main ERROR RandomAccessFileManager 
(/var/log/hive/operation_logs/7cbc9115-f9e8-4554-99f2-
196aced99788/mapan_20200326204229_2b889f65-cc49-4de5-b3b5-0bccd05b3812)
java.io.IOException: Could not create directory
/var/log/hive/operation_logs/7cbc9115-f9e8-4554-99f2-196aced99788
java.io.IOException: Could not create directory
/var/log/hive/operation_logs/7cbc9115-f9e8-4554-99f2-196aced99788
at org.apache.logging.log4j.core.util.FileUtils.mkdir(FileUtils.java:119)
at org.apache.logging.log4j.core.util.FileUtils.makeParentDirs(FileUtils.java:136)
at org.apache.logging.log4j.core.appender.RandomAccessFileManager$RandomAccessFileManagerFactory.createManager(RandomAccessFileManager.java:198)
at org.apache.logging.log4j.core.appender.RandomAccessFileManager$RandomAccessFileManagerFactory.createManager(RandomAccessFileManager.java:177)
at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:112)
at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
at org.apache.logging.log4j.core.appender.RandomAccessFileManager.getFileManager(RandomAccessFileManager.java:74)
at org.apache.hadoop.hive.ql.log.HushableRandomAccessFileAppender.createAppender(HushableRandomAccessFileAppender.java:178)
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.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:132)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
at org.apache.logging.log4j.core.appender.routing.RoutingAppender.createAppender(RoutingAppender.java:271)
at org.apache.logging.log4j.core.appender.routing.RoutingAppender.getControl(RoutingAppender.java:255)
at org.apache.logging.log4j.core.appender.routing.RoutingAppender.append(RoutingAppender.java:225)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:433)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:417)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:403)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1993)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1852)
at org.apache.logging.slf4j.Log4jLogger.info(Log4jLogger.java:179)
at org.apache.hadoop.hive.ql.exec.mapjoin.MapJoinMemoryExhaustionHandler.<init>(MapJoinMemoryExhaustionHandler.java:61)
at org.apache.hadoop.hive.ql.exec.HashTableSinkOperator.initializeOp(HashTableSinkOperator.java:129)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:358)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:546)
at org.apache.hadoop.hive.ql.exec.Operator.initializeChildren(Operator.java:498)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:368)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:546)
at org.apache.hadoop.hive.ql.exec.Operator.initializeChildren(Operator.java:498)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:368)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:546)
at org.apache.hadoop.hive.ql.exec.Operator.initializeChildren(Operator.java:498)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:368)
at org.apache.hadoop.hive.ql.exec.mr.MapredLocalTask.initializeOperators(MapredLocalTask.java:514)
at org.apache.hadoop.hive.ql.exec.mr.MapredLocalTask.startForward(MapredLocalTask.java:418)
at org.apache.hadoop.hive.ql.exec.mr.MapredLocalTask.executeInProcess(MapredLocalTask.java:393)
at org.apache.hadoop.hive.ql.exec.mr.ExecDriver.main(ExecDriver.java:779)
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.util.RunJar.run(RunJar.java:313)
at org.apache.hadoop.util.RunJar.main(RunJar.java:227)

很明显日志中提到如下关键错误:

1
2
3
4
main ERROR RandomAccessFileManager 
(/var/log/hive/operation_logs/7cbc9115-f9e8-4554-99f2-
196aced99788/mapan_20200326204229_2b889f65-cc49-4de5-b3b5-0bccd05b3812)
java.io.IOException: Could not create directory

由于我是使用的mapan用户登录并运行的hive-cli,所以我猜测是由于mapan用户没有/var/log/hive/operation_logs/的权限所导致的。切换hive用户尝试
sudo -u hive hive进入hive-cli,然后跑同样一段HQL发现可以正常运行,OK那么问题基本可以确定了,给对应目录添加写权限即可。
sudo chmod -R o+w /var/log/hive/operation_logs/
再次使用mapan用户进入hive -cli,跑同样的HQL,没有再报错,问题解决。