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

fix_ha_client #21

Closed
wants to merge 1 commit into from
Closed
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 @@ -356,7 +356,7 @@ private TuGraphSingleRpcClient getClient(Lgraph.ProtoGraphQueryType type, String

private TuGraphSingleRpcClient getClient(boolean isReadQuery) throws Exception {
if (isReadQuery) {
if (rpcClientPool.size() == 0){
if (rpcClientPool.isEmpty()){
throw new Exception("all instance is down, refuse req!");
}
TuGraphSingleRpcClient rpcClient = rpcClientPool.get(rpcClientPool.size() - 1);
Expand Down Expand Up @@ -396,13 +396,17 @@ private void refreshClientPool() {
});
} else {
for (String url : urls) {
TuGraphSingleRpcClient rpcClient = new TuGraphSingleRpcClient("list://" + url, user, password);
String result = rpcClient.callCypher("CALL dbms.ha.clusterInfo()", "default", 10);
ClusterInfo clusterInfo = JSON.parseObject(JSON.parseArray(result).get(0).toString(), new TypeReference<ClusterInfo>(){});
if (clusterInfo.isMaster()) {
leaderClient = rpcClient;
try {
TuGraphSingleRpcClient rpcClient = new TuGraphSingleRpcClient("list://" + url, user, password);
String result = rpcClient.callCypher("CALL dbms.ha.clusterInfo()", "default", 10);
ClusterInfo clusterInfo = JSON.parseObject(JSON.parseArray(result).get(0).toString(), new TypeReference<ClusterInfo>(){});
if (clusterInfo.isMaster()) {
leaderClient = rpcClient;
}
rpcClientPool.add(rpcClient);
} catch (Exception e) {
log.error(e.getMessage());
}
rpcClientPool.add(rpcClient);
}
}
}
Expand Down Expand Up @@ -438,9 +442,9 @@ private <E> E doubleCheckQuery(QueryInterface<E> queryInterface) throws Exceptio
return queryInterface.method();
} catch (Exception e2) {
log.error(e2.getMessage());
throw e2;
}
}
return null;
}

private static class TuGraphSingleRpcClient {
Expand Down
Loading