HDFS-16923. [SBN read] getlisting RPC to observer will throw NPE if path does not exist (#5400)

Signed-off-by: Erik Krogen <xkrogen@apache.org>

(cherry picked from commit 6bd2444815)
This commit is contained in:
ZanderXu 2023-03-02 08:18:38 +08:00 committed by Erik Krogen
parent 91ce13ea01
commit a7c1fad0c9
2 changed files with 13 additions and 1 deletions

View File

@ -4090,7 +4090,7 @@ DirectoryListing getListing(String src, byte[] startAfter,
logAuditEvent(false, operationName, src); logAuditEvent(false, operationName, src);
throw e; throw e;
} }
if (needLocation && isObserver()) { if (dl != null && needLocation && isObserver()) {
for (HdfsFileStatus fs : dl.getPartialListing()) { for (HdfsFileStatus fs : dl.getPartialListing()) {
if (fs instanceof HdfsLocatedFileStatus) { if (fs instanceof HdfsLocatedFileStatus) {
LocatedBlocks lbs = ((HdfsLocatedFileStatus) fs).getLocatedBlocks(); LocatedBlocks lbs = ((HdfsLocatedFileStatus) fs).getLocatedBlocks();

View File

@ -64,6 +64,7 @@
import org.apache.hadoop.hdfs.server.namenode.TestFsck; import org.apache.hadoop.hdfs.server.namenode.TestFsck;
import org.apache.hadoop.hdfs.tools.GetGroups; import org.apache.hadoop.hdfs.tools.GetGroups;
import org.apache.hadoop.ipc.ObserverRetryOnActiveException; import org.apache.hadoop.ipc.ObserverRetryOnActiveException;
import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.concurrent.HadoopExecutors; import org.apache.hadoop.util.concurrent.HadoopExecutors;
import org.junit.After; import org.junit.After;
@ -608,6 +609,17 @@ public void run() {
} }
} }
@Test
public void testGetListingForDeletedDir() throws Exception {
Path path = new Path("/dir1/dir2/testFile");
dfs.create(path).close();
assertTrue(dfs.delete(new Path("/dir1/dir2"), true));
LambdaTestUtils.intercept(FileNotFoundException.class,
() -> dfs.listLocatedStatus(new Path("/dir1/dir2")));
}
@Test @Test
public void testSimpleReadEmptyDirOrFile() throws IOException { public void testSimpleReadEmptyDirOrFile() throws IOException {
// read empty dir // read empty dir