From 584eef4a8ad869bbf23255238eb0e1cdcaf417ad Mon Sep 17 00:00:00 2001
From: Todd Lipcon <todd@cloudera.com>
Date: Tue, 2 Feb 2010 13:38:43 -0800
Subject: [PATCH] HDFS-455, MAPREDUCE-1441, HADOOP-6534. Allow spaces in between comma-separated elements in directory list configurations.

This fixes any configuration consisting of a comma-separated list of directories
(eg dfs.data.dir, dfs.name.dir, fs.checkpoint.dir, mapred.local.dir, etc) so that
the elements may also contain separating whitespace. Without this patch,
setting mapred.local.dir to "/disk1, /disk2" would create a directory by the name
" " in the user's home directory, or fail outright. The patch trims the directory
names as they are fetched from the configuration.
---
 .../org/apache/hadoop/fs/LocalDirAllocator.java    |    2 +-
 .../hadoop/hdfs/server/datanode/DataNode.java      |    2 +-
 .../hadoop/hdfs/server/namenode/FSImage.java       |    4 ++--
 .../hadoop/hdfs/server/namenode/FSNamesystem.java  |    4 ++--
 src/mapred/org/apache/hadoop/mapred/JobConf.java   |    2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/core/org/apache/hadoop/fs/LocalDirAllocator.java b/src/core/org/apache/hadoop/fs/LocalDirAllocator.java
index 5d04d28..5e7e2ee 100644
--- a/src/core/org/apache/hadoop/fs/LocalDirAllocator.java
+++ b/src/core/org/apache/hadoop/fs/LocalDirAllocator.java
@@ -209,7 +209,7 @@ public class LocalDirAllocator {
     private void confChanged(Configuration conf) throws IOException {
       String newLocalDirs = conf.get(contextCfgItemName);
       if (!newLocalDirs.equals(savedLocalDirs)) {
-        localDirs = conf.getStrings(contextCfgItemName);
+        localDirs = conf.getTrimmedStrings(contextCfgItemName);
         localFS = FileSystem.getLocal(conf);
         int numDirs = localDirs.length;
         ArrayList<String> dirs = new ArrayList<String>(numDirs);
diff --git a/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
index 4c50a51..12b8cea 100644
--- a/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
+++ b/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
@@ -1258,7 +1258,7 @@ public class DataNode extends Configured
           " anymore. RackID resolution is handled by the NameNode.");
       System.exit(-1);
     }
-    String[] dataDirs = conf.getStrings("dfs.data.dir");
+    String[] dataDirs = conf.getTrimmedStrings("dfs.data.dir");
     dnThreadName = "DataNode: [" +
                         StringUtils.arrayToString(dataDirs) + "]";
     return makeInstance(dataDirs, conf);
diff --git a/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSImage.java b/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSImage.java
index 35e406d..cd6d27a 100644
--- a/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSImage.java
+++ b/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSImage.java
@@ -1548,7 +1548,7 @@ public class FSImage extends Storage {
 
   static Collection<File> getCheckpointDirs(Configuration conf,
                                             String defaultName) {
-    Collection<String> dirNames = conf.getStringCollection("fs.checkpoint.dir");
+    Collection<String> dirNames = conf.getTrimmedStringCollection("fs.checkpoint.dir");
     if (dirNames.size() == 0 && defaultName != null) {
       dirNames.add(defaultName);
     }
@@ -1562,7 +1562,7 @@ public class FSImage extends Storage {
   static Collection<File> getCheckpointEditsDirs(Configuration conf,
                                                  String defaultName) {
     Collection<String> dirNames = 
-                conf.getStringCollection("fs.checkpoint.edits.dir");
+                conf.getTrimmedStringCollection("fs.checkpoint.edits.dir");
  if (dirNames.size() == 0 && defaultName != null) {
    dirNames.add(defaultName);
  }
diff --git a/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index e5e80df..7400d5f 100644
--- a/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -349,7 +349,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
   }
 
   public static Collection<File> getNamespaceDirs(Configuration conf) {
-    Collection<String> dirNames = conf.getStringCollection("dfs.name.dir");
+    Collection<String> dirNames = conf.getTrimmedStringCollection("dfs.name.dir");
     if (dirNames.isEmpty())
       dirNames.add("/tmp/hadoop/dfs/name");
     Collection<File> dirs = new ArrayList<File>(dirNames.size());
@@ -361,7 +361,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
   
   public static Collection<File> getNamespaceEditsDirs(Configuration conf) {
     Collection<String> editsDirNames = 
-            conf.getStringCollection("dfs.name.edits.dir");
+            conf.getTrimmedStringCollection("dfs.name.edits.dir");
     if (editsDirNames.isEmpty())
       editsDirNames.add("/tmp/hadoop/dfs/name");
     Collection<File> dirs = new ArrayList<File>(editsDirNames.size());
diff --git a/src/mapred/org/apache/hadoop/mapred/JobConf.java b/src/mapred/org/apache/hadoop/mapred/JobConf.java
index 1292bd4..8367ed9 100644
--- a/src/mapred/org/apache/hadoop/mapred/JobConf.java
+++ b/src/mapred/org/apache/hadoop/mapred/JobConf.java
@@ -254,7 +254,7 @@ public class JobConf extends Configuration {
   }
 
   public String[] getLocalDirs() throws IOException {
-    return getStrings("mapred.local.dir");
+    return getTrimmedStrings("mapred.local.dir");
   }
 
   public void deleteLocalFiles() throws IOException {
-- 
1.6.0.4

