From 82479d63830530ed0503ad3791c0428b4e30be6b Mon Sep 17 00:00:00 2001 From: zhangliang Date: Sun, 24 Sep 2023 22:54:29 +0800 Subject: [PATCH] Rename ResourceMetaData.dataSourceMap --- .../database/resource/ResourceMetaData.java | 13 +++++------ .../resource/storage/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 | 18 +++++++-------- .../switcher/ResourceSwitchManager.java | 22 +++++++++---------- .../manager/switcher/SwitchingResource.java | 2 +- .../mode/manager/ContextManagerTest.java | 6 ++--- .../switcher/ResourceSwitchManagerTest.java | 12 +++++----- .../YamlProxyConfigurationSwapperTest.java | 2 +- 14 files changed, 53 insertions(+), 54 deletions(-) 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 f0ba8a800e5d6..017403b01c690 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,7 +43,7 @@ @Getter public final class ResourceMetaData { - private final Map storageNodeDataSources; + private final Map dataSourceMap; private final StorageUnitMetaData storageUnitMetaData; @@ -52,16 +52,15 @@ public ResourceMetaData(final Map dataSources) { } public ResourceMetaData(final String databaseName, final Map dataSources) { - storageNodeDataSources = StorageResourceUtils.getStorageNodeDataSources(dataSources); - storageUnitMetaData = new StorageUnitMetaData(databaseName, storageNodeDataSources, - dataSources.entrySet().stream() - .collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), + dataSourceMap = StorageResourceUtils.getStorageNodeDataSources(dataSources); + storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSourceMap, dataSources.entrySet().stream() + .collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), StorageResourceUtils.getStorageUnitNodeMappers(dataSources)); } public ResourceMetaData(final String databaseName, final StorageResource storageResource, final Map propsMap) { - storageNodeDataSources = storageResource.getStorageNodeDataSources(); - storageUnitMetaData = new StorageUnitMetaData(databaseName, storageNodeDataSources, propsMap, storageResource.getStorageUnitNodeMappers()); + dataSourceMap = storageResource.getDataSourceMap(); + storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSourceMap, propsMap, storageResource.getStorageUnitNodeMappers()); } /** diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/storage/StorageResource.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/storage/StorageResource.java index 818712af07564..76c44e6bebd83 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/storage/StorageResource.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/storage/StorageResource.java @@ -31,14 +31,14 @@ @Getter public class StorageResource { - private final Map storageNodeDataSources; + private final Map dataSourceMap; private final Map storageUnitNodeMappers; private final Map wrappedDataSources; - public StorageResource(final Map storageNodeDataSources, final Map storageUnitNodeMappers) { - this.storageNodeDataSources = storageNodeDataSources; + public StorageResource(final Map dataSourceMap, final Map storageUnitNodeMappers) { + this.dataSourceMap = dataSourceMap; this.storageUnitNodeMappers = storageUnitNodeMappers; wrappedDataSources = createWrappedDataSources(); } @@ -46,7 +46,7 @@ public StorageResource(final Map storageNodeDataSources private Map createWrappedDataSources() { Map result = new LinkedHashMap<>(storageUnitNodeMappers.size(), 1F); for (Entry entry : storageUnitNodeMappers.entrySet()) { - DataSource dataSource = storageNodeDataSources.get(entry.getValue().getStorageNode()); + DataSource dataSource = dataSourceMap.get(entry.getValue().getStorageNode()); if (null != dataSource) { result.put(entry.getKey(), new CatalogSwitchableDataSource(dataSource, entry.getValue().getCatalog(), entry.getValue().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 a5aa710f10b88..491adcd3ccf3f 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().getStorageNodeDataSources().get(new StorageNode("normal_db")); + HikariDataSource hikariDataSource = (HikariDataSource) databaseConfig.getStorageResource().getDataSourceMap().get(new StorageNode("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 16476889fd17d..0e17a499708eb 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().getStorageNodeDataSources().get(new StorageNode("foo_ds")); + MockedDataSource dataSource = (MockedDataSource) databaseConfig.getStorageResource().getDataSourceMap().get(new StorageNode("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 380119975e8d1..881657d1646f1 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().getStorageNodeDataSources(); + .getDatabase(DefaultDatabase.LOGIC_NAME).getResourceMetaData().getDataSourceMap(); assertTrue(((HikariDataSource) dataSourceMap.get(new StorageNode("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 9bb4a1961827b..900886279b839 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().getStorageNodeDataSources()); + return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSourceMap()); } 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().getStorageNodeDataSources().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy()); + databaseConfigs.get(databaseName).getStorageResource().getDataSourceMap().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 460be290390c0..c1428e65b1288 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().getStorageNodeDataSources()); + return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSourceMap()); } 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().getStorageNodeDataSources().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy()); + databaseConfigs.get(databaseName).getStorageResource().getDataSourceMap().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 c8a30ac444738..7c7e09819f1fe 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().getStorageNodeDataSources(), resource); + Map newStorageNodes = getNewStorageNodes(database.getResourceMetaData().getDataSourceMap(), resource); Map newStorageUnitNodeMappers = getNewStorageUnitNodeMappers(database.getResourceMetaData().getStorageUnitMetaData().getStorageUnits(), resource); StorageResource newStorageResource = new StorageResource(newStorageNodes, newStorageUnitNodeMappers); Map propsMap = database.getResourceMetaData().getStorageUnitMetaData().getStorageUnits().entrySet().stream() @@ -286,7 +286,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().getStorageNodeDataSources().containsKey(entry.getKey())) { + if (!resource.getStaleStorageResource().getDataSourceMap().containsKey(entry.getKey())) { result.put(entry.getKey(), entry.getValue()); } } @@ -365,10 +365,10 @@ private DatabaseConfiguration getDatabaseConfiguration(final ResourceMetaData re } private StorageResource getMergedStorageResource(final ResourceMetaData currentResourceMetaData, final SwitchingResource switchingResource) { - Map storageNodeDataSources = currentResourceMetaData.getStorageNodeDataSources(); + Map storageNodeDataSources = currentResourceMetaData.getDataSourceMap(); Map storageUnitNodeMappers = currentResourceMetaData.getStorageUnitMetaData().getUnitNodeMappers(); - if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getStorageNodeDataSources().isEmpty()) { - storageNodeDataSources.putAll(switchingResource.getNewStorageResource().getStorageNodeDataSources()); + if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getDataSourceMap().isEmpty()) { + storageNodeDataSources.putAll(switchingResource.getNewStorageResource().getDataSourceMap()); } if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getStorageUnitNodeMappers().isEmpty()) { storageUnitNodeMappers.putAll(switchingResource.getNewStorageResource().getStorageUnitNodeMappers()); 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 84fff446e03a3..9bb79919f1c49 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 @@ -55,9 +55,9 @@ public SwitchingResource registerStorageUnit(final ResourceMetaData resourceMeta } private StorageResource getRegisterNewStorageResource(final ResourceMetaData resourceMetaData, final StorageResourceWithProperties toBeCreatedStorageResource) { - Map storageNodes = new LinkedHashMap<>(toBeCreatedStorageResource.getStorageNodeDataSources().size(), 1F); - for (StorageNode each : toBeCreatedStorageResource.getStorageNodeDataSources().keySet()) { - if (!resourceMetaData.getStorageNodeDataSources().containsKey(each)) { + Map storageNodes = new LinkedHashMap<>(toBeCreatedStorageResource.getDataSourceMap().size(), 1F); + for (StorageNode each : toBeCreatedStorageResource.getDataSourceMap().keySet()) { + if (!resourceMetaData.getDataSourceMap().containsKey(each)) { storageNodes.put(each, DataSourcePoolCreator.create(toBeCreatedStorageResource.getDataSourcePoolPropertiesMap().get(each.getName()))); } } @@ -80,17 +80,17 @@ public SwitchingResource alterStorageUnit(final ResourceMetaData resourceMetaDat } private StorageResource getAlterNewStorageResource(final StorageResourceWithProperties toBeAlteredStorageResource) { - Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageResource.getStorageNodeDataSources().size(), 1F); - for (StorageNode each : toBeAlteredStorageResource.getStorageNodeDataSources().keySet()) { + Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageResource.getDataSourceMap().size(), 1F); + for (StorageNode each : toBeAlteredStorageResource.getDataSourceMap().keySet()) { storageNodes.put(each, DataSourcePoolCreator.create(toBeAlteredStorageResource.getDataSourcePoolPropertiesMap().get(each.getName()))); } return new StorageResource(storageNodes, toBeAlteredStorageResource.getStorageUnitNodeMappers()); } private StorageResource getStaleStorageResource(final ResourceMetaData resourceMetaData, final StorageResourceWithProperties toBeAlteredStorageResource) { - Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageResource.getStorageNodeDataSources().size(), 1F); - for (Entry entry : resourceMetaData.getStorageNodeDataSources().entrySet()) { - if (toBeAlteredStorageResource.getStorageNodeDataSources().containsKey(entry.getKey())) { + Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageResource.getDataSourceMap().size(), 1F); + for (Entry entry : resourceMetaData.getDataSourceMap().entrySet()) { + if (toBeAlteredStorageResource.getDataSourceMap().containsKey(entry.getKey())) { storageNodes.put(entry.getKey(), entry.getValue()); } } @@ -117,7 +117,7 @@ private StorageResource getToBeRemovedStaleStorageResource(final ResourceMetaDat Map reservedStorageUnitNodeMappers = resourceMetaData.getStorageUnitMetaData().getUnitNodeMappers(); Map storageNodes = new LinkedHashMap<>(1, 1F); if (reservedStorageUnitNodeMappers.values().stream().noneMatch(each -> each.getStorageNode().equals(storageUnitNodeMapper.getStorageNode()))) { - storageNodes.put(storageUnitNodeMapper.getStorageNode(), resourceMetaData.getStorageNodeDataSources().get(storageUnitNodeMapper.getStorageNode())); + storageNodes.put(storageUnitNodeMapper.getStorageNode(), resourceMetaData.getDataSourceMap().get(storageUnitNodeMapper.getStorageNode())); } return new StorageResource(storageNodes, Collections.singletonMap(storageUnitName, storageUnitNodeMapper)); } 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 e2b5da6e102a8..ed7cf1ca365ea 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,8 +85,8 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet mergedDataSourcePoolPropertiesMap.putAll(toBeChangedPropsMap); StorageResourceWithProperties toBeChangedStorageResource = StorageResourceCreator.createStorageResourceWithoutDataSource(toBeChangedPropsMap); StorageResource staleStorageResource = getStaleDataSources(resourceMetaData, toBeChangedStorageResource); - staleStorageResource.getStorageNodeDataSources() - .putAll(getToBeDeletedDataSources(resourceMetaData.getStorageNodeDataSources(), toBeChangedStorageResource.getStorageNodeDataSources().keySet())); + staleStorageResource.getDataSourceMap() + .putAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageResource.getDataSourceMap().keySet())); staleStorageResource.getStorageUnitNodeMappers().putAll( getToBeDeletedStorageUnitNodeMappers(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageResource.getStorageUnitNodeMappers().keySet())); return new SwitchingResource(resourceMetaData, createNewStorageResource(resourceMetaData, toBeChangedStorageResource), staleStorageResource, mergedDataSourcePoolPropertiesMap); @@ -94,17 +94,17 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet private StorageResource createNewStorageResource(final ResourceMetaData resourceMetaData, final StorageResourceWithProperties toBeChangedStorageResource) { Map storageNodes = - getNewStorageNodes(resourceMetaData, toBeChangedStorageResource.getStorageNodeDataSources(), toBeChangedStorageResource.getDataSourcePoolPropertiesMap()); + getNewStorageNodes(resourceMetaData, toBeChangedStorageResource.getDataSourceMap(), toBeChangedStorageResource.getDataSourcePoolPropertiesMap()); Map storageUnitNodeMappers = getNewStorageUnitNodeMappers(resourceMetaData, toBeChangedStorageResource.getStorageUnitNodeMappers()); return new StorageResource(storageNodes, storageUnitNodeMappers); } private Map getNewStorageNodes(final ResourceMetaData resourceMetaData, final Map toBeChangedStorageNodes, final Map propsMap) { - Map result = new LinkedHashMap<>(resourceMetaData.getStorageNodeDataSources()); - result.keySet().removeAll(getToBeDeletedDataSources(resourceMetaData.getStorageNodeDataSources(), toBeChangedStorageNodes.keySet()).keySet()); - result.putAll(getChangedDataSources(resourceMetaData.getStorageNodeDataSources(), toBeChangedStorageNodes, propsMap)); - result.putAll(getToBeAddedDataSources(resourceMetaData.getStorageNodeDataSources(), toBeChangedStorageNodes, propsMap)); + Map result = new LinkedHashMap<>(resourceMetaData.getDataSourceMap()); + result.keySet().removeAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodes.keySet()).keySet()); + result.putAll(getChangedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodes, propsMap)); + result.putAll(getToBeAddedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodes, propsMap)); return result; } @@ -146,8 +146,8 @@ private StorageResource getToBeRemovedStaleDataSources(final ResourceMetaData re .filter(entry -> !toBeRemovedStorageResource.getStorageUnitNodeMappers().containsKey(entry.getKey())) .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getUnitNodeMapper())); Collection inUsedDataSourceNames = reservedStorageUnitNodeMappers.values().stream().map(StorageUnitNodeMapper::getStorageNode).collect(Collectors.toSet()); - Map staleStorageNodes = resourceMetaData.getStorageNodeDataSources().entrySet().stream() - .filter(entry -> toBeRemovedStorageResource.getStorageNodeDataSources().containsKey(entry.getKey()) && !inUsedDataSourceNames.contains(entry.getKey())) + Map staleStorageNodes = resourceMetaData.getDataSourceMap().entrySet().stream() + .filter(entry -> toBeRemovedStorageResource.getDataSourceMap().containsKey(entry.getKey()) && !inUsedDataSourceNames.contains(entry.getKey())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map staleStorageUnitNodeMappers = resourceMetaData.getStorageUnitMetaData().getStorageUnits().entrySet().stream() .filter(entry -> !reservedStorageUnitNodeMappers.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getUnitNodeMapper())); @@ -155,9 +155,9 @@ private StorageResource getToBeRemovedStaleDataSources(final ResourceMetaData re } private StorageResource getStaleDataSources(final ResourceMetaData resourceMetaData, final StorageResourceWithProperties toBeChangedStorageResource) { - Map storageNodes = new LinkedHashMap<>(resourceMetaData.getStorageNodeDataSources().size(), 1F); + Map storageNodes = new LinkedHashMap<>(resourceMetaData.getDataSourceMap().size(), 1F); Map storageUnitNodeMappers = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getUnitNodeMappers().size(), 1F); - storageNodes.putAll(getToBeChangedDataSources(resourceMetaData.getStorageNodeDataSources(), toBeChangedStorageResource.getDataSourcePoolPropertiesMap())); + storageNodes.putAll(getToBeChangedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageResource.getDataSourcePoolPropertiesMap())); storageUnitNodeMappers.putAll(getChangedStorageUnitNodeMappers(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedStorageResource.getStorageUnitNodeMappers())); return new StorageResource(storageNodes, storageUnitNodeMappers); } 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 3fe81345e195a..5888e44ed3dd0 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 @@ -47,6 +47,6 @@ public final class SwitchingResource { * Close stale data sources. */ public void closeStaleDataSources() { - staleStorageResource.getStorageNodeDataSources().values().stream().filter(Objects::nonNull).forEach(resourceMetaData::close); + staleStorageResource.getDataSourceMap().values().stream().filter(Objects::nonNull).forEach(resourceMetaData::close); } } 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 e0065d2e780c1..388e2f6545ac6 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 @@ -221,7 +221,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.getStorageNodeDataSources()).thenReturn(StorageResourceUtils.getStorageNodeDataSources(dataSources)); + when(resourceMetaData.getDataSourceMap()).thenReturn(StorageResourceUtils.getStorageNodeDataSources(dataSources)); StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(resourceMetaData.getStorageUnitMetaData()).thenReturn(storageUnitMetaData); when(storageUnitMetaData.getStorageUnits()).thenReturn(Collections.emptyMap()); @@ -244,7 +244,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().getStorageNodeDataSources().get(new StorageNode("foo_ds"))); + .getResourceMetaData().getDataSourceMap().get(new StorageNode("foo_ds"))); } private ResourceMetaData createOriginalResource() { @@ -261,7 +261,7 @@ private ResourceMetaData createOriginalResource() { } when(result.getStorageUnitMetaData().getStorageUnits()).thenReturn(storageUnits); when(result.getStorageUnitMetaData().getUnitNodeMappers()).thenReturn(storageUnitNodeMappers); - when(result.getStorageNodeDataSources()).thenReturn(storageNodeDataSourceMap); + when(result.getDataSourceMap()).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 73ec3bbd89c7e..94e491dc27276 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("sharding_db", dataSourceMap), Collections.emptyMap()); - assertTrue(actual.getNewStorageResource().getStorageNodeDataSources().isEmpty()); - assertThat(actual.getStaleStorageResource().getStorageNodeDataSources().size(), is(2)); + assertTrue(actual.getNewStorageResource().getDataSourceMap().isEmpty()); + assertThat(actual.getStaleStorageResource().getDataSourceMap().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().getStorageNodeDataSources().size(), is(3)); - assertTrue(actual.getNewStorageResource().getStorageNodeDataSources().containsKey(new StorageNode("not_change"))); - assertTrue(actual.getNewStorageResource().getStorageNodeDataSources().containsKey(new StorageNode("new"))); - assertTrue(actual.getNewStorageResource().getStorageNodeDataSources().containsKey(new StorageNode("replace"))); + assertThat(actual.getNewStorageResource().getDataSourceMap().size(), is(3)); + assertTrue(actual.getNewStorageResource().getDataSourceMap().containsKey(new StorageNode("not_change"))); + assertTrue(actual.getNewStorageResource().getDataSourceMap().containsKey(new StorageNode("new"))); + assertTrue(actual.getNewStorageResource().getDataSourceMap().containsKey(new StorageNode("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 d8592cbfe01ce..336da862d6d1e 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().getStorageNodeDataSources().get(new StorageNode("foo_db")); + HikariDataSource dataSource = (HikariDataSource) actual.get("swapper_test").getStorageResource().getDataSourceMap().get(new StorageNode("foo_db")); assertThat(dataSource.getJdbcUrl(), is("jdbc:h2:mem:foo_db;DB_CLOSE_DELAY=-1")); assertThat(dataSource.getUsername(), is("sa")); assertThat(dataSource.getPassword(), is(""));