Repository: hbase
Updated Branches:
  refs/heads/master e89baeaf9 -> f1b97a6aa


HBASE-11707 Using Map instead of list in FailedServers of RpcClient (Liu 
Shaohui)

Signed-off-by: Michael Stack <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/f1b97a6a
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/f1b97a6a
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/f1b97a6a

Branch: refs/heads/master
Commit: f1b97a6aa0206636cdfeafaad70af914e91979d3
Parents: e89baea
Author: Michael Stack <[email protected]>
Authored: Fri Jun 30 12:08:45 2017 -0700
Committer: Michael Stack <[email protected]>
Committed: Sat Jul 1 12:24:44 2017 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/ipc/FailedServers.java  | 36 +++++++++++---------
 1 file changed, 19 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/f1b97a6a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java
----------------------------------------------------------------------
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 868cdc6..238b7a3 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<Pair<Long, String>> failedServers = new 
LinkedList<>();
+  private final Map<String, Long> failedServers = new HashMap<String, Long>();
+  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<Pair<Long, String>> it = failedServers.iterator();
-    while (it.hasNext()) {
-      Pair<Long, String> 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;
   }
 }

Reply via email to