diff --git itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java index 275e3d7..0dcc3ce 100644 --- itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java +++ itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java @@ -1358,9 +1358,12 @@ public QTestSetup() { public void preTest(HiveConf conf) throws Exception { if (zooKeeperCluster == null) { - String tmpdir = System.getProperty("test.tmp.dir"); + //create temp dir + String tmpBaseDir = System.getProperty("test.tmp.dir"); + File tmpDir = Utilities.createTempDir(tmpBaseDir); + zooKeeperCluster = new MiniZooKeeperCluster(); - zkPort = zooKeeperCluster.startup(new File(tmpdir, "zookeeper")); + zkPort = zooKeeperCluster.startup(tmpDir); } if (zooKeeper != null) { diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index 9afc80b..daf4e4a 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -3087,5 +3087,31 @@ private static void createTmpDirs(Configuration conf, } } } + + /** + * Create a temp dir in specified baseDir + * This can go away once hive moves to support only JDK 7 + * and can use Files.createTempDirectory + * Guava Files.createTempDir() does not take a base dir + * @param baseDir - directory under which new temp dir will be created + * @return File object for new temp dir + */ + public static File createTempDir(String baseDir){ + //try creating the temp dir MAX_ATTEMPTS times + final int MAX_ATTEMPS = 30; + for(int i = 0; i < MAX_ATTEMPS; i++){ + //pick a random file name + String tempDirName = "tmp_" + ((int)(100000 * Math.random())); + + //return if dir could successfully be created with that file name + File tempDir = new File(baseDir, tempDirName); + if(tempDir.mkdir()){ + return tempDir; + } + } + throw new IllegalStateException("Failed to create a temp dir under " + + baseDir + " Giving up after " + MAX_ATTEMPS + " attemps"); + + } }