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 2022/11/21 16:41:16 UTC

[hadoop] branch branch-3.3 updated: HDFS-16832. [SBN READ] Follow-on to HDFS-16732. Fix NPE when check the block location of empty directory (#5099)

This is an automated email from the ASF dual-hosted git repository.

xkrogen pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-3.3 by this push:
     new 4addf31ef42 HDFS-16832. [SBN READ] Follow-on to HDFS-16732. Fix NPE when check the block location of empty directory (#5099)
4addf31ef42 is described below

commit 4addf31ef42f603ccc496b680b0225a7cba5b0b1
Author: zhengchenyu <zh...@gmail.com>
AuthorDate: Tue Nov 22 00:26:16 2022 +0800

    HDFS-16832. [SBN READ] Follow-on to HDFS-16732. Fix NPE when check the block location of empty directory (#5099)
    
    Signed-off-by: Erik Krogen <xk...@apache.org>
    Reviewed-by: Zengqiang Xu <xu...@163.com>
    
    (cherry picked from commit dc2fba45fef68ff65488a1e587e6211cc3386188)
---
 .../hadoop/hdfs/server/namenode/FSNamesystem.java  | 12 ++++++++---
 .../hdfs/server/namenode/ha/TestObserverNode.java  | 23 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 3 deletions(-)

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 cb0cf39760e..c7046708bae 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
@@ -8747,9 +8747,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
 
   private void checkBlockLocationsWhenObserver(LocatedBlocks blocks, String src)
       throws ObserverRetryOnActiveException {
-    for (LocatedBlock b : blocks.getLocatedBlocks()) {
-      if (b.getLocations() == null || b.getLocations().length == 0) {
-        throw new ObserverRetryOnActiveException("Zero blocklocations for " + src);
+    if (blocks == null) {
+      return;
+    }
+    List<LocatedBlock> locatedBlockList = blocks.getLocatedBlocks();
+    if (locatedBlockList != null) {
+      for (LocatedBlock b : locatedBlockList) {
+        if (b.getLocations() == null || b.getLocations().length == 0) {
+          throw new ObserverRetryOnActiveException("Zero blocklocations for " + src);
+        }
       }
     }
   }
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 a9101171945..d7e2d118549 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
@@ -608,6 +608,29 @@ public class TestObserverNode {
     }
   }
 
+  @Test
+  public void testSimpleReadEmptyDirOrFile() throws IOException {
+    // read empty dir
+    dfs.mkdirs(new Path("/emptyDir"));
+    assertSentTo(0);
+
+    dfs.getClient().listPaths("/", new byte[0], true);
+    assertSentTo(2);
+
+    dfs.getClient().getLocatedFileInfo("/emptyDir", true);
+    assertSentTo(2);
+
+    // read empty file
+    dfs.create(new Path("/emptyFile"), (short)1);
+    assertSentTo(0);
+
+    dfs.getClient().getLocatedFileInfo("/emptyFile", true);
+    assertSentTo(2);
+
+    dfs.getClient().getBlockLocations("/emptyFile", 0, 1);
+    assertSentTo(2);
+  }
+
   private static void assertSentTo(DistributedFileSystem fs, int nnIdx)
       throws IOException {
     assertTrue("Request was not sent to the expected namenode " + nnIdx,


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org