fix(agent): avoid validation contention on active JDBC pools
Closes #5567
This commit is contained in:
5 files changed
+73
-4
No files matched your search
@@ -278,6 +278,10 @@ public abstract class AbstractJdbcAgent extends BaseDatabaseAgent {
|
||||
return poolRegistry != null;
|
||||
}
|
||||
|
||||
final synchronized boolean hasActivePooledLeases() {
|
||||
return poolRegistry != null && poolIdentity != null && poolRegistry.hasActiveLeases(poolIdentity);
|
||||
}
|
||||
|
||||
final synchronized boolean quarantinePooledConnection() {
|
||||
pooledConnectionPoisoned = true;
|
||||
return requestActive && pooledLease != null && pooledLease.quarantine();
|
||||
|
||||
@@ -125,6 +125,11 @@ final class JdbcConnectionPoolRegistry implements AutoCloseable {
|
||||
return physicalConnectionBudget.activeCount();
|
||||
}
|
||||
|
||||
boolean hasActiveLeases(String identity) {
|
||||
PoolEntry entry = pools.get(digest(identity));
|
||||
return entry != null && entry.hasActiveLeases();
|
||||
}
|
||||
|
||||
private PoolEntry createPoolEntry(String key, ConnectionFactory connectionFactory) {
|
||||
try {
|
||||
ConnectionFactoryDataSource factoryDataSource = new ConnectionFactoryDataSource(
|
||||
@@ -695,6 +700,10 @@ final class JdbcConnectionPoolRegistry implements AutoCloseable {
|
||||
return retired;
|
||||
}
|
||||
|
||||
private synchronized boolean hasActiveLeases() {
|
||||
return activeLeases > 0;
|
||||
}
|
||||
|
||||
private void retireAfterCheckoutFailure(OperationDeadline deadline) {
|
||||
synchronized (this) {
|
||||
retired = true;
|
||||
|
||||
@@ -91,6 +91,11 @@ public final class JsonRpcServer {
|
||||
Object dispatchForRuntime(String method, JsonObject params) throws Exception {
|
||||
return AgentExecutionContext.withJdbcExecutor(jdbcExecutor, () -> {
|
||||
AbstractJdbcAgent jdbcAgent = pooledJdbcAgent();
|
||||
if (AgentProtocol.METHOD_VALIDATE_CONNECTION.equals(method)
|
||||
&& jdbcAgent != null
|
||||
&& jdbcAgent.hasActivePooledLeases()) {
|
||||
return Collections.singletonMap("ok", true);
|
||||
}
|
||||
boolean manageConnection = jdbcAgent != null && requiresConnectedConnection(method);
|
||||
if (manageConnection) {
|
||||
jdbcAgent.beginPooledRequest();
|
||||
|
||||
Reference in new issue
Block a user