Skip to content

Commit

Permalink
testOnBorrows takes no effect when backend connection was take direct…
Browse files Browse the repository at this point in the history
…ly from connection pool (#2519)
  • Loading branch information
PanternBao authored Mar 12, 2021
1 parent 478515e commit 07c5f6b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,33 +127,35 @@ public void getConnection(final String schema, final ResponseHandler handler,
throw new IOException("primary dbInstance switched");
}

BackendConnection con = (BackendConnection) connectionPool.borrowDirectly(schema);
if (con != null) {
if (!StringUtil.equals(con.getSchema(), schema)) {
// need do sharding syn in before sql send
con.setSchema(schema);
if (!config.getPoolConfig().getTestOnBorrow()) {
BackendConnection con = (BackendConnection) connectionPool.borrowDirectly(schema);
if (con != null) {
if (!StringUtil.equals(con.getSchema(), schema)) {
// need do sharding syn in before sql send
con.setSchema(schema);
}
TraceManager.crossThread(con.getBackendService(), "backend-response-service", service);
con.getBackendService().setAttachment(attachment);
handler.connectionAcquired(con);
return;
}
TraceManager.crossThread(con.getBackendService(), "backend-response-service", service);
con.getBackendService().setAttachment(attachment);
handler.connectionAcquired(con);
return;
}

DbleServer.getInstance().getComplexQueryExecutor().execute(() -> {
BackendConnection con1;
BackendConnection conn;
try {
con1 = getConnection(schema, config.getPoolConfig().getConnectionTimeout());
conn = getConnection(schema, config.getPoolConfig().getConnectionTimeout());
} catch (IOException e) {
handler.connectionError(e, attachment);
return;
}
if (!StringUtil.equals(con1.getSchema(), schema)) {
if (!StringUtil.equals(conn.getSchema(), schema)) {
// need do sharding syn in before sql send
con1.setSchema(schema);
conn.setSchema(schema);
}
TraceManager.crossThread(con1.getBackendService(), "backend-response-service", service);
con1.getBackendService().setAttachment(attachment);
handler.connectionAcquired(con1);
TraceManager.crossThread(conn.getBackendService(), "backend-response-service", service);
conn.getBackendService().setAttachment(attachment);
handler.connectionAcquired(conn);
});
} finally {
TraceManager.finishSpan(traceObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ private void newPooledEntry(final String schema, final int waiting) {
}
}


public void release(final PooledConnection conn) {
if (poolConfig.getTestOnReturn()) {
ConnectionHeartBeatHandler heartBeatHandler = new ConnectionHeartBeatHandler((BackendConnection) conn, false, this);
Expand Down

0 comments on commit 07c5f6b

Please sign in to comment.