Просмотр исходного кода

HDFS-14419. Avoid repeated calls to the listOpenFiles function. Contributed by HuangTao.

Wei-Chiu Chuang 6 лет назад
Родитель
Сommit
99f88c30cb

+ 6 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java

@@ -25,6 +25,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.NavigableSet;
 import java.util.Set;
@@ -302,7 +303,9 @@ public class LeaseManager {
 
     int count = 0;
     String fullPathName = null;
-    for (Long inodeId: inodeIds) {
+    Iterator<Long> inodeIdIterator = inodeIds.iterator();
+    while (inodeIdIterator.hasNext()) {
+      Long inodeId = inodeIdIterator.next();
       final INodeFile inodeFile =
           fsnamesystem.getFSDirectory().getInode(inodeId).asFile();
       if (!inodeFile.isUnderConstruction()) {
@@ -323,7 +326,8 @@ public class LeaseManager {
         break;
       }
     }
-    boolean hasMore = (numResponses < remainingLeases.size());
+    // avoid rescanning all leases when we have checked all leases already
+    boolean hasMore = inodeIdIterator.hasNext();
     return new BatchedListEntries<>(openFileEntries, hasMore);
   }