HiveServer2 在 hdfs /tmp/hive/hive 中生成很多目录

Posted

技术标签:

【中文标题】HiveServer2 在 hdfs /tmp/hive/hive 中生成很多目录【英文标题】:HiveServer2 generate a lot of directories in hdfs /tmp/hive/hive 【发布时间】:2015-08-31 07:55:37 【问题描述】:

我们使用 Hiveserver2(在 Hortonworks HDP2.2 发行版上)创建新的类。一段时间后,我们在 hdfs 上的 /tmp/hive/hive 中有超过 1048576 个目录,因为 hive 服务器在此位置生成它。

有人遇到过类似的问题吗? 来自 hiveserver 的日志:

2015-08-31 06:48:15,828 WARN  [HiveServer2-Handler-Pool: Thread-1104]: conf.HiveConf (HiveConf.java:initialize(2499)) - HiveConf of name hive.heapsize does not exist
2015-08-31 06:48:15,829 WARN  [HiveServer2-Handler-Pool: Thread-1104]: conf.HiveConf (HiveConf.java:initialize(2499)) - HiveConf of name hive.server2.enable.impersonation does not exist
2015-08-31 06:48:15,829 WARN  [HiveServer2-Handler-Pool: Thread-1104]: conf.HiveConf (HiveConf.java:initialize(2499)) - HiveConf of name hive.auto.convert.sortmerge.join.noconditionaltask does not exist
2015-08-31 06:48:15,833 INFO  [HiveServer2-Handler-Pool: Thread-1104]: thrift.ThriftCLIService (ThriftCLIService.java:OpenSession(232)) - Client protocol version: HIVE_CLI_SERVICE_PROTOCOL_V6
2015-08-31 06:48:15,835 INFO  [HiveServer2-Handler-Pool: Thread-1104]: session.SessionState (SessionState.java:createPath(558)) - Created local directory: /tmp/ffd9e5e7-7a4e-472e-b5f1-9c7f8acb0bff_resources
2015-08-31 06:48:15,883 INFO  [HiveServer2-Handler-Pool: Thread-1104]: session.SessionState (SessionState.java:createPath(558)) - Created HDFS directory: /tmp/hive/hive/ffd9e5e7-7a4e-472e-b5f1-9c7f8acb0bff
2015-08-31 06:48:15,884 INFO  [HiveServer2-Handler-Pool: Thread-1104]: session.SessionState (SessionState.java:createPath(558)) - Created local directory: /tmp/hive/ffd9e5e7-7a4e-472e-b5f1-9c7f8acb0bff
2015-08-31 06:48:16,064 INFO  [HiveServer2-Handler-Pool: Thread-1104]: session.SessionState (SessionState.java:createPath(558)) - Created HDFS directory: /tmp/hive/hive/ffd9e5e7-7a4e-472e-b5f1-9c7f8acb0bff/_tmp_space.db
2015-08-31 06:48:16,065 INFO  [HiveServer2-Handler-Pool: Thread-1104]: session.SessionState (SessionState.java:start(460)) - No Tez session required at this point. hive.execution.engine=mr.

创建会话时的 Hiveserver 方法:

 /**
   * Create dirs & session paths for this session:
   * 1. HDFS scratch dir
   * 2. Local scratch dir
   * 3. Local downloaded resource dir
   * 4. HDFS session path
   * 5. Local session path
   * 6. HDFS temp table space
   * @param userName
   * @throws IOException
   */
  private void createSessionDirs(String userName) throws IOException 
    HiveConf conf = getConf();
    Path rootHDFSDirPath = createRootHDFSDir(conf);
    // Now create session specific dirs
    String scratchDirPermission = HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCHDIRPERMISSION);
    Path path;
    // 1. HDFS scratch dir
    path = new Path(rootHDFSDirPath, userName);
    hdfsScratchDirURIString = path.toUri().toString();
    createPath(conf, path, scratchDirPermission, false, false);
    // 2. Local scratch dir
    path = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.LOCALSCRATCHDIR));
    createPath(conf, path, scratchDirPermission, true, false);
    // 3. Download resources dir
    path = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.DOWNLOADED_RESOURCES_DIR));
    createPath(conf, path, scratchDirPermission, true, false);
    // Finally, create session paths for this session
    // Local & non-local tmp location is configurable. however it is the same across
    // all external file systems
    String sessionId = getSessionId();
    // 4. HDFS session path
    hdfsSessionPath = new Path(hdfsScratchDirURIString, sessionId);
    createPath(conf, hdfsSessionPath, scratchDirPermission, false, true);
    conf.set(HDFS_SESSION_PATH_KEY, hdfsSessionPath.toUri().toString());
    // 5. Local session path
    localSessionPath = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.LOCALSCRATCHDIR), sessionId);
    createPath(conf, localSessionPath, scratchDirPermission, true, true);
    conf.set(LOCAL_SESSION_PATH_KEY, localSessionPath.toUri().toString());
    // 6. HDFS temp table space
    hdfsTmpTableSpace = new Path(hdfsSessionPath, TMP_PREFIX);
    createPath(conf, hdfsTmpTableSpace, scratchDirPermission, false, true);
    conf.set(TMP_TABLE_SPACE_KEY, hdfsTmpTableSpace.toUri().toString());
  

【问题讨论】:

同样的问题:hortonworks.com/community/forums/topic/… 【参考方案1】:

我们之前遇到过类似的问题。 Manily hive 在运行 Hive 客户端的机器和默认的 HDFS 实例上都使用临时文件夹。这些文件夹用于存储每个查询的临时/中间数据集,通常在查询完成时由 hive 客户端清理。但是,在 Hive 客户端异常终止的情况下,可能会留下一些数据。详细配置如下:

在 HDFS 集群上,默认设置为 /tmp/hive- 并由配置变量 hive.exec.scratchdir 控制 在客户端机器上,这被硬编码到 /tmp/ 请注意,将数据写入表/分区时,Hive 将首先写入目标表文件系统上的临时位置(使用 hive.exec.scratchdir 作为临时位置),然后将数据移动到目标表。这适用于所有情况 - 无论表存储在 HDFS(正常情况)还是存储在 S3 甚至 NFS 等文件系统中。

Source

因此您可以使用手动脚本或作业定期清理临时位置,或者您可以使用 cron 脚本清理 30 或 60 天数据

【讨论】:

不是这种问题。每次创建新会话配置单元时都会产生会话“_tmp_space.db”,但不会将其删除。我完成了描述。请检查。【参考方案2】:

这里有答案。 https://issues.apache.org/jira/browse/HIVE-15068

更高版本的 Hive 解决了这个问题。对于低版本,好吧,写一个 cron 作业就行了

【讨论】:

以上是关于HiveServer2 在 hdfs /tmp/hive/hive 中生成很多目录的主要内容,如果未能解决你的问题,请参考以下文章

CDH/CDP中开启kerberos后如何访问HDFS/YARN/HIVESERVER2 等服务的webui

Hiveserver2阻塞原因排查

Hiveserver2高可用实现

强制 HiveServer2 运行 MapReduce 作业

连接HiveServer2的图形化工具SQuirrel和Dbeaver

Hive入门