diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java index 376827ab6cd21..80cdf27f0020d 100644 --- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java +++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java @@ -45,12 +45,12 @@ public Optional export(final String pluginTyp GaugeMetricFamilyMetricsCollector result = MetricsCollectorRegistry.get(config, pluginType); result.cleanMetrics(); MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); - result.addMetric(Collections.singletonList("database_count"), metaDataContexts.getMetaData().getDatabases().size()); + result.addMetric(Collections.singletonList("database_count"), metaDataContexts.getMetaData().getAllDatabases().size()); result.addMetric(Collections.singletonList("storage_unit_count"), getStorageUnitCount(metaDataContexts)); return Optional.of(result); } private int getStorageUnitCount(final MetaDataContexts metaDataContexts) { - return metaDataContexts.getMetaData().getDatabases().values().stream().map(each -> each.getResourceMetaData().getStorageUnits().size()).reduce(0, Integer::sum); + return metaDataContexts.getMetaData().getAllDatabases().stream().map(each -> each.getResourceMetaData().getStorageUnits().size()).reduce(0, Integer::sum); } } diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java index 64ce8e8f02ac9..5663a0dddfdea 100644 --- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java +++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java @@ -81,7 +81,7 @@ private ContextManager mockContextManager() { when(database.getResourceMetaData().getStorageUnits()).thenReturn(Collections.singletonMap("ds_0", mock(StorageUnit.class))); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getDatabases()).thenReturn(Collections.singletonMap("sharding_db", database)); + when(metaData.getAllDatabases()).thenReturn(Collections.singleton(database)); MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java index 228de852c43fb..594d99fbc9eea 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.infra.rule.scope.GlobalRule; import org.apache.shardingsphere.infra.rule.scope.GlobalRule.GlobalRuleChangedType; +import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.Optional; @@ -68,6 +69,15 @@ public ShardingSphereMetaData(final Map database temporaryProps = new TemporaryConfigurationProperties(props.getProps()); } + /** + * Get all databases. + * + * @return all databases + */ + public Collection getAllDatabases() { + return databases.values(); + } + /** * Judge contains database from meta data or not. * diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/MySQLShardingSphereStatisticsBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/MySQLShardingSphereStatisticsBuilder.java index 5365a50fb1e49..f8fd2cf450f93 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/MySQLShardingSphereStatisticsBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/MySQLShardingSphereStatisticsBuilder.java @@ -29,7 +29,6 @@ import org.apache.shardingsphere.infra.metadata.statistics.builder.ShardingSphereStatisticsBuilder; import java.util.Collections; -import java.util.Map.Entry; /** * ShardingSphere statistics builder for MySQL. @@ -46,11 +45,11 @@ public final class MySQLShardingSphereStatisticsBuilder implements ShardingSpher @Override public ShardingSphereStatistics build(final ShardingSphereMetaData metaData) { ShardingSphereStatistics result = new ShardingSphereStatistics(); - for (Entry entry : metaData.getDatabases().entrySet()) { + for (ShardingSphereDatabase each : metaData.getAllDatabases()) { ShardingSphereDatabaseData databaseData = new ShardingSphereDatabaseData(); - initSchemas(entry.getValue(), databaseData); + initSchemas(each, databaseData); if (!databaseData.getSchemaData().isEmpty()) { - result.putDatabase(entry.getKey(), databaseData); + result.putDatabase(each.getName(), databaseData); } } return result; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLShardingSphereStatisticsBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLShardingSphereStatisticsBuilder.java index c4c64fc402903..9aa632484299e 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLShardingSphereStatisticsBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLShardingSphereStatisticsBuilder.java @@ -57,11 +57,11 @@ public final class PostgreSQLShardingSphereStatisticsBuilder implements Sharding @Override public ShardingSphereStatistics build(final ShardingSphereMetaData metaData) { ShardingSphereStatistics result = new ShardingSphereStatistics(); - for (Entry entry : metaData.getDatabases().entrySet()) { + for (ShardingSphereDatabase each : metaData.getAllDatabases()) { ShardingSphereDatabaseData databaseData = new ShardingSphereDatabaseData(); - initSchemas(entry.getValue(), databaseData); + initSchemas(each, databaseData); if (!databaseData.getSchemaData().isEmpty()) { - result.putDatabase(entry.getKey(), databaseData); + result.putDatabase(each.getName(), databaseData); } } return result; diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLShardingSphereStatisticsBuilderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLShardingSphereStatisticsBuilderTest.java index 2fdfcc80b86fd..daafa53d0621a 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLShardingSphereStatisticsBuilderTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLShardingSphereStatisticsBuilderTest.java @@ -24,8 +24,8 @@ import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics; import org.junit.jupiter.api.Test; +import java.util.Collection; import java.util.Collections; -import java.util.Map; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -45,17 +45,18 @@ void assertBuild() { private ShardingSphereMetaData mockMetaData() { ShardingSphereMetaData result = mock(ShardingSphereMetaData.class); - Map databaseMap = mockDatabaseMap(); - when(result.getDatabases()).thenReturn(databaseMap); + Collection databases = mockDatabases(); + when(result.getAllDatabases()).thenReturn(databases); return result; } - private Map mockDatabaseMap() { + private Collection mockDatabases() { ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); + when(database.getName()).thenReturn("logic_db"); ShardingSphereSchema schema = mockSchema(); when(database.getAllSchemas()).thenReturn(Collections.singleton(schema)); when(database.getSchema("pg_catalog")).thenReturn(schema); - return Collections.singletonMap("logic_db", database); + return Collections.singleton(database); } private ShardingSphereSchema mockSchema() { diff --git a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/utils/StatisticsAssembleUtils.java b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/utils/StatisticsAssembleUtils.java index 1e70d9cf7ec38..2bbf5a38e2ed1 100644 --- a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/utils/StatisticsAssembleUtils.java +++ b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/utils/StatisticsAssembleUtils.java @@ -49,9 +49,9 @@ public static ShardingSphereTableData assembleTableData(final ShardingSphereTabl // TODO move this logic to ShardingSphere statistics ShardingSphereTableData result = new ShardingSphereTableData(table.getName()); if (EnumerableConstants.PG_DATABASE.equalsIgnoreCase(table.getName())) { - assembleOpenGaussDatabaseData(result, metaData.getDatabases().values()); + assembleOpenGaussDatabaseData(result, metaData.getAllDatabases()); } else if (EnumerableConstants.PG_TABLES.equalsIgnoreCase(table.getName())) { - for (ShardingSphereDatabase each : metaData.getDatabases().values()) { + for (ShardingSphereDatabase each : metaData.getAllDatabases()) { assembleOpenGaussTableData(result, each.getAllSchemas()); } } else if (EnumerableConstants.PG_ROLES.equalsIgnoreCase(table.getName())) { diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java index 02f019185f593..7a60596056d65 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java @@ -198,7 +198,7 @@ private void persistTable(final ShardingSphereDatabase database, final String sc * @return pre-selected database name */ public String getPreSelectedDatabaseName() { - return InstanceType.JDBC == computeNodeInstanceContext.getInstance().getMetaData().getType() ? metaDataContexts.get().getMetaData().getDatabases().keySet().iterator().next() : null; + return InstanceType.JDBC == computeNodeInstanceContext.getInstance().getMetaData().getType() ? metaDataContexts.get().getMetaData().getAllDatabases().iterator().next().getName() : null; } @Override diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java index e261e2354f7ef..ab74bef88515d 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java @@ -53,7 +53,7 @@ public void close() { private Collection getAllRules() { Collection result = new LinkedList<>(metaData.getGlobalRuleMetaData().getRules()); - metaData.getDatabases().values().stream().map(each -> each.getRuleMetaData().getRules()).forEach(result::addAll); + metaData.getAllDatabases().stream().map(each -> each.getRuleMetaData().getRules()).forEach(result::addAll); return result; } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java index 36ac87b94a536..6318ad6ec6a2f 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java @@ -168,10 +168,10 @@ private static void closeGeneratedDataSources(final String databaseName, final M } private static ShardingSphereStatistics initStatistics(final MetaDataPersistService persistService, final ShardingSphereMetaData metaData) { - if (metaData.getDatabases().isEmpty()) { + if (metaData.getAllDatabases().isEmpty()) { return new ShardingSphereStatistics(); } - DatabaseType protocolType = metaData.getDatabases().values().iterator().next().getProtocolType(); + DatabaseType protocolType = metaData.getAllDatabases().iterator().next().getProtocolType(); DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(protocolType).getDialectDatabaseMetaData(); // TODO can `protocolType instanceof SchemaSupportedDatabaseType ? "PostgreSQL" : protocolType.getType()` replace to trunk database type? DatabaseType databaseType = dialectDatabaseMetaData.getDefaultSchema().isPresent() ? TypedSPILoader.getService(DatabaseType.class, "PostgreSQL") : protocolType; @@ -238,7 +238,7 @@ private static void persistDatabaseConfigurations(final MetaDataContexts metadat } private static void persistMetaData(final MetaDataContexts metaDataContexts, final MetaDataPersistService persistService) { - metaDataContexts.getMetaData().getDatabases().values().forEach(each -> each.getAllSchemas().forEach(schema -> { + metaDataContexts.getMetaData().getAllDatabases().forEach(each -> each.getAllSchemas().forEach(schema -> { if (schema.isEmpty()) { persistService.getDatabaseMetaDataFacade().getSchema().add(each.getName(), schema.getName()); } @@ -247,7 +247,7 @@ private static void persistMetaData(final MetaDataContexts metaDataContexts, fin for (Entry databaseDataEntry : metaDataContexts.getStatistics().getDatabaseData().entrySet()) { for (Entry schemaDataEntry : databaseDataEntry.getValue().getSchemaData().entrySet()) { persistService.getShardingSphereDataPersistService().persist( - metaDataContexts.getMetaData().getDatabases().get(databaseDataEntry.getKey().toLowerCase()), schemaDataEntry.getKey(), schemaDataEntry.getValue()); + metaDataContexts.getMetaData().getDatabase(databaseDataEntry.getKey()), schemaDataEntry.getKey(), schemaDataEntry.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 7568dbcf6293d..2c23c3c81596e 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 @@ -87,7 +87,7 @@ void setUp() throws SQLException { ShardingSphereDatabase database = mockDatabase(); when(metaDataContexts.getMetaData().containsDatabase("foo_db")).thenReturn(true); when(metaDataContexts.getMetaData().getDatabase("foo_db")).thenReturn(database); - when(metaDataContexts.getMetaData().getDatabases().values()).thenReturn(Collections.singleton(database)); + when(metaDataContexts.getMetaData().getAllDatabases()).thenReturn(Collections.singleton(database)); when(computeNodeInstanceContext.getInstance()).thenReturn(new ComputeNodeInstance(new ProxyInstanceMetaData("foo_id", 3307), Collections.emptyList())); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); contextManager = new ContextManager(metaDataContexts, computeNodeInstanceContext, mock(PersistRepository.class)); @@ -174,7 +174,9 @@ void assertReloadTableWithDataSourceName() throws SQLException { @Test void assertGetPreSelectedDatabaseNameWithJDBC() { when(computeNodeInstanceContext.getInstance()).thenReturn(new ComputeNodeInstance(new JDBCInstanceMetaData("foo_id", "foo_db"), Collections.emptyList())); - when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("foo_db", mock(ShardingSphereDatabase.class))); + ShardingSphereDatabase database = mock(ShardingSphereDatabase.class); + when(database.getName()).thenReturn("foo_db"); + when(metaDataContexts.getMetaData().getAllDatabases()).thenReturn(Collections.singleton(database)); assertThat(contextManager.getPreSelectedDatabaseName(), is("foo_db")); } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManagerTest.java index 627fe3d678f26..e505af62edf89 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManagerTest.java @@ -67,7 +67,7 @@ void setUp() { ShardingSphereDatabase database = mockDatabase(); when(metaDataContexts.getMetaData().containsDatabase("foo_db")).thenReturn(true); when(metaDataContexts.getMetaData().getDatabase("foo_db")).thenReturn(database); - when(metaDataContexts.getMetaData().getDatabases().values()).thenReturn(Collections.singleton(database)); + when(metaDataContexts.getMetaData().getAllDatabases()).thenReturn(Collections.singleton(database)); schemaMetaDataManager = new SchemaMetaDataManager(new AtomicReference<>(metaDataContexts), mock(PersistRepository.class)); } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngineTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngineTest.java index b6512f67dffed..1b2a77808d9d0 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngineTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngineTest.java @@ -83,7 +83,7 @@ private ShardingSphereMetaData mockMetaData() { ShardingSphereMetaData result = mock(ShardingSphereMetaData.class); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class); when(database.getName()).thenReturn("logic_db"); - when(result.getDatabases()).thenReturn(Collections.singletonMap("logic_db", database)); + when(result.getAllDatabases()).thenReturn(Collections.singleton(database)); when(result.getDatabase("logic_db")).thenReturn(database); when(result.containsDatabase("logic_db")).thenReturn(true); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java index ee2234b025f1a..c2da0ec039206 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java @@ -184,7 +184,7 @@ private void afterStorageUnitsAltered(final String databaseName, final MetaDataC .getSchema().alterByRuleAltered(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), each)); Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseData().get(databaseName)) .ifPresent(optional -> optional.getSchemaData().forEach((schemaName, schemaData) -> metaDataPersistService.getShardingSphereDataPersistService() - .persist(originalMetaDataContexts.getMetaData().getDatabases().get(databaseName.toLowerCase()), schemaName, schemaData))); + .persist(originalMetaDataContexts.getMetaData().getDatabase(databaseName), schemaName, schemaData))); metaDataPersistService.persistReloadDatabaseByAlter(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), originalMetaDataContexts.getMetaData().getDatabase(databaseName)); } @@ -194,7 +194,7 @@ private void afterStorageUnitsDropped(final String databaseName, final MetaDataC .getSchema().alterByRuleDropped(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), each)); Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseData().get(databaseName)) .ifPresent(optional -> optional.getSchemaData().forEach((schemaName, schemaData) -> metaDataPersistService.getShardingSphereDataPersistService() - .persist(originalMetaDataContexts.getMetaData().getDatabases().get(databaseName.toLowerCase()), schemaName, schemaData))); + .persist(originalMetaDataContexts.getMetaData().getDatabase(databaseName), schemaName, schemaData))); metaDataPersistService.persistReloadDatabaseByDrop(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), originalMetaDataContexts.getMetaData().getDatabase(databaseName)); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/executor/callback/ProxyJDBCExecutorCallback.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/executor/callback/ProxyJDBCExecutorCallback.java index 2631c70cb9ae0..6005088cf5f75 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/executor/callback/ProxyJDBCExecutorCallback.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/executor/callback/ProxyJDBCExecutorCallback.java @@ -111,9 +111,9 @@ private DatabaseType getProtocolTypeType() { if (null != configuredDatabaseType) { return configuredDatabaseType; } - if (ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases().isEmpty()) { + if (ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getAllDatabases().isEmpty()) { return TypedSPILoader.getService(DatabaseType.class, "MySQL"); } - return ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases().values().iterator().next().getProtocolType(); + return ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getAllDatabases().iterator().next().getProtocolType(); } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java index bf9c52cef9143..4c1e12fe6e933 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java @@ -79,7 +79,7 @@ public boolean databaseExists(final String name) { * @return all database names */ public Collection getAllDatabaseNames() { - return contextManager.getMetaDataContexts().getMetaData().getDatabases().values().stream().map(ShardingSphereDatabase::getName).collect(Collectors.toList()); + return contextManager.getMetaDataContexts().getMetaData().getAllDatabases().stream().map(ShardingSphereDatabase::getName).collect(Collectors.toList()); } /** @@ -97,7 +97,7 @@ public Optional getInstanceStateContext() { * @return database type */ public DatabaseType getDatabaseType() { - Collection databases = contextManager.getMetaDataContexts().getMetaData().getDatabases().values(); + Collection databases = contextManager.getMetaDataContexts().getMetaData().getAllDatabases(); return databases.stream().flatMap(each -> each.getResourceMetaData().getStorageUnits().values().stream()).findFirst().map(StorageUnit::getStorageType) .orElseGet(DatabaseTypeEngine::getDefaultStorageType); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java index e09c85bb2b82a..9c4de4e7e4589 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java @@ -79,12 +79,12 @@ private String generateExportData(final ShardingSphereMetaData metaData, final E private Map> getAllStorageNodes(final ShardingSphereMetaData metaData) { Map> storageNodes = new LinkedHashMap<>(); - metaData.getDatabases().values().forEach(each -> { + for (ShardingSphereDatabase each : metaData.getAllDatabases()) { if (each.getResourceMetaData().getAllInstanceDataSourceNames().isEmpty()) { - return; + continue; } storageNodes.putAll(generateDatabaseExportStorageNodesData(each)); - }); + } return storageNodes; } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java index 34f70664ee047..81e88ce46b6c0 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java @@ -120,7 +120,7 @@ void setUp() { private ContextManager mockContextManager() { ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); when(metaData.getDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)); - when(metaData.getDatabases().values().iterator().next().getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); + when(metaData.getAllDatabases().iterator().next().getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(metaData.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(0); TransactionRule transactionRule = mock(TransactionRule.class); when(transactionRule.getDefaultType()).thenReturn(TransactionType.LOCAL); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java index 4f4ecd507f3c6..9d98488a8d834 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java @@ -104,7 +104,7 @@ void setUp() { when(databaseConnectionManager.getConnectionSession().getUsedDatabaseName()).thenReturn(DefaultDatabase.LOGIC_NAME); ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); when(metaData.getDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)); - when(metaData.getDatabases().values().iterator().next().getProtocolType()).thenReturn(databaseType); + when(metaData.getAllDatabases().iterator().next().getProtocolType()).thenReturn(databaseType); when(metaData.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(0); when(transactionRule.getDefaultType()).thenReturn(TransactionType.XA); when(metaData.getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Arrays.asList(mock(SQLFederationRule.class), transactionRule))); diff --git a/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java b/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java index 523060245170b..417ae2424cade 100644 --- a/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java +++ b/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java @@ -49,7 +49,7 @@ public final class ShardingSphereProxyVersion { */ public static void setVersion(final ContextManager contextManager) { CommonConstants.PROXY_VERSION.set(getProxyVersion()); - contextManager.getMetaDataContexts().getMetaData().getDatabases().values().forEach(ShardingSphereProxyVersion::setDatabaseVersion); + contextManager.getMetaDataContexts().getMetaData().getAllDatabases().forEach(ShardingSphereProxyVersion::setDatabaseVersion); } private static String getProxyVersion() { diff --git a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java index ae64a3eae2f94..0b2a5a8322a6d 100644 --- a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java +++ b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java @@ -47,10 +47,10 @@ public static DatabaseType getDatabaseType() { return configuredDatabaseType.get(); } MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); - if (metaDataContexts.getMetaData().getDatabases().isEmpty()) { + if (metaDataContexts.getMetaData().getAllDatabases().isEmpty()) { return TypedSPILoader.getService(DatabaseType.class, DEFAULT_FRONTEND_DATABASE_PROTOCOL_TYPE); } - Optional database = metaDataContexts.getMetaData().getDatabases().values().stream().filter(ShardingSphereDatabase::containsDataSource).findFirst(); + Optional database = metaDataContexts.getMetaData().getAllDatabases().stream().filter(ShardingSphereDatabase::containsDataSource).findFirst(); return database.isPresent() ? database.get().getResourceMetaData().getStorageUnits().values().iterator().next().getStorageType() : TypedSPILoader.getService(DatabaseType.class, DEFAULT_FRONTEND_DATABASE_PROTOCOL_TYPE); diff --git a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java index 81f6da4a516e2..f70d8d5293740 100644 --- a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java +++ b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java @@ -90,7 +90,7 @@ void assertExecuteWithDistributedTransaction() { private ContextManager mockContextManager() { ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); when(metaData.getDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)); - when(metaData.getDatabases().values().iterator().next().getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); + when(metaData.getAllDatabases().iterator().next().getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(metaData.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(0); TransactionRule transactionRule = mock(TransactionRule.class); when(transactionRule.getDefaultType()).thenReturn(TransactionType.XA);