15
15
import com .xxdb .data .*;
16
16
import com .xxdb .data .Void ;
17
17
import com .xxdb .io .*;
18
-
18
+ import org .slf4j .Logger ;
19
+ import org .slf4j .LoggerFactory ;
19
20
import javax .net .ssl .SSLContext ;
20
21
import javax .net .ssl .SSLSocketFactory ;
21
22
import javax .net .ssl .TrustManager ;
@@ -55,6 +56,7 @@ public class DBConnection {
55
56
private int [] serverVersion_ ;
56
57
private boolean isReverseStreaming_ = false ;
57
58
59
+ private static final Logger log = LoggerFactory .getLogger (DBConnection .class );
58
60
59
61
private enum ServerExceptionState {
60
62
NEW_LEADER , WAIT , CONN_FAIL , OTHER_EXCEPTION , DATA_NODE_NOT_AVAILABLE
@@ -200,6 +202,7 @@ private boolean connect()throws IOException{
200
202
socket_ .connect (new InetSocketAddress (hostName_ ,port_ ), 3000 );
201
203
}
202
204
} catch (ConnectException ex ) {
205
+ log .error ("Connect to " + this .hostName_ + ":" + this .port_ + " failed." );
203
206
throw ex ;
204
207
}
205
208
if (this .connTimeout_ > 0 ) {
@@ -251,6 +254,7 @@ private boolean connect()throws IOException{
251
254
}
252
255
}
253
256
257
+ log .info ("Connect to " + this .hostName_ + ":" + this .port_ + " successfully." );
254
258
return true ;
255
259
}
256
260
@@ -838,7 +842,7 @@ public boolean connect(String hostName, int port, String userId, String password
838
842
}
839
843
840
844
if (pMinNode != null && !pMinNode .equals (connectedNode )){
841
- System . out . println ("Switch to node: " + pMinNode .hostName + ":" + pMinNode .port );
845
+ log . info ("Switch to node: " + pMinNode .hostName + ":" + pMinNode .port );
842
846
conn_ .close ();
843
847
switchDataNode (pMinNode );
844
848
}
@@ -880,14 +884,17 @@ public void switchDataNode(Node node) throws IOException{
880
884
do {
881
885
if (node .hostName != null && node .hostName .length () > 0 ){
882
886
if (connectNode (node )){
887
+ log .info ("Switch to node: " + node .hostName + ":" + node .port + " successfully." );
883
888
break ;
884
889
}
885
890
}
886
891
if (nodes_ .isEmpty ()){
887
- throw new RuntimeException ("Failed to connect to " + node .hostName + ":" + node .port );
892
+ log .error ("Connect to " + node .hostName + ":" + node .port + " failed." );
893
+ throw new RuntimeException ("Connect to " + node .hostName + ":" + node .port + " failed." );
888
894
}
889
895
int index = nodeRandom_ .nextInt (nodes_ .size ());
890
896
if (connectNode (nodes_ .get (index ))){
897
+ log .info ("Switch to node: " + nodes_ .get (index ).hostName + ":" + nodes_ .get (index ).port + " successfully." );
891
898
break ;
892
899
}
893
900
try {
@@ -903,7 +910,7 @@ public void switchDataNode(Node node) throws IOException{
903
910
}
904
911
905
912
public boolean connectNode (Node node ) throws IOException {
906
- System . out . println ("Connect to " + node .hostName + ":" + node .port + "." );
913
+ log . info ("Connect to " + node .hostName + ":" + node .port + "." );
907
914
while (!closed_ ){
908
915
try {
909
916
return conn_ .connect (node .hostName , node .port , uid_ , pwd_ , connTimeout_ );
0 commit comments