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 e78d0bd4c1d Remove useless RuleConfigurationPersistDecorator (#34322) e78d0bd4c1d is described below commit e78d0bd4c1d8c243c88074ede4a274cc22eee347 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Sun Jan 12 16:05:44 2025 +0800 Remove useless RuleConfigurationPersistDecorator (#34322) * Simplify MetaDataContextsFactory * Remove useless RuleConfigurationPersistDecorator --- .../spi/RuleConfigurationPersistDecorator.java | 66 ---------------- .../mode/metadata/MetaDataContextManager.java | 8 +- .../mode/metadata/MetaDataContextsFactory.java | 32 ++------ .../RuleConfigurationPersistDecorateEngine.java | 78 ------------------- ...RuleConfigurationPersistDecorateEngineTest.java | 91 ---------------------- .../handler/global/GlobalRuleChangedHandler.java | 8 +- .../ral/updatable/SetDistVariableExecutor.java | 10 +-- .../util/ClusterExportMetaDataGenerator.java | 8 +- 8 files changed, 14 insertions(+), 287 deletions(-) diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RuleConfigurationPersistDecorator.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RuleConfigurationPersistDecorator.java deleted file mode 100644 index dd6f12a5376..00000000000 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RuleConfigurationPersistDecorator.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.mode.spi; - -import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; - -/** - * Rule configuration persist decorator. - * - * @param <T> type of rule configuration - */ -@SingletonSPI -public interface RuleConfigurationPersistDecorator<T extends RuleConfiguration> extends TypedSPI { - - /** - * Decorate rule configuration. - * - * @param ruleConfig to be decorated rule configuration - * @return decorated rule configuration - */ - T decorate(T ruleConfig); - - /** - * Check whether the rule configuration can be restored. - * - * @param ruleConfig rule configuration to be checked - * @return can be restored or not - */ - boolean canBeRestored(T ruleConfig); - - /** - * Restore rule configuration. - * - * @param ruleConfig rule configuration to be restored - * @return restored rule configuration - */ - RuleConfiguration restore(T ruleConfig); - - /** - * Get rule type. - * - * @return rule type - */ - Class<? extends ShardingSphereRule> getRuleType(); - - @Override - Class<T> getType(); -} diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextManager.java index 145b4d232db..785a811f438 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextManager.java @@ -28,7 +28,6 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.manager.GenericSchemaManager; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; -import org.apache.shardingsphere.mode.metadata.decorator.RuleConfigurationPersistDecorateEngine; import org.apache.shardingsphere.mode.metadata.manager.DatabaseRuleConfigurationManager; import org.apache.shardingsphere.mode.metadata.manager.GlobalConfigurationManager; import org.apache.shardingsphere.mode.metadata.manager.ResourceSwitchManager; @@ -72,8 +71,6 @@ public class MetaDataContextManager { private final GlobalConfigurationManager globalConfigurationManager; - private final RuleConfigurationPersistDecorateEngine ruleConfigPersistDecorateEngine; - public MetaDataContextManager(final AtomicReference<MetaDataContexts> metaDataContexts, final ComputeNodeInstanceContext computeNodeInstanceContext, final PersistRepository repository) { this.metaDataContexts = metaDataContexts; this.computeNodeInstanceContext = computeNodeInstanceContext; @@ -85,7 +82,6 @@ public class MetaDataContextManager { ruleItemManager = new RuleItemManager(metaDataContexts, repository, databaseRuleConfigurationManager); globalConfigurationManager = new GlobalConfigurationManager(metaDataContexts, repository); metaDataPersistService = new MetaDataPersistService(repository); - ruleConfigPersistDecorateEngine = new RuleConfigurationPersistDecorateEngine(computeNodeInstanceContext); } /** @@ -154,8 +150,8 @@ public class MetaDataContextManager { .createChangedDatabase(database.getName(), false, switchingResource, ruleConfigs, metaDataContexts.get(), metaDataPersistService, computeNodeInstanceContext); metaDataContexts.get().getMetaData().putDatabase(changedDatabase); ConfigurationProperties props = new ConfigurationProperties(metaDataPersistService.getPropsService().load()); - RuleMetaData changedGlobalMetaData = new RuleMetaData(GlobalRulesBuilder.buildRules( - ruleConfigPersistDecorateEngine.restore(metaDataPersistService.getGlobalRuleService().load()), metaDataContexts.get().getMetaData().getAllDatabases(), props)); + Collection<RuleConfiguration> globalRuleConfigs = metaDataPersistService.getGlobalRuleService().load(); + RuleMetaData changedGlobalMetaData = new RuleMetaData(GlobalRulesBuilder.buildRules(globalRuleConfigs, metaDataContexts.get().getMetaData().getAllDatabases(), props)); ShardingSphereMetaData metaData = new ShardingSphereMetaData( metaDataContexts.get().getMetaData().getAllDatabases(), metaDataContexts.get().getMetaData().getGlobalResourceMetaData(), changedGlobalMetaData, props); MetaDataContexts result = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(metaDataPersistService, metaData)); 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 69b164fccd8..3e0ab1a1a21 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 @@ -37,21 +37,16 @@ import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUn import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereDatabaseData; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereSchemaData; -import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; -import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter; -import org.apache.shardingsphere.mode.metadata.decorator.RuleConfigurationPersistDecorateEngine; import org.apache.shardingsphere.mode.metadata.factory.ExternalMetaDataFactory; import org.apache.shardingsphere.mode.metadata.factory.InternalMetaDataFactory; import org.apache.shardingsphere.mode.metadata.manager.SwitchingResource; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; -import org.apache.shardingsphere.mode.spi.RuleConfigurationPersistDecorator; import javax.sql.DataSource; import java.sql.SQLException; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; @@ -98,9 +93,7 @@ public final class MetaDataContextsFactory { Collection<RuleConfiguration> globalRuleConfigs = persistService.getGlobalRuleService().load(); ConfigurationProperties props = new ConfigurationProperties(persistService.getPropsService().load()); Map<String, ShardingSphereDatabase> databases = InternalMetaDataFactory.create(persistService, effectiveDatabaseConfigs, props, instanceContext); - MetaDataContexts result = newMetaDataContexts(persistService, param, globalRuleConfigs, databases, props); - restoreRules(result, instanceContext); - return result; + return newMetaDataContexts(persistService, param, globalRuleConfigs, databases, props); } private static MetaDataContexts newMetaDataContexts(final MetaDataPersistService persistService, final ContextManagerBuilderParameter param, @@ -139,25 +132,10 @@ public final class MetaDataContextsFactory { } } - @SuppressWarnings({"unchecked", "rawtypes"}) - private static void restoreRules(final MetaDataContexts metaDataContexts, final ComputeNodeInstanceContext instanceContext) { - if (!instanceContext.getModeConfiguration().isCluster()) { - return; - } - for (RuleConfigurationPersistDecorator each : ShardingSphereServiceLoader.getServiceInstances(RuleConfigurationPersistDecorator.class)) { - ShardingSphereRule rule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(each.getRuleType()); - metaDataContexts.getMetaData().getGlobalRuleMetaData().getRules().removeIf(eachRule -> each.getRuleType() == eachRule.getClass()); - RuleConfiguration restoredRuleConfig = each.restore(rule.getConfiguration()); - ShardingSphereRule rebuiltRule = GlobalRulesBuilder.buildRules( - Collections.singleton(restoredRuleConfig), metaDataContexts.getMetaData().getAllDatabases(), metaDataContexts.getMetaData().getProps()).iterator().next(); - metaDataContexts.getMetaData().getGlobalRuleMetaData().getRules().add(rebuiltRule); - } - } - - private static void persistDatabaseConfigurations(final MetaDataContexts metadataContexts, final ContextManagerBuilderParameter param, final MetaDataPersistService persistService, - final ComputeNodeInstanceContext instanceContext) { - RuleConfigurationPersistDecorateEngine ruleConfigPersistDecorateEngine = new RuleConfigurationPersistDecorateEngine(instanceContext); - persistService.persistGlobalRuleConfiguration(ruleConfigPersistDecorateEngine.decorate(metadataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations()), param.getProps()); + private static void persistDatabaseConfigurations(final MetaDataContexts metadataContexts, + final ContextManagerBuilderParameter param, final MetaDataPersistService persistService, final ComputeNodeInstanceContext instanceContext) { + Collection<RuleConfiguration> globalRuleConfigs = metadataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations(); + persistService.persistGlobalRuleConfiguration(globalRuleConfigs, param.getProps()); for (Entry<String, ? extends DatabaseConfiguration> entry : param.getDatabaseConfigs().entrySet()) { String databaseName = entry.getKey(); persistService.persistConfigurations(entry.getKey(), entry.getValue(), diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/decorator/RuleConfigurationPersistDecorateEngine.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/decorator/RuleConfigurationPersistDecorateEngine.java deleted file mode 100644 index af1a4dbade5..00000000000 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/decorator/RuleConfigurationPersistDecorateEngine.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.mode.metadata.decorator; - -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.spi.RuleConfigurationPersistDecorator; - -import java.util.Collection; -import java.util.stream.Collectors; - -/** - * Rule configuration persist decorate engine. - */ -@RequiredArgsConstructor -public final class RuleConfigurationPersistDecorateEngine { - - private final ComputeNodeInstanceContext computeNodeInstanceContext; - - /** - * Decorate rule configurations. - * - * @param ruleConfigs to be decorated rule configurations - * @return decorated rule configurations - */ - @SuppressWarnings("unchecked") - public Collection<RuleConfiguration> decorate(final Collection<RuleConfiguration> ruleConfigs) { - if (!computeNodeInstanceContext.getModeConfiguration().isCluster()) { - return ruleConfigs; - } - return ruleConfigs.stream() - .map(each -> TypedSPILoader.findService(RuleConfigurationPersistDecorator.class, each.getClass()).map(optional -> optional.decorate(each)).orElse(each)).collect(Collectors.toList()); - } - - /** - * Restore rule configurations. - * - * @param ruleConfigs to be restored rule configurations - * @return restored rule configurations - */ - @SuppressWarnings("unchecked") - public Collection<RuleConfiguration> restore(final Collection<RuleConfiguration> ruleConfigs) { - if (!computeNodeInstanceContext.getModeConfiguration().isCluster()) { - return ruleConfigs; - } - return ruleConfigs.stream() - .map(each -> TypedSPILoader.findService(RuleConfigurationPersistDecorator.class, each.getClass()).map(optional -> optional.restore(each)).orElse(each)).collect(Collectors.toList()); - } - - /** - * Try to restore rule configurations. - * - * @param ruleConfigs to be restored rule configurations - * @return restored rule configurations - */ - @SuppressWarnings("unchecked") - public Collection<RuleConfiguration> tryRestore(final Collection<RuleConfiguration> ruleConfigs) { - return ruleConfigs.stream().map(each -> TypedSPILoader.findService(RuleConfigurationPersistDecorator.class, each.getClass()) - .filter(optional -> optional.canBeRestored(each)).map(optional -> optional.restore(each)).orElse(each)).collect(Collectors.toList()); - } -} diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/decorator/RuleConfigurationPersistDecorateEngineTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/decorator/RuleConfigurationPersistDecorateEngineTest.java deleted file mode 100644 index 5c5d4644ff9..00000000000 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/decorator/RuleConfigurationPersistDecorateEngineTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.mode.metadata.decorator; - -import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.spi.RuleConfigurationPersistDecorator; -import org.apache.shardingsphere.test.mock.AutoMockExtension; -import org.apache.shardingsphere.test.mock.StaticMockSettings; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Answers; -import org.mockito.Mock; - -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@ExtendWith(AutoMockExtension.class) -@StaticMockSettings(TypedSPILoader.class) -class RuleConfigurationPersistDecorateEngineTest { - - private RuleConfigurationPersistDecorateEngine decorateEngine; - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ComputeNodeInstanceContext computeNodeInstanceContext; - - @BeforeEach - void setUp() { - decorateEngine = new RuleConfigurationPersistDecorateEngine(computeNodeInstanceContext); - } - - @Test - void assertDecorateIfNotClusterMode() { - Collection<RuleConfiguration> ruleConfigs = Collections.singleton(mock(RuleConfiguration.class)); - assertThat(decorateEngine.decorate(ruleConfigs), is(ruleConfigs)); - } - - @Test - void assertDecorateIfClusterMode() { - when(computeNodeInstanceContext.getModeConfiguration().isCluster()).thenReturn(true); - when(TypedSPILoader.findService(eq(RuleConfigurationPersistDecorator.class), any())).thenReturn(Optional.empty()); - Collection<RuleConfiguration> ruleConfigs = Collections.singletonList(mock(RuleConfiguration.class)); - assertThat(decorateEngine.decorate(ruleConfigs), is(ruleConfigs)); - } - - @Test - void assertRestoreIfNotClusterMode() { - Collection<RuleConfiguration> ruleConfigs = Collections.singleton(mock(RuleConfiguration.class)); - assertThat(decorateEngine.restore(ruleConfigs), is(ruleConfigs)); - } - - @Test - void assertRestoreIfClusterMode() { - when(computeNodeInstanceContext.getModeConfiguration().isCluster()).thenReturn(true); - when(TypedSPILoader.findService(eq(RuleConfigurationPersistDecorator.class), any())).thenReturn(Optional.empty()); - Collection<RuleConfiguration> ruleConfigs = Collections.singletonList(mock(RuleConfiguration.class)); - assertThat(decorateEngine.restore(ruleConfigs), is(ruleConfigs)); - } - - @Test - void assertTryRestore() { - when(TypedSPILoader.findService(eq(RuleConfigurationPersistDecorator.class), any())).thenReturn(Optional.empty()); - Collection<RuleConfiguration> ruleConfigs = Collections.singletonList(mock(RuleConfiguration.class)); - assertThat(decorateEngine.tryRestore(ruleConfigs), is(ruleConfigs)); - } -} diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/GlobalRuleChangedHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/GlobalRuleChangedHandler.java index fef06a5ffae..639f1ce7422 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/GlobalRuleChangedHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/GlobalRuleChangedHandler.java @@ -19,14 +19,12 @@ package org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global; import com.google.common.base.Preconditions; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.metadata.persist.node.GlobalNodePath; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.cluster.dispatch.checker.ActiveVersionChecker; import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.DataChangedEventHandler; -import org.apache.shardingsphere.mode.spi.RuleConfigurationPersistDecorator; +import org.apache.shardingsphere.mode.metadata.persist.node.GlobalNodePath; import java.util.Arrays; import java.util.Collection; @@ -47,7 +45,6 @@ public final class GlobalRuleChangedHandler implements DataChangedEventHandler { return Arrays.asList(Type.ADDED, Type.UPDATED); } - @SuppressWarnings("unchecked") @Override public void handle(final ContextManager contextManager, final DataChangedEvent event) { if (!org.apache.shardingsphere.mode.path.GlobalNodePath.isRuleActiveVersionPath(event.getKey())) { @@ -60,7 +57,6 @@ public final class GlobalRuleChangedHandler implements DataChangedEventHandler { ActiveVersionChecker.checkActiveVersion(contextManager, event); Optional<RuleConfiguration> ruleConfig = contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().load(ruleName.get()); Preconditions.checkArgument(ruleConfig.isPresent(), "Can not find rule configuration with name: %s", ruleName.get()); - contextManager.getMetaDataContextManager().getGlobalConfigurationManager().alterGlobalRuleConfiguration( - TypedSPILoader.findService(RuleConfigurationPersistDecorator.class, ruleConfig.get().getClass()).map(optional -> optional.restore(ruleConfig.get())).orElse(ruleConfig.get())); + contextManager.getMetaDataContextManager().getGlobalConfigurationManager().alterGlobalRuleConfiguration(ruleConfig.get()); } } 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 3326907589b..cafc69fd255 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 @@ -36,7 +36,6 @@ import org.apache.shardingsphere.logging.constant.LoggingConstants; import org.apache.shardingsphere.logging.rule.LoggingRule; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; -import org.apache.shardingsphere.mode.metadata.decorator.RuleConfigurationPersistDecorateEngine; import org.slf4j.LoggerFactory; import java.sql.SQLException; @@ -104,7 +103,7 @@ public final class SetDistVariableExecutor implements DistSQLUpdateExecutor<SetD if (LoggingConstants.SQL_SHOW.equalsIgnoreCase(propertyKey.getKey())) { metaDataContexts.getMetaData().getGlobalRuleMetaData().findSingleRule(LoggingRule.class).flatMap(LoggingRule::getSQLLogger).ifPresent(option -> { option.getProps().setProperty(LoggingConstants.SQL_LOG_ENABLE, value); - decorateGlobalRuleConfiguration(contextManager); + persistGlobalRuleConfigurations(contextManager); }); } } @@ -113,14 +112,13 @@ public final class SetDistVariableExecutor implements DistSQLUpdateExecutor<SetD if (LoggingConstants.SQL_SIMPLE.equalsIgnoreCase(propertyKey.getKey())) { metaDataContexts.getMetaData().getGlobalRuleMetaData().findSingleRule(LoggingRule.class).flatMap(LoggingRule::getSQLLogger).ifPresent(optional -> { optional.getProps().setProperty(LoggingConstants.SQL_LOG_SIMPLE, value); - decorateGlobalRuleConfiguration(contextManager); + persistGlobalRuleConfigurations(contextManager); }); } } - private void decorateGlobalRuleConfiguration(final ContextManager contextManager) { - RuleConfigurationPersistDecorateEngine ruleConfigPersistDecorateEngine = new RuleConfigurationPersistDecorateEngine(contextManager.getComputeNodeInstanceContext()); - Collection<RuleConfiguration> globalRuleConfigs = ruleConfigPersistDecorateEngine.decorate(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getConfigurations()); + private void persistGlobalRuleConfigurations(final ContextManager contextManager) { + Collection<RuleConfiguration> globalRuleConfigs = contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getConfigurations(); contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().persist(globalRuleConfigs); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ClusterExportMetaDataGenerator.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ClusterExportMetaDataGenerator.java index f788c8967f6..3a5ddb3c29e 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ClusterExportMetaDataGenerator.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ClusterExportMetaDataGenerator.java @@ -28,7 +28,6 @@ import org.apache.shardingsphere.infra.util.json.JsonUtils; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.metadata.decorator.RuleConfigurationPersistDecorateEngine; import org.apache.shardingsphere.proxy.backend.distsql.export.ExportedClusterInfo; import org.apache.shardingsphere.proxy.backend.distsql.export.ExportedMetaData; import org.apache.shardingsphere.proxy.backend.distsql.export.ExportedSnapshotInfo; @@ -59,7 +58,7 @@ public final class ClusterExportMetaDataGenerator { ExportedMetaData exportedMetaData = new ExportedMetaData(); exportedMetaData.setDatabases(generatorDatabasesExportData()); exportedMetaData.setProps(generatePropsData(metaData.getProps().getProps())); - exportedMetaData.setRules(generateRulesData(getGlobalRules(metaData))); + exportedMetaData.setRules(generateRulesData(metaData.getGlobalRuleMetaData().getConfigurations())); ExportedClusterInfo exportedClusterInfo = new ExportedClusterInfo(); exportedClusterInfo.setMetaData(exportedMetaData); generateSnapshotInfo(metaData, exportedClusterInfo); @@ -91,11 +90,6 @@ public final class ClusterExportMetaDataGenerator { return result.toString(); } - private Collection<RuleConfiguration> getGlobalRules(final ShardingSphereMetaData metaData) { - RuleConfigurationPersistDecorateEngine ruleConfigPersistDecorateEngine = new RuleConfigurationPersistDecorateEngine(contextManager.getComputeNodeInstanceContext()); - return ruleConfigPersistDecorateEngine.decorate(metaData.getGlobalRuleMetaData().getConfigurations()); - } - @SuppressWarnings({"rawtypes", "unchecked"}) private String generateRulesData(final Collection<RuleConfiguration> rules) { if (rules.isEmpty()) {