From a54c3437af8ad5384bfd0f6f68ef0f45197fa4a8 Mon Sep 17 00:00:00 2001 From: Kihwal Lee Date: Wed, 9 Aug 2017 16:51:19 -0500 Subject: [PATCH] HDFS-12278. LeaseManager operations are inefficient in 2.8. Contributed by Rushabh S Shah. --- .../hdfs/server/namenode/LeaseManager.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java index e160c9f2bf4..99edc447429 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java @@ -26,9 +26,10 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; -import java.util.PriorityQueue; +import java.util.NavigableSet; import java.util.SortedMap; import java.util.TreeMap; +import java.util.TreeSet; import com.google.common.collect.Lists; import org.apache.commons.logging.Log; @@ -84,11 +85,15 @@ public class LeaseManager { // private final SortedMap leases = new TreeMap<>(); // Set of: Lease - private final PriorityQueue sortedLeases = new PriorityQueue<>(512, + private final NavigableSet sortedLeases = new TreeSet<>( new Comparator() { @Override public int compare(Lease o1, Lease o2) { - return Long.signum(o1.getLastUpdate() - o2.getLastUpdate()); + if (o1.getLastUpdate() != o2.getLastUpdate()) { + return Long.signum(o1.getLastUpdate() - o2.getLastUpdate()); + } else { + return o1.holder.compareTo(o2.holder); + } } }); // INodeID -> Lease @@ -428,9 +433,10 @@ public class LeaseManager { long start = monotonicNow(); - while(!sortedLeases.isEmpty() && sortedLeases.peek().expiredHardLimit() - && !isMaxLockHoldToReleaseLease(start)) { - Lease leaseToCheck = sortedLeases.peek(); + while(!sortedLeases.isEmpty() && + sortedLeases.first().expiredHardLimit() + && !isMaxLockHoldToReleaseLease(start)) { + Lease leaseToCheck = sortedLeases.first(); LOG.info(leaseToCheck + " has expired hard limit"); final List removing = new ArrayList<>();