Skip to content

Commit 6bd2444

Browse files
authored
HDFS-16923. [SBN read] getlisting RPC to observer will throw NPE if path does not exist (#5400)
Signed-off-by: Erik Krogen <[email protected]>
1 parent e1ca466 commit 6bd2444

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4174,7 +4174,7 @@ DirectoryListing getListing(String src, byte[] startAfter,
41744174
logAuditEvent(false, operationName, src);
41754175
throw e;
41764176
}
4177-
if (needLocation && isObserver()) {
4177+
if (dl != null && needLocation && isObserver()) {
41784178
for (HdfsFileStatus fs : dl.getPartialListing()) {
41794179
if (fs instanceof HdfsLocatedFileStatus) {
41804180
LocatedBlocks lbs = ((HdfsLocatedFileStatus) fs).getLocatedBlocks();

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.apache.hadoop.ipc.ObserverRetryOnActiveException;
7272
import org.apache.hadoop.ipc.metrics.RpcMetrics;
7373
import org.apache.hadoop.test.GenericTestUtils;
74+
import org.apache.hadoop.test.LambdaTestUtils;
7475
import org.apache.hadoop.util.Time;
7576
import org.apache.hadoop.util.concurrent.HadoopExecutors;
7677
import org.junit.After;
@@ -652,6 +653,17 @@ public void run() {
652653
}
653654
}
654655

656+
@Test
657+
public void testGetListingForDeletedDir() throws Exception {
658+
Path path = new Path("/dir1/dir2/testFile");
659+
dfs.create(path).close();
660+
661+
assertTrue(dfs.delete(new Path("/dir1/dir2"), true));
662+
663+
LambdaTestUtils.intercept(FileNotFoundException.class,
664+
() -> dfs.listLocatedStatus(new Path("/dir1/dir2")));
665+
}
666+
655667
@Test
656668
public void testSimpleReadEmptyDirOrFile() throws IOException {
657669
// read empty dir

0 commit comments

Comments
 (0)