Bladeren bron

Fix for HADOOP-3. Don't permit jobs to write to a pre-existing output directory. Contributed by Owen O'Malley.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@387928 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 jaren geleden
bovenliggende
commit
f6db106b47
2 gewijzigde bestanden met toevoegingen van 19 en 4 verwijderingen
  1. 14 3
      src/java/org/apache/hadoop/mapred/JobClient.java
  2. 5 1
      src/java/org/apache/hadoop/mapred/JobConf.java

+ 14 - 3
src/java/org/apache/hadoop/mapred/JobClient.java

@@ -247,8 +247,20 @@ public class JobClient implements MRConstants {
           getFs().copyFromLocalFile(new File(originalJarPath), submitJarFile);
         }
 
-        // Write job file to JobTracker's fs
-        FSDataOutputStream out = getFs().create(submitJobFile);
+        FileSystem fs = getFs();
+
+        // Ensure that the output directory is set and not already there
+        File outDir = job.getOutputDir();
+        if (outDir == null && job.getNumReduceTasks() != 0) {
+            throw new IOException("Output directory not set in JobConf.");
+        }
+        if (outDir != null && fs.exists(outDir)) {
+            throw new IOException("Output directory " + outDir + 
+                                  " already exists.");
+        }
+
+        // Write job file to JobTracker's fs        
+        FSDataOutputStream out = fs.create(submitJobFile);
         try {
           job.write(out);
         } finally {
@@ -347,7 +359,6 @@ public class JobClient implements MRConstants {
         }
 
         // Process args
-        String jobTrackerStr = argv[0];
         String jobTrackerSpec = null;
         String submitJobFile = null;
         String jobid = null;

+ 5 - 1
src/java/org/apache/hadoop/mapred/JobConf.java

@@ -143,7 +143,11 @@ public class JobConf extends Configuration {
     return result;
   }
 
-  public File getOutputDir() { return new File(get("mapred.output.dir")); }
+  public File getOutputDir() { 
+    String name = get("mapred.output.dir");
+    return name == null ? null: new File(name);
+  }
+
   public void setOutputDir(File dir) { set("mapred.output.dir", dir); }
 
   public InputFormat getInputFormat() {