Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RoundRobinLoadBalancer enhancement #357

Merged
merged 5 commits into from
Jan 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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