You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/05/14 04:50:00 UTC
[shardingsphere] branch master updated: Fix sonar issue of TransactionRule (#25654)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 7fa106466d3 Fix sonar issue of TransactionRule (#25654)
7fa106466d3 is described below
commit 7fa106466d3c20379ddb444663522014209181d4
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun May 14 12:49:49 2023 +0800
Fix sonar issue of TransactionRule (#25654)
---
.../transaction/rule/TransactionRule.java | 22 ++++++++++++++++------
.../consistencycheck/ConsistencyCheckJobTest.java | 2 +-
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
index 2fdb584cd20..a251583ac9b 100644
--- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
+++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Transaction rule.
@@ -51,7 +52,7 @@ public final class TransactionRule implements GlobalRule, ResourceHeldRule<Shard
private final Map<String, ShardingSphereDatabase> databases;
- private volatile ShardingSphereTransactionManagerEngine resource;
+ private final AtomicReference<ShardingSphereTransactionManagerEngine> resource;
public TransactionRule(final TransactionRuleConfiguration ruleConfig, final Map<String, ShardingSphereDatabase> databases) {
configuration = ruleConfig;
@@ -59,7 +60,7 @@ public final class TransactionRule implements GlobalRule, ResourceHeldRule<Shard
providerType = ruleConfig.getProviderType();
props = ruleConfig.getProps();
this.databases = new ConcurrentHashMap<>(databases);
- resource = createTransactionManagerEngine(this.databases);
+ resource = new AtomicReference<>(createTransactionManagerEngine(this.databases));
}
private synchronized ShardingSphereTransactionManagerEngine createTransactionManagerEngine(final Map<String, ShardingSphereDatabase> databases) {
@@ -81,6 +82,15 @@ public final class TransactionRule implements GlobalRule, ResourceHeldRule<Shard
return result;
}
+ /**
+ * Get resource.
+ *
+ * @return resource
+ */
+ public ShardingSphereTransactionManagerEngine getResource() {
+ return resource.get();
+ }
+
@Override
public synchronized void addResource(final ShardingSphereDatabase database) {
// TODO process null when for information_schema
@@ -107,18 +117,18 @@ public final class TransactionRule implements GlobalRule, ResourceHeldRule<Shard
}
private void rebuildEngine() {
- ShardingSphereTransactionManagerEngine previousEngine = resource;
+ ShardingSphereTransactionManagerEngine previousEngine = resource.get();
if (null != previousEngine) {
closeEngine(previousEngine);
}
- resource = createTransactionManagerEngine(databases);
+ resource.set(createTransactionManagerEngine(databases));
}
private void closeEngine() {
- ShardingSphereTransactionManagerEngine engine = resource;
+ ShardingSphereTransactionManagerEngine engine = resource.get();
if (null != engine) {
closeEngine(engine);
- resource = new ShardingSphereTransactionManagerEngine();
+ resource.set(new ShardingSphereTransactionManagerEngine());
}
}
diff --git a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobTest.java b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobTest.java
index 0dcd41a9279..a94f97f7405 100644
--- a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobTest.java
+++ b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobTest.java
@@ -47,7 +47,7 @@ class ConsistencyCheckJobTest {
}
@Test
- void assertBuildPipelineJobItemContext() throws ReflectiveOperationException {
+ void assertBuildPipelineJobItemContext() {
ConsistencyCheckJobId pipelineJobId = new ConsistencyCheckJobId(PipelineContextKey.buildForProxy(), JobConfigurationBuilder.createYamlMigrationJobConfiguration().getJobId());
String checkJobId = new ConsistencyCheckJobAPI().marshalJobId(pipelineJobId);
Map<String, Object> expectTableCheckPosition = Collections.singletonMap("t_order", 100);