Skip to content

Commit 0bd3b35

Browse files
author
chengyitian
committed
AJ-736: fix issue about tryReconnectNums;
1 parent 5396792 commit 0bd3b35

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/com/xxdb/DBConnection.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,33 +908,39 @@ private void initConnection() throws IOException{
908908

909909
public void switchDataNode(Node node) throws IOException{
910910
int attempt = 0;
911+
boolean isConnected = false;
911912
do {
912913
attempt ++;
913-
if (node.hostName != null && node.hostName.length() > 0){
914-
if (connectNode(node)){
914+
if (node.hostName != null && node.hostName.length() > 0) {
915+
if (connectNode(node)) {
915916
log.info("Switch to node: " + node.hostName + ":" + node.port + " successfully.");
917+
isConnected = true;
916918
break;
917919
}
918920
}
921+
919922
if (nodes_.isEmpty()){
920923
log.error("com.xxdb.DBConnection.switchDataNode nodes_ is empty. Current node hostName: " + node.hostName + ", port: " + node.port);
921924
log.error("Connect to " + node.hostName + ":" + node.port + " failed.");
922925
throw new RuntimeException("Connect to " + node.hostName + ":" + node.port + " failed.");
923926
}
927+
924928
int index = nodeRandom_.nextInt(nodes_.size());
925929
if (connectNode(nodes_.get(index))){
926930
log.info("Switch to node: " + nodes_.get(index).hostName + ":" + nodes_.get(index).port + " successfully.");
931+
isConnected = true;
927932
break;
928933
}
934+
929935
try {
930936
Thread.sleep(1000);
931-
}catch (Exception e){
937+
} catch (Exception e){
932938
e.printStackTrace();
933939
return;
934940
}
935941
} while (!closed_ && (tryReconnectNums == -1 || attempt < tryReconnectNums));
936942

937-
if (!closed_ && tryReconnectNums > 0)
943+
if (!closed_ && !isConnected)
938944
throw new RuntimeException("Connect to " + node.hostName + ":" + node.port + " failed after " + attempt + " reconnect attemps.");
939945

940946
if (initialScript_!=null && initialScript_.length() > 0){

0 commit comments

Comments
 (0)