diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/DatabaseBasedPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/DatabaseBasedPersistService.java index 0232d5a79fabe..f9b7840449db0 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/DatabaseBasedPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/DatabaseBasedPersistService.java @@ -67,17 +67,17 @@ default T load(String databaseName, String name) { * Delete configurations. * * @param databaseName database name - * @param configs configurations + * @param configs to be deleted configurations * @return meta data versions */ - Collection deleteConfig(String databaseName, T configs); + Collection deleteConfigurations(String databaseName, T configs); /** * Persist configurations. * * @param databaseName database name - * @param configs configurations + * @param configs to be persisted configurations * @return meta data versions */ - Collection persistConfig(String databaseName, T configs); + Collection persistConfigurations(String databaseName, T configs); } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceNodePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceNodePersistService.java index 62502f8bfcae0..370c8501793ce 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceNodePersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceNodePersistService.java @@ -88,7 +88,7 @@ public void delete(final String databaseName, final String name) { } @Override - public Collection deleteConfig(final String databaseName, final Map dataSourceConfigs) { + public Collection deleteConfigurations(final String databaseName, final Map dataSourceConfigs) { Collection result = new LinkedList<>(); for (Entry entry : dataSourceConfigs.entrySet()) { String delKey = DataSourceMetaDataNode.getDataSourceNodeNode(databaseName, entry.getKey()); @@ -99,7 +99,7 @@ public Collection deleteConfig(final String databaseName, final } @Override - public Collection persistConfig(final String databaseName, final Map dataSourceConfigs) { + public Collection persistConfigurations(final String databaseName, final Map dataSourceConfigs) { Collection result = new LinkedList<>(); for (Entry entry : dataSourceConfigs.entrySet()) { List versions = repository.getChildrenKeys(DataSourceMetaDataNode.getDataSourceNodeVersionsNode(databaseName, entry.getKey())); diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceUnitPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceUnitPersistService.java index 26dcd9879f475..b18ab364fcadc 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceUnitPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceUnitPersistService.java @@ -88,7 +88,7 @@ public void delete(final String databaseName, final String name) { } @Override - public Collection deleteConfig(final String databaseName, final Map dataSourceConfigs) { + public Collection deleteConfigurations(final String databaseName, final Map dataSourceConfigs) { Collection result = new LinkedList<>(); for (Entry entry : dataSourceConfigs.entrySet()) { String delKey = DataSourceMetaDataNode.getDataSourceUnitNode(databaseName, entry.getKey()); @@ -99,7 +99,7 @@ public Collection deleteConfig(final String databaseName, final } @Override - public Collection persistConfig(final String databaseName, final Map dataSourceConfigs) { + public Collection persistConfigurations(final String databaseName, final Map dataSourceConfigs) { Collection result = new LinkedList<>(); for (Entry entry : dataSourceConfigs.entrySet()) { List versions = repository.getChildrenKeys(DataSourceMetaDataNode.getDataSourceUnitVersionsNode(databaseName, entry.getKey())); diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java index 6bc5ef3ae3761..3316d2e60ca40 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java @@ -32,7 +32,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Map.Entry; /** @@ -52,8 +51,7 @@ public DatabaseRulePersistService(final PersistRepository repository) { @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void persist(final String databaseName, final Collection configs) { - Map yamlConfigs = new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs); - for (Entry entry : yamlConfigs.entrySet()) { + for (Entry entry : new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs).entrySet()) { Collection repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey()); if (!repositoryTuples.isEmpty()) { persistDataNodes(databaseName, entry.getValue().getRuleTagName().toLowerCase(), repositoryTuples); @@ -63,8 +61,8 @@ public void persist(final String databaseName, final Collection load(final String databaseName) { - Collection repositoryTuple = getRepositoryTuple(DatabaseRuleMetaDataNode.getRulesNode(databaseName)); - return repositoryTuple.isEmpty() ? Collections.emptyList() : new YamlDataNodeRuleConfigurationSwapperEngine().swapToRuleConfigurations(repositoryTuple); + Collection repositoryTuples = getRepositoryTuple(DatabaseRuleMetaDataNode.getRulesNode(databaseName)); + return repositoryTuples.isEmpty() ? Collections.emptyList() : new YamlDataNodeRuleConfigurationSwapperEngine().swapToRuleConfigurations(repositoryTuples); } @Override @@ -74,10 +72,9 @@ public void delete(final String databaseName, final String name) { @SuppressWarnings({"unchecked", "rawtypes"}) @Override - public Collection persistConfig(final String databaseName, final Collection configs) { + public Collection persistConfigurations(final String databaseName, final Collection configs) { Collection result = new LinkedList<>(); - Map yamlConfigs = new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs); - for (Entry entry : yamlConfigs.entrySet()) { + for (Entry entry : new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs).entrySet()) { Collection repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey()); if (!repositoryTuples.isEmpty()) { result.addAll(persistDataNodes(databaseName, entry.getValue().getRuleTagName().toLowerCase(), repositoryTuples)); @@ -102,10 +99,9 @@ private Collection persistDataNodes(final String databaseName, @SuppressWarnings({"unchecked", "rawtypes"}) @Override - public Collection deleteConfig(final String databaseName, final Collection configs) { + public Collection deleteConfigurations(final String databaseName, final Collection configs) { Collection result = new LinkedList<>(); - Map yamlConfigs = new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs); - for (Entry entry : yamlConfigs.entrySet()) { + for (Entry entry : new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs).entrySet()) { Collection repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey()); if (repositoryTuples.isEmpty()) { continue; diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java index 157af02fb39f8..514670167d1ec 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java @@ -31,7 +31,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Map.Entry; /** @@ -51,8 +50,8 @@ public GlobalRulePersistService(final PersistRepository repository) { @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void persist(final Collection globalRuleConfigs) { - Map yamlConfigs = new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(globalRuleConfigs); - for (Entry entry : yamlConfigs.entrySet()) { + for (Entry entry : new YamlDataNodeGlobalRuleConfigurationSwapperEngine() + .swapToYamlRuleConfigurations(globalRuleConfigs).entrySet()) { Collection repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey()); if (!repositoryTuples.isEmpty()) { persistDataNodes(repositoryTuples); @@ -64,8 +63,8 @@ public void persist(final Collection globalRuleConfigs) { @Override public Collection persistConfigurations(final Collection globalRuleConfigs) { Collection result = new LinkedList<>(); - Map yamlConfigs = new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(globalRuleConfigs); - for (Entry entry : yamlConfigs.entrySet()) { + for (Entry entry : new YamlDataNodeGlobalRuleConfigurationSwapperEngine() + .swapToYamlRuleConfigurations(globalRuleConfigs).entrySet()) { Collection repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey()); if (!repositoryTuples.isEmpty()) { result.addAll(persistDataNodes(repositoryTuples)); @@ -91,13 +90,13 @@ private Collection persistDataNodes(final Collection load() { - Collection repositoryTuple = getRepositoryTuple(GlobalNode.getGlobalRuleRootNode()); - return repositoryTuple.isEmpty() ? Collections.emptyList() : new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToRuleConfigurations(repositoryTuple); + Collection repositoryTuples = getRepositoryTuple(GlobalNode.getGlobalRuleRootNode()); + return repositoryTuples.isEmpty() ? Collections.emptyList() : new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToRuleConfigurations(repositoryTuples); } @Override public RuleConfiguration load(final String ruleName) { - Collection repositoryTuple = getRepositoryTuple(GlobalNode.getGlobalRuleNode(ruleName)); - return new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapSingleRuleToRuleConfiguration(ruleName, repositoryTuple).orElse(null); + Collection repositoryTuples = getRepositoryTuple(GlobalNode.getGlobalRuleNode(ruleName)); + return new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapSingleRuleToRuleConfiguration(ruleName, repositoryTuples).orElse(null); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java index 8f281988218d4..55364ba04895e 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java @@ -376,9 +376,8 @@ public synchronized void alterGlobalRuleConfiguration(final RuleConfiguration ru @SuppressWarnings("rawtypes") @SneakyThrows(Exception.class) private void closeStaleTransactionRule(final RuleConfiguration ruleConfig) { - Map yamlConfigs = - new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(Collections.singletonList(ruleConfig)); - for (Entry entry : yamlConfigs.entrySet()) { + for (Entry entry : new YamlDataNodeGlobalRuleConfigurationSwapperEngine() + .swapToYamlRuleConfigurations(Collections.singleton(ruleConfig)).entrySet()) { if ("transaction".equalsIgnoreCase(entry.getValue().getRuleTagName())) { Optional transactionRule = metaDataContexts.get().getMetaData().getGlobalRuleMetaData().findSingleRule(TransactionRule.class); if (!transactionRule.isPresent()) { diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterModeContextManager.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterModeContextManager.java index 0163709741c30..c3d212582ee45 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterModeContextManager.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterModeContextManager.java @@ -94,18 +94,18 @@ public void alterSchemaMetaData(final AlterSchemaMetaDataPOJO alterSchemaMetaDat @Override public void registerStorageUnits(final String databaseName, final Map toBeRegisteredProps) { - contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().persistConfig(databaseName, toBeRegisteredProps); + contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().persistConfigurations(databaseName, toBeRegisteredProps); } @Override public void alterStorageUnits(final String databaseName, final Map toBeUpdatedProps) { DatabaseBasedPersistService> dataSourceService = contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService(); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfig(databaseName, toBeUpdatedProps)); + contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeUpdatedProps)); } @Override public void unregisterStorageUnits(final String databaseName, final Collection toBeDroppedStorageUnitNames) { - contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().deleteConfig(databaseName, + contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().deleteConfigurations(databaseName, getToBeDroppedDataSourcePoolProperties(contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().load(databaseName), toBeDroppedStorageUnitNames)); } @@ -123,13 +123,13 @@ private Map getToBeDroppedDataSourcePoolProper public void alterSingleRuleConfiguration(final String databaseName, final Collection ruleConfigs) { ruleConfigs.removeIf(each -> !each.getClass().isAssignableFrom(SingleRuleConfiguration.class)); contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService() - .switchActiveVersion(contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().persistConfig(databaseName, ruleConfigs)); + .switchActiveVersion(contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().persistConfigurations(databaseName, ruleConfigs)); } @Override public Collection alterRuleConfiguration(final String databaseName, final RuleConfiguration toBeAlteredRuleConfig) { if (null != toBeAlteredRuleConfig) { - return contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().persistConfig(databaseName, Collections.singleton(toBeAlteredRuleConfig)); + return contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().persistConfigurations(databaseName, Collections.singleton(toBeAlteredRuleConfig)); } return Collections.emptyList(); } @@ -137,7 +137,7 @@ public Collection alterRuleConfiguration(final String databaseN @Override public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) { if (null != toBeRemovedRuleConfig) { - contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfig(databaseName, Collections.singleton(toBeRemovedRuleConfig)); + contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig)); } } diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java index 71dd0d792cf8a..7748699c0d5c2 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java @@ -220,7 +220,7 @@ public void registerStorageUnits(final String databaseName, final Map contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService() .persistByAlterConfiguration(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), schemaName, schema)); DatabaseBasedPersistService> dataSourceService = contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService(); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfig(databaseName, toBeRegisteredProps)); + contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeRegisteredProps)); clearServiceCache(); } @@ -232,7 +232,7 @@ public void alterStorageUnits(final String databaseName, final Map ((GlobalRule) each).refresh(contextManager.getMetaDataContexts().getMetaData().getDatabases(), GlobalRuleChangedType.DATABASE_CHANGED)); DatabaseBasedPersistService> dataSourceService = contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService(); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfig(databaseName, toBeUpdatedProps)); + contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeUpdatedProps)); switchingResource.closeStaleDataSources(); clearServiceCache(); } @@ -256,7 +256,7 @@ public void unregisterStorageUnits(final String databaseName, final Collection ruleConfigs) { ruleConfigs.removeIf(each -> !each.getClass().isAssignableFrom(SingleRuleConfiguration.class)); Collection metaDataVersions = contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService() - .persistConfig(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), ruleConfigs); + .persistConfigurations(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), ruleConfigs); contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions); contextManager.getConfigurationContextManager().alterRuleConfiguration(databaseName, ruleConfigs.iterator().next()); clearServiceCache(); @@ -266,7 +266,7 @@ public void alterSingleRuleConfiguration(final String databaseName, final Collec public Collection alterRuleConfiguration(final String databaseName, final RuleConfiguration toBeAlteredRuleConfig) { if (null != toBeAlteredRuleConfig) { Collection metaDataVersions = contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService() - .persistConfig(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), Collections.singletonList(toBeAlteredRuleConfig)); + .persistConfigurations(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), Collections.singletonList(toBeAlteredRuleConfig)); contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions); sendDatabaseRuleChangedEvent(databaseName, metaDataVersions); clearServiceCache(); @@ -291,7 +291,7 @@ private void sendDatabaseRuleChangedEvent(final String databaseName, final MetaD public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) { if (null != toBeRemovedRuleConfig) { sendDatabaseRuleChangedEvent(databaseName, - contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfig(databaseName, Collections.singleton(toBeRemovedRuleConfig))); + contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig))); clearServiceCache(); } }