From 6e8d44feea0497c7a0cc5ac32d73f834a1d164b0 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 28 Sep 2023 19:59:02 +0800 Subject: [PATCH] Rename StorageResource's variable names (#28615) * Rename ResourceMetaData.dataSources * Rename variable names * Rename StorageResource's variable names --- .../database/ShardingSphereDatabase.java | 2 +- .../database/resource/ResourceMetaData.java | 12 ++++---- .../database/resource/StorageResource.java | 8 ++--- ...rceGeneratedDatabaseConfigurationTest.java | 2 +- ...urceProvidedDatabaseConfigurationTest.java | 2 +- .../ShardingSphereDataSourceTest.java | 2 +- .../persist/MetaDataPersistService.java | 4 +-- .../persist/NewMetaDataPersistService.java | 4 +-- .../context/ConfigurationContextManager.java | 10 +++---- .../switcher/NewResourceSwitchManager.java | 6 ++-- .../switcher/ResourceSwitchManager.java | 30 +++++++++---------- .../manager/switcher/SwitchingResource.java | 2 +- .../mode/manager/ContextManagerTest.java | 6 ++-- .../switcher/ResourceSwitchManagerTest.java | 12 ++++---- .../YamlProxyConfigurationSwapperTest.java | 2 +- 15 files changed, 52 insertions(+), 52 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java index 087c5dedb01d1..51cb72ca3f60d 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java @@ -124,7 +124,7 @@ public static ShardingSphereDatabase create(final String name, final DatabaseTyp } private static ResourceMetaData createResourceMetaData(final String databaseName, final StorageResource storageResource, final Map propsMap) { - return new ResourceMetaData(databaseName, storageResource.getDataSourceMap(), storageResource.getStorageUnitNodeMap(), propsMap); + return new ResourceMetaData(databaseName, storageResource.getDataSources(), storageResource.getStorageUnitNodeMap(), propsMap); } /** diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java index 51ab60a081c40..f6d0e3ddaa7b9 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java @@ -43,21 +43,21 @@ @Getter public final class ResourceMetaData { - private final Map dataSourceMap; + private final Map dataSources; private final StorageUnitMetaData storageUnitMetaData; public ResourceMetaData(final Map dataSources) { - dataSourceMap = StorageNodeUtils.getStorageNodeDataSources(dataSources); - storageUnitMetaData = new StorageUnitMetaData(null, dataSourceMap, dataSources.entrySet().stream() + this.dataSources = StorageNodeUtils.getStorageNodeDataSources(dataSources); + storageUnitMetaData = new StorageUnitMetaData(null, this.dataSources, dataSources.entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), StorageUnitNodeMapUtils.fromDataSources(dataSources)); } - public ResourceMetaData(final String databaseName, final Map dataSourceMap, + public ResourceMetaData(final String databaseName, final Map dataSources, final Map storageUnitNodeMap, final Map propsMap) { - this.dataSourceMap = dataSourceMap; - storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSourceMap, propsMap, storageUnitNodeMap); + this.dataSources = dataSources; + storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSources, propsMap, storageUnitNodeMap); } /** diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/StorageResource.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/StorageResource.java index bc995f8d5cef2..8c7686ae19141 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/StorageResource.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/StorageResource.java @@ -33,14 +33,14 @@ @Getter public final class StorageResource { - private final Map dataSourceMap; + private final Map dataSources; private final Map storageUnitNodeMap; private final Map wrappedDataSources; - public StorageResource(final Map dataSourceMap, final Map storageUnitNodeMap) { - this.dataSourceMap = dataSourceMap; + public StorageResource(final Map dataSources, final Map storageUnitNodeMap) { + this.dataSources = dataSources; this.storageUnitNodeMap = storageUnitNodeMap; wrappedDataSources = createWrappedDataSources(); } @@ -49,7 +49,7 @@ private Map createWrappedDataSources() { Map result = new LinkedHashMap<>(storageUnitNodeMap.size(), 1F); for (Entry entry : storageUnitNodeMap.entrySet()) { StorageNode storageNode = entry.getValue(); - DataSource dataSource = dataSourceMap.get(storageNode.getName()); + DataSource dataSource = dataSources.get(storageNode.getName()); if (null != dataSource) { result.put(entry.getKey(), new CatalogSwitchableDataSource(dataSource, storageNode.getCatalog(), storageNode.getUrl())); } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfigurationTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfigurationTest.java index 2ae87a4f66d89..696d8c75aaee6 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfigurationTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfigurationTest.java @@ -50,7 +50,7 @@ void assertGetDataSources() { @Test void assertGetStorageNodes() { DataSourceGeneratedDatabaseConfiguration databaseConfig = createDataSourceGeneratedDatabaseConfiguration(); - HikariDataSource hikariDataSource = (HikariDataSource) databaseConfig.getStorageResource().getDataSourceMap().get(new StorageNodeName("normal_db")); + HikariDataSource hikariDataSource = (HikariDataSource) databaseConfig.getStorageResource().getDataSources().get(new StorageNodeName("normal_db")); assertThat(hikariDataSource.getJdbcUrl(), is("jdbc:mock://127.0.0.1/normal_db")); assertThat(hikariDataSource.getUsername(), is("root")); assertThat(hikariDataSource.getPassword(), is("")); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfigurationTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfigurationTest.java index d0ca3628adc38..796b69589758f 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfigurationTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfigurationTest.java @@ -45,7 +45,7 @@ void assertGetDataSources() { @Test void assertGetStorageNodes() { DataSourceProvidedDatabaseConfiguration databaseConfig = createDataSourceProvidedDatabaseConfiguration(); - MockedDataSource dataSource = (MockedDataSource) databaseConfig.getStorageResource().getDataSourceMap().get(new StorageNodeName("foo_ds")); + MockedDataSource dataSource = (MockedDataSource) databaseConfig.getStorageResource().getDataSources().get(new StorageNodeName("foo_ds")); assertThat(dataSource.getUrl(), is("jdbc:mock://127.0.0.1/foo_ds")); assertThat(dataSource.getUsername(), is("root")); assertThat(dataSource.getPassword(), is("root")); diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java index 7f46cd4ffb601..de2c40f748f8d 100644 --- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java +++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java @@ -133,7 +133,7 @@ void assertClose() throws Exception { ShardingSphereDataSource actual = createShardingSphereDataSource(dataSource); actual.close(); Map dataSourceMap = getContextManager(actual).getMetaDataContexts().getMetaData() - .getDatabase(DefaultDatabase.LOGIC_NAME).getResourceMetaData().getDataSourceMap(); + .getDatabase(DefaultDatabase.LOGIC_NAME).getResourceMetaData().getDataSources(); assertTrue(((HikariDataSource) dataSourceMap.get(new StorageNodeName("ds"))).isClosed()); } } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/MetaDataPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/MetaDataPersistService.java index e17c37587673a..5274f108d9f9a 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/MetaDataPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/MetaDataPersistService.java @@ -115,7 +115,7 @@ private Collection decorateRuleConfigs(final String databaseN private Map getDataSourcePoolPropertiesMap(final DatabaseConfiguration databaseConfigs) { if (!databaseConfigs.getDataSources().isEmpty() && databaseConfigs.getDataSourcePoolPropertiesMap().isEmpty()) { - return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSourceMap()); + return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSources()); } return databaseConfigs.getDataSourcePoolPropertiesMap(); } @@ -132,7 +132,7 @@ private Map getDataSourcePoolPropertiesMap(fin public Map getEffectiveDataSources(final String databaseName, final Map databaseConfigs) { Map propsMap = dataSourceUnitService.load(databaseName); if (databaseConfigs.containsKey(databaseName) && !databaseConfigs.get(databaseName).getDataSources().isEmpty()) { - databaseConfigs.get(databaseName).getStorageResource().getDataSourceMap().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy()); + databaseConfigs.get(databaseName).getStorageResource().getDataSources().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy()); } return propsMap.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.createConfiguration(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/NewMetaDataPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/NewMetaDataPersistService.java index c557a740b0322..c94ae23f4c09e 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/NewMetaDataPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/NewMetaDataPersistService.java @@ -121,7 +121,7 @@ private Collection decorateRuleConfigs(final String databaseN private Map getDataSourcePoolPropertiesMap(final DatabaseConfiguration databaseConfigs) { if (!databaseConfigs.getDataSources().isEmpty() && databaseConfigs.getDataSourcePoolPropertiesMap().isEmpty()) { - return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSourceMap()); + return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSources()); } return databaseConfigs.getDataSourcePoolPropertiesMap(); } @@ -145,7 +145,7 @@ private Map getDataSourcePoolPropertiesMap(fin public Map getEffectiveDataSources(final String databaseName, final Map databaseConfigs) { Map propsMap = dataSourceUnitService.load(databaseName); if (databaseConfigs.containsKey(databaseName) && !databaseConfigs.get(databaseName).getDataSources().isEmpty()) { - databaseConfigs.get(databaseName).getStorageResource().getDataSourceMap().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy()); + databaseConfigs.get(databaseName).getStorageResource().getDataSources().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy()); } return propsMap.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.createConfiguration(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); 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 66e798088bd37..1de6e2f1164c6 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 @@ -274,7 +274,7 @@ public void alterSchemaMetaData(final String databaseName, final ShardingSphereD * @return ShardingSphere databases */ public Map renewDatabase(final ShardingSphereDatabase database, final SwitchingResource resource) { - Map newStorageNodes = getNewStorageNodes(database.getResourceMetaData().getDataSourceMap(), resource); + Map newStorageNodes = getNewStorageNodes(database.getResourceMetaData().getDataSources(), resource); Map newStorageUnitNodeMap = getNewStorageUnitNodeMap(database.getResourceMetaData().getStorageUnitMetaData().getStorageUnits(), resource); Map propsMap = database.getResourceMetaData().getStorageUnitMetaData().getStorageUnits().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> currentValue, LinkedHashMap::new)); @@ -285,7 +285,7 @@ public Map renewDatabase(final ShardingSphereDat private Map getNewStorageNodes(final Map currentStorageNodes, final SwitchingResource resource) { Map result = new LinkedHashMap<>(); for (Entry entry : currentStorageNodes.entrySet()) { - if (!resource.getStaleStorageResource().getDataSourceMap().containsKey(entry.getKey())) { + if (!resource.getStaleStorageResource().getDataSources().containsKey(entry.getKey())) { result.put(entry.getKey(), entry.getValue()); } } @@ -364,10 +364,10 @@ private DatabaseConfiguration getDatabaseConfiguration(final ResourceMetaData re } private StorageResource getMergedStorageResource(final ResourceMetaData currentResourceMetaData, final SwitchingResource switchingResource) { - Map storageNodeDataSources = currentResourceMetaData.getDataSourceMap(); + Map storageNodeDataSources = currentResourceMetaData.getDataSources(); Map storageUnitNodeMap = currentResourceMetaData.getStorageUnitMetaData().getStorageUnitNodeMap(); - if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getDataSourceMap().isEmpty()) { - storageNodeDataSources.putAll(switchingResource.getNewStorageResource().getDataSourceMap()); + if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getDataSources().isEmpty()) { + storageNodeDataSources.putAll(switchingResource.getNewStorageResource().getDataSources()); } if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getStorageUnitNodeMap().isEmpty()) { storageUnitNodeMap.putAll(switchingResource.getNewStorageResource().getStorageUnitNodeMap()); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java index a4f4368b2d50f..7c5fdeba9cdc0 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java @@ -61,7 +61,7 @@ private StorageResource getRegisterNewStorageResource(final ResourceMetaData res Map storageNodeDataSourcePoolProps = StorageUnitNodeMapUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); Map newStorageNodes = new LinkedHashMap<>(storageNodeNames.size(), 1F); for (StorageNodeName each : storageNodeNames) { - if (!resourceMetaData.getDataSourceMap().containsKey(each)) { + if (!resourceMetaData.getDataSources().containsKey(each)) { newStorageNodes.put(each, DataSourcePoolCreator.create(storageNodeDataSourcePoolProps.get(each))); } } @@ -96,7 +96,7 @@ private StorageResource getAlterNewStorageResource(final Map storageUintNodeMap) { Collection toBeAlteredStorageNodeNames = storageUintNodeMap.values().stream().map(StorageNode::getName).collect(Collectors.toSet()); Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageNodeNames.size(), 1F); - for (Entry entry : resourceMetaData.getDataSourceMap().entrySet()) { + for (Entry entry : resourceMetaData.getDataSources().entrySet()) { if (toBeAlteredStorageNodeNames.contains(entry.getKey())) { storageNodes.put(entry.getKey(), entry.getValue()); } @@ -124,7 +124,7 @@ private StorageResource getToBeRemovedStaleStorageResource(final ResourceMetaDat Map reservedStorageUintNodeMap = resourceMetaData.getStorageUnitMetaData().getStorageUnitNodeMap(); Map storageNodes = new LinkedHashMap<>(1, 1F); if (reservedStorageUintNodeMap.values().stream().noneMatch(each -> each.equals(storageNode))) { - storageNodes.put(storageNode.getName(), resourceMetaData.getDataSourceMap().get(storageNode.getName())); + storageNodes.put(storageNode.getName(), resourceMetaData.getDataSources().get(storageNode.getName())); } return new StorageResource(storageNodes, Collections.singletonMap(storageUnitName, storageNode)); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java index 6da5665c2eabf..a4006d5d0122f 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java @@ -85,9 +85,9 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet Map toBeChangedStorageUnitNodeMap = StorageUnitNodeMapUtils.fromDataSourcePoolProperties(toBeChangedPropsMap); StorageResource staleStorageResource = getStaleDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, toBeChangedPropsMap); Collection toBeChangedStorageNodeNames = toBeChangedStorageUnitNodeMap.values().stream().map(StorageNode::getName).collect(Collectors.toSet()); - staleStorageResource.getDataSourceMap().putAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeNames)); + staleStorageResource.getDataSources().putAll(getToBeDeletedDataSources(resourceMetaData.getDataSources(), toBeChangedStorageNodeNames)); staleStorageResource.getStorageUnitNodeMap().putAll( - getToBeDeletedStorageUnitNodeMappers(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageUnitNodeMap.keySet())); + getToBeDeletedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageUnitNodeMap.keySet())); return new SwitchingResource(resourceMetaData, createNewStorageResource(resourceMetaData, toBeChangedStorageUnitNodeMap, toBeChangedPropsMap), staleStorageResource, mergedDataSourcePoolPropertiesMap); } @@ -104,16 +104,16 @@ private StorageResource createNewStorageResource(final ResourceMetaData resource private Map getNewStorageNodes(final ResourceMetaData resourceMetaData, final Collection toBeChangedStorageNodeName, final Map propsMap) { - Map result = new LinkedHashMap<>(resourceMetaData.getDataSourceMap()); - result.keySet().removeAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeName).keySet()); - result.putAll(getChangedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeName, propsMap)); - result.putAll(getToBeAddedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeName, propsMap)); + Map result = new LinkedHashMap<>(resourceMetaData.getDataSources()); + result.keySet().removeAll(getToBeDeletedDataSources(resourceMetaData.getDataSources(), toBeChangedStorageNodeName).keySet()); + result.putAll(getChangedDataSources(resourceMetaData.getDataSources(), toBeChangedStorageNodeName, propsMap)); + result.putAll(getToBeAddedDataSources(resourceMetaData.getDataSources(), toBeChangedStorageNodeName, propsMap)); return result; } private Map getNewStorageUnitNodeMap(final ResourceMetaData resourceMetaData, final Map toBeChangedStorageUnitNodeMap) { Map result = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getStorageUnitNodeMap()); - result.keySet().removeAll(getToBeDeletedStorageUnitNodeMappers(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageUnitNodeMap.keySet()).keySet()); + result.keySet().removeAll(getToBeDeletedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageUnitNodeMap.keySet()).keySet()); result.putAll(getChangedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageUnitNodeMap)); result.putAll(getToBeAddedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getStorageUnitNodeMap(), toBeChangedStorageUnitNodeMap)); return result; @@ -153,7 +153,7 @@ private StorageResource getToBeRemovedStaleDataSources(final ResourceMetaData re .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageNode())); Collection toBeRemovedStorageNodeNames = toRemovedStorageUnitNodeMap.values().stream().map(StorageNode::getName).collect(Collectors.toSet()); Collection inUsedDataSourceNames = reservedStorageUnitNodeMap.values().stream().map(StorageNode::getName).collect(Collectors.toSet()); - Map staleStorageNodes = resourceMetaData.getDataSourceMap().entrySet().stream() + Map staleStorageNodes = resourceMetaData.getDataSources().entrySet().stream() .filter(entry -> toBeRemovedStorageNodeNames.contains(entry.getKey()) && !inUsedDataSourceNames.contains(entry.getKey())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map staleStorageUnitNodeMap = resourceMetaData.getStorageUnitMetaData().getStorageUnits().entrySet().stream() @@ -163,11 +163,11 @@ private StorageResource getToBeRemovedStaleDataSources(final ResourceMetaData re private StorageResource getStaleDataSources(final ResourceMetaData resourceMetaData, final Map toBeChangedStorageUnitNodeMap, final Map storageUnitDataSourcePoolProps) { - Map storageNodes = new LinkedHashMap<>(resourceMetaData.getDataSourceMap().size(), 1F); - Map storageUnitNodeMappers = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getStorageUnitNodeMap().size(), 1F); - storageNodes.putAll(getToBeChangedDataSources(resourceMetaData.getDataSourceMap(), StorageUnitNodeMapUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps))); - storageUnitNodeMappers.putAll(getChangedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageUnitNodeMap)); - return new StorageResource(storageNodes, storageUnitNodeMappers); + Map storageNodes = new LinkedHashMap<>(resourceMetaData.getDataSources().size(), 1F); + Map storageUnitNodeMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getStorageUnitNodeMap().size(), 1F); + storageNodes.putAll(getToBeChangedDataSources(resourceMetaData.getDataSources(), StorageUnitNodeMapUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps))); + storageUnitNodeMap.putAll(getChangedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageUnitNodeMap)); + return new StorageResource(storageNodes, storageUnitNodeMap); } private Map getToBeChangedDataSources(final Map storageNodes, @@ -193,8 +193,8 @@ private Map getToBeDeletedDataSources(final Map getToBeDeletedStorageUnitNodeMappers(final Map storageUnits, - final Collection toBeChangedStorageUnitNames) { + private Map getToBeDeletedStorageUnitNodeMap(final Map storageUnits, + final Collection toBeChangedStorageUnitNames) { Map result = new LinkedHashMap<>(storageUnits.size(), 1F); for (Entry entry : storageUnits.entrySet()) { if (!toBeChangedStorageUnitNames.contains(entry.getKey())) { diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResource.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResource.java index 2c2459e07e6cb..7a800636f7e64 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResource.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResource.java @@ -48,6 +48,6 @@ public final class SwitchingResource { * Close stale data sources. */ public void closeStaleDataSources() { - staleStorageResource.getDataSourceMap().values().stream().filter(Objects::nonNull).forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy()); + staleStorageResource.getDataSources().values().stream().filter(Objects::nonNull).forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy()); } } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java index fb2908342acfa..2b099cd8d381c 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java @@ -222,7 +222,7 @@ private void assertAlteredDataSource(final MockedDataSource actual) { void assertAlterRuleConfiguration() { ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); Map dataSources = Collections.singletonMap("foo_ds", new MockedDataSource()); - when(resourceMetaData.getDataSourceMap()).thenReturn(StorageNodeUtils.getStorageNodeDataSources(dataSources)); + when(resourceMetaData.getDataSources()).thenReturn(StorageNodeUtils.getStorageNodeDataSources(dataSources)); StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(resourceMetaData.getStorageUnitMetaData()).thenReturn(storageUnitMetaData); when(storageUnitMetaData.getStorageUnits()).thenReturn(Collections.emptyMap()); @@ -245,7 +245,7 @@ void assertAlterDataSourceConfiguration() { Collections.singletonMap("foo_ds", new DataSourcePoolProperties(MockedDataSource.class.getName(), createProperties("test", "test")))); assertThat(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaData().getStorageUnits().size(), is(3)); assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db") - .getResourceMetaData().getDataSourceMap().get(new StorageNodeName("foo_ds"))); + .getResourceMetaData().getDataSources().get(new StorageNodeName("foo_ds"))); } private ResourceMetaData createOriginalResource() { @@ -262,7 +262,7 @@ private ResourceMetaData createOriginalResource() { } when(result.getStorageUnitMetaData().getStorageUnits()).thenReturn(storageUnits); when(result.getStorageUnitMetaData().getStorageUnitNodeMap()).thenReturn(storageUnitNodeMap); - when(result.getDataSourceMap()).thenReturn(storageNodeDataSourceMap); + when(result.getDataSources()).thenReturn(storageNodeDataSourceMap); return result; } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java index 2dbceba9c2f61..268574521af90 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java @@ -53,8 +53,8 @@ void assertCreateByAlterDataSourcePoolProperties() { dataSourceMap.put("ds_0", new MockedDataSource()); dataSourceMap.put("ds_1", new MockedDataSource()); SwitchingResource actual = new ResourceSwitchManager().createByAlterDataSourcePoolProperties(new ResourceMetaData(dataSourceMap), Collections.emptyMap()); - assertTrue(actual.getNewStorageResource().getDataSourceMap().isEmpty()); - assertThat(actual.getStaleStorageResource().getDataSourceMap().size(), is(2)); + assertTrue(actual.getNewStorageResource().getDataSources().isEmpty()); + assertThat(actual.getStaleStorageResource().getDataSources().size(), is(2)); actual.closeStaleDataSources(); assertStaleDataSource((MockedDataSource) dataSourceMap.get("ds_0")); assertStaleDataSource((MockedDataSource) dataSourceMap.get("ds_1")); @@ -85,10 +85,10 @@ private Map getDataSourcePoolProperties(final int initialCapacit } private void assertNewDataSources(final SwitchingResource actual) { - assertThat(actual.getNewStorageResource().getDataSourceMap().size(), is(3)); - assertTrue(actual.getNewStorageResource().getDataSourceMap().containsKey(new StorageNodeName("not_change"))); - assertTrue(actual.getNewStorageResource().getDataSourceMap().containsKey(new StorageNodeName("new"))); - assertTrue(actual.getNewStorageResource().getDataSourceMap().containsKey(new StorageNodeName("replace"))); + assertThat(actual.getNewStorageResource().getDataSources().size(), is(3)); + assertTrue(actual.getNewStorageResource().getDataSources().containsKey(new StorageNodeName("not_change"))); + assertTrue(actual.getNewStorageResource().getDataSources().containsKey(new StorageNodeName("new"))); + assertTrue(actual.getNewStorageResource().getDataSources().containsKey(new StorageNodeName("replace"))); } private void assertStaleDataSources(final Map originalDataSourceMap) { diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java index d6d690ac1cd6a..9b84e070aae9b 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java @@ -56,7 +56,7 @@ void assertSwap() throws IOException { private void assertDataSources(final ProxyConfiguration proxyConfig) { Map actual = proxyConfig.getDatabaseConfigurations(); assertThat(actual.size(), is(1)); - HikariDataSource dataSource = (HikariDataSource) actual.get("swapper_test").getStorageResource().getDataSourceMap().get(new StorageNodeName("foo_db")); + HikariDataSource dataSource = (HikariDataSource) actual.get("swapper_test").getStorageResource().getDataSources().get(new StorageNodeName("foo_db")); assertThat(dataSource.getJdbcUrl(), is("jdbc:h2:mem:foo_db;DB_CLOSE_DELAY=-1")); assertThat(dataSource.getUsername(), is("sa")); assertThat(dataSource.getPassword(), is(""));