Skip to content

Commit ad4463b

Browse files
authored
RoundRobinLoadBalancer enhancement (#357)
* send yield command as ping, for fail fast * use ConcurrentHashMap instead of HashMap, to avoid volatile problem
1 parent e9935d7 commit ad4463b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

client/src/main/java/com/vesoft/nebula/client/graph/net/RoundRobinLoadBalancer.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import com.vesoft.nebula.client.graph.exception.ClientServerIncompatibleException;
66
import com.vesoft.nebula.client.graph.exception.IOErrorException;
77
import java.util.ArrayList;
8-
import java.util.HashMap;
98
import java.util.List;
109
import java.util.Map;
10+
import java.util.concurrent.ConcurrentHashMap;
1111
import java.util.concurrent.Executors;
1212
import java.util.concurrent.ScheduledExecutorService;
1313
import java.util.concurrent.TimeUnit;
@@ -20,7 +20,7 @@ public class RoundRobinLoadBalancer implements LoadBalancer {
2020
private static final int S_OK = 0;
2121
private static final int S_BAD = 1;
2222
private final List<HostAddress> addresses = new ArrayList<>();
23-
private final Map<HostAddress, Integer> serversStatus = new HashMap<>();
23+
private final Map<HostAddress, Integer> serversStatus = new ConcurrentHashMap<>();
2424
private final int timeout;
2525
private final AtomicInteger pos = new AtomicInteger(0);
2626
private final int delayTime = 60; // unit seconds
@@ -80,8 +80,9 @@ public boolean ping(HostAddress addr) {
8080
} else {
8181
connection.open(addr, this.timeout);
8282
}
83+
boolean pong = connection.ping();
8384
connection.close();
84-
return true;
85+
return pong;
8586
} catch (IOErrorException | ClientServerIncompatibleException e) {
8687
return false;
8788
}

0 commit comments

Comments
 (0)