You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by xk...@apache.org on 2023/03/04 00:33:03 UTC
[hadoop] 02/02: HDFS-16923. [SBN read] getlisting RPC to observer will throw NPE if path does not exist (#5400)
This is an automated email from the ASF dual-hosted git repository.
xkrogen pushed a commit to branch branch-3.3.5
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit d4ea9687a8e818179fd39e8c453b6c23b178ecb6
Author: ZanderXu <za...@apache.org>
AuthorDate: Thu Mar 2 08:18:38 2023 +0800
HDFS-16923. [SBN read] getlisting RPC to observer will throw NPE if path does not exist (#5400)
Signed-off-by: Erik Krogen <xk...@apache.org>
(cherry picked from commit 6bd24448154fcd3ab9099d7783cc7f7f76c61e08)
(cherry picked from commit a7c1fad0c9a675195579c971962ddd32e5d9fc51)
---
.../org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java | 2 +-
.../hadoop/hdfs/server/namenode/ha/TestObserverNode.java | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index c7046708bae..e8f243bd275 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -4087,7 +4087,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
logAuditEvent(false, operationName, src);
throw e;
}
- if (needLocation && isObserver()) {
+ if (dl != null && needLocation && isObserver()) {
for (HdfsFileStatus fs : dl.getPartialListing()) {
if (fs instanceof HdfsLocatedFileStatus) {
LocatedBlocks lbs = ((HdfsLocatedFileStatus) fs).getLocatedBlocks();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java
index d7e2d118549..178f2fcde90 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java
@@ -64,6 +64,7 @@ import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.hdfs.server.namenode.TestFsck;
import org.apache.hadoop.hdfs.tools.GetGroups;
import org.apache.hadoop.ipc.ObserverRetryOnActiveException;
+import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.concurrent.HadoopExecutors;
import org.junit.After;
@@ -608,6 +609,17 @@ public class TestObserverNode {
}
}
+ @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
public void testSimpleReadEmptyDirOrFile() throws IOException {
// read empty dir
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org