HADOOP-8437. getLocalPathForWrite should throw IOException for invalid paths. 
Contributed by Brahma Reddy Battula


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/fd026f53
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/fd026f53
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/fd026f53

Branch: refs/heads/HADOOP-11890
Commit: fd026f535cc09e99a7d4d5d2a8c13eabe8865315
Parents: ecbfd68
Author: Zhihai Xu <[email protected]>
Authored: Thu Oct 1 11:56:49 2015 -0700
Committer: Zhihai Xu <[email protected]>
Committed: Thu Oct 1 11:56:49 2015 -0700

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt    |  3 +++
 .../org/apache/hadoop/fs/LocalDirAllocator.java    |  6 ++++--
 .../apache/hadoop/fs/TestLocalDirAllocator.java    | 17 +++++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/fd026f53/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 5d583be..544a345 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -1106,6 +1106,9 @@ Release 2.8.0 - UNRELEASED
     HADOOP-10296. Incorrect null check in SwiftRestClient#buildException().
     (Rahul Palamuttam and Kanaka Kumar Avvaru via aajisaka)
 
+    HADOOP-8437. getLocalPathForWrite should throw IOException for invalid
+    paths. (Brahma Reddy Battula via zxu)
+
   OPTIMIZATIONS
 
     HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString()

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fd026f53/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java
index ccea6e5..70cf87d 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java
@@ -304,8 +304,10 @@ public class LocalDirAllocator {
         dirDF = dfList.toArray(new DF[dirs.size()]);
         savedLocalDirs = newLocalDirs;
         
-        // randomize the first disk picked in the round-robin selection 
-        dirNumLastAccessed = dirIndexRandomizer.nextInt(dirs.size());
+        if (dirs.size() > 0) {
+          // randomize the first disk picked in the round-robin selection
+          dirNumLastAccessed = dirIndexRandomizer.nextInt(dirs.size());
+        }
       }
     }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fd026f53/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java
index 2e31174..8cbe283 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java
@@ -458,4 +458,21 @@ public class TestLocalDirAllocator {
     }
   }
 
+  /**
+   * Test to check the LocalDirAllocation for the invalid path HADOOP-8437
+   *
+   * @throws Exception
+   */
+  @Test(timeout = 30000)
+  public void testGetLocalPathForWriteForInvalidPaths() throws Exception {
+    conf.set(CONTEXT, " ");
+    try {
+      dirAllocator.getLocalPathForWrite("/test", conf);
+      fail("not throwing the exception");
+    } catch (IOException e) {
+      assertEquals("Incorrect exception message",
+          "No space available in any of the local directories.", 
e.getMessage());
+    }
+  }
+
 }

Reply via email to