Sfoglia il codice sorgente

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

Zhihai Xu 9 anni fa
parent
commit
fd026f535c

+ 3 - 0
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()

+ 4 - 2
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());
+        }
       }
     }
 

+ 17 - 0
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());
+    }
+  }
+
 }