Skip to content

Commit

Permalink
RoundRobinLoadBalancer enhancement (vesoft-inc#357)
Browse files Browse the repository at this point in the history
* send yield command as ping, for fail fast
* use ConcurrentHashMap instead of HashMap, to avoid volatile problem
  • Loading branch information
heziai authored Jan 17, 2022
1 parent e9935d7 commit ad4463b
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.vesoft.nebula.client.graph.exception.ClientServerIncompatibleException;
import com.vesoft.nebula.client.graph.exception.IOErrorException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand All @@ -20,7 +20,7 @@ public class RoundRobinLoadBalancer implements LoadBalancer {
private static final int S_OK = 0;
private static final int S_BAD = 1;
private final List<HostAddress> addresses = new ArrayList<>();
private final Map<HostAddress, Integer> serversStatus = new HashMap<>();
private final Map<HostAddress, Integer> serversStatus = new ConcurrentHashMap<>();
private final int timeout;
private final AtomicInteger pos = new AtomicInteger(0);
private final int delayTime = 60; // unit seconds
Expand Down Expand Up @@ -80,8 +80,9 @@ public boolean ping(HostAddress addr) {
} else {
connection.open(addr, this.timeout);
}
boolean pong = connection.ping();
connection.close();
return true;
return pong;
} catch (IOErrorException | ClientServerIncompatibleException e) {
return false;
}
Expand Down

0 comments on commit ad4463b

Please sign in to comment.