diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java index 868cdc681b6..238b7a3fdbd 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java @@ -18,8 +18,10 @@ package org.apache.hadoop.hbase.ipc; import java.net.InetSocketAddress; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; +import java.util.Map; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.classification.InterfaceAudience; @@ -31,7 +33,8 @@ import org.apache.hadoop.hbase.util.Pair; */ @InterfaceAudience.Private public class FailedServers { - private final LinkedList> failedServers = new LinkedList<>(); + private final Map failedServers = new HashMap(); + private long latestExpiry = 0; private final int recheckServersTimeout; public FailedServers(Configuration conf) { @@ -44,7 +47,8 @@ public class FailedServers { */ public synchronized void addToFailedServers(InetSocketAddress address) { final long expiry = EnvironmentEdgeManager.currentTime() + recheckServersTimeout; - failedServers.addFirst(new Pair<>(expiry, address.toString())); + this.failedServers.put(address.toString(), expiry); + this.latestExpiry = expiry; } /** @@ -56,23 +60,21 @@ public class FailedServers { if (failedServers.isEmpty()) { return false; } - - final String lookup = address.toString(); final long now = EnvironmentEdgeManager.currentTime(); - - // iterate, looking for the search entry and cleaning expired entries - Iterator> it = failedServers.iterator(); - while (it.hasNext()) { - Pair cur = it.next(); - if (cur.getFirst() < now) { - it.remove(); - } else { - if (lookup.equals(cur.getSecond())) { - return true; - } - } + if (now > this.latestExpiry) { + failedServers.clear(); + return false; + } + String key = address.toString(); + Long expiry = this.failedServers.get(key); + if (expiry == null) { + return false; + } + if (expiry >= now) { + return true; + } else { + this.failedServers.remove(key); } - return false; } }