diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfiguration.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfiguration.java index fffb14ebb0323..0c450f59942fb 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfiguration.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfiguration.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.metadata.database.resource.StorageResource; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapperUtils; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapper; import javax.sql.DataSource; @@ -56,8 +56,8 @@ public DataSourceGeneratedDatabaseConfiguration(final Map getStorageNodeDataSourceMap(final Map mappers) { - Map result = new LinkedHashMap<>(mappers.size(), 1F); + private Map getStorageNodeDataSourceMap(final Map mappers) { + Map result = new LinkedHashMap<>(mappers.size(), 1F); for (Entry entry : mappers.entrySet()) { result.computeIfAbsent(entry.getValue().getStorageNode().getName(), key -> DataSourcePoolCreator.create(entry.getKey(), dataSourcePoolPropertiesMap.get(entry.getKey()), true, result.values())); 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 a9c5a3e8b89e7..7564aa9c3956d 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 @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeUtils; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; @@ -43,7 +43,7 @@ @Getter public final class ResourceMetaData { - private final Map dataSourceMap; + private final Map dataSourceMap; private final StorageUnitMetaData storageUnitMetaData; @@ -54,7 +54,7 @@ public ResourceMetaData(final Map dataSources) { StorageUnitNodeMapperUtils.fromDataSources(dataSources)); } - public ResourceMetaData(final String databaseName, final Map dataSourceMap, + public ResourceMetaData(final String databaseName, final Map dataSourceMap, final Map storageUnitNodeMappers, final Map propsMap) { this.dataSourceMap = dataSourceMap; storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSourceMap, propsMap, storageUnitNodeMappers); 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 9a2d17636d27a..d5f960f63bfeb 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 @@ -20,7 +20,7 @@ import lombok.Getter; import org.apache.shardingsphere.infra.datasource.pool.CatalogSwitchableDataSource; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapper; import javax.sql.DataSource; @@ -34,13 +34,13 @@ @Getter public final class StorageResource { - private final Map dataSourceMap; + private final Map dataSourceMap; private final Map storageUnitNodeMappers; private final Map wrappedDataSources; - public StorageResource(final Map dataSourceMap, final Map storageUnitNodeMappers) { + public StorageResource(final Map dataSourceMap, final Map storageUnitNodeMappers) { this.dataSourceMap = dataSourceMap; this.storageUnitNodeMappers = storageUnitNodeMappers; wrappedDataSources = createWrappedDataSources(); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java index 8fda655822d9a..98e0b0337299e 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java @@ -25,7 +25,7 @@ @Getter public final class StorageNode { - private final StorageNodeIdentifier name; + private final StorageNodeName name; private final String url; @@ -36,7 +36,7 @@ public StorageNode(final String name, final String url) { } public StorageNode(final String name, final String url, final String catalog) { - this.name = new StorageNodeIdentifier(name); + this.name = new StorageNodeName(name); this.url = url; this.catalog = catalog; } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeIdentifier.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeName.java similarity index 87% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeIdentifier.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeName.java index 2d7a547bbeac9..ec6941710ba83 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeIdentifier.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeName.java @@ -22,17 +22,17 @@ import lombok.RequiredArgsConstructor; /** - * Storage node identifier. + * Storage node name. */ @RequiredArgsConstructor @Getter -public final class StorageNodeIdentifier { +public final class StorageNodeName { private final String name; @Override public boolean equals(final Object obj) { - return obj instanceof StorageNodeIdentifier && ((StorageNodeIdentifier) obj).name.equalsIgnoreCase(name); + return obj instanceof StorageNodeName && ((StorageNodeName) obj).name.equalsIgnoreCase(name); } @Override diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeUtils.java index 4c36e6dfccded..3b6fca81e8dcf 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeUtils.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeUtils.java @@ -38,8 +38,8 @@ public final class StorageNodeUtils { * @param dataSources data sources * @return storage node data sources */ - public static Map getStorageNodeDataSources(final Map dataSources) { + public static Map getStorageNodeDataSources(final Map dataSources) { return dataSources.entrySet().stream().collect( - Collectors.toMap(entry -> new StorageNodeIdentifier(entry.getKey()), Entry::getValue, (oldValue, currentValue) -> currentValue, () -> new LinkedHashMap<>(dataSources.size(), 1F))); + Collectors.toMap(entry -> new StorageNodeName(entry.getKey()), Entry::getValue, (oldValue, currentValue) -> currentValue, () -> new LinkedHashMap<>(dataSources.size(), 1F))); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java index e940c22317996..75864e6b474c1 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager; import javax.sql.DataSource; @@ -54,25 +54,25 @@ public final class StorageUnit { private final ConnectionProperties connectionProperties; - public StorageUnit(final String databaseName, final Map storageNodeDataSources, + public StorageUnit(final String databaseName, final Map storageNodeDataSources, final DataSourcePoolProperties props, final StorageUnitNodeMapper unitNodeMapper) { this.dataSourcePoolProperties = props; this.unitNodeMapper = unitNodeMapper; dataSource = getStorageUnitDataSource(storageNodeDataSources, unitNodeMapper); - Map enabledStorageNodeDataSources = getEnabledStorageNodeDataSources(databaseName, storageNodeDataSources); + Map enabledStorageNodeDataSources = getEnabledStorageNodeDataSources(databaseName, storageNodeDataSources); storageType = createStorageType(enabledStorageNodeDataSources, unitNodeMapper); connectionProperties = createConnectionProperties(enabledStorageNodeDataSources, unitNodeMapper, storageType).orElse(null); } - private DataSource getStorageUnitDataSource(final Map storageNodeDataSources, final StorageUnitNodeMapper mapper) { + private DataSource getStorageUnitDataSource(final Map storageNodeDataSources, final StorageUnitNodeMapper mapper) { StorageNode storageNode = mapper.getStorageNode(); DataSource dataSource = storageNodeDataSources.get(storageNode.getName()); return new CatalogSwitchableDataSource(dataSource, storageNode.getCatalog(), storageNode.getUrl()); } - private Map getEnabledStorageNodeDataSources(final String databaseName, final Map storageNodeDataSources) { + private Map getEnabledStorageNodeDataSources(final String databaseName, final Map storageNodeDataSources) { Map toBeCheckedDataSources = new LinkedHashMap<>(storageNodeDataSources.size(), 1F); - for (Entry entry : storageNodeDataSources.entrySet()) { + for (Entry entry : storageNodeDataSources.entrySet()) { toBeCheckedDataSources.put(entry.getKey().getName(), entry.getValue()); } Map enabledDataSources = DataSourceStateManager.getInstance().getEnabledDataSources(databaseName, toBeCheckedDataSources); @@ -80,13 +80,13 @@ private Map getEnabledStorageNodeDataSources( .filter(entry -> enabledDataSources.containsKey(entry.getKey().getName())).collect(Collectors.toMap(Entry::getKey, Entry::getValue)); } - private DatabaseType createStorageType(final Map enabledStorageNodeDataSources, final StorageUnitNodeMapper unitNodeMapper) { + private DatabaseType createStorageType(final Map enabledStorageNodeDataSources, final StorageUnitNodeMapper unitNodeMapper) { return DatabaseTypeEngine.getStorageType(enabledStorageNodeDataSources.containsKey(unitNodeMapper.getStorageNode().getName()) ? Collections.singleton(enabledStorageNodeDataSources.get(unitNodeMapper.getStorageNode().getName())) : Collections.emptyList()); } - private Optional createConnectionProperties(final Map enabledStorageNodeDataSources, + private Optional createConnectionProperties(final Map enabledStorageNodeDataSources, final StorageUnitNodeMapper mapper, final DatabaseType storageType) { StorageNode storageNode = mapper.getStorageNode(); if (!enabledStorageNodeDataSources.containsKey(storageNode.getName())) { diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java index 0878b2524ab69..81ef617ad7ad0 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java @@ -19,7 +19,7 @@ import lombok.Getter; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import javax.sql.DataSource; import java.util.LinkedHashMap; @@ -41,7 +41,7 @@ public final class StorageUnitMetaData { // TODO zhangliang: should refactor private final Map dataSources; - public StorageUnitMetaData(final String databaseName, final Map storageNodeDataSources, + public StorageUnitMetaData(final String databaseName, final Map storageNodeDataSources, final Map dataSourcePoolPropertiesMap, final Map unitNodeMappers) { this.unitNodeMappers = unitNodeMappers; storageUnits = new LinkedHashMap<>(unitNodeMappers.size(), 1F); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapperUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapperUtils.java index b3229140f6dc6..e5c6144e3f92e 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapperUtils.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapperUtils.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import javax.sql.DataSource; import java.util.LinkedHashMap; @@ -106,14 +106,14 @@ private static StorageUnitNodeMapper createStorageUnitNodeMapper(final String st * @param storageUnitDataSourcePoolProps storage unit grouped data source pool properties map * @return storage node grouped data source pool properties map */ - public static Map getStorageNodeDataSourcePoolProperties(final Map storageUnitDataSourcePoolProps) { - Map result = new LinkedHashMap<>(); + public static Map getStorageNodeDataSourcePoolProperties(final Map storageUnitDataSourcePoolProps) { + Map result = new LinkedHashMap<>(); for (Entry entry : storageUnitDataSourcePoolProps.entrySet()) { Map standardProps = entry.getValue().getConnectionPropertySynonyms().getStandardProperties(); String url = standardProps.get("url").toString(); boolean isInstanceConnectionAvailable = new DatabaseTypeRegistry(DatabaseTypeFactory.get(url)).getDialectDatabaseMetaData().isInstanceConnectionAvailable(); - StorageNodeIdentifier storageNodeIdentifier = new StorageNodeIdentifier(getStorageNodeName(entry.getKey(), url, standardProps.get("username").toString(), isInstanceConnectionAvailable)); - result.putIfAbsent(storageNodeIdentifier, entry.getValue()); + StorageNodeName storageNodeName = new StorageNodeName(getStorageNodeName(entry.getKey(), url, standardProps.get("username").toString(), isInstanceConnectionAvailable)); + result.putIfAbsent(storageNodeName, entry.getValue()); } return result; } 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 ff0a33911d61c..2ae87a4f66d89 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 @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.datasource.pool.config.DataSourceConfiguration; import org.apache.shardingsphere.infra.datasource.pool.config.PoolConfiguration; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration; import org.junit.jupiter.api.Test; @@ -50,7 +50,7 @@ void assertGetDataSources() { @Test void assertGetStorageNodes() { DataSourceGeneratedDatabaseConfiguration databaseConfig = createDataSourceGeneratedDatabaseConfiguration(); - HikariDataSource hikariDataSource = (HikariDataSource) databaseConfig.getStorageResource().getDataSourceMap().get(new StorageNodeIdentifier("normal_db")); + HikariDataSource hikariDataSource = (HikariDataSource) databaseConfig.getStorageResource().getDataSourceMap().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 034ae50e210fe..d0ca3628adc38 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 @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.datasource.pool.CatalogSwitchableDataSource; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.junit.jupiter.api.Test; @@ -45,7 +45,7 @@ void assertGetDataSources() { @Test void assertGetStorageNodes() { DataSourceProvidedDatabaseConfiguration databaseConfig = createDataSourceProvidedDatabaseConfiguration(); - MockedDataSource dataSource = (MockedDataSource) databaseConfig.getStorageResource().getDataSourceMap().get(new StorageNodeIdentifier("foo_ds")); + MockedDataSource dataSource = (MockedDataSource) databaseConfig.getStorageResource().getDataSourceMap().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 711e3a6a75ff8..7f46cd4ffb601 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 @@ -22,7 +22,7 @@ import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.infra.state.instance.InstanceState; @@ -132,9 +132,9 @@ void assertClose() throws Exception { try (HikariDataSource dataSource = createHikariDataSource()) { ShardingSphereDataSource actual = createShardingSphereDataSource(dataSource); actual.close(); - Map dataSourceMap = getContextManager(actual).getMetaDataContexts().getMetaData() + Map dataSourceMap = getContextManager(actual).getMetaDataContexts().getMetaData() .getDatabase(DefaultDatabase.LOGIC_NAME).getResourceMetaData().getDataSourceMap(); - assertTrue(((HikariDataSource) dataSourceMap.get(new StorageNodeIdentifier("ds"))).isClosed()); + 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 32ed997f03629..e17c37587673a 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 @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.datasource.pool.config.DataSourceConfiguration; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; @@ -120,9 +120,9 @@ private Map getDataSourcePoolPropertiesMap(fin return databaseConfigs.getDataSourcePoolPropertiesMap(); } - private Map getDataSourcePoolPropertiesMap(final Map storageNodeDataSources) { + private Map getDataSourcePoolPropertiesMap(final Map storageNodeDataSources) { Map result = new LinkedHashMap<>(storageNodeDataSources.size(), 1F); - for (Entry entry : storageNodeDataSources.entrySet()) { + for (Entry entry : storageNodeDataSources.entrySet()) { result.put(entry.getKey().getName(), DataSourcePoolPropertiesCreator.create(entry.getValue())); } return result; 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 7b93950749717..c557a740b0322 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 @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; @@ -126,9 +126,9 @@ private Map getDataSourcePoolPropertiesMap(fin return databaseConfigs.getDataSourcePoolPropertiesMap(); } - private Map getDataSourcePoolPropertiesMap(final Map storageNodeDataSources) { + private Map getDataSourcePoolPropertiesMap(final Map storageNodeDataSources) { Map result = new LinkedHashMap<>(storageNodeDataSources.size(), 1F); - for (Entry entry : storageNodeDataSources.entrySet()) { + for (Entry entry : storageNodeDataSources.entrySet()) { result.put(entry.getKey().getName(), DataSourcePoolPropertiesCreator.create(entry.getValue())); } return result; 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 b11c5e2caa226..f79132f3c51f9 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 @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.StorageResource; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapper; @@ -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().getDataSourceMap(), resource); Map newStorageUnitNodeMappers = getNewStorageUnitNodeMappers(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)); @@ -282,9 +282,9 @@ public Map renewDatabase(final ShardingSphereDat new ResourceMetaData(database.getName(), newStorageNodes, newStorageUnitNodeMappers, propsMap), database.getRuleMetaData(), database.getSchemas())); } - private Map getNewStorageNodes(final Map currentStorageNodes, final SwitchingResource resource) { - Map result = new LinkedHashMap<>(); - for (Entry entry : currentStorageNodes.entrySet()) { + 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())) { result.put(entry.getKey(), entry.getValue()); } @@ -364,7 +364,7 @@ private DatabaseConfiguration getDatabaseConfiguration(final ResourceMetaData re } private StorageResource getMergedStorageResource(final ResourceMetaData currentResourceMetaData, final SwitchingResource switchingResource) { - Map storageNodeDataSources = currentResourceMetaData.getDataSourceMap(); + Map storageNodeDataSources = currentResourceMetaData.getDataSourceMap(); Map storageUnitNodeMappers = currentResourceMetaData.getStorageUnitMetaData().getUnitNodeMappers(); if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getDataSourceMap().isEmpty()) { storageNodeDataSources.putAll(switchingResource.getNewStorageResource().getDataSourceMap()); 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 afd30b2a699dd..5448050a69ae6 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 @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.StorageResource; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapperUtils; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapper; import javax.sql.DataSource; @@ -57,10 +57,10 @@ public SwitchingResource registerStorageUnit(final ResourceMetaData resourceMeta private StorageResource getRegisterNewStorageResource(final ResourceMetaData resourceMetaData, final Map mappers, final Map storageUnitDataSourcePoolProps) { - Collection storageNodeIdentifiers = mappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); - Map storageNodeDataSourcePoolProps = StorageUnitNodeMapperUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); - Map newStorageNodes = new LinkedHashMap<>(storageNodeIdentifiers.size(), 1F); - for (StorageNodeIdentifier each : storageNodeIdentifiers) { + Collection storageNodeNames = mappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); + Map storageNodeDataSourcePoolProps = StorageUnitNodeMapperUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); + Map newStorageNodes = new LinkedHashMap<>(storageNodeNames.size(), 1F); + for (StorageNodeName each : storageNodeNames) { if (!resourceMetaData.getDataSourceMap().containsKey(each)) { newStorageNodes.put(each, DataSourcePoolCreator.create(storageNodeDataSourcePoolProps.get(each))); } @@ -84,20 +84,20 @@ public SwitchingResource alterStorageUnit(final ResourceMetaData resourceMetaDat } private StorageResource getAlterNewStorageResource(final Map mappers, final Map storageUnitDataSourcePoolProps) { - Collection toBeAlteredStorageNodeIdentifiers = mappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); - Map storageNodeDataSourcePoolProps = StorageUnitNodeMapperUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); - Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageNodeIdentifiers.size(), 1F); - for (StorageNodeIdentifier each : toBeAlteredStorageNodeIdentifiers) { + Collection toBeAlteredStorageNodeNames = mappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); + Map storageNodeDataSourcePoolProps = StorageUnitNodeMapperUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); + Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageNodeNames.size(), 1F); + for (StorageNodeName each : toBeAlteredStorageNodeNames) { storageNodes.put(each, DataSourcePoolCreator.create(storageNodeDataSourcePoolProps.get(each))); } return new StorageResource(storageNodes, mappers); } private StorageResource getStaleStorageResource(final ResourceMetaData resourceMetaData, final Map mappers) { - Collection toBeAlteredStorageNodeIdentifiers = mappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); - Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageNodeIdentifiers.size(), 1F); - for (Entry entry : resourceMetaData.getDataSourceMap().entrySet()) { - if (toBeAlteredStorageNodeIdentifiers.contains(entry.getKey())) { + Collection toBeAlteredStorageNodeNames = mappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); + Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageNodeNames.size(), 1F); + for (Entry entry : resourceMetaData.getDataSourceMap().entrySet()) { + if (toBeAlteredStorageNodeNames.contains(entry.getKey())) { storageNodes.put(entry.getKey(), entry.getValue()); } } @@ -122,7 +122,7 @@ public SwitchingResource unregisterStorageUnit(final ResourceMetaData resourceMe private StorageResource getToBeRemovedStaleStorageResource(final ResourceMetaData resourceMetaData, final String storageUnitName) { StorageUnitNodeMapper storageUnitNodeMapper = resourceMetaData.getStorageUnitMetaData().getUnitNodeMappers().remove(storageUnitName); Map reservedStorageUnitNodeMappers = resourceMetaData.getStorageUnitMetaData().getUnitNodeMappers(); - Map storageNodes = new LinkedHashMap<>(1, 1F); + Map storageNodes = new LinkedHashMap<>(1, 1F); if (reservedStorageUnitNodeMappers.values().stream().noneMatch(each -> each.getStorageNode().equals(storageUnitNodeMapper.getStorageNode()))) { storageNodes.put(storageUnitNodeMapper.getStorageNode().getName(), resourceMetaData.getDataSourceMap().get(storageUnitNodeMapper.getStorageNode().getName())); } 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 fca32d1365fa5..e4d5429209c9a 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 @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.StorageResource; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapperUtils; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapper; @@ -84,8 +84,8 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet mergedDataSourcePoolPropertiesMap.putAll(toBeChangedPropsMap); Map toBeChangedMappers = StorageUnitNodeMapperUtils.fromDataSourcePoolProperties(toBeChangedPropsMap); StorageResource staleStorageResource = getStaleDataSources(resourceMetaData, toBeChangedMappers, toBeChangedPropsMap); - Collection toBeChangedStorageNodeIdentifiers = toBeChangedMappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); - staleStorageResource.getDataSourceMap().putAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeIdentifiers)); + Collection toBeChangedStorageNodeNames = toBeChangedMappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); + staleStorageResource.getDataSourceMap().putAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeNames)); staleStorageResource.getStorageUnitNodeMappers().putAll( getToBeDeletedStorageUnitNodeMappers(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedMappers.keySet())); return new SwitchingResource(resourceMetaData, @@ -94,20 +94,20 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet private StorageResource createNewStorageResource(final ResourceMetaData resourceMetaData, final Map toBeChangedMappers, final Map storageUnitDataSourcePoolProps) { - Collection toBeChangedStorageNodeIdentifier = toBeChangedMappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); - Map storageNodeDataSourcePoolProps = StorageUnitNodeMapperUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); - Map storageNodes = - getNewStorageNodes(resourceMetaData, toBeChangedStorageNodeIdentifier, storageNodeDataSourcePoolProps); + Collection toBeChangedStorageNodeName = toBeChangedMappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); + Map storageNodeDataSourcePoolProps = StorageUnitNodeMapperUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); + Map storageNodes = + getNewStorageNodes(resourceMetaData, toBeChangedStorageNodeName, storageNodeDataSourcePoolProps); Map storageUnitNodeMappers = getNewStorageUnitNodeMappers(resourceMetaData, toBeChangedMappers); return new StorageResource(storageNodes, storageUnitNodeMappers); } - private Map getNewStorageNodes(final ResourceMetaData resourceMetaData, final Collection toBeChangedStorageNodeIdentifier, - final Map propsMap) { - Map result = new LinkedHashMap<>(resourceMetaData.getDataSourceMap()); - result.keySet().removeAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeIdentifier).keySet()); - result.putAll(getChangedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeIdentifier, propsMap)); - result.putAll(getToBeAddedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodeIdentifier, propsMap)); + 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)); return result; } @@ -119,29 +119,29 @@ private Map getNewStorageUnitNodeMappers(final Re return result; } - private Map getChangedDataSources(final Map storageNodes, - final Collection toBeChangedStorageNodeIdentifier, - final Map propsMap) { - Collection toBeChangedDataSourceNames = toBeChangedStorageNodeIdentifier.stream() + private Map getChangedDataSources(final Map storageNodes, + final Collection toBeChangedStorageNodeName, + final Map propsMap) { + Collection toBeChangedDataSourceNames = toBeChangedStorageNodeName.stream() .filter(each -> isModifiedDataSource(storageNodes, each, propsMap.get(each))).collect(Collectors.toList()); - Map result = new LinkedHashMap<>(toBeChangedStorageNodeIdentifier.size(), 1F); - for (StorageNodeIdentifier each : toBeChangedDataSourceNames) { + Map result = new LinkedHashMap<>(toBeChangedStorageNodeName.size(), 1F); + for (StorageNodeName each : toBeChangedDataSourceNames) { result.put(each, DataSourcePoolCreator.create(propsMap.get(each))); } return result; } - private boolean isModifiedDataSource(final Map originalDataSources, - final StorageNodeIdentifier storageNodeIdentifier, final DataSourcePoolProperties propsMap) { - return originalDataSources.containsKey(storageNodeIdentifier) && !propsMap.equals(DataSourcePoolPropertiesCreator.create(originalDataSources.get(storageNodeIdentifier))); + private boolean isModifiedDataSource(final Map originalDataSources, + final StorageNodeName storageNodeName, final DataSourcePoolProperties propsMap) { + return originalDataSources.containsKey(storageNodeName) && !propsMap.equals(DataSourcePoolPropertiesCreator.create(originalDataSources.get(storageNodeName))); } - private Map getToBeAddedDataSources(final Map storageNodes, - final Collection toBeChangedStorageNodeIdentifier, - final Map propsMap) { - Collection toBeAddedDataSourceNames = toBeChangedStorageNodeIdentifier.stream().filter(each -> !storageNodes.containsKey(each)).collect(Collectors.toList()); - Map result = new LinkedHashMap<>(); - for (StorageNodeIdentifier each : toBeAddedDataSourceNames) { + private Map getToBeAddedDataSources(final Map storageNodes, + final Collection toBeChangedStorageNodeName, + final Map propsMap) { + Collection toBeAddedDataSourceNames = toBeChangedStorageNodeName.stream().filter(each -> !storageNodes.containsKey(each)).collect(Collectors.toList()); + Map result = new LinkedHashMap<>(); + for (StorageNodeName each : toBeAddedDataSourceNames) { result.put(each, DataSourcePoolCreator.create(propsMap.get(each))); } return result; @@ -151,10 +151,10 @@ private StorageResource getToBeRemovedStaleDataSources(final ResourceMetaData re Map reservedStorageUnitNodeMappers = resourceMetaData.getStorageUnitMetaData().getStorageUnits().entrySet().stream() .filter(entry -> !toRemovedMappers.containsKey(entry.getKey())) .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getUnitNodeMapper())); - Collection toBeRemovedStorageNodeIdentifiers = toRemovedMappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); - Collection inUsedDataSourceNames = reservedStorageUnitNodeMappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); - Map staleStorageNodes = resourceMetaData.getDataSourceMap().entrySet().stream() - .filter(entry -> toBeRemovedStorageNodeIdentifiers.contains(entry.getKey()) && !inUsedDataSourceNames.contains(entry.getKey())) + Collection toBeRemovedStorageNodeNames = toRemovedMappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); + Collection inUsedDataSourceNames = reservedStorageUnitNodeMappers.values().stream().map(each -> each.getStorageNode().getName()).collect(Collectors.toSet()); + Map staleStorageNodes = resourceMetaData.getDataSourceMap().entrySet().stream() + .filter(entry -> toBeRemovedStorageNodeNames.contains(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())); @@ -163,29 +163,29 @@ private StorageResource getToBeRemovedStaleDataSources(final ResourceMetaData re private StorageResource getStaleDataSources(final ResourceMetaData resourceMetaData, final Map toBeChangedMappers, final Map storageUnitDataSourcePoolProps) { - Map storageNodes = new LinkedHashMap<>(resourceMetaData.getDataSourceMap().size(), 1F); + Map storageNodes = new LinkedHashMap<>(resourceMetaData.getDataSourceMap().size(), 1F); Map storageUnitNodeMappers = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getUnitNodeMappers().size(), 1F); storageNodes.putAll(getToBeChangedDataSources(resourceMetaData.getDataSourceMap(), StorageUnitNodeMapperUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps))); storageUnitNodeMappers.putAll(getChangedStorageUnitNodeMappers(resourceMetaData.getStorageUnitMetaData().getStorageUnits(), toBeChangedMappers)); return new StorageResource(storageNodes, storageUnitNodeMappers); } - private Map getToBeChangedDataSources(final Map storageNodes, - final Map propsMap) { - Map result = new LinkedHashMap<>(storageNodes.size(), 1F); - for (Entry entry : propsMap.entrySet()) { - StorageNodeIdentifier storageNodeIdentifier = entry.getKey(); - if (isModifiedDataSource(storageNodes, storageNodeIdentifier, entry.getValue())) { - result.put(storageNodeIdentifier, storageNodes.get(storageNodeIdentifier)); + private Map getToBeChangedDataSources(final Map storageNodes, + final Map propsMap) { + Map result = new LinkedHashMap<>(storageNodes.size(), 1F); + for (Entry entry : propsMap.entrySet()) { + StorageNodeName storageNodeName = entry.getKey(); + if (isModifiedDataSource(storageNodes, storageNodeName, entry.getValue())) { + result.put(storageNodeName, storageNodes.get(storageNodeName)); } } return result; } - private Map getToBeDeletedDataSources(final Map storageNodes, - final Collection toBeChangedDataSourceNames) { - Map result = new LinkedHashMap<>(storageNodes.size(), 1F); - for (Entry entry : storageNodes.entrySet()) { + private Map getToBeDeletedDataSources(final Map storageNodes, + final Collection toBeChangedDataSourceNames) { + Map result = new LinkedHashMap<>(storageNodes.size(), 1F); + for (Entry entry : storageNodes.entrySet()) { if (!toBeChangedDataSourceNames.contains(entry.getKey())) { result.put(entry.getKey(), entry.getValue()); } 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 eb2868a3f0238..3c63782839066 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 @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeUtils; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapper; @@ -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 StorageNodeIdentifier("foo_ds"))); + .getResourceMetaData().getDataSourceMap().get(new StorageNodeName("foo_ds"))); } private ResourceMetaData createOriginalResource() { @@ -254,7 +254,7 @@ private ResourceMetaData createOriginalResource() { originalDataSources.put("ds_1", new MockedDataSource()); originalDataSources.put("ds_2", new MockedDataSource()); when(result.getStorageUnitMetaData().getDataSources()).thenReturn(originalDataSources); - Map storageNodeDataSourceMap = StorageNodeUtils.getStorageNodeDataSources(originalDataSources); + Map storageNodeDataSourceMap = StorageNodeUtils.getStorageNodeDataSources(originalDataSources); Map storageUnits = new LinkedHashMap<>(2, 1F); Map storageUnitNodeMappers = StorageUnitNodeMapperUtils.fromDataSources(originalDataSources); for (Entry entry : storageUnitNodeMappers.entrySet()) { 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 face5419b7849..2dbceba9c2f61 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 @@ -18,7 +18,7 @@ package org.apache.shardingsphere.mode.manager.switcher; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.awaitility.Awaitility; @@ -86,9 +86,9 @@ 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 StorageNodeIdentifier("not_change"))); - assertTrue(actual.getNewStorageResource().getDataSourceMap().containsKey(new StorageNodeIdentifier("new"))); - assertTrue(actual.getNewStorageResource().getDataSourceMap().containsKey(new StorageNodeIdentifier("replace"))); + 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"))); } private void assertStaleDataSources(final Map originalDataSourceMap) { diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java index b2ad9221da3bf..8cebd574e4dca 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.StorageResource; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; @@ -36,8 +36,8 @@ class SwitchingResourceTest { void assertCloseStaleDataSources() { MockedDataSource staleDataSource = new MockedDataSource(); ResourceMetaData resourceMetaData = mock(ResourceMetaData.class); - StorageResource newStorageResource = new StorageResource(Collections.singletonMap(new StorageNodeIdentifier("new_ds"), new MockedDataSource()), Collections.emptyMap()); - StorageResource staleStorageResource = new StorageResource(Collections.singletonMap(new StorageNodeIdentifier("stale_ds"), staleDataSource), Collections.emptyMap()); + StorageResource newStorageResource = new StorageResource(Collections.singletonMap(new StorageNodeName("new_ds"), new MockedDataSource()), Collections.emptyMap()); + StorageResource staleStorageResource = new StorageResource(Collections.singletonMap(new StorageNodeName("stale_ds"), staleDataSource), Collections.emptyMap()); new SwitchingResource(resourceMetaData, newStorageResource, staleStorageResource, Collections.emptyMap()).closeStaleDataSources(); Awaitility.await().pollDelay(10L, TimeUnit.MILLISECONDS).until(staleDataSource::isClosed); assertTrue(staleDataSource.isClosed()); 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 ecf976187987b..d6d690ac1cd6a 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 @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeIdentifier; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.proxy.backend.config.ProxyConfiguration; import org.apache.shardingsphere.proxy.backend.config.ProxyConfigurationLoader; import org.apache.shardingsphere.proxy.backend.config.YamlProxyConfiguration; @@ -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 StorageNodeIdentifier("foo_db")); + HikariDataSource dataSource = (HikariDataSource) actual.get("swapper_test").getStorageResource().getDataSourceMap().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(""));