HBASE-11707 Using Map instead of list in FailedServers of RpcClient (Liu Shaohui)
Signed-off-by: Michael Stack <stack@apache.org>
This commit is contained in:
parent
e89baeaf93
commit
f1b97a6aa0
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue