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 af8b1e2f599 Refactor SetDistVariableExecutor (#32365)
af8b1e2f599 is described below
commit af8b1e2f59945942d713345ac1ba59a2e35515b0
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 2 00:28:08 2024 +0800
Refactor SetDistVariableExecutor (#32365)
---
.../mode/metadata/MetaDataContextsFactory.java | 11 ++++++-----
.../ral/updatable/SetDistVariableExecutor.java | 20 ++++++++++++++++++--
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java
index a3997acad3d..f1c5385d14e 100644
---
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java
+++
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java
@@ -112,7 +112,7 @@ public final class MetaDataContextsFactory {
if (isDatabaseMetaDataExisted) {
restoreRules(result, computeNodeInstanceContext);
} else {
- persistDatabaseConfigurations(result, param, persistService);
+ persistDatabaseConfigurations(result, param, persistService,
computeNodeInstanceContext);
persistMetaData(result, persistService);
}
return result;
@@ -223,8 +223,9 @@ public final class MetaDataContextsFactory {
}
}
- private static void persistDatabaseConfigurations(final MetaDataContexts
metadataContexts, final ContextManagerBuilderParameter param, final
MetaDataPersistService persistService) {
-
persistService.persistGlobalRuleConfiguration(decorateGlobalRuleConfigurations(param.getGlobalRuleConfigs()),
param.getProps());
+ private static void persistDatabaseConfigurations(final MetaDataContexts
metadataContexts, final ContextManagerBuilderParameter param, final
MetaDataPersistService persistService,
+ final
ComputeNodeInstanceContext computeNodeInstanceContext) {
+
persistService.persistGlobalRuleConfiguration(decorateGlobalRuleConfigurations(param.getGlobalRuleConfigs(),
computeNodeInstanceContext), param.getProps());
for (Entry<String, ? extends DatabaseConfiguration> entry :
param.getDatabaseConfigs().entrySet()) {
String databaseName = entry.getKey();
persistService.persistConfigurations(entry.getKey(),
entry.getValue(),
@@ -235,11 +236,11 @@ public final class MetaDataContextsFactory {
}
@SuppressWarnings({"rawtypes", "unchecked"})
- private static Collection<RuleConfiguration>
decorateGlobalRuleConfigurations(final Collection<RuleConfiguration>
globalRuleConfigs) {
+ private static Collection<RuleConfiguration>
decorateGlobalRuleConfigurations(final Collection<RuleConfiguration>
globalRuleConfigs, final ComputeNodeInstanceContext computeNodeInstanceContext)
{
Collection<RuleConfiguration> result = new LinkedList<>();
for (RuleConfiguration each : globalRuleConfigs) {
Optional<RulePersistDecorator> rulePersistDecorator =
TypedSPILoader.findService(RulePersistDecorator.class, each.getClass());
- result.add(rulePersistDecorator.isPresent() ?
rulePersistDecorator.get().decorate(each) : each);
+ result.add(rulePersistDecorator.isPresent() &&
computeNodeInstanceContext.isCluster() ?
rulePersistDecorator.get().decorate(each) : each);
}
return result;
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java
index d3b04aef273..409d46e4a5d 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java
@@ -24,6 +24,7 @@ import
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExec
import
org.apache.shardingsphere.distsql.statement.ral.updatable.SetDistVariableStatement;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.kernel.syntax.InvalidVariableValueException;
import
org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException;
@@ -31,13 +32,18 @@ import
org.apache.shardingsphere.infra.props.TypedPropertyKey;
import org.apache.shardingsphere.infra.props.TypedPropertyValue;
import
org.apache.shardingsphere.infra.props.exception.TypedPropertyValueException;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.logging.constant.LoggingConstants;
import org.apache.shardingsphere.logging.util.LoggingUtils;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.mode.spi.RulePersistDecorator;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Optional;
import java.util.Properties;
/**
@@ -101,7 +107,7 @@ public final class SetDistVariableExecutor implements
DistSQLUpdateExecutor<SetD
if (LoggingConstants.SQL_SHOW.equalsIgnoreCase(propertyKey.getKey())) {
LoggingUtils.getSQLLogger(metaDataContexts.getMetaData().getGlobalRuleMetaData()).ifPresent(option
-> {
option.getProps().setProperty(LoggingConstants.SQL_LOG_ENABLE,
value);
-
contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().persist(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations());
+ decorateGlobalRuleConfiguration(contextManager);
});
}
}
@@ -110,11 +116,21 @@ public final class SetDistVariableExecutor implements
DistSQLUpdateExecutor<SetD
if
(LoggingConstants.SQL_SIMPLE.equalsIgnoreCase(propertyKey.getKey())) {
LoggingUtils.getSQLLogger(metaDataContexts.getMetaData().getGlobalRuleMetaData()).ifPresent(option
-> {
option.getProps().setProperty(LoggingConstants.SQL_LOG_SIMPLE,
value);
-
contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().persist(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations());
+ decorateGlobalRuleConfiguration(contextManager);
});
}
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private void decorateGlobalRuleConfiguration(final ContextManager
contextManager) {
+ Collection<RuleConfiguration> globalRuleConfigs = new LinkedList<>();
+ for (RuleConfiguration each :
contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getConfigurations())
{
+ Optional<RulePersistDecorator> rulePersistDecorator =
TypedSPILoader.findService(RulePersistDecorator.class, each);
+ globalRuleConfigs.add(rulePersistDecorator.isPresent() &&
contextManager.getComputeNodeInstanceContext().isCluster() ?
rulePersistDecorator.get().decorate(each) : each);
+ }
+
contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().persist(globalRuleConfigs);
+ }
+
@Override
public Class<SetDistVariableStatement> getType() {
return SetDistVariableStatement.class;