File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -908,33 +908,39 @@ private void initConnection() throws IOException{
908
908
909
909
public void switchDataNode (Node node ) throws IOException {
910
910
int attempt = 0 ;
911
+ boolean isConnected = false ;
911
912
do {
912
913
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 )) {
915
916
log .info ("Switch to node: " + node .hostName + ":" + node .port + " successfully." );
917
+ isConnected = true ;
916
918
break ;
917
919
}
918
920
}
921
+
919
922
if (nodes_ .isEmpty ()){
920
923
log .error ("com.xxdb.DBConnection.switchDataNode nodes_ is empty. Current node hostName: " + node .hostName + ", port: " + node .port );
921
924
log .error ("Connect to " + node .hostName + ":" + node .port + " failed." );
922
925
throw new RuntimeException ("Connect to " + node .hostName + ":" + node .port + " failed." );
923
926
}
927
+
924
928
int index = nodeRandom_ .nextInt (nodes_ .size ());
925
929
if (connectNode (nodes_ .get (index ))){
926
930
log .info ("Switch to node: " + nodes_ .get (index ).hostName + ":" + nodes_ .get (index ).port + " successfully." );
931
+ isConnected = true ;
927
932
break ;
928
933
}
934
+
929
935
try {
930
936
Thread .sleep (1000 );
931
- }catch (Exception e ){
937
+ } catch (Exception e ){
932
938
e .printStackTrace ();
933
939
return ;
934
940
}
935
941
} while (!closed_ && (tryReconnectNums == -1 || attempt < tryReconnectNums ));
936
942
937
- if (!closed_ && tryReconnectNums > 0 )
943
+ if (!closed_ && ! isConnected )
938
944
throw new RuntimeException ("Connect to " + node .hostName + ":" + node .port + " failed after " + attempt + " reconnect attemps." );
939
945
940
946
if (initialScript_ !=null && initialScript_ .length () > 0 ){
You can’t perform that action at this time.
0 commit comments