You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by lu...@apache.org on 2022/07/15 10:44:04 UTC
[shardingsphere] branch master updated: Fix alter local transaction rule (#19197)
This is an automated email from the ASF dual-hosted git repository.
lujingshang 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 66d18d1268e Fix alter local transaction rule (#19197)
66d18d1268e is described below
commit 66d18d1268e8019b7cf5cd9d3ed6ef8f8076f041
Author: Zhangcheng <fl...@outlook.com>
AuthorDate: Fri Jul 15 18:43:58 2022 +0800
Fix alter local transaction rule (#19197)
* Fix alter local transaction rule
* Add test cases for fix alter local transaction rule
---
.../src/main/antlr4/imports/RALStatement.g4 | 2 +-
.../core/common/CommonDistSQLStatementVisitor.java | 7 ++++--
.../transaction/rule/TransactionRule.java | 3 ---
.../xa/XAShardingSphereTransactionManager.java | 4 +++-
.../jaxb/cases/domain/SQLParserTestCases.java | 8 +++++++
...AlterLocalTransactionRuleStatementTestCase.java | 26 ++++++++++++++++++++++
.../AlterXATransactionRuleStatementTestCase.java | 26 ++++++++++++++++++++++
.../src/main/resources/case/ral/common.xml | 2 ++
.../main/resources/sql/supported/ral/common.xml | 2 ++
9 files changed, 73 insertions(+), 7 deletions(-)
diff --git a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4 b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
index 1355a75d02a..4c978393663 100644
--- a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
+++ b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
@@ -144,7 +144,7 @@ filePath
;
transactionRuleDefinition
- : LP DEFAULT EQ defaultType COMMA providerDefinition
+ : LP DEFAULT EQ defaultType (COMMA providerDefinition)?
;
providerDefinition
diff --git a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
index f8c6b888d0a..2458ba893d5 100644
--- a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
+++ b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
@@ -344,8 +344,11 @@ public final class CommonDistSQLStatementVisitor extends CommonDistSQLStatementB
@Override
public ASTNode visitTransactionRuleDefinition(final TransactionRuleDefinitionContext ctx) {
String defaultType = getIdentifierValue(ctx.defaultType());
- TransactionProviderSegment provider = (TransactionProviderSegment) visit(ctx.providerDefinition());
- return new AlterTransactionRuleStatement(defaultType, provider);
+ if (null != ctx.providerDefinition()) {
+ TransactionProviderSegment provider = (TransactionProviderSegment) visit(ctx.providerDefinition());
+ return new AlterTransactionRuleStatement(defaultType, provider);
+ }
+ return new AlterTransactionRuleStatement(defaultType, new TransactionProviderSegment(null, null));
}
@Override
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
index ec270376883..eec58026a72 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
@@ -83,7 +83,6 @@ public final class TransactionRule implements GlobalRule, ResourceHeldRule<Shard
if (null == database) {
return;
}
- databases.put(database.getName(), database);
rebuildEngine();
}
@@ -92,13 +91,11 @@ public final class TransactionRule implements GlobalRule, ResourceHeldRule<Shard
if (!databases.containsKey(databaseName)) {
return;
}
- databases.remove(databaseName);
rebuildEngine();
}
@Override
public synchronized void closeStaleResource() {
- databases.clear();
closeEngine();
}
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
index c4690e1fbd7..2b196d25c54 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
@@ -121,6 +121,8 @@ public final class XAShardingSphereTransactionManager implements ShardingSphereT
each.close();
}
cachedDataSources.clear();
- xaTransactionManagerProvider.close();
+ if (null != xaTransactionManagerProvider) {
+ xaTransactionManagerProvider.close();
+ }
}
}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index a81d02f9546..e2bb80d7a12 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -258,8 +258,10 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AddShardingHintDatabaseValueStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AddShardingHintTableValueStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterInstanceStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterLocalTransactionRuleStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterSQLParserRuleStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterTrafficRuleStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterXATransactionRuleStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ApplyDistSQLStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ClearHintStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ClearReadwriteSplittingHintStatementTestCase;
@@ -1270,6 +1272,12 @@ public final class SQLParserTestCases {
@XmlElement(name = "alter-sql-parser-rule")
private final List<AlterSQLParserRuleStatementTestCase> alterSQLParserRuleTestCases = new LinkedList<>();
+
+ @XmlElement(name = "alter-local-transaction-rule")
+ private final List<AlterLocalTransactionRuleStatementTestCase> alterLocalTransactionRuleTestCases = new LinkedList<>();
+
+ @XmlElement(name = "alter-xa-transaction-rule")
+ private final List<AlterXATransactionRuleStatementTestCase> alterXATransactionRuleTestCases = new LinkedList<>();
@XmlElement(name = "drop-traffic-rule")
private final List<DropTrafficRuleStatementTestCase> dropTrafficRuleTestCases = new LinkedList<>();
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterLocalTransactionRuleStatementTestCase.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterLocalTransactionRuleStatementTestCase.java
new file mode 100644
index 00000000000..622ad4de4fc
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterLocalTransactionRuleStatementTestCase.java
@@ -0,0 +1,26 @@
+/*
+ * 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.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral;
+
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+/**
+ * Alter local transaction rule statement test case.
+ */
+public final class AlterLocalTransactionRuleStatementTestCase extends SQLParserTestCase {
+}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterXATransactionRuleStatementTestCase.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterXATransactionRuleStatementTestCase.java
new file mode 100644
index 00000000000..f15486dd386
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterXATransactionRuleStatementTestCase.java
@@ -0,0 +1,26 @@
+/*
+ * 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.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral;
+
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+/**
+ * Alter XA transaction rule statement test case.
+ */
+public final class AlterXATransactionRuleStatementTestCase extends SQLParserTestCase {
+}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/common.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/common.xml
index 85048b05879..0558e13f92f 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/common.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/common.xml
@@ -49,6 +49,8 @@
<sql-statement-cache initial-capacity="11" maximum-size="11" />
</sql-parser>
</alter-sql-parser-rule>
+ <alter-local-transaction-rule sql-case-id="alter-local-transaction-rule" />
+ <alter-xa-transaction-rule sql-case-id="alter-xa-transaction-rule" />
<show-traffic-rules sql-case-id="show-traffic-rules" rule-name="rule_name" />
<drop-traffic-rule sql-case-id="drop-traffic-rule">
<rule-name>rule_name</rule-name>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/common.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/common.xml
index 9af1167a555..b21a79e33a4 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/common.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/common.xml
@@ -41,6 +41,8 @@
<distsql-case id="show-transaction-rule" value="SHOW TRANSACTION RULE" />
<distsql-case id="show-sql-parser-rule" value="SHOW SQL_PARSER RULE" />
<distsql-case id="alter-sql-parser-rule" value="ALTER SQL_PARSER RULE SQL_COMMENT_PARSE_ENABLE=false,PARSE_TREE_CACHE(INITIAL_CAPACITY=10, MAXIMUM_SIZE=11,CONCURRENCY_LEVEL=1), SQL_STATEMENT_CACHE(INITIAL_CAPACITY=11, MAXIMUM_SIZE=11,CONCURRENCY_LEVEL=100)" />
+ <distsql-case id="alter-local-transaction-rule" value="ALTER TRANSACTION RULE (DEFAULT=LOCAL)" />
+ <distsql-case id="alter-xa-transaction-rule" value="ALTER TRANSACTION RULE(DEFAULT=XA, TYPE(NAME=Atomikos))" />
<distsql-case id="show-traffic-rules" value="SHOW TRAFFIC RULE rule_name" />
<distsql-case id="drop-traffic-rule" value="DROP TRAFFIC RULE rule_name" />
<distsql-case id="export-database-config" value="EXPORT DATABASE CONFIG FROM database_name" />