You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2022/09/07 11:40:34 UTC
[shardingsphere] branch master updated: Reuse StartNestedXATransactionException (#20861)
This is an automated email from the ASF dual-hosted git repository.
yx9o 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 b0945c70987 Reuse StartNestedXATransactionException (#20861)
b0945c70987 is described below
commit b0945c709872cadbba52878e7e39cae26f48d6d7
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Sep 7 19:40:23 2022 +0800
Reuse StartNestedXATransactionException (#20861)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../StartNestedXATransactionException.java | 33 ++++++++++++++++++++++
.../handler/transaction/TransactionXAHandler.java | 5 ++--
4 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 3ad4d917de0..a7ac7840620 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -36,6 +36,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 25000 | 11320 | Switch transaction type failed, please terminate the current transaction |
| 25000 | 11321 | JDBC does not support operations across multiple logical databases in transaction |
| 25000 | 11322 | Failed to create \`%s\` XA data source |
+| 25000 | 11323 | Can not start new XA transaction in a active transaction |
| 42S02 | 11400 | Can not get traffic execution unit |
| 42000 | 12000 | Unsupported command: %s |
| 44000 | 13000 | SQL check failed, error message: %s |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index eb7241cc4c9..51a760c69c0 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -36,6 +36,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| 25000 | 11320 | Switch transaction type failed, please terminate the current transaction |
| 25000 | 11321 | JDBC does not support operations across multiple logical databases in transaction |
| 25000 | 11322 | Failed to create \`%s\` XA data source |
+| 25000 | 11323 | Can not start new XA transaction in a active transaction |
| 42S02 | 11400 | Can not get traffic execution unit |
| 42000 | 12000 | Unsupported command: %s |
| 44000 | 13000 | SQL check failed, error message: %s |
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/exception/StartNestedXATransactionException.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/exception/StartNestedXATransactionException.java
new file mode 100644
index 00000000000..287231fc28f
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/exception/StartNestedXATransactionException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.exception;
+
+import org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException;
+import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Start nested XA transaction exception.
+ */
+public final class StartNestedXATransactionException extends ShardingSphereSQLException {
+
+ private static final long serialVersionUID = 7761100591709104351L;
+
+ public StartNestedXATransactionException() {
+ super(XOpenSQLState.INVALID_TRANSACTION_STATE, 11323, "Can not start new XA transaction in a active transaction");
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
index 9ce6b9f5625..cfefb146e7f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.TCLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.XAStatement;
+import org.apache.shardingsphere.transaction.exception.StartNestedXATransactionException;
import java.sql.SQLException;
import java.util.Collections;
@@ -67,12 +68,12 @@ public final class TransactionXAHandler implements ProxyBackendHandler {
switch (tclStatement.getOp()) {
case "START":
case "BEGIN":
- /**
+ /*
* we have to let session occupy the thread when doing xa transaction.
* according to https://dev.mysql.com/doc/refman/5.7/en/xa-states.html XA and local transactions are mutually exclusive
*/
if (connectionSession.getTransactionStatus().isInTransaction()) {
- throw new SQLException("can not start in a Active transaction");
+ throw new StartNestedXATransactionException();
}
ResponseHeader header = backendHandler.execute();
connectionSession.getConnectionContext().getTransactionConnectionContext().setInTransaction(true);