File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1289,26 +1289,29 @@ public void switchDataNode(Node node) throws IOException{
12891289 boolean isConnected = false ;
12901290 do {
12911291 attempt ++;
1292- if (node .hostName != null && node .hostName .length () > 0 ) {
1292+ boolean ifReconnectSingleNodeTry = false ;
1293+ if (Utils .isNotEmpty (node .hostName )) {
12931294 if (connectNode (node )) {
12941295 if (nodes_ .size () > 1 )
12951296 log .info ("Switch to node: " + node .hostName + ":" + node .port + " successfully." );
12961297 isConnected = true ;
12971298 break ;
12981299 }
1299- } else {
1300- if (nodes_ .isEmpty ()){
1301- log .error ("Connect to " + node .hostName + ":" + node .port + " failed." );
1302- throw new RuntimeException ("Connect to " + node .hostName + ":" + node .port + " failed." );
1303- }
13041300
1305- int index = nodeRandom_ .nextInt (nodes_ .size ());
1306- if (connectNode (nodes_ .get (index ))) {
1307- if (nodes_ .size () > 1 )
1308- log .info ("Switch to node: " + nodes_ .get (index ).hostName + ":" + nodes_ .get (index ).port + " successfully." );
1309- isConnected = true ;
1310- break ;
1311- }
1301+ ifReconnectSingleNodeTry = nodes_ .size () == 1 ;
1302+ }
1303+
1304+ if (nodes_ .isEmpty ()){
1305+ log .error ("Connect to " + node .hostName + ":" + node .port + " failed." );
1306+ throw new RuntimeException ("Connect to " + node .hostName + ":" + node .port + " failed." );
1307+ }
1308+
1309+ int index = nodeRandom_ .nextInt (nodes_ .size ());
1310+ if (!ifReconnectSingleNodeTry && connectNode (nodes_ .get (index ))) {
1311+ if (nodes_ .size () > 1 )
1312+ log .info ("Switch to node: " + nodes_ .get (index ).hostName + ":" + nodes_ .get (index ).port + " successfully." );
1313+ isConnected = true ;
1314+ break ;
13121315 }
13131316
13141317 try {
Original file line number Diff line number Diff line change @@ -722,6 +722,10 @@ public static boolean isEmpty(CharSequence cs) {
722722 return cs == null || cs .length () == 0 ;
723723 }
724724
725+ public static boolean isNotEmpty (CharSequence cs ) {
726+ return cs != null && cs .length () > 0 ;
727+ }
728+
725729 private static final BigDecimal DECIMAL128_MIN_VALUE = new BigDecimal ("-170141183460469231731687303715884105728" );
726730 private static final BigDecimal DECIMAL128_MAX_VALUE = new BigDecimal ("170141183460469231731687303715884105728" );
727731
You can’t perform that action at this time.
0 commit comments