You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/05/25 07:21:05 UTC

[shardingsphere] branch master updated: Optimize sql interception strength for scaling (#17932)

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

zhonghongsheng 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 6f9ae3ce31b Optimize sql interception strength for scaling (#17932)
6f9ae3ce31b is described below

commit 6f9ae3ce31bbb3e459c527f19dd3a55a07424d00
Author: gin <ja...@163.com>
AuthorDate: Wed May 25 15:20:59 2022 +0800

    Optimize sql interception strength for scaling (#17932)
---
 .../backend/communication/DatabaseCommunicationEngine.java  | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 17aca41b52a..d1b767626f0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -49,6 +49,8 @@ import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader
 import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
 import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
 
 import java.sql.SQLException;
@@ -231,9 +233,14 @@ public abstract class DatabaseCommunicationEngine<T> {
     }
     
     private void lockedWrite(final SQLStatement sqlStatement) {
-        if (sqlStatement instanceof SelectStatement) {
-            return;
+        if (sqlStatement instanceof DMLStatement) {
+            if (sqlStatement instanceof SelectStatement) {
+                return;
+            }
+            throw new DatabaseLockedException(backendConnection.getConnectionSession().getDatabaseName());
+        }
+        if (sqlStatement instanceof DDLStatement) {
+            throw new DatabaseLockedException(backendConnection.getConnectionSession().getDatabaseName());
         }
-        throw new DatabaseLockedException(backendConnection.getConnectionSession().getDatabaseName());
     }
 }