You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2021/04/25 04:57:02 UTC

[shardingsphere] branch master updated: Use running task count instead of is in use on backend connection (#10186)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new b3f0837  Use running task count instead of is in use on backend connection (#10186)
b3f0837 is described below

commit b3f08370c302ee171c8f50f878235e7e13ba5d76
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Apr 25 12:56:26 2021 +0800

    Use running task count instead of is in use on backend connection (#10186)
---
 .../backend/communication/jdbc/connection/BackendConnection.java    | 6 +++---
 .../shardingsphere/proxy/frontend/command/CommandExecutorTask.java  | 4 ++--
 .../proxy/frontend/postgresql/PostgreSQLFrontendEngine.java         | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java
index 46d16f41..7d1ebad 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java
@@ -50,6 +50,7 @@ import java.util.List;
 import java.util.Optional;
 import java.util.Properties;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Backend connection.
@@ -67,14 +68,13 @@ public final class BackendConnection implements ExecutorJDBCManager {
     private volatile int connectionId;
     
     @Setter
-    private volatile boolean inUse;
-    
-    @Setter
     private volatile Grantee grantee;
     
     @Setter
     private volatile CalciteExecutor calciteExecutor;
     
+    private final AtomicInteger runningTaskCount = new AtomicInteger(0);
+    
     private final Multimap<String, Connection> cachedConnections = LinkedHashMultimap.create();
     
     private final Collection<Statement> cachedStatements = new CopyOnWriteArrayList<>();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
index 1b24d48..23d8839 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
@@ -61,7 +61,7 @@ public final class CommandExecutorTask implements Runnable {
      */
     @Override
     public void run() {
-        backendConnection.setInUse(true);
+        backendConnection.getRunningTaskCount().incrementAndGet();
         boolean isNeedFlush = false;
         try (PacketPayload payload = databaseProtocolFrontendEngine.getCodecEngine().createPacketPayload((ByteBuf) message)) {
             ConnectionStatus connectionStatus = backendConnection.getConnectionStatus();
@@ -75,7 +75,7 @@ public final class CommandExecutorTask implements Runnable {
             // CHECKSTYLE:ON
             processException(ex);
         } finally {
-            backendConnection.setInUse(false);
+            backendConnection.getRunningTaskCount().decrementAndGet();
             Collection<SQLException> exceptions = closeExecutionResources();
             if (isNeedFlush) {
                 context.flush();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
index e3d1542..5ca3d7e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
@@ -52,7 +52,7 @@ public final class PostgreSQLFrontendEngine implements DatabaseProtocolFrontendE
     
     private void waitingForFinish(final BackendConnection backendConnection) {
         int tryTimes = 0;
-        while (backendConnection.isInUse() && tryTimes++ < 3) {
+        while (backendConnection.getRunningTaskCount().get() > 0 && tryTimes++ < 3) {
             try {
                 Thread.sleep(500L);
             } catch (final InterruptedException ex) {