public class ClearDanglingScratchDir
A tool to remove dangling scratch directory. A scratch directory could be left behind
in some cases, such as when vm restarts and leave no chance for Hive to run shutdown hook.
The tool will test a scratch directory is use, if not, remove it.
We rely on HDFS write lock for to detect if a scratch directory is in use:
1. A HDFS client open HDFS file ($scratchdir/inuse.lck) for write and only close
it at the time the session is closed
2. cleardanglingscratchDir can try to open $scratchdir/inuse.lck for write. If the
corresponding HiveCli/HiveServer2 is still running, we will get exception.
Otherwise, we know the session is dead
3. If the HiveCli/HiveServer2 dies without closing the HDFS file, NN will reclaim the
lease after 10 min, ie, the HDFS file hold by the dead HiveCli/HiveServer2 is writable
again after 10 min. Once it become writable, cleardanglingscratchDir will be able to