Skip to content

Commit e202477

Browse files
author
chengyitian
committed
AJ-679: optimize error info when pool init connect faild; fix issue about DBConnection use highAvailabilitySites;
1 parent 90aa8c3 commit e202477

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/com/xxdb/DBConnection.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,12 +790,14 @@ public boolean connect(String hostName, int port, String userId, String password
790790

791791
if (bt!=null) {
792792
if (!loadBalance_) {
793-
BasicStringVector colHost = (BasicStringVector) bt.getColumn("host");
794-
BasicIntVector colPort = (BasicIntVector) bt.getColumn("port");
795-
for (int i = 0; i < colHost.rows(); i++) {
796-
Node curNode = new Node(colHost.getString(i), colPort.getInt(i));
797-
if (!(curNode.hostName.equals(hostName) && curNode.port == port))
798-
nodes_.add(curNode);
793+
if (highAvailabilitySites == null) {
794+
BasicStringVector colHost = (BasicStringVector) bt.getColumn("host");
795+
BasicIntVector colPort = (BasicIntVector) bt.getColumn("port");
796+
for (int i = 0; i < colHost.rows(); i++) {
797+
Node curNode = new Node(colHost.getString(i), colPort.getInt(i));
798+
if (!(curNode.hostName.equals(hostName) && curNode.port == port))
799+
nodes_.add(curNode);
800+
}
799801
}
800802
} else {
801803
// enable loadBalance

src/com/xxdb/ExclusiveDBConnectionPool.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,15 @@ public ExclusiveDBConnectionPool(String host, int port, String uid, String pwd,
8181
// not enable loadBalance
8282
for (int i=0; i<count; ++i) {
8383
DBConnection conn = new DBConnection(false, useSSL, compress, usePython);
84-
if(!conn.connect(host, port, uid, pwd, initialScript, enableHighAvailability, highAvailabilitySites, false, loadBalance))
85-
throw new RuntimeException("Can't connect to the specified host.");
84+
try {
85+
boolean isConnected = conn.connect(host, port, uid, pwd, initialScript, enableHighAvailability, highAvailabilitySites, false, loadBalance);
86+
if (!isConnected) {
87+
throw new RuntimeException("Can't connect to the specified host.");
88+
}
89+
} catch (Exception e) {
90+
throw new RuntimeException("Can't connect to the specified host: ", e);
91+
}
92+
8693
workers_.add(new AsyncWorker(conn));
8794
}
8895
} else {

0 commit comments

Comments
 (0)