Index: common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
===================================================================
--- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (revision 1172022)
+++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (working copy)
@@ -478,6 +478,8 @@
// The class responsible for logging client side performance metrics
// Must be a subclass of org.apache.hadoop.hive.ql.log.PerfLogger
HIVE_PERF_LOGGER("hive.exec.perf.logger", "org.apache.hadoop.hive.ql.log.PerfLogger"),
+ // Whether to delete the scrachdir while startup
+ HIVE_START_CLEANUP_SCRACHDIR("hive.start.cleanup.scrachdir", false),
;
public final String varname;
Index: conf/hive-default.xml
===================================================================
--- conf/hive-default.xml (revision 1172022)
+++ conf/hive-default.xml (working copy)
@@ -1187,4 +1187,10 @@
The class responsible logging client side performance metrics. Must be a subclass of org.apache.hadoop.hive.ql.log.PerfLogger
+
+ hive.start.cleanup.scrachdir
+ false
+ To cleanup the hive scrachdir while starting the hive server
+
+
Index: service/src/java/org/apache/hadoop/hive/service/HiveServer.java
===================================================================
--- service/src/java/org/apache/hadoop/hive/service/HiveServer.java (revision 1172022)
+++ service/src/java/org/apache/hadoop/hive/service/HiveServer.java (working copy)
@@ -60,7 +60,8 @@
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportFactory;
-
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
import com.facebook.fb303.fb_status;
/**
@@ -647,6 +648,20 @@
}
}
}
+
+ private static void cleanUpScratchDir(HiveConf hiveConf) {
+ String hiveScratchDir = hiveConf.get(HiveConf.ConfVars.SCRATCHDIR.varname);
+ try {
+ Path jobScratchDir = new Path(hiveScratchDir);
+ HiveServerHandler.LOG.info("Cleaning scratchDir : " + hiveScratchDir);
+ FileSystem fileSystem = jobScratchDir.getFileSystem(hiveConf);
+ fileSystem.delete(jobScratchDir, true);
+ }
+ // Even if the cleanup throws some exception we can start.
+ catch (Throwable e) {
+ HiveServerHandler.LOG.warn("Unable to delete scratchDir : " + hiveScratchDir, e);
+ }
+ }
public static void main(String[] args) {
try {
@@ -666,10 +681,12 @@
HiveServerHandler.LOG.warn(e.getMessage());
}
+ HiveConf conf = new HiveConf(HiveServerHandler.class);
+ if (conf.getBoolVar(HiveConf.ConfVars.HIVE_START_CLEANUP_SCRACHDIR)) {
+ cleanUpScratchDir(conf);
+ }
TServerTransport serverTransport = new TServerSocket(cli.port);
- HiveConf conf = new HiveConf(HiveServerHandler.class);
-
// set all properties specified on the command line
for (Map.Entry