From 07f94056927d290fd6df2e5f87bf4a8f738e0c6d Mon Sep 17 00:00:00 2001 From: Zhihai Xu Date: Thu, 1 Oct 2015 11:56:49 -0700 Subject: [PATCH] HADOOP-8437. getLocalPathForWrite should throw IOException for invalid paths. Contributed by Brahma Reddy Battula (cherry picked from commit fd026f535cc09e99a7d4d5d2a8c13eabe8865315) --- 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(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 04a84f1ebbb..176cc11d791 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() 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 ccea6e5a2be..70cf87dc7a4 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()); + } } } 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 5f56f9a0fb6..ed2441054e6 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()); + } + } + }