Skip to content

Commit a4d7884

Browse files
author
chengyitian
committed
AJ-742: optimize single connection reconnect nums logic; optimize log info for enable high sites when init connect;
1 parent a06af2e commit a4d7884

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/com/xxdb/DBConnection.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,10 @@ public boolean connect(String hostName, int port, String userId, String password
793793
}
794794
}
795795

796-
if (attempt == totalConnectAttemptNums)
796+
if (attempt == totalConnectAttemptNums) {
797+
log.error("Connect failed after " + attempt + " reconnect attemps for every node in high availability sites.");
797798
return false;
799+
}
798800
} else {
799801
// infinite try to connect.
800802
for (Node one : nodes_) {
@@ -950,11 +952,13 @@ public void switchDataNode(Node node) throws IOException{
950952
throw new RuntimeException("Connect to " + node.hostName + ":" + node.port + " failed.");
951953
}
952954

953-
int index = nodeRandom_.nextInt(nodes_.size());
954-
if (connectNode(nodes_.get(index))){
955-
log.info("Switch to node: " + nodes_.get(index).hostName + ":" + nodes_.get(index).port + " successfully.");
956-
isConnected = true;
957-
break;
955+
if (nodes_.size() > 1) {
956+
int index = nodeRandom_.nextInt(nodes_.size());
957+
if (connectNode(nodes_.get(index))){
958+
log.info("Switch to node: " + nodes_.get(index).hostName + ":" + nodes_.get(index).port + " successfully.");
959+
isConnected = true;
960+
break;
961+
}
958962
}
959963

960964
try {

0 commit comments

Comments
 (0)