diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index cbadb05..d5adc67 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.URI; import java.util.AbstractMap; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -685,18 +686,51 @@ public class Hive { return; //srcs = new FileStatus[0]; Why is this needed? } + // check that source and target paths exist checkPaths(fs, srcs, destf, false); // move it, move it + Map movedFiles = new HashMap(srcs.length); + boolean dirExisted = true; try { + if (!fs.exists(destf)) { + fs.mkdirs(destf); + dirExisted = false; + } for(int i=0; i entry : movedFiles.entrySet()) { + try { + fs.rename(entry.getValue(), entry.getKey()); + } catch (IOException ioe) { + LOG.warn("Couldn't undo rename of " + + String.valueOf(entry.getKey()) + " to " + + String.valueOf(entry.getValue())); + // At this point we have left a file in the directory, so we should + // not rmr the destination directory during recovery + dirExisted = true; + } + } + // If the dir didn't exist when we started, we should remove that too + if (!dirExisted) { + try { + fs.delete(destf, true); + } catch (IOException ioe) { + LOG.warn("Couldn't clean up new directory " + String.valueOf(destf), ioe); + } + } throw new HiveException("addFiles: error while moving files!!!", e); } }