Skip to content

Commit a66db0f

Browse files
committed
HADOOP-19387: Fix LocalDirAllocator::getLocalPathForWrite unable to recover when the thread is interrupted
1 parent f38d707 commit a66db0f

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ private Context confChanged(Configuration conf)
346346
}
347347
ctx.localDirs = dirs.toArray(new Path[dirs.size()]);
348348
ctx.dirDF = dfList.toArray(new DF[dirs.size()]);
349-
ctx.savedLocalDirs = newLocalDirs;
350349

351350
if (dirs.size() > 0) {
351+
ctx.savedLocalDirs = newLocalDirs;
352352
// randomize the first disk picked in the round-robin selection
353353
ctx.dirNumLastAccessed.set(dirIndexRandomizer.nextInt(dirs.size()));
354354
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,5 +567,23 @@ public void testDirectoryRecovery() throws Throwable {
567567
// and expect to get a new file back
568568
dirAllocator.getLocalPathForWrite("file2", -1, conf);
569569
}
570+
571+
/**
572+
* Test for HADOOP-19387 LocalDirAllocator cannot recover after thread interruption.
573+
*/
574+
@Test(timeout = 30000)
575+
public void testInterruptionRecovery() throws Throwable {
576+
577+
String dir0 = buildBufferDir(ROOT, 7);
578+
conf.set(CONTEXT, dir0);
579+
try {
580+
Thread.currentThread().interrupt();
581+
assertThrows(DiskErrorException.class, () -> dirAllocator.getLocalPathForWrite("file2", 1, conf));
582+
} finally {
583+
Thread.interrupted();
584+
}
585+
// expect to get a file with no exceptions
586+
dirAllocator.getLocalPathForWrite("file2", 1, conf);
587+
}
570588
}
571589

0 commit comments

Comments
 (0)