You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2022/01/13 11:49:19 UTC
[shardingsphere] branch master updated: fix for start transaction error in pg and opengauss (#14735)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 39f1a8e fix for start transaction error in pg and opengauss (#14735)
39f1a8e is described below
commit 39f1a8e06b6a9cea67af064886c1668befd86a13
Author: JingShang Lu <lu...@apache.org>
AuthorDate: Thu Jan 13 19:48:24 2022 +0800
fix for start transaction error in pg and opengauss (#14735)
* fix for start transaction error in pg and opengauss
* fix
* fix
---
.../TransactionBackendHandlerFactory.java | 3 ++-
.../command/query/PostgreSQLCommand.java | 28 +++++++++++-----------
.../statement/tcl/StartTransactionStatement.java} | 11 ++++-----
.../tcl/OpenGaussStartTransactionStatement.java | 4 ++--
.../tcl/PostgreSQLStartTransactionStatement.java | 4 ++--
5 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactory.java
index 4b7480c..3c3cc1f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactory.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.BroadcastDatabaseBackendHandler;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.BeginTransactionStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.StartTransactionStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.CommitStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.ReleaseSavepointStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.RollbackStatement;
@@ -49,7 +50,7 @@ public final class TransactionBackendHandlerFactory {
*/
public static TextProtocolBackendHandler newInstance(final SQLStatementContext<? extends TCLStatement> sqlStatementContext, final String sql, final ConnectionSession connectionSession) {
TCLStatement tclStatement = sqlStatementContext.getSqlStatement();
- if (tclStatement instanceof BeginTransactionStatement) {
+ if (tclStatement instanceof BeginTransactionStatement || tclStatement instanceof StartTransactionStatement) {
return new TransactionBackendHandler(tclStatement, TransactionOperationType.BEGIN, connectionSession);
}
if (tclStatement instanceof SetAutoCommitStatement) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
index c762463..c4c0f1d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
@@ -22,11 +22,13 @@ import org.apache.shardingsphere.distsql.parser.statement.rdl.create.AddResource
import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.AnalyzeTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ResetParameterStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.VacuumStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterFunctionStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterProcedureStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterSequenceStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTablespaceStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterViewStatement;
@@ -34,12 +36,15 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatab
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateFunctionStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateProcedureStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateSequenceStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTablespaceStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropDatabaseStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropFunctionStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropProcedureStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropSequenceStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTablespaceStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
@@ -50,18 +55,13 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DoStatement
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.BeginTransactionStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.CommitStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.ReleaseSavepointStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.RollbackStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.SavepointStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.SetTransactionStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLResetParameterStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterSequenceStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateSequenceStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateTablespaceStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropSequenceStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.tcl.PostgreSQLBeginTransactionStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.tcl.PostgreSQLStartTransactionStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.StartTransactionStatement;
import java.util.Arrays;
import java.util.Collection;
@@ -87,7 +87,7 @@ public enum PostgreSQLCommand {
ALTER_FUNCTION(AlterFunctionStatement.class),
ALTER_INDEX(AlterIndexStatement.class),
ALTER_PROCEDURE(AlterProcedureStatement.class),
- ALTER_SEQUENCE(PostgreSQLAlterSequenceStatement.class),
+ ALTER_SEQUENCE(AlterSequenceStatement.class),
ALTER_TABLESPACE(AlterTablespaceStatement.class),
ALTER_TABLE(AlterTableStatement.class),
ALTER_VIEW(AlterViewStatement.class),
@@ -96,27 +96,27 @@ public enum PostgreSQLCommand {
CREATE_FUNCTION(CreateFunctionStatement.class),
CREATE_INDEX(CreateIndexStatement.class),
CREATE_PROCEDURE(CreateProcedureStatement.class),
- CREATE_SEQUENCE(PostgreSQLCreateSequenceStatement.class),
- CREATE_TABLESPACE(PostgreSQLCreateTablespaceStatement.class),
+ CREATE_SEQUENCE(CreateSequenceStatement.class),
+ CREATE_TABLESPACE(CreateTablespaceStatement.class),
CREATE_TABLE(CreateTableStatement.class),
CREATE_VIEW(CreateViewStatement.class),
DROP_DATABASE(DropDatabaseStatement.class),
DROP_FUNCTION(DropFunctionStatement.class),
DROP_INDEX(DropIndexStatement.class),
DROP_PROCEDURE(DropProcedureStatement.class),
- DROP_SEQUENCE(PostgreSQLDropSequenceStatement.class),
+ DROP_SEQUENCE(DropSequenceStatement.class),
DROP_TABLESPACE(DropTablespaceStatement.class),
DROP_TABLE(DropTableStatement.class),
DROP_VIEW(DropViewStatement.class),
TRUNCATE_TABLE(TruncateStatement.class),
- BEGIN(PostgreSQLBeginTransactionStatement.class),
- START_TRANSACTION(PostgreSQLStartTransactionStatement.class),
+ BEGIN(BeginTransactionStatement.class),
+ START_TRANSACTION(StartTransactionStatement.class),
COMMIT(CommitStatement.class),
SAVEPOINT(SavepointStatement.class),
ROLLBACK(RollbackStatement.class),
RELEASE(ReleaseSavepointStatement.class),
SET(SetStatement.class, SetTransactionStatement.class),
- RESET(PostgreSQLResetParameterStatement.class);
+ RESET(ResetParameterStatement.class);
private static final Map<Class<? extends SQLStatement>, Optional<PostgreSQLCommand>> COMPUTED_CLASSES = new ConcurrentHashMap<>(64, 1);
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/tcl/OpenGaussStartTransactionStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/tcl/StartTransactionStatement.java
similarity index 68%
copy from shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/tcl/OpenGaussStartTransactionStatement.java
copy to shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/tcl/StartTransactionStatement.java
index 553a7c2..6240ed5 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/tcl/OpenGaussStartTransactionStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/tcl/StartTransactionStatement.java
@@ -15,15 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.tcl;
+package org.apache.shardingsphere.sql.parser.sql.common.statement.tcl;
-import lombok.ToString;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.BeginTransactionStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
/**
- * OpenGauss start transaction statement.
+ * Start transaction statement.
*/
-@ToString
-public final class OpenGaussStartTransactionStatement extends BeginTransactionStatement implements OpenGaussStatement {
+public abstract class StartTransactionStatement extends AbstractSQLStatement implements TCLStatement {
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/tcl/OpenGaussStartTransactionStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/tcl/OpenGaussStartTransactionStatement.java
index 553a7c2..cb40979 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/tcl/OpenGaussStartTransactionStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/tcl/OpenGaussStartTransactionStatement.java
@@ -18,12 +18,12 @@
package org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.tcl;
import lombok.ToString;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.BeginTransactionStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.StartTransactionStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement;
/**
* OpenGauss start transaction statement.
*/
@ToString
-public final class OpenGaussStartTransactionStatement extends BeginTransactionStatement implements OpenGaussStatement {
+public final class OpenGaussStartTransactionStatement extends StartTransactionStatement implements OpenGaussStatement {
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/tcl/PostgreSQLStartTransactionStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/tcl/PostgreSQLStartTransactionStatement.java
index 9fe8b22..303f816 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/tcl/PostgreSQLStartTransactionStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/tcl/PostgreSQLStartTransactionStatement.java
@@ -18,12 +18,12 @@
package org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.tcl;
import lombok.ToString;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.BeginTransactionStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.StartTransactionStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement;
/**
* PostgreSQL start transaction statement.
*/
@ToString
-public final class PostgreSQLStartTransactionStatement extends BeginTransactionStatement implements PostgreSQLStatement {
+public final class PostgreSQLStartTransactionStatement extends StartTransactionStatement implements PostgreSQLStatement {
}