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/10/18 12:12:30 UTC

[shardingsphere] branch master updated: Make field of MySQLServerPreparedStatement final (#21581)

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

zhangliang 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 86bb6651ace Make field of MySQLServerPreparedStatement final (#21581)
86bb6651ace is described below

commit 86bb6651acedaa275d6fe69a6bc00c55e68f7acf
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Tue Oct 18 20:12:22 2022 +0800

    Make field of MySQLServerPreparedStatement final (#21581)
---
 .../mysql/command/query/binary/MySQLServerPreparedStatement.java   | 7 ++++---
 .../command/query/binary/execute/MySQLComStmtExecuteExecutor.java  | 3 ++-
 .../query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java  | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/MySQLServerPreparedStatement.java b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/MySQLServerPreparedStatement.java
index f92d8e420d4..b11adb706f3 100644
--- a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/MySQLServerPreparedStatement.java
+++ b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/MySQLServerPreparedStatement.java
@@ -25,14 +25,15 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.proxy.backend.session.ServerPreparedStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * Binary prepared statement for MySQL.
+ * This class may be accessed serially in different threads due to MySQL Proxy using a shared unbounded thread pool.
  */
 @RequiredArgsConstructor
 @Getter
@@ -45,9 +46,9 @@ public final class MySQLServerPreparedStatement implements ServerPreparedStateme
     
     private final SQLStatementContext<?> sqlStatementContext;
     
-    private final Map<Integer, byte[]> longData = new ConcurrentHashMap<>();
+    private final List<MySQLPreparedStatementParameterType> parameterTypes = new CopyOnWriteArrayList<>();
     
-    private List<MySQLPreparedStatementParameterType> parameterTypes = Collections.emptyList();
+    private final Map<Integer, byte[]> longData = new ConcurrentHashMap<>();
     
     @Override
     public Optional<SQLStatementContext<?>> getSqlStatementContext() {
diff --git a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
index b792fd4e999..fc51a10da12 100644
--- a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
+++ b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
@@ -87,7 +87,8 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
     private MySQLServerPreparedStatement updateAndGetPreparedStatement() {
         MySQLServerPreparedStatement result = connectionSession.getServerPreparedStatementRegistry().getPreparedStatement(packet.getStatementId());
         if (MySQLNewParametersBoundFlag.PARAMETER_TYPE_EXIST == packet.getNewParametersBoundFlag()) {
-            result.setParameterTypes(packet.getNewParameterTypes());
+            result.getParameterTypes().clear();
+            result.getParameterTypes().addAll(packet.getNewParameterTypes());
         }
         return result;
     }
diff --git a/proxy/frontend/reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java b/proxy/frontend/reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
index 40afdd8a739..7c3b3da277f 100644
--- a/proxy/frontend/reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
+++ b/proxy/frontend/reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
@@ -127,7 +127,8 @@ public final class ReactiveMySQLComStmtExecuteExecutor implements ReactiveComman
     private MySQLServerPreparedStatement updateAndGetPreparedStatement() {
         MySQLServerPreparedStatement result = connectionSession.getServerPreparedStatementRegistry().getPreparedStatement(packet.getStatementId());
         if (MySQLNewParametersBoundFlag.PARAMETER_TYPE_EXIST == packet.getNewParametersBoundFlag()) {
-            result.setParameterTypes(packet.getNewParameterTypes());
+            result.getParameterTypes().clear();
+            result.getParameterTypes().addAll(packet.getNewParameterTypes());
         }
         return result;
     }