Bladeren bron

HDFS-17768. Observer namenode network delay causing empty block location for getBatchedListing (#7593)

(cherry picked from commit caf8af0de3e63ba8423760582bc640d51f0d558b)
(cherry picked from commit 8eb2211b3ffa3e3b487093eee65a77d4c115737f)
Dimas Shidqi Parikesit 2 weken geleden
bovenliggende
commit
448bbe1b96

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

@@ -4188,11 +4188,22 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
           if (dirListing == null) {
             throw new FileNotFoundException("Path " + src + " does not exist");
           }
+          if (needLocation && isObserver()) {
+            for (HdfsFileStatus fs : dirListing.getPartialListing()) {
+              if (fs instanceof HdfsLocatedFileStatus) {
+                LocatedBlocks lbs = ((HdfsLocatedFileStatus) fs).getLocatedBlocks();
+                checkBlockLocationsWhenObserver(lbs, fs.toString());
+              }
+            }
+          }
           listing = new HdfsPartialListing(
               srcsIndex, Lists.newArrayList(dirListing.getPartialListing()));
           numEntries += listing.getPartialListing().size();
           lastListing = dirListing;
         } catch (Exception e) {
+          if (e instanceof ObserverRetryOnActiveException) {
+            throw (ObserverRetryOnActiveException) e;
+          }
           if (e instanceof AccessControlException) {
             logAuditEvent(false, operationName, src);
           }
@@ -4255,6 +4266,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
             true,
             returnedStartAfter);
       }
+    } catch(ObserverRetryOnActiveException e){
+      throw e;
     } finally {
       readUnlock(operationName);
     }

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

@@ -376,6 +376,9 @@ public class TestObserverNode {
     dfs.getClient().getLocatedFileInfo(testPath.toString(), false);
     assertSentTo(0);
 
+    dfs.getClient().batchedListPaths(new String[]{"/"}, new byte[0], true);
+    assertSentTo(0);
+
     Mockito.reset(bmSpy);
   }