hive在运行过程中,会发现 hdfs /tmp/hive/hive or hdfs 目录占用空间巨大!
hive在运行过程中会生产大量的中间会话在/tmp目录下,
如果hive正常运行结束,临时会话会被自动清理掉,
如果hive中断,或者异常退出,这些中间会话就会一直保存在hdfs上。必须手动清理掉!
#!/bin/bash
usage=“Usage: cleanup.sh [days]”
if [ ! “$1” ]
then
echo $usage
exit 1
fi
now=$(date +%s)
hadoop fs -ls /tmp/hive/hdfs | grep “^d” | while read f; do
dir_date=echo $f | awk '{print $6}'
difference=$(( ( $now -
(
d
a
t
e
−
d
"
(date -d "
(date−d"dir_date" +%s) ) / (24 * 60 * 60 ) ))
if [ $difference -gt $1 ]; then
echo $f
hadoop fs -rm -r -skipTrash echo $f| awk '{ print $8 }'
;
fi
done