From 3ab7c90946c88fba2aeb5c93c370b0d6479a266d Mon Sep 17 00:00:00 2001 From: zhangliang Date: Sun, 12 Jan 2025 15:59:19 +0800 Subject: [PATCH] Remove useless RuleConfigurationPersistDecorator --- .../RuleConfigurationPersistDecorator.java | 66 -------------- .../mode/metadata/MetaDataContextManager.java | 8 +- .../metadata/MetaDataContextsFactory.java | 32 +------ ...uleConfigurationPersistDecorateEngine.java | 78 ---------------- ...onfigurationPersistDecorateEngineTest.java | 91 ------------------- .../global/GlobalRuleChangedHandler.java | 8 +- .../updatable/SetDistVariableExecutor.java | 10 +- .../util/ClusterExportMetaDataGenerator.java | 8 +- 8 files changed, 14 insertions(+), 287 deletions(-) delete mode 100644 mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RuleConfigurationPersistDecorator.java delete mode 100644 mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/decorator/RuleConfigurationPersistDecorateEngine.java delete mode 100644 mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/decorator/RuleConfigurationPersistDecorateEngineTest.java 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 dd6f12a5376f4..0000000000000 --- 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 type of rule configuration - */ -@SingletonSPI -public interface RuleConfigurationPersistDecorator 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 getRuleType(); - - @Override - Class 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 145b4d232db4b..785a811f4383f 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.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, final ComputeNodeInstanceContext computeNodeInstanceContext, final PersistRepository repository) { this.metaDataContexts = metaDataContexts; this.computeNodeInstanceContext = computeNodeInstanceContext; @@ -85,7 +82,6 @@ public MetaDataContextManager(final AtomicReference metaDataCo ruleItemManager = new RuleItemManager(metaDataContexts, repository, databaseRuleConfigurationManager); globalConfigurationManager = new GlobalConfigurationManager(metaDataContexts, repository); metaDataPersistService = new MetaDataPersistService(repository); - ruleConfigPersistDecorateEngine = new RuleConfigurationPersistDecorateEngine(computeNodeInstanceContext); } /** @@ -154,8 +150,8 @@ private MetaDataContexts createMetaDataContexts(final ShardingSphereDatabase dat .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 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 69b164fccd827..3e0ab1a1a210f 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.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 @@ private static MetaDataContexts createByRepository(final MetaDataPersistService Collection globalRuleConfigs = persistService.getGlobalRuleService().load(); ConfigurationProperties props = new ConfigurationProperties(persistService.getPropsService().load()); Map 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 @@ private static void closeGeneratedDataSources(final String databaseName, final M } } - @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 globalRuleConfigs = metadataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations(); + persistService.persistGlobalRuleConfiguration(globalRuleConfigs, param.getProps()); for (Entry 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 af1a4dbade5f0..0000000000000 --- 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 decorate(final Collection 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 restore(final Collection 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 tryRestore(final Collection 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 5c5d4644ff952..0000000000000 --- 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 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 ruleConfigs = Collections.singletonList(mock(RuleConfiguration.class)); - assertThat(decorateEngine.decorate(ruleConfigs), is(ruleConfigs)); - } - - @Test - void assertRestoreIfNotClusterMode() { - Collection 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 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 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 fef06a5ffae1f..639f1ce742271 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 @@ 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 Collection getSubscribedTypes() { 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 void handle(final ContextManager contextManager, final DataChangedEvent e ActiveVersionChecker.checkActiveVersion(contextManager, event); Optional 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 3326907589b48..cafc69fd2552c 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.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 @@ private void syncSQLShowToLoggingRule(final TypedPropertyKey propertyKey, final 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 @@ private void syncSQLSimpleToLoggingRule(final TypedPropertyKey propertyKey, fina 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 globalRuleConfigs = ruleConfigPersistDecorateEngine.decorate(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getConfigurations()); + private void persistGlobalRuleConfigurations(final ContextManager contextManager) { + Collection 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 f788c8967f633..3a5ddb3c29eab 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.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 String generateJsonFormat() { 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 @@ private String generatePropsData(final Properties props) { return result.toString(); } - private Collection getGlobalRules(final ShardingSphereMetaData metaData) { - RuleConfigurationPersistDecorateEngine ruleConfigPersistDecorateEngine = new RuleConfigurationPersistDecorateEngine(contextManager.getComputeNodeInstanceContext()); - return ruleConfigPersistDecorateEngine.decorate(metaData.getGlobalRuleMetaData().getConfigurations()); - } - @SuppressWarnings({"rawtypes", "unchecked"}) private String generateRulesData(final Collection rules) { if (rules.isEmpty()) {