From a4d92b5f4641cd0f00a9dc64f83125a391c32dc5 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Wed, 21 Nov 2018 23:23:48 +0800 Subject: [PATCH] #1238 Release connection when create a new transaction. --- .../backend/jdbc/connection/BackendConnection.java | 8 ++++---- .../jdbc/connection/BackendTransactionManager.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendConnection.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendConnection.java index a708b6a5afdc4c..015d722a06b63b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendConnection.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendConnection.java @@ -185,9 +185,7 @@ public void close() throws SQLException { exceptions.addAll(closeStatements()); exceptions.addAll(closeResultSets()); if (ConnectionStatus.TERMINATED == status) { - exceptions.addAll(closeConnections()); - cachedConnections.clear(); - methodInvocations.clear(); + exceptions.addAll(releaseConnections()); } throwSQLExceptionIfNecessary(exceptions); } @@ -218,7 +216,7 @@ private Collection closeStatements() { return result; } - private Collection closeConnections() { + Collection releaseConnections() { Collection result = new LinkedList<>(); for (Connection each : cachedConnections.values()) { try { @@ -227,6 +225,8 @@ private Collection closeConnections() { result.add(ex); } } + cachedConnections.clear(); + methodInvocations.clear(); return result; } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendTransactionManager.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendTransactionManager.java index 2d90fd2fcdd07f..857e965def2a95 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendTransactionManager.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendTransactionManager.java @@ -56,7 +56,7 @@ public void doInTransaction(final TransactionOperationType operationType) throws } if (TransactionOperationType.BEGIN == operationType && ConnectionStatus.TRANSACTION != connection.getStatus()) { connection.setStatus(ConnectionStatus.TRANSACTION); - connection.getCachedConnections().clear(); + connection.releaseConnections(); } if (TransactionType.LOCAL == transactionType) { doLocalTransaction(operationType);