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
549fb1677b
commit
f4c99a6a89
|
@ -18,8 +18,10 @@
|
||||||
package org.apache.hadoop.hbase.ipc;
|
package org.apache.hadoop.hbase.ipc;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
||||||
|
@ -31,7 +33,8 @@ import org.apache.hadoop.hbase.util.Pair;
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class FailedServers {
|
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;
|
private final int recheckServersTimeout;
|
||||||
|
|
||||||
public FailedServers(Configuration conf) {
|
public FailedServers(Configuration conf) {
|
||||||
|
@ -44,7 +47,8 @@ public class FailedServers {
|
||||||
*/
|
*/
|
||||||
public synchronized void addToFailedServers(InetSocketAddress address) {
|
public synchronized void addToFailedServers(InetSocketAddress address) {
|
||||||
final long expiry = EnvironmentEdgeManager.currentTime() + recheckServersTimeout;
|
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()) {
|
if (failedServers.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String lookup = address.toString();
|
|
||||||
final long now = EnvironmentEdgeManager.currentTime();
|
final long now = EnvironmentEdgeManager.currentTime();
|
||||||
|
if (now > this.latestExpiry) {
|
||||||
// iterate, looking for the search entry and cleaning expired entries
|
failedServers.clear();
|
||||||
Iterator<Pair<Long, String>> it = failedServers.iterator();
|
return false;
|
||||||
while (it.hasNext()) {
|
}
|
||||||
Pair<Long, String> cur = it.next();
|
String key = address.toString();
|
||||||
if (cur.getFirst() < now) {
|
Long expiry = this.failedServers.get(key);
|
||||||
it.remove();
|
if (expiry == null) {
|
||||||
} else {
|
return false;
|
||||||
if (lookup.equals(cur.getSecond())) {
|
}
|
||||||
|
if (expiry >= now) {
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
this.failedServers.remove(key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue