Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ public Path getLocalPathForWrite(String pathStr, long size,
Context ctx = confChanged(conf);
int numDirs = ctx.localDirs.length;
int numDirsSearched = 0;
long maxCapacity = 0;
//remove the leading slash from the path (to make sure that the uri
//resolution results in a valid path on the dir being checked)
if (pathStr.startsWith("/")) {
Expand Down Expand Up @@ -441,6 +442,9 @@ public Path getLocalPathForWrite(String pathStr, long size,
int dirNum = ctx.getAndIncrDirNumLastAccessed(randomInc);
while (numDirsSearched < numDirs) {
long capacity = ctx.dirDF[dirNum].getAvailable();
if (capacity > maxCapacity) {
maxCapacity = capacity;
}
if (capacity > size) {
returnPath =
createPath(ctx.localDirs[dirNum], pathStr, checkWrite);
Expand All @@ -460,7 +464,8 @@ public Path getLocalPathForWrite(String pathStr, long size,

//no path found
throw new DiskErrorException("Could not find any valid local " +
"directory for " + pathStr);
"directory for " + pathStr + " with requested size " + size +
" as the max capacity in any directory is " + maxCapacity);
}

/** Creates a file on the local FS. Pass size as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,23 @@ public void testGetLocalPathForWriteForInvalidPaths() throws Exception {
}
}

/**
* Test to check the LocalDirAllocation for the less space HADOOP-16769
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add trailing "." for javadocs

*
* @throws Exception
*/
@Test(timeout = 30000)
public void testGetLocalPathForWriteForLessSpace() throws Exception {
String dir0 = buildBufferDir(ROOT, 0);
String dir1 = buildBufferDir(ROOT, 1);
conf.set(CONTEXT, dir0 + "," + dir1);
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use LambaTestUtils.intercept, which will do the catch, reporting on failure and error message checks

dirAllocator.getLocalPathForWrite("p1/x", 3_000_000_000_000L, conf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's going to happen on a disk with >3TB of capacity? Should we go for a bigger number?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed updating the pull request. I have a new code change that uses Long.MAX_VALUE, instead of this hardcoded number and then use a regex to match the error message. I will create a new pull request

fail("not throwing the exception");
} catch (IOException e) {
assertTrue(e.getMessage().matches("Could not find any valid local directory for p1/x with requested " +
"size 3000000000000 as the max capacity in any directory is [0-9]*"));
}
}

}