瀏覽代碼

Merge -r 723830:723831 from trunk to move the change log of HADOOP-4717 into branch 0.18

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.18@723839 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 16 年之前
父節點
當前提交
3443c909e6

+ 3 - 0
CHANGES.txt

@@ -75,6 +75,9 @@ Release 0.18.3 - Unreleased
     tasks in the JobTracker's task commit thread. 
     tasks in the JobTracker's task commit thread. 
     (Amareshwari Sriramadasu via ddas)
     (Amareshwari Sriramadasu via ddas)
 
 
+    HADOOP-4717. Removal of default port# in NameNode.getUri() causes a
+    map/reduce job failed to prompt temporary output. (hairong)
+
 Release 0.18.2 - 2008-11-03
 Release 0.18.2 - 2008-11-03
 
 
   BUG FIXES
   BUG FIXES

+ 18 - 0
src/hdfs/org/apache/hadoop/dfs/DistributedFileSystem.java

@@ -84,6 +84,24 @@ public class DistributedFileSystem extends FileSystem {
     super.checkPath(path);
     super.checkPath(path);
   }
   }
 
 
+  /** Normalize paths that explicitly specify the default port. */
+  public Path makeQualified(Path path) {
+    URI thisUri = this.getUri();
+    URI thatUri = path.toUri();
+    String thatAuthority = thatUri.getAuthority();
+    if (thatUri.getScheme() != null
+        && thatUri.getScheme().equalsIgnoreCase(thisUri.getScheme())
+        && thatUri.getPort() == NameNode.DEFAULT_PORT
+        && thisUri.getPort() == -1
+        && thatAuthority.substring(0,thatAuthority.indexOf(":"))
+        .equalsIgnoreCase(thisUri.getAuthority())) {
+      path = new Path(thisUri.getScheme(), thisUri.getAuthority(),
+                      thatUri.getPath());
+    }
+    return super.makeQualified(path);
+  }
+
+
   public Path getWorkingDirectory() {
   public Path getWorkingDirectory() {
     return workingDir;
     return workingDir;
   }
   }

+ 7 - 2
src/mapred/org/apache/hadoop/mapred/Task.java

@@ -579,8 +579,13 @@ abstract class Task implements Writable, Configurable {
     }
     }
   }
   }
   
   
-  private Path getFinalPath(Path jobOutputDir, Path taskOutput) {
-    URI relativePath = taskOutputPath.toUri().relativize(taskOutput.toUri());
+  private Path getFinalPath(Path jobOutputDir, Path taskOutput) throws IOException {
+    URI taskOutputUri = taskOutput.toUri();
+    URI relativePath = taskOutputPath.toUri().relativize(taskOutputUri);
+    if (taskOutputUri == relativePath) {//taskOutputPath is not a parent of taskOutput
+      throw new IOException("Can not get the relative path: base = " +
+          taskOutputPath + " child = " + taskOutput);
+    }
     if (relativePath.getPath().length() > 0) {
     if (relativePath.getPath().length() > 0) {
       return new Path(jobOutputDir, relativePath.getPath());
       return new Path(jobOutputDir, relativePath.getPath());
     } else {
     } else {

+ 34 - 0
src/test/org/apache/hadoop/mapred/TestMiniMRWithDFS.java

@@ -33,6 +33,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.dfs.MiniDFSCluster;
 import org.apache.hadoop.dfs.MiniDFSCluster;
+import org.apache.hadoop.dfs.NameNode;
 import org.apache.hadoop.examples.WordCount;
 import org.apache.hadoop.examples.WordCount;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.FileUtil;
@@ -246,4 +247,37 @@ public class TestMiniMRWithDFS extends TestCase {
     }
     }
   }
   }
   
   
+  public void testWithDFSWithDefaultPort() throws IOException {
+    MiniDFSCluster dfs = null;
+    MiniMRCluster mr = null;
+    FileSystem fileSys = null;
+    try {
+      final int taskTrackers = 4;
+
+      Configuration conf = new Configuration();
+      // start a dfs with the default port number
+      dfs = new MiniDFSCluster(
+          NameNode.DEFAULT_PORT, conf, 4, true, true, null, null);
+      fileSys = dfs.getFileSystem();
+      mr = new MiniMRCluster(taskTrackers, fileSys.getUri().toString(), 1);
+
+      JobConf jobConf = mr.createJobConf();
+      TestResult result;
+      final Path inDir = new Path("./wc/input");
+      final Path outDir = new Path("hdfs://" +
+          dfs.getNameNode().getNameNodeAddress().getHostName() +
+          ":" + NameNode.DEFAULT_PORT +"/./wc/output");
+      String input = "The quick brown fox\nhas many silly\nred fox sox\n";
+      result = launchWordCount(jobConf, inDir, outDir, input, 3, 1);
+      assertEquals("The\t1\nbrown\t1\nfox\t2\nhas\t1\nmany\t1\n" +
+                   "quick\t1\nred\t1\nsilly\t1\nsox\t1\n", result.output);
+    } catch (java.net.BindException be) {
+      LOG.info("Skip the test this time because can not start namenode on port "
+          + NameNode.DEFAULT_PORT, be);
+    } finally {
+      if (dfs != null) { dfs.shutdown(); }
+      if (mr != null) { mr.shutdown();
+      }
+    }
+  }
 }
 }