Repository: hadoop
Updated Branches:
  refs/heads/branch-2 db145e0c9 -> 07f940569


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

(cherry picked from commit fd026f535cc09e99a7d4d5d2a8c13eabe8865315)


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

Branch: refs/heads/branch-2
Commit: 07f94056927d290fd6df2e5f87bf4a8f738e0c6d
Parents: db145e0
Author: Zhihai Xu <[email protected]>
Authored: Thu Oct 1 11:56:49 2015 -0700
Committer: Zhihai Xu <[email protected]>
Committed: Thu Oct 1 12:04:27 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/07f94056/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 04a84f1..176cc11 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -601,6 +601,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/07f94056/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/07f94056/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 5f56f9a..ed24410 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