瀏覽代碼

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 年之前
父節點
當前提交
f6db106b47
共有 2 個文件被更改,包括 19 次插入4 次删除
  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);
           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 {
         try {
           job.write(out);
           job.write(out);
         } finally {
         } finally {
@@ -347,7 +359,6 @@ public class JobClient implements MRConstants {
         }
         }
 
 
         // Process args
         // Process args
-        String jobTrackerStr = argv[0];
         String jobTrackerSpec = null;
         String jobTrackerSpec = null;
         String submitJobFile = null;
         String submitJobFile = null;
         String jobid = 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;
     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 void setOutputDir(File dir) { set("mapred.output.dir", dir); }
 
 
   public InputFormat getInputFormat() {
   public InputFormat getInputFormat() {