是否存在Hive配置属性可自动清理表对应的scratch dir临时目录
问题描述
我有一张表:table_1 -- 19亿条记录 -- ORC格式 -- 大小229G
我通过脚本关联table1和<some other table>创建table2:
table2 - 3万条记录 -- ORC格式 -- 大小229G
我查看table2的HDFS路径时,发现存在大量scratchdir目录,总共占用220G空间:
[root@host ~]$ hadoop fs -du -s -h /db_name/data/db/db_name.db/managed/table2 220.8 G /db_name/data/db/db_name.db/managed/table2 [root@lnx1397 ~]$ ls -ltr /mapr/mapre04p//db_name/data/db/db_name.db/managed/table2 total 2943 drwxr-xr-x 4 root root 2 Sep 16 23:29 _scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-17 drwxr-xr-x 4 root root 2 Sep 16 23:29 _scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-18 drwxr-xr-x 4 root root 2 Sep 16 23:30 _scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-19 drwxr-xr-x 4 root root 2 Sep 16 23:42 _scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-20 drwxr-xr-x 7 root root 5 Sep 16 23:45 _scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-1 -rwxr-xr-x 1 root root 3010663 Sep 17 00:25 000000_0 [root@host ~]$ du -sh /mapr/mapre04p//db_name/data/db/db_name.db/managed/table2/* 2.9M /mapr/mapre04p//db_name/data/db/db_name.db/managed/table2/000000_0 221G /mapr/mapre04p//db_name/data/db/db_name.db/managed/table2/_scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-1 1.0K /mapr/mapre04p//db_name/data/db/db_name.db/managed/table2/_scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-17 1.0K /mapr/mapre04p//db_name/data/db/db_name.db/managed/table2/_scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-18 1.0K /mapr/mapre04p//db_name/data/db/db_name.db/managed/table2/_scratchdir_hive_2021-09-16_23-29-42_576_3081873685168820741-19 1.0K /mapr/mapre04p//db_name/data/db/receipt
数据库卷总容量为1TB,我有删除table1的脚本,但目前作业因scratch目录占用空间过高触发磁盘配额超限错误而失败。
请问是否存在对应的Hive属性或配置项可以自动清理这些scratchdir临时目录?
解答
存在对应的Hive配置可以实现scratch临时目录的自动清理,这类遗留目录一般是Hive作业异常终止(被kill、执行失败)时,没有触发正常的临时目录回收逻辑导致的。
核心配置项
你可以在hive-site.xml中调整以下配置:
hive.start.cleanup.scratchdir:设置为true后,HiveServer2启动时会自动清理所有过期的scratch目录,默认值为false。hive.scratchdir.cleanup.interval:运行时定期清理scratch目录的时间间隔,单位为秒,默认值为86400(24小时),你可以根据需要调小,比如设置为3600(每小时清理一次)。hive.scratchdir.cleanup.age.threshold.hours:scratch目录的过期阈值,超过该时长的目录才会被清理,默认值为24小时。注意该阈值需要大于你集群中最长运行的Hive作业时长,避免误删正在运行作业的临时目录导致任务失败。
紧急处理方案
当前磁盘配额已经超限,你可以先手动删除过期的scratch目录释放空间:
hadoop fs -rm -r /db_name/data/db/db_name.db/managed/table2/_scratchdir_hive_*
这些临时目录和表的正式数据无关,删除不会影响table2的正常使用。
内容的提问来源于stack exchange,提问作者Vijiy
相关产品推荐
相关产品推荐

