diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index 4c9acce..6feaf8f 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -2624,26 +2624,29 @@ private static void copyFiles(final HiveConf conf, final FileSystem destFs, files = new FileStatus[] {src}; } - for (FileStatus srcFile : files) { - - final Path srcP = srcFile.getPath(); - final boolean needToCopy = needToCopy(srcP, destf, srcFs, destFs); - // Strip off the file type, if any so we don't make: - // 000000_0.gz -> 000000_0.gz_copy_1 - final String name; - final String filetype; - String itemName = srcP.getName(); - int index = itemName.lastIndexOf('.'); - if (index >= 0) { - filetype = itemName.substring(index); - name = itemName.substring(0, index); - } else { - name = itemName; - filetype = ""; - } + final SessionState parentSession = SessionState.get(); + for (final FileStatus srcFile : files) { + futures.add(pool.submit(new Callable>() { @Override public ObjectPair call() throws Exception { + SessionState.setCurrentSessionState(parentSession); + final Path srcP = srcFile.getPath(); + final boolean needToCopy = needToCopy(srcP, destf, srcFs, destFs); + // Strip off the file type, if any so we don't make: + // 000000_0.gz -> 000000_0.gz_copy_1 + final String name; + final String filetype; + String itemName = srcP.getName(); + int index = itemName.lastIndexOf('.'); + if (index >= 0) { + filetype = itemName.substring(index); + name = itemName.substring(0, index); + } else { + name = itemName; + filetype = ""; + } + Path destPath = new Path(destf, srcP.getName()); if (!needToCopy && !isSrcLocal) { for (int counter = 1; !destFs.rename(srcP,destPath); counter++) { @@ -2654,7 +2657,7 @@ private static void copyFiles(final HiveConf conf, final FileSystem destFs, } if (inheritPerms) { - ShimLoader.getHadoopShims().setFullFileStatus(conf, fullDestStatus, destFs, destf); + ShimLoader.getHadoopShims().setFullFileStatus(conf, fullDestStatus, destFs, destPath); } if (null != newFiles) { newFiles.add(destPath); diff --git a/shims/common/src/main/java/org/apache/hadoop/hive/shims/ShimLoader.java b/shims/common/src/main/java/org/apache/hadoop/hive/shims/ShimLoader.java index 0fe3169..28d3e48 100644 --- a/shims/common/src/main/java/org/apache/hadoop/hive/shims/ShimLoader.java +++ b/shims/common/src/main/java/org/apache/hadoop/hive/shims/ShimLoader.java @@ -31,7 +31,7 @@ public abstract class ShimLoader { public static String HADOOP23VERSIONNAME = "0.23"; - private static HadoopShims hadoopShims; + private static volatile HadoopShims hadoopShims; private static JettyShims jettyShims; private static AppenderSkeleton eventCounter; private static HadoopThriftAuthBridge hadoopThriftAuthBridge; @@ -88,9 +88,13 @@ * Factory method to get an instance of HadoopShims based on the * version of Hadoop on the classpath. */ - public static synchronized HadoopShims getHadoopShims() { + public static HadoopShims getHadoopShims() { if (hadoopShims == null) { - hadoopShims = loadShims(HADOOP_SHIM_CLASSES, HadoopShims.class); + synchronized (ShimLoader.class) { + if (hadoopShims == null) { + hadoopShims = loadShims(HADOOP_SHIM_CLASSES, HadoopShims.class); + } + } } return hadoopShims; }