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 a62dbd0 fix generate narayana config file when user define the
transaction props (#16009)
a62dbd0 is described below
commit a62dbd05363d87aae51b9d7a946cff0a61556d48
Author: JingShang Lu <[email protected]>
AuthorDate: Sun Mar 13 12:50:09 2022 +0800
fix generate narayana config file when user define the transaction props
(#16009)
---
.../mode/metadata/persist/MetaDataPersistService.java | 10 ++++++----
.../mode/manager/cluster/ClusterContextManagerBuilder.java | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
index 37552d9..62c73a8 100644
---
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.mode.metadata.persist;
+import com.google.common.base.Preconditions;
import lombok.Getter;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.schema.SchemaConfiguration;
@@ -39,6 +40,7 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Properties;
/**
@@ -152,10 +154,10 @@ public final class MetaDataPersistService {
*/
public void persistTransactionRule(final Properties props, final boolean
isOverwrite) {
Collection<RuleConfiguration> ruleConfigurations =
globalRuleService.load();
- for (RuleConfiguration each : ruleConfigurations) {
- if (each instanceof TransactionRuleConfiguration) {
- ((TransactionRuleConfiguration) each).getProps().putAll(props);
- }
+ Optional<RuleConfiguration> ruleConfiguration =
ruleConfigurations.stream().filter(each -> each instanceof
TransactionRuleConfiguration).findFirst();
+ Preconditions.checkState(ruleConfiguration.isPresent());
+ if (props.equals(((TransactionRuleConfiguration)
ruleConfiguration.get()).getProps())) {
+ return;
}
globalRuleService.persist(ruleConfigurations, isOverwrite);
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 6253e39..83edd5e 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -84,7 +84,7 @@ public final class ClusterContextManagerBuilder implements
ContextManagerBuilder
Optional<TransactionConfigurationFileGenerator> fileGenerator =
transactionRule.isPresent()
?
TransactionConfigurationFileGeneratorFactory.newInstance(transactionRule.get().getProviderType())
: Optional.empty();
if (!schemaName.isPresent() || !fileGenerator.isPresent()) {
- return new Properties();
+ return transactionRule.isPresent() ?
transactionRule.get().getProps() : new Properties();
}
ShardingSphereMetaData metaData =
metaDataContexts.getMetaData(schemaName.get());
Properties result =
fileGenerator.get().getTransactionProps(transactionRule.get().getProps(),