diff --git a/rpc-client/src/main/java/com/antgroup/tugraph/TuGraphDbRpcClient.java b/rpc-client/src/main/java/com/antgroup/tugraph/TuGraphDbRpcClient.java index 1c711c4..e23504c 100644 --- a/rpc-client/src/main/java/com/antgroup/tugraph/TuGraphDbRpcClient.java +++ b/rpc-client/src/main/java/com/antgroup/tugraph/TuGraphDbRpcClient.java @@ -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); @@ -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(){}); - 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(){}); + if (clusterInfo.isMaster()) { + leaderClient = rpcClient; + } + rpcClientPool.add(rpcClient); + } catch (Exception e) { + log.error(e.getMessage()); } - rpcClientPool.add(rpcClient); } } } @@ -438,9 +442,9 @@ private E doubleCheckQuery(QueryInterface queryInterface) throws Exceptio return queryInterface.method(); } catch (Exception e2) { log.error(e2.getMessage()); - throw e2; } } + return null; } private static class TuGraphSingleRpcClient {