From 56e3553f40f4a36099a58facd90fa94c85c43340 Mon Sep 17 00:00:00 2001 From: Andrew Bayer Date: Fri, 22 Jul 2011 20:04:16 +0000 Subject: [PATCH] SQOOP-81. Creation of /tmp/sqoop/compile is not multi-user friendly. Create nonce dirs as /tmp/sqoop-${user.name}/compile. Remove unused compilation directories at end of execution. Do not memoize nonce compilation directory names in metastore. From: Aaron Kimball git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149975 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/com/cloudera/sqoop/SqoopOptions.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/java/com/cloudera/sqoop/SqoopOptions.java b/src/java/com/cloudera/sqoop/SqoopOptions.java index c7eb1625..3ebf22cb 100644 --- a/src/java/com/cloudera/sqoop/SqoopOptions.java +++ b/src/java/com/cloudera/sqoop/SqoopOptions.java @@ -116,6 +116,10 @@ public enum IncrementalMode { @StoredAsProperty("codegen.output.dir") private String codeOutputDir; @StoredAsProperty("codegen.compile.dir") private String jarOutputDir; + // Boolean specifying whether jarOutputDir is a nonce tmpdir (true), or + // explicitly set by the user (false). If the former, disregard any value + // for jarOutputDir saved in the metastore. + @StoredAsProperty("codegen.auto.compile.dir") private boolean jarDirIsAuto; private String hadoopHome; // not serialized to metastore. @StoredAsProperty("db.split.column") private String splitByCol; @StoredAsProperty("db.where.clause") private String whereClause; @@ -428,6 +432,14 @@ public void loadProperties(Properties props) { this.password = props.getProperty("db.password", this.password); } + if (this.jarDirIsAuto) { + // We memoized a user-specific nonce dir for compilation to the data + // store. Disregard that setting and create a new nonce dir. + String localUsername = System.getProperty("user.name", "unknown"); + this.jarOutputDir = getNonceJarDir(tmpDir + "sqoop-" + localUsername + + "/compile"); + } + String colListStr = props.getProperty("db.column.list", null); if (null != colListStr) { this.columns = listToArray(colListStr); @@ -554,7 +566,9 @@ public String getTempDir() { /** * Return the name of a directory that does not exist before * calling this method, and does exist afterward. We should be - * the only client of this directory. + * the only client of this directory. If this directory is not + * used during the lifetime of the JVM, schedule it to be removed + * when the JVM exits. */ private static String getNonceJarDir(String tmpBase) { @@ -576,6 +590,9 @@ private static String getNonceJarDir(String tmpBase) { if (hashDir.mkdirs()) { // We created the directory. Use it. + // If this directory is not actually filled with files, delete it + // when the JVM quits. + hashDir.deleteOnExit(); break; } } @@ -624,7 +641,10 @@ private void initDefaults(Configuration baseConfiguration) { } this.tmpDir = myTmpDir; - this.jarOutputDir = getNonceJarDir(tmpDir + "sqoop/compile"); + String localUsername = System.getProperty("user.name", "unknown"); + this.jarOutputDir = getNonceJarDir(tmpDir + "sqoop-" + localUsername + + "/compile"); + this.jarDirIsAuto = true; this.layout = FileLayout.TextFile; this.areDelimsManuallySet = false; @@ -941,6 +961,7 @@ public String getJarOutputDir() { public void setJarOutputDir(String outDir) { this.jarOutputDir = outDir; + this.jarDirIsAuto = false; } /**