diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java index 30fb1fd01dfe0..f2fc0fcdaf097 100644 --- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java +++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java @@ -35,6 +35,7 @@ import org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -84,6 +85,6 @@ private ContextManager mockContextManager() { ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext( new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext()); - return new ContextManager(metaDataContexts, computeNodeInstanceContext); + return new ContextManager(metaDataContexts, computeNodeInstanceContext, mock(PersistRepository.class)); } } diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java index 3dd403011943b..be934e121087a 100644 --- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java +++ b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -73,6 +74,6 @@ private ContextManager mockContextManager() { ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext( new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext()); - return new ContextManager(metaDataContexts, computeNodeInstanceContext); + return new ContextManager(metaDataContexts, computeNodeInstanceContext, mock(PersistRepository.class)); } } diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java index 9ba188fd2c32b..f8dcce5ec9c13 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java @@ -77,7 +77,7 @@ private void checkBeforeUpdate(final AlterReadwriteSplittingStorageUnitStatusSta private void updateStatus(final ContextManager contextManager, final AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement) { DataSourceState status = sqlStatement.isEnable() ? DataSourceState.ENABLED : DataSourceState.DISABLED; - new QualifiedDataSourceStatusService(contextManager.getMetaDataContexts().getPersistService().getRepository()) + new QualifiedDataSourceStatusService(contextManager.getRepository()) .changeStatus(database.getName(), sqlStatement.getRuleName(), sqlStatement.getStorageUnitName(), status); } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java index 22525d5feca6a..20d07acebce6b 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java @@ -55,7 +55,7 @@ public void executeUpdate() { checkBeforeUpdate(); RuleConfiguration currentRuleConfig = rule.map(ShardingSphereRule::getConfiguration).orElse(null); if (getRefreshStatus(rule.isPresent())) { - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService() + contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() .switchActiveVersion(DatabaseRuleOperatorFactory.newInstance(contextManager, executor).operate(sqlStatement, database, currentRuleConfig)); } } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java index 85e675c4cb3ba..f4472436f1462 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java @@ -109,7 +109,7 @@ private Map getTrafficDataSourceMap(final String databaseNam if (rule.getStrategyRules().isEmpty()) { return Collections.emptyMap(); } - MetaDataPersistService persistService = contextManager.getMetaDataContexts().getPersistService(); + MetaDataPersistService persistService = contextManager.getPersistServiceFacade().getMetaDataPersistService(); String actualDatabaseName = contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(); Map propsMap = persistService.getDataSourceUnitService().load(actualDatabaseName); Preconditions.checkState(!propsMap.isEmpty(), "Can not get data source properties from meta data."); diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java index a611dc0e6337b..9391da3a3940b 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java @@ -78,7 +78,7 @@ private ContextManager mockContextManager() throws SQLException { Map storageUnits = mockStorageUnits(); when(result.getStorageUnits(DefaultDatabase.LOGIC_NAME)).thenReturn(storageUnits); MetaDataPersistService persistService = mockMetaDataPersistService(); - when(result.getMetaDataContexts().getPersistService()).thenReturn(persistService); + when(result.getPersistServiceFacade().getMetaDataPersistService()).thenReturn(persistService); when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn( new RuleMetaData(Arrays.asList(mock(AuthorityRule.class, RETURNS_DEEP_STUBS), mock(TransactionRule.class, RETURNS_DEEP_STUBS), mock(TrafficRule.class, RETURNS_DEEP_STUBS)))); diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/api/PipelineAPIFactory.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/api/PipelineAPIFactory.java index 2d169478de261..b8ad17805f071 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/api/PipelineAPIFactory.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/api/PipelineAPIFactory.java @@ -63,7 +63,7 @@ public static PipelineGovernanceFacade getPipelineGovernanceFacade(final Pipelin @Override protected PipelineGovernanceFacade initialize() { ContextManager contextManager = PipelineContextManager.getContext(contextKey).getContextManager(); - return new PipelineGovernanceFacade((ClusterPersistRepository) contextManager.getMetaDataContexts().getPersistService().getRepository()); + return new PipelineGovernanceFacade((ClusterPersistRepository) contextManager.getPersistServiceFacade().getMetaDataPersistService().getRepository()); } }).get(); } diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineDistributedBarrier.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineDistributedBarrier.java index 70035e61e100e..88ddf2a17570e 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineDistributedBarrier.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineDistributedBarrier.java @@ -163,7 +163,7 @@ private final class PersistRepositoryLazyInitializer extends LazyInitializer versions = repository.getChildrenKeys(TableMetaDataNode.getTableVersionsNode(databaseName, schemaName, tableName)); String nextActiveVersion = versions.isEmpty() ? DEFAULT_VERSION : String.valueOf(Integer.parseInt(versions.get(0)) + 1); - repository.persist(TableMetaDataNode.getTableVersionNode(databaseName, schemaName, tableName, nextActiveVersion), - YamlEngine.marshal(new YamlTableSwapper().swapToYamlConfiguration(entry.getValue()))); + if (entry.getValue() != null) { + repository.persist(TableMetaDataNode.getTableVersionNode(databaseName, schemaName, tableName, nextActiveVersion), + YamlEngine.marshal(new YamlTableSwapper().swapToYamlConfiguration(entry.getValue()))); + } if (Strings.isNullOrEmpty(getActiveVersion(databaseName, schemaName, tableName))) { repository.persist(TableMetaDataNode.getTableActiveVersionNode(databaseName, schemaName, tableName), DEFAULT_VERSION); } 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 8293ccd04d958..159240a79501e 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 @@ -46,6 +46,7 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.service.PersistServiceFacade; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.mode.state.StateContext; import java.sql.SQLException; @@ -77,15 +78,18 @@ public final class ContextManager implements AutoCloseable { private final PersistServiceFacade persistServiceFacade; - public ContextManager(final MetaDataContexts metaDataContexts, final ComputeNodeInstanceContext computeNodeInstanceContext) { + private final PersistRepository repository; + + public ContextManager(final MetaDataContexts metaDataContexts, final ComputeNodeInstanceContext computeNodeInstanceContext, final PersistRepository repository) { this.metaDataContexts = new AtomicReference<>(metaDataContexts); this.computeNodeInstanceContext = computeNodeInstanceContext; - shardingSphereDatabaseContextManager = new ShardingSphereDatabaseContextManager(this.metaDataContexts); - configurationContextManager = new ConfigurationContextManager(this.metaDataContexts, computeNodeInstanceContext); - resourceMetaDataContextManager = new ResourceMetaDataContextManager(this.metaDataContexts); + this.repository = repository; + persistServiceFacade = new PersistServiceFacade(repository, computeNodeInstanceContext.getModeConfiguration(), this); + shardingSphereDatabaseContextManager = new ShardingSphereDatabaseContextManager(this.metaDataContexts, persistServiceFacade); + configurationContextManager = new ConfigurationContextManager(this.metaDataContexts, computeNodeInstanceContext, persistServiceFacade); + resourceMetaDataContextManager = new ResourceMetaDataContextManager(this.metaDataContexts, persistServiceFacade); executorEngine = ExecutorEngine.createExecutorEngineWithSize(metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)); stateContext = new StateContext(); - persistServiceFacade = new PersistServiceFacade(metaDataContexts.getPersistService().getRepository(), computeNodeInstanceContext.getModeConfiguration(), this); } /** @@ -138,7 +142,7 @@ public Map getStorageUnits(final String databaseName) { public void refreshDatabaseMetaData(final ShardingSphereDatabase database, final boolean force) { try { MetaDataContexts reloadedMetaDataContexts = createMetaDataContexts(database); - MetaDataPersistService persistService = metaDataContexts.get().getPersistService(); + MetaDataPersistService persistService = persistServiceFacade.getMetaDataPersistService(); if (force) { metaDataContexts.set(reloadedMetaDataContexts); metaDataContexts.get().getMetaData().getDatabase(database.getName()).getSchemas() @@ -165,14 +169,14 @@ public void refreshTableMetaData(final ShardingSphereDatabase database) { deletedSchemaNames(database.getName(), reloadedMetaDataContexts.getMetaData().getDatabase(database.getName()), database); metaDataContexts.set(reloadedMetaDataContexts); metaDataContexts.get().getMetaData().getDatabase(database.getName()).getSchemas() - .forEach((schemaName, schema) -> metaDataContexts.get().getPersistService().getDatabaseMetaDataService().compareAndPersist(database.getName(), schemaName, schema)); + .forEach((schemaName, schema) -> persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().compareAndPersist(database.getName(), schemaName, schema)); } catch (final SQLException ex) { log.error("Refresh table meta data: {} failed", database.getName(), ex); } } private MetaDataContexts createMetaDataContexts(final ShardingSphereDatabase database) throws SQLException { - MetaDataPersistService metaDataPersistService = metaDataContexts.get().getPersistService(); + MetaDataPersistService metaDataPersistService = persistServiceFacade.getMetaDataPersistService(); Map dataSourcePoolPropsFromRegCenter = metaDataPersistService.getDataSourceUnitService().load(database.getName()); SwitchingResource switchingResource = new ResourceSwitchManager().alterStorageUnit(database.getResourceMetaData(), dataSourcePoolPropsFromRegCenter); metaDataContexts.get().getMetaData().getDatabases().putAll(configurationContextManager.renewDatabase(database, switchingResource)); @@ -196,7 +200,7 @@ private MetaDataContexts createMetaDataContexts(final ShardingSphereDatabase dat */ public void deletedSchemaNames(final String databaseName, final ShardingSphereDatabase reloadDatabase, final ShardingSphereDatabase currentDatabase) { GenericSchemaManager.getToBeDeletedSchemaNames(reloadDatabase.getSchemas(), currentDatabase.getSchemas()).keySet() - .forEach(each -> metaDataContexts.get().getPersistService().getDatabaseMetaDataService().dropSchema(databaseName, each)); + .forEach(each -> persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().dropSchema(databaseName, each)); } /** @@ -211,11 +215,11 @@ public void reloadSchema(final ShardingSphereDatabase database, final String sch ShardingSphereSchema reloadedSchema = loadSchema(database, schemaName, dataSourceName); if (reloadedSchema.getTables().isEmpty()) { database.dropSchema(schemaName); - metaDataContexts.get().getPersistService().getDatabaseMetaDataService().dropSchema(database.getName(), + persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().dropSchema(database.getName(), schemaName); } else { database.addSchema(schemaName, reloadedSchema); - metaDataContexts.get().getPersistService().getDatabaseMetaDataService() + persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService() .compareAndPersist(database.getName(), schemaName, reloadedSchema); } } catch (final SQLException ex) { @@ -230,7 +234,7 @@ private ShardingSphereSchema loadSchema(final ShardingSphereDatabase database, f Collections.singletonMap(dataSourceName, database.getResourceMetaData().getStorageUnits().get(dataSourceName).getDataSource()), database.getRuleMetaData().getRules(), metaDataContexts.get().getMetaData().getProps(), schemaName); ShardingSphereSchema result = GenericSchemaBuilder.build(material).get(schemaName); - result.getViews().putAll(metaDataContexts.get().getPersistService().getDatabaseMetaDataService().getViewMetaDataPersistService().load(database.getName(), schemaName)); + result.getViews().putAll(persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().getViewMetaDataPersistService().load(database.getName(), schemaName)); return result; } @@ -273,7 +277,7 @@ public void reloadTable(final ShardingSphereDatabase database, final String sche private void persistTable(final ShardingSphereDatabase database, final String schemaName, final String tableName, final GenericSchemaBuilderMaterial material) throws SQLException { ShardingSphereSchema schema = GenericSchemaBuilder.build(Collections.singleton(tableName), material).getOrDefault(schemaName, new ShardingSphereSchema()); - metaDataContexts.get().getPersistService().getDatabaseMetaDataService().getTableMetaDataPersistService() + persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().getTableMetaDataPersistService() .persist(database.getName(), schemaName, Collections.singletonMap(tableName, schema.getTable(tableName))); } @@ -281,5 +285,6 @@ private void persistTable(final ShardingSphereDatabase database, final String sc public void close() { executorEngine.close(); metaDataContexts.get().close(); + repository.close(); } } 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 859803b68a22e..4684a182c355c 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 @@ -40,15 +40,16 @@ import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration; -import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; -import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; -import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity; import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine; import org.apache.shardingsphere.metadata.factory.ExternalMetaDataFactory; import org.apache.shardingsphere.metadata.factory.InternalMetaDataFactory; +import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.switcher.ResourceSwitchManager; import org.apache.shardingsphere.mode.manager.switcher.SwitchingResource; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.service.PersistServiceFacade; +import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity; import org.apache.shardingsphere.transaction.rule.TransactionRule; import javax.sql.DataSource; @@ -76,6 +77,8 @@ public final class ConfigurationContextManager { private final ComputeNodeInstanceContext computeNodeInstanceContext; + private final PersistServiceFacade persistServiceFacade; + /** * Register storage unit. * @@ -132,7 +135,7 @@ private void buildNewMetaDataContext(final String databaseName, final SwitchingR MetaDataContexts reloadMetaDataContexts = createMetaDataContexts(databaseName, false, switchingResource, null); persistSchemaMetaData(databaseName, reloadMetaDataContexts, isDropConfig); Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseData().get(databaseName)) - .ifPresent(optional -> optional.getSchemaData().forEach((schemaName, schemaData) -> reloadMetaDataContexts.getPersistService().getShardingSphereDataPersistService() + .ifPresent(optional -> optional.getSchemaData().forEach((schemaName, schemaData) -> persistServiceFacade.getMetaDataPersistService().getShardingSphereDataPersistService() .persist(databaseName, schemaName, schemaData, metaDataContexts.get().getMetaData().getDatabases()))); alterSchemaMetaData(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.get().getMetaData().getDatabase(databaseName), isDropConfig); metaDataContexts.set(reloadMetaDataContexts); @@ -142,10 +145,10 @@ private void buildNewMetaDataContext(final String databaseName, final SwitchingR private void persistSchemaMetaData(final String databaseName, final MetaDataContexts reloadMetaDataContexts, final boolean isDropConfig) { if (isDropConfig) { - reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getSchemas().forEach((schemaName, schema) -> reloadMetaDataContexts.getPersistService().getDatabaseMetaDataService() + reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getSchemas().forEach((schemaName, schema) -> persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService() .persistByDropConfiguration(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), schemaName, schema)); } else { - reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getSchemas().forEach((schemaName, schema) -> reloadMetaDataContexts.getPersistService().getDatabaseMetaDataService() + reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getSchemas().forEach((schemaName, schema) -> persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService() .persistByAlterConfiguration(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), schemaName, schema)); } } @@ -233,11 +236,11 @@ public void alterSchemaMetaData(final String databaseName, final ShardingSphereD Map toBeAlterSchemas = GenericSchemaManager.getToBeDeletedTablesBySchemas(reloadDatabase.getSchemas(), currentDatabase.getSchemas()); Map toBeAddedSchemas = GenericSchemaManager.getToBeAddedTablesBySchemas(reloadDatabase.getSchemas(), currentDatabase.getSchemas()); if (isDropConfig) { - toBeAddedSchemas.forEach((key, value) -> metaDataContexts.get().getPersistService().getDatabaseMetaDataService().persistByDropConfiguration(databaseName, key, value)); + toBeAddedSchemas.forEach((key, value) -> persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().persistByDropConfiguration(databaseName, key, value)); } else { - toBeAddedSchemas.forEach((key, value) -> metaDataContexts.get().getPersistService().getDatabaseMetaDataService().persistByAlterConfiguration(databaseName, key, value)); + toBeAddedSchemas.forEach((key, value) -> persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().persistByAlterConfiguration(databaseName, key, value)); } - toBeAlterSchemas.forEach((key, value) -> metaDataContexts.get().getPersistService().getDatabaseMetaDataService().delete(databaseName, key, value)); + toBeAlterSchemas.forEach((key, value) -> persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().delete(databaseName, key, value)); } /** @@ -320,7 +323,7 @@ public synchronized Map createChangedDatabases(f DatabaseConfiguration toBeCreatedDatabaseConfig = getDatabaseConfiguration( metaDataContexts.get().getMetaData().getDatabase(databaseName).getResourceMetaData(), switchingResource, toBeCreatedRuleConfigs); ShardingSphereDatabase changedDatabase = createChangedDatabase(metaDataContexts.get().getMetaData().getDatabase(databaseName).getName(), internalLoadMetaData, - metaDataContexts.get().getPersistService(), toBeCreatedDatabaseConfig, metaDataContexts.get().getMetaData().getProps(), computeNodeInstanceContext); + persistServiceFacade.getMetaDataPersistService(), toBeCreatedDatabaseConfig, metaDataContexts.get().getMetaData().getProps(), computeNodeInstanceContext); Map result = new LinkedHashMap<>(metaDataContexts.get().getMetaData().getDatabases()); result.put(databaseName.toLowerCase(), changedDatabase); return result; @@ -366,7 +369,7 @@ private Map newShardingSphereSchemas(final Shardin public Map newShardingSphereDatabase(final ShardingSphereDatabase originalDatabase) { return Collections.singletonMap(originalDatabase.getName().toLowerCase(), new ShardingSphereDatabase(originalDatabase.getName(), originalDatabase.getProtocolType(), originalDatabase.getResourceMetaData(), originalDatabase.getRuleMetaData(), - metaDataContexts.get().getPersistService().getDatabaseMetaDataService().loadSchemas(originalDatabase.getName()))); + persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().loadSchemas(originalDatabase.getName()))); } /** @@ -414,6 +417,6 @@ public synchronized void alterProperties(final Properties props) { } private MetaDataContexts newMetaDataContexts(final ShardingSphereMetaData metaData) { - return MetaDataContextsFactory.create(metaDataContexts.get().getPersistService(), metaData); + return MetaDataContextsFactory.create(persistServiceFacade.getMetaDataPersistService(), metaData); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ResourceMetaDataContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ResourceMetaDataContextManager.java index 1e4dbcddaf860..3463544e13db4 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ResourceMetaDataContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ResourceMetaDataContextManager.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.metadata.refresher.util.TableRefreshUtils; +import org.apache.shardingsphere.mode.service.PersistServiceFacade; import java.util.Collections; import java.util.Optional; @@ -45,6 +46,8 @@ public final class ResourceMetaDataContextManager { private final AtomicReference metaDataContexts; + private final PersistServiceFacade persistServiceFacade; + /** * Add database. * @@ -56,7 +59,7 @@ public synchronized void addDatabase(final String databaseName) { } DatabaseType protocolType = DatabaseTypeEngine.getProtocolType(Collections.emptyMap(), metaDataContexts.get().getMetaData().getProps()); metaDataContexts.get().getMetaData().addDatabase(databaseName, protocolType, metaDataContexts.get().getMetaData().getProps()); - metaDataContexts.set(MetaDataContextsFactory.create(metaDataContexts.get().getPersistService(), metaDataContexts.get().getMetaData())); + metaDataContexts.set(MetaDataContextsFactory.create(persistServiceFacade.getMetaDataPersistService(), metaDataContexts.get().getMetaData())); } /** diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ShardingSphereDatabaseContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ShardingSphereDatabaseContextManager.java index 09b2d2df2aaf4..ccf49cbc12f3a 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ShardingSphereDatabaseContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ShardingSphereDatabaseContextManager.java @@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereRowData; import org.apache.shardingsphere.infra.yaml.data.swapper.YamlShardingSphereRowDataSwapper; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.service.PersistServiceFacade; import java.util.ArrayList; import java.util.List; @@ -38,6 +39,8 @@ public final class ShardingSphereDatabaseContextManager { private final AtomicReference metaDataContexts; + private final PersistServiceFacade persistServiceFacade; + /** * Add ShardingSphere database data. * 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 910a7328d80ac..e261e2354f7ef 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 @@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import java.util.Collection; import java.util.LinkedList; @@ -33,14 +32,11 @@ @Getter public final class MetaDataContexts implements AutoCloseable { - private final MetaDataPersistService persistService; - private final ShardingSphereMetaData metaData; private final ShardingSphereStatistics statistics; - public MetaDataContexts(final MetaDataPersistService persistService, final ShardingSphereMetaData metaData, final ShardingSphereStatistics statistics) { - this.persistService = persistService; + public MetaDataContexts(final ShardingSphereMetaData metaData, final ShardingSphereStatistics statistics) { this.metaData = metaData; this.statistics = statistics; } @@ -48,7 +44,6 @@ public MetaDataContexts(final MetaDataPersistService persistService, final Shard @SneakyThrows(Exception.class) @Override public void close() { - persistService.getRepository().close(); for (ShardingSphereRule each : getAllRules()) { if (each instanceof AutoCloseable) { ((AutoCloseable) each).close(); 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 b2535dcc3fad2..a1217a7220248 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 @@ -49,8 +49,8 @@ import org.apache.shardingsphere.metadata.factory.ExternalMetaDataFactory; import org.apache.shardingsphere.metadata.factory.InternalMetaDataFactory; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; -import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus; import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter; +import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus; import javax.sql.DataSource; import java.sql.SQLException; @@ -112,10 +112,10 @@ public static MetaDataContexts create(final MetaDataPersistService persistServic RuleMetaData globalRuleMetaData = new RuleMetaData(GlobalRulesBuilder.buildRules(globalRuleConfigs, databases, props)); ShardingSphereMetaData shardingSphereMetaData = new ShardingSphereMetaData(databases, globalResourceMetaData, globalRuleMetaData, props); ShardingSphereStatistics shardingSphereStatistics = initStatistics(persistService, shardingSphereMetaData); - MetaDataContexts result = new MetaDataContexts(persistService, shardingSphereMetaData, shardingSphereStatistics); + MetaDataContexts result = new MetaDataContexts(shardingSphereMetaData, shardingSphereStatistics); if (!isDatabaseMetaDataExisted) { - persistDatabaseConfigurations(result, param); - persistMetaData(result); + persistDatabaseConfigurations(result, param, persistService); + persistMetaData(result, persistService); } return result; } @@ -128,7 +128,7 @@ public static MetaDataContexts create(final MetaDataPersistService persistServic * @return meta data contexts */ public static MetaDataContexts create(final MetaDataPersistService persistService, final ShardingSphereMetaData metaData) { - return new MetaDataContexts(persistService, metaData, initStatistics(persistService, metaData)); + return new MetaDataContexts(metaData, initStatistics(persistService, metaData)); } private static Collection getDatabaseNames(final ComputeNodeInstanceContext computeNodeInstanceContext, @@ -218,21 +218,21 @@ private static void useLoadedToReplaceInitBySchemaData(final ShardingSphereSchem } } - private static void persistDatabaseConfigurations(final MetaDataContexts metadataContexts, final ContextManagerBuilderParameter param) { - metadataContexts.getPersistService().persistGlobalRuleConfiguration(param.getGlobalRuleConfigs(), param.getProps()); + private static void persistDatabaseConfigurations(final MetaDataContexts metadataContexts, final ContextManagerBuilderParameter param, final MetaDataPersistService persistService) { + persistService.persistGlobalRuleConfiguration(param.getGlobalRuleConfigs(), param.getProps()); for (Entry entry : param.getDatabaseConfigs().entrySet()) { String databaseName = entry.getKey(); - metadataContexts.getPersistService().persistConfigurations(entry.getKey(), entry.getValue(), + persistService.persistConfigurations(entry.getKey(), entry.getValue(), metadataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnits().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, each -> each.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), metadataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRules()); } } - private static void persistMetaData(final MetaDataContexts metaDataContexts) { - metaDataContexts.getMetaData().getDatabases().values().forEach(each -> each.getSchemas() - .forEach((schemaName, schema) -> metaDataContexts.getPersistService().getDatabaseMetaDataService().persistByAlterConfiguration(each.getName(), schemaName, schema))); - metaDataContexts.getStatistics().getDatabaseData().forEach((databaseName, databaseData) -> databaseData.getSchemaData().forEach((schemaName, schemaData) -> metaDataContexts - .getPersistService().getShardingSphereDataPersistService().persist(databaseName, schemaName, schemaData, metaDataContexts.getMetaData().getDatabases()))); + private static void persistMetaData(final MetaDataContexts metaDataContexts, final MetaDataPersistService persistService) { + metaDataContexts.getMetaData().getDatabases().values().forEach(each -> each.getSchemas().forEach((schemaName, schema) -> persistService.getDatabaseMetaDataService() + .persistByAlterConfiguration(each.getName(), schemaName, schema))); + metaDataContexts.getStatistics().getDatabaseData().forEach((databaseName, databaseData) -> databaseData.getSchemaData().forEach((schemaName, schemaData) -> persistService + .getShardingSphereDataPersistService().persist(databaseName, schemaName, schemaData, metaDataContexts.getMetaData().getDatabases()))); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/service/PersistServiceFacade.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/service/PersistServiceFacade.java index de646661a2221..1f06cccb0e7b6 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/service/PersistServiceFacade.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/service/PersistServiceFacade.java @@ -20,6 +20,7 @@ import lombok.Getter; import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.mode.state.StatePersistService; @@ -30,6 +31,8 @@ @Getter public final class PersistServiceFacade { + private final MetaDataPersistService metaDataPersistService; + private final ComputeNodePersistService computeNodePersistService; private final StatePersistService statePersistService; @@ -37,6 +40,7 @@ public final class PersistServiceFacade { private final MetaDataManagerPersistService metaDataManagerPersistService; public PersistServiceFacade(final PersistRepository repository, final ModeConfiguration modeConfiguration, final ContextManager contextManager) { + metaDataPersistService = new MetaDataPersistService(repository); computeNodePersistService = new ComputeNodePersistService(repository); statePersistService = new StatePersistService(repository); metaDataManagerPersistService = TypedSPILoader.getService(MetaDataManagerPersistServiceBuilder.class, modeConfiguration.getType()).build(contextManager); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java index 8c2cb2ad48478..3643dca1dff5f 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java @@ -43,12 +43,14 @@ public final class RuleItemChangedSubscriber implements EventSubscriber { @SuppressWarnings({"rawtypes", "unchecked", "unused"}) @Subscribe public void renew(final AlterRuleItemEvent event) { - if (!event.getActiveVersion().equals(contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey()))) { + if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .getActiveVersionByFullPath(event.getActiveVersionKey()))) { return; } RuleItemConfigurationChangedProcessor processor = TypedSPILoader.getService(RuleItemConfigurationChangedProcessor.class, event.getType()); String yamlContent = - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().getVersionPathByActiveVersion(event.getActiveVersionKey(), event.getActiveVersion()); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .getVersionPathByActiveVersion(event.getActiveVersionKey(), event.getActiveVersion()); String databaseName = event.getDatabaseName(); RuleConfiguration currentRuleConfig = processor.findRuleConfiguration(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName)); synchronized (this) { 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 b0e80fe334180..95e5ce0c18838 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 @@ -40,9 +40,9 @@ import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; -import org.apache.shardingsphere.metadata.persist.service.database.DatabaseMetaDataPersistService; +import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.util.PropertiesBuilder; import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; @@ -89,7 +89,7 @@ void setUp() { when(metaDataContexts.getMetaData().getDatabases().values()).thenReturn(Collections.singleton(database)); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); - contextManager = new ContextManager(metaDataContexts, computeNodeInstanceContext); + contextManager = new ContextManager(metaDataContexts, computeNodeInstanceContext, mock(PersistRepository.class)); } private ShardingSphereDatabase mockDatabase() { @@ -243,21 +243,13 @@ void assertAlterProperties() { @Test void assertReloadSchema() { when(metaDataContexts.getMetaData().getDatabase("foo_db").getName()).thenReturn("foo_db"); - DatabaseMetaDataPersistService databaseMetaDataPersistService = mock(DatabaseMetaDataPersistService.class, RETURNS_DEEP_STUBS); - MetaDataPersistService persistService = mock(MetaDataPersistService.class); - when(persistService.getDatabaseMetaDataService()).thenReturn(databaseMetaDataPersistService); - when(metaDataContexts.getPersistService()).thenReturn(persistService); ShardingSphereDatabase database = mockDatabase(); contextManager.reloadSchema(database, "foo_schema", "foo_ds"); - verify(databaseMetaDataPersistService).dropSchema("foo_db", "foo_schema"); + verify(contextManager.getRepository()).delete(DatabaseMetaDataNode.getMetaDataSchemaPath("foo_db", "foo_schema")); } @Test void assertReloadTable() { - DatabaseMetaDataPersistService databaseMetaDataPersistService = mock(DatabaseMetaDataPersistService.class, RETURNS_DEEP_STUBS); - MetaDataPersistService persistService = mock(MetaDataPersistService.class); - when(persistService.getDatabaseMetaDataService()).thenReturn(databaseMetaDataPersistService); - when(metaDataContexts.getPersistService()).thenReturn(persistService); ShardingSphereDatabase database = mockDatabase(); contextManager.reloadTable(database, "foo_schema", "foo_table"); assertTrue(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnits().containsKey("foo_ds")); diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactoryTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactoryTest.java index 1bfb368c20f5f..de344bd39c24e 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactoryTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactoryTest.java @@ -120,7 +120,6 @@ void assertCreateWithProxyInstanceMetaData() throws SQLException { when(databaseMetaDataPersistService.loadAllDatabaseNames()).thenReturn(Collections.singletonList("foo_db")); when(metaDataPersistService.getDatabaseMetaDataService()).thenReturn(databaseMetaDataPersistService); try (MetaDataContexts actual = MetaDataContextsFactory.create(metaDataPersistService, createContextManagerBuilderParameter(), mock(ComputeNodeInstanceContext.class, RETURNS_DEEP_STUBS))) { - assertThat(actual.getPersistService(), is(metaDataPersistService)); assertThat(actual.getMetaData().getGlobalRuleMetaData().getRules().size(), is(1)); assertThat(actual.getMetaData().getGlobalRuleMetaData().getRules().iterator().next(), instanceOf(MockedRule.class)); assertTrue(actual.getMetaData().getDatabases().containsKey("foo_db")); diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index 0d477c8b0e4be..a4d13f555ce68 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -69,7 +69,7 @@ public ContextManager build(final ContextManagerBuilderParameter param, final Ev } MetaDataPersistService metaDataPersistService = new MetaDataPersistService(repository); MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, param, computeNodeInstanceContext, new QualifiedDataSourceStatusService(repository).loadStatus()); - ContextManager result = new ContextManager(metaDataContexts, computeNodeInstanceContext); + ContextManager result = new ContextManager(metaDataContexts, computeNodeInstanceContext, repository); createSubscribers(eventBusContext, repository); registerOnline(eventBusContext, computeNodeInstanceContext, repository, param, result); setClusterState(result); diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java index bbe45c2fead68..0da5fe1907009 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java @@ -43,11 +43,12 @@ public final class ConfigurationChangedSubscriber implements EventSubscriber { */ @Subscribe public void renew(final RegisterStorageUnitEvent event) { - if (!event.getActiveVersion().equals(contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey()))) { + if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .getActiveVersionByFullPath(event.getActiveVersionKey()))) { return; } contextManager.getConfigurationContextManager().registerStorageUnit(event.getDatabaseName(), - contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().load(event.getDatabaseName(), event.getStorageUnitName())); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService().load(event.getDatabaseName(), event.getStorageUnitName())); } /** @@ -57,11 +58,12 @@ public void renew(final RegisterStorageUnitEvent event) { */ @Subscribe public void renew(final AlterStorageUnitEvent event) { - if (!event.getActiveVersion().equals(contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey()))) { + if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .getActiveVersionByFullPath(event.getActiveVersionKey()))) { return; } contextManager.getConfigurationContextManager().alterStorageUnit( - event.getDatabaseName(), contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().load(event.getDatabaseName(), event.getStorageUnitName())); + event.getDatabaseName(), contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService().load(event.getDatabaseName(), event.getStorageUnitName())); } /** @@ -84,10 +86,11 @@ public void renew(final UnregisterStorageUnitEvent event) { */ @Subscribe public synchronized void renew(final AlterGlobalRuleConfigurationEvent event) { - if (!event.getActiveVersion().equals(contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey()))) { + if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .getActiveVersionByFullPath(event.getActiveVersionKey()))) { return; } - contextManager.getMetaDataContexts().getPersistService().getGlobalRuleService().load(event.getRuleSimpleName()) + contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().load(event.getRuleSimpleName()) .ifPresent(optional -> contextManager.getConfigurationContextManager().alterGlobalRuleConfiguration(optional)); } @@ -99,9 +102,10 @@ public synchronized void renew(final AlterGlobalRuleConfigurationEvent event) { */ @Subscribe public synchronized void renew(final AlterPropertiesEvent event) { - if (!event.getActiveVersion().equals(contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey()))) { + if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .getActiveVersionByFullPath(event.getActiveVersionKey()))) { return; } - contextManager.getConfigurationContextManager().alterProperties(contextManager.getMetaDataContexts().getPersistService().getPropsService().load()); + contextManager.getConfigurationContextManager().alterProperties(contextManager.getPersistServiceFacade().getMetaDataPersistService().getPropsService().load()); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriber.java index 05afc49a5eab2..e8e234deba865 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriber.java @@ -90,10 +90,11 @@ public synchronized void renew(final SchemaDeletedEvent event) { */ @Subscribe public synchronized void renew(final CreateOrAlterTableEvent event) { - if (!event.getActiveVersion().equals(contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey()))) { + if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .getActiveVersionByFullPath(event.getActiveVersionKey()))) { return; } - Map tables = contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService() + Map tables = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService() .getTableMetaDataPersistService().load(event.getDatabaseName(), event.getSchemaName(), event.getTableName()); contextManager.getResourceMetaDataContextManager().alterSchema(event.getDatabaseName(), event.getSchemaName(), tables.values().iterator().next(), null); } @@ -115,10 +116,11 @@ public synchronized void renew(final DropTableEvent event) { */ @Subscribe public synchronized void renew(final CreateOrAlterViewEvent event) { - if (!event.getActiveVersion().equals(contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey()))) { + if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .getActiveVersionByFullPath(event.getActiveVersionKey()))) { return; } - Map views = contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService() + Map views = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService() .getViewMetaDataPersistService().load(event.getDatabaseName(), event.getSchemaName(), event.getViewName()); contextManager.getResourceMetaDataContextManager().alterSchema(event.getDatabaseName(), event.getSchemaName(), null, views.values().iterator().next()); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/service/ClusterMetaDataManagerPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/service/ClusterMetaDataManagerPersistService.java index eaddbaa387078..38d61ff5795a8 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/service/ClusterMetaDataManagerPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/service/ClusterMetaDataManagerPersistService.java @@ -49,17 +49,17 @@ public final class ClusterMetaDataManagerPersistService implements MetaDataManag @Override public void createDatabase(final String databaseName) { - contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService().addDatabase(databaseName); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService().addDatabase(databaseName); } @Override public void dropDatabase(final String databaseName) { - contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService().dropDatabase(databaseName); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService().dropDatabase(databaseName); } @Override public void createSchema(final String databaseName, final String schemaName) { - contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService().addSchema(databaseName, schemaName); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService().addSchema(databaseName, schemaName); } @Override @@ -67,7 +67,7 @@ public void alterSchema(final AlterSchemaPOJO alterSchemaPOJO) { String databaseName = alterSchemaPOJO.getDatabaseName(); String schemaName = alterSchemaPOJO.getSchemaName(); ShardingSphereSchema schema = contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getSchema(schemaName); - DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService(); + DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService(); databaseMetaDataService.persistByAlterConfiguration(databaseName, alterSchemaPOJO.getRenameSchemaName(), schema); databaseMetaDataService.getViewMetaDataPersistService().persist(databaseName, alterSchemaPOJO.getRenameSchemaName(), schema.getViews()); databaseMetaDataService.dropSchema(databaseName, schemaName); @@ -75,7 +75,7 @@ public void alterSchema(final AlterSchemaPOJO alterSchemaPOJO) { @Override public void dropSchema(final String databaseName, final Collection schemaNames) { - DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService(); + DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService(); schemaNames.forEach(each -> databaseMetaDataService.dropSchema(databaseName, each)); } @@ -85,7 +85,7 @@ public void alterSchemaMetaData(final AlterSchemaMetaDataPOJO alterSchemaMetaDat String schemaName = alterSchemaMetaDataPOJO.getSchemaName(); Map tables = alterSchemaMetaDataPOJO.getAlteredTables().stream().collect(Collectors.toMap(ShardingSphereTable::getName, table -> table)); Map views = alterSchemaMetaDataPOJO.getAlteredViews().stream().collect(Collectors.toMap(ShardingSphereView::getName, view -> view)); - DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService(); + DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService(); databaseMetaDataService.getTableMetaDataPersistService().persist(databaseName, schemaName, tables); databaseMetaDataService.getViewMetaDataPersistService().persist(databaseName, schemaName, views); alterSchemaMetaDataPOJO.getDroppedTables().forEach(each -> databaseMetaDataService.getTableMetaDataPersistService().delete(databaseName, schemaName, each)); @@ -94,19 +94,21 @@ public void alterSchemaMetaData(final AlterSchemaMetaDataPOJO alterSchemaMetaDat @Override public void registerStorageUnits(final String databaseName, final Map toBeRegisteredProps) { - contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().persistConfigurations(databaseName, toBeRegisteredProps); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService().persistConfigurations(databaseName, toBeRegisteredProps); } @Override public void alterStorageUnits(final String databaseName, final Map toBeUpdatedProps) { - DatabaseBasedPersistService> dataSourceService = contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService(); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeUpdatedProps)); + DatabaseBasedPersistService> dataSourceService = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService(); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeUpdatedProps)); } @Override public void unregisterStorageUnits(final String databaseName, final Collection toBeDroppedStorageUnitNames) { - contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().deleteConfigurations(databaseName, - getToBeDroppedDataSourcePoolProperties(contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().load(databaseName), toBeDroppedStorageUnitNames)); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService().deleteConfigurations(databaseName, + getToBeDroppedDataSourcePoolProperties(contextManager.getPersistServiceFacade().getMetaDataPersistService() + .getDataSourceUnitService().load(databaseName), toBeDroppedStorageUnitNames)); } private Map getToBeDroppedDataSourcePoolProperties(final Map propsMap, final Collection toBeDroppedResourceNames) { @@ -122,14 +124,15 @@ private Map getToBeDroppedDataSourcePoolProper @Override public void alterSingleRuleConfiguration(final String databaseName, final Collection ruleConfigs) { ruleConfigs.removeIf(each -> !each.getClass().isAssignableFrom(SingleRuleConfiguration.class)); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService() - .switchActiveVersion(contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().persistConfigurations(databaseName, ruleConfigs)); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .switchActiveVersion(contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService().persistConfigurations(databaseName, ruleConfigs)); } @Override public Collection alterRuleConfiguration(final String databaseName, final RuleConfiguration toBeAlteredRuleConfig) { if (null != toBeAlteredRuleConfig) { - return contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().persistConfigurations(databaseName, Collections.singleton(toBeAlteredRuleConfig)); + return contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService() + .persistConfigurations(databaseName, Collections.singleton(toBeAlteredRuleConfig)); } return Collections.emptyList(); } @@ -137,22 +140,22 @@ public Collection alterRuleConfiguration(final String databaseN @Override public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) { if (null != toBeRemovedRuleConfig) { - contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig)); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig)); } } @Override public void removeRuleConfiguration(final String databaseName, final String ruleName) { - contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().delete(databaseName, ruleName); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService().delete(databaseName, ruleName); } @Override public void alterGlobalRuleConfiguration(final RuleConfiguration toBeAlteredRuleConfig) { - contextManager.getMetaDataContexts().getPersistService().getGlobalRuleService().persist(Collections.singleton(toBeAlteredRuleConfig)); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().persist(Collections.singleton(toBeAlteredRuleConfig)); } @Override public void alterProperties(final Properties props) { - contextManager.getMetaDataContexts().getPersistService().getPropsService().persist(props); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getPropsService().persist(props); } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessListChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessListChangedSubscriberTest.java index 1a831fe5d2926..50a6721557f1c 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessListChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessListChangedSubscriberTest.java @@ -83,7 +83,7 @@ class ProcessListChangedSubscriberTest { void setUp() throws SQLException { EventBusContext eventBusContext = new EventBusContext(); contextManager = new ClusterContextManagerBuilder().build(createContextManagerBuilderParameter(), eventBusContext); - contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), + contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getPersistServiceFacade().getMetaDataPersistService(), new ShardingSphereMetaData(createDatabases(), contextManager.getMetaDataContexts().getMetaData().getGlobalResourceMetaData(), contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), new ConfigurationProperties(new Properties())))); subscriber = new ProcessListChangedSubscriber(contextManager, repository); diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java index 9ac799c8edfae..b003d9e79caa5 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java @@ -80,7 +80,7 @@ class ResourceMetaDataChangedSubscriberTest { @BeforeEach void setUp() throws SQLException { contextManager = new ClusterContextManagerBuilder().build(createContextManagerBuilderParameter(), new EventBusContext()); - contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), + contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getPersistServiceFacade().getMetaDataPersistService(), new ShardingSphereMetaData(createDatabases(), contextManager.getMetaDataContexts().getMetaData().getGlobalResourceMetaData(), contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), new ConfigurationProperties(new Properties())))); subscriber = new ResourceMetaDataChangedSubscriber(contextManager); diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java index 15ab1b2825a8a..f708bbf6c4e7e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java @@ -86,7 +86,7 @@ class StateChangedSubscriberTest { void setUp() throws SQLException { EventBusContext eventBusContext = new EventBusContext(); contextManager = new ClusterContextManagerBuilder().build(createContextManagerBuilderParameter(), eventBusContext); - contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), + contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getPersistServiceFacade().getMetaDataPersistService(), new ShardingSphereMetaData(createDatabases(), contextManager.getMetaDataContexts().getMetaData().getGlobalResourceMetaData(), contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), new ConfigurationProperties(new Properties())))); subscriber = new StateChangedSubscriber(contextManager); diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java index a6048e6690753..5c2b3da39b068 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java @@ -49,7 +49,7 @@ public ContextManager build(final ContextManagerBuilderParameter param, final Ev MetaDataPersistService persistService = new MetaDataPersistService(repository); ComputeNodeInstanceContext computeNodeInstanceContext = buildComputeNodeInstanceContext(param, eventBusContext); MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(persistService, param, computeNodeInstanceContext); - ContextManager result = new ContextManager(metaDataContexts, computeNodeInstanceContext); + ContextManager result = new ContextManager(metaDataContexts, computeNodeInstanceContext, repository); new StandaloneEventSubscriberRegistry(result).register(); return result; } diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/service/StandaloneMetaDataManagerPersistService.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/service/StandaloneMetaDataManagerPersistService.java index 1099ebf8b87a8..0bfcd58c2874e 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/service/StandaloneMetaDataManagerPersistService.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/service/StandaloneMetaDataManagerPersistService.java @@ -71,14 +71,14 @@ public StandaloneMetaDataManagerPersistService(final ContextManager contextManag @Override public void createDatabase(final String databaseName) { contextManager.getResourceMetaDataContextManager().addDatabase(databaseName); - contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService().addDatabase(databaseName); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService().addDatabase(databaseName); clearServiceCache(); } @Override public void dropDatabase(final String databaseName) { contextManager.getResourceMetaDataContextManager().dropDatabase(databaseName); - contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService().dropDatabase(databaseName); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService().dropDatabase(databaseName); clearServiceCache(); } @@ -89,7 +89,7 @@ public void createSchema(final String databaseName, final String schemaName) { ShardingSphereDatabase database = metaData.getDatabase(databaseName); database.addSchema(schemaName, schema); metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); - contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService().persistByAlterConfiguration(databaseName, schemaName, schema); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService().persistByAlterConfiguration(databaseName, schemaName, schema); } @Override @@ -99,7 +99,7 @@ public void alterSchema(final AlterSchemaPOJO alterSchemaPOJO) { putSchemaMetaData(database, alterSchemaPOJO.getSchemaName(), alterSchemaPOJO.getRenameSchemaName(), alterSchemaPOJO.getLogicDataSourceName()); removeSchemaMetaData(database, alterSchemaPOJO.getSchemaName()); metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); - DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService(); + DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService(); databaseMetaDataService.persistByAlterConfiguration(alterSchemaPOJO.getDatabaseName(), alterSchemaPOJO.getRenameSchemaName(), database.getSchema(alterSchemaPOJO.getRenameSchemaName())); databaseMetaDataService.getViewMetaDataPersistService().persist(alterSchemaPOJO.getDatabaseName(), alterSchemaPOJO.getRenameSchemaName(), database.getSchema(alterSchemaPOJO.getRenameSchemaName()).getViews()); @@ -204,7 +204,7 @@ public void alterSchemaMetaData(final AlterSchemaMetaDataPOJO alterSchemaMetaDat addDataNode(database, alterSchemaMetaDataPOJO.getLogicDataSourceName(), schemaName, tables, views); removeDataNode(database, schemaName, alterSchemaMetaDataPOJO.getDroppedTables(), alterSchemaMetaDataPOJO.getDroppedViews()); metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); - DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService(); + DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService(); databaseMetaDataService.getTableMetaDataPersistService().persist(databaseName, schemaName, tables); databaseMetaDataService.getViewMetaDataPersistService().persist(databaseName, schemaName, views); alterSchemaMetaDataPOJO.getDroppedTables().forEach(each -> databaseMetaDataService.getTableMetaDataPersistService().delete(databaseName, schemaName, each)); @@ -215,14 +215,16 @@ public void alterSchemaMetaData(final AlterSchemaMetaDataPOJO alterSchemaMetaDat public void registerStorageUnits(final String databaseName, final Map toBeRegisteredProps) throws SQLException { SwitchingResource switchingResource = new ResourceSwitchManager().registerStorageUnit(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData(), toBeRegisteredProps); - contextManager.getMetaDataContexts().getMetaData().getDatabases().putAll(contextManager.getConfigurationContextManager().createChangedDatabases(databaseName, false, switchingResource, null)); + contextManager.getMetaDataContexts().getMetaData().getDatabases().putAll(contextManager.getConfigurationContextManager() + .createChangedDatabases(databaseName, false, switchingResource, null)); contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRules() .forEach(each -> ((GlobalRule) each).refresh(contextManager.getMetaDataContexts().getMetaData().getDatabases(), GlobalRuleChangedType.DATABASE_CHANGED)); contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getSchemas() - .forEach((schemaName, schema) -> contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService() + .forEach((schemaName, schema) -> contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataService() .persistByAlterConfiguration(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), schemaName, schema)); - DatabaseBasedPersistService> dataSourceService = contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService(); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeRegisteredProps)); + DatabaseBasedPersistService> dataSourceService = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService(); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeRegisteredProps)); clearServiceCache(); } @@ -230,11 +232,13 @@ public void registerStorageUnits(final String databaseName, final Map toBeUpdatedProps) throws SQLException { SwitchingResource switchingResource = new ResourceSwitchManager().alterStorageUnit(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData(), toBeUpdatedProps); - contextManager.getMetaDataContexts().getMetaData().getDatabases().putAll(contextManager.getConfigurationContextManager().createChangedDatabases(databaseName, true, switchingResource, null)); + contextManager.getMetaDataContexts().getMetaData().getDatabases().putAll(contextManager.getConfigurationContextManager() + .createChangedDatabases(databaseName, true, switchingResource, null)); contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRules() .forEach(each -> ((GlobalRule) each).refresh(contextManager.getMetaDataContexts().getMetaData().getDatabases(), GlobalRuleChangedType.DATABASE_CHANGED)); - DatabaseBasedPersistService> dataSourceService = contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService(); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeUpdatedProps)); + DatabaseBasedPersistService> dataSourceService = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService(); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService() + .switchActiveVersion(dataSourceService.persistConfigurations(databaseName, toBeUpdatedProps)); switchingResource.closeStaleDataSources(); clearServiceCache(); } @@ -257,9 +261,9 @@ public void unregisterStorageUnits(final String databaseName, final Collection ruleConfigs) { ruleConfigs.removeIf(each -> !each.getClass().isAssignableFrom(SingleRuleConfiguration.class)); - Collection metaDataVersions = contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService() + Collection metaDataVersions = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService() .persistConfigurations(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), ruleConfigs); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions); contextManager.getConfigurationContextManager().alterRuleConfiguration(databaseName, ruleConfigs.iterator().next()); clearServiceCache(); } @@ -267,9 +271,9 @@ public void alterSingleRuleConfiguration(final String databaseName, final Collec @Override public Collection alterRuleConfiguration(final String databaseName, final RuleConfiguration toBeAlteredRuleConfig) { if (null != toBeAlteredRuleConfig) { - Collection metaDataVersions = contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService() + Collection metaDataVersions = contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService() .persistConfigurations(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), Collections.singletonList(toBeAlteredRuleConfig)); - contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions); sendDatabaseRuleChangedEvent(databaseName, metaDataVersions); clearServiceCache(); } @@ -291,28 +295,29 @@ private void sendDatabaseRuleChangedEvent(final String databaseName, final MetaD public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) { if (null != toBeRemovedRuleConfig) { sendDatabaseRuleChangedEvent(databaseName, - contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig))); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService() + .deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig))); clearServiceCache(); } } @Override public void removeRuleConfiguration(final String databaseName, final String ruleName) { - contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().delete(databaseName, ruleName); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService().delete(databaseName, ruleName); clearServiceCache(); } @Override public void alterGlobalRuleConfiguration(final RuleConfiguration toBeAlteredRuleConfig) { contextManager.getConfigurationContextManager().alterGlobalRuleConfiguration(toBeAlteredRuleConfig); - contextManager.getMetaDataContexts().getPersistService().getGlobalRuleService().persist(Collections.singleton(toBeAlteredRuleConfig)); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().persist(Collections.singleton(toBeAlteredRuleConfig)); clearServiceCache(); } @Override public void alterProperties(final Properties props) { contextManager.getConfigurationContextManager().alterProperties(props); - contextManager.getMetaDataContexts().getPersistService().getPropsService().persist(props); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getPropsService().persist(props); clearServiceCache(); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java index f0384da4642e2..d3b04aef27394 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java @@ -25,6 +25,8 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; +import org.apache.shardingsphere.infra.exception.kernel.syntax.InvalidVariableValueException; +import org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException; import org.apache.shardingsphere.infra.props.TypedPropertyKey; import org.apache.shardingsphere.infra.props.TypedPropertyValue; import org.apache.shardingsphere.infra.props.exception.TypedPropertyValueException; @@ -33,8 +35,6 @@ import org.apache.shardingsphere.logging.util.LoggingUtils; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; -import org.apache.shardingsphere.infra.exception.kernel.syntax.InvalidVariableValueException; -import org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException; import org.slf4j.LoggerFactory; import java.sql.SQLException; @@ -71,8 +71,8 @@ private void handleConfigurationProperty(final ContextManager contextManager, fi props.put(propertyKey.getKey(), getValue(propertyKey, value)); contextManager.getPersistServiceFacade().getMetaDataManagerPersistService().alterProperties(props); refreshRootLogger(props); - syncSQLShowToLoggingRule(propertyKey, metaDataContexts, value); - syncSQLSimpleToLoggingRule(propertyKey, metaDataContexts, value); + syncSQLShowToLoggingRule(propertyKey, metaDataContexts, value, contextManager); + syncSQLSimpleToLoggingRule(propertyKey, metaDataContexts, value, contextManager); } private Object getValue(final TypedPropertyKey propertyKey, final String value) { @@ -97,20 +97,20 @@ private void renewRootLoggerLevel(final Logger rootLogger, final Properties prop rootLogger.setLevel(Level.valueOf(props.getOrDefault(ConfigurationPropertyKey.SYSTEM_LOG_LEVEL.getKey(), ConfigurationPropertyKey.SYSTEM_LOG_LEVEL.getDefaultValue()).toString())); } - private void syncSQLShowToLoggingRule(final TypedPropertyKey propertyKey, final MetaDataContexts metaDataContexts, final String value) { + private void syncSQLShowToLoggingRule(final TypedPropertyKey propertyKey, final MetaDataContexts metaDataContexts, final String value, final ContextManager contextManager) { if (LoggingConstants.SQL_SHOW.equalsIgnoreCase(propertyKey.getKey())) { LoggingUtils.getSQLLogger(metaDataContexts.getMetaData().getGlobalRuleMetaData()).ifPresent(option -> { option.getProps().setProperty(LoggingConstants.SQL_LOG_ENABLE, value); - metaDataContexts.getPersistService().getGlobalRuleService().persist(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations()); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().persist(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations()); }); } } - private void syncSQLSimpleToLoggingRule(final TypedPropertyKey propertyKey, final MetaDataContexts metaDataContexts, final String value) { + private void syncSQLSimpleToLoggingRule(final TypedPropertyKey propertyKey, final MetaDataContexts metaDataContexts, final String value, final ContextManager contextManager) { if (LoggingConstants.SQL_SIMPLE.equalsIgnoreCase(propertyKey.getKey())) { LoggingUtils.getSQLLogger(metaDataContexts.getMetaData().getGlobalRuleMetaData()).ifPresent(option -> { option.getProps().setProperty(LoggingConstants.SQL_LOG_SIMPLE, value); - metaDataContexts.getPersistService().getGlobalRuleService().persist(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations()); + contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().persist(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations()); }); } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java index 7df940380bb26..565d8d7737ed6 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java @@ -130,7 +130,8 @@ private void importRules(final String databaseName, final Collection addRule(ruleConfigs, each, database)); - metaDataContexts.getPersistService().getDatabaseRulePersistService().persist(metaDataContexts.getMetaData().getDatabase(databaseName).getName(), ruleConfigs); + ProxyContext.getInstance().getContextManager().getPersistServiceFacade().getMetaDataPersistService().getDatabaseRulePersistService() + .persist(metaDataContexts.getMetaData().getDatabase(databaseName).getName(), ruleConfigs); } private void addRule(final Collection ruleConfigs, final RuleConfiguration ruleConfig, final ShardingSphereDatabase database) { 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 3ea244d952ba2..18d70ce4b9591 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 @@ -32,6 +32,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ConnectionPostProcessor; import org.apache.shardingsphere.proxy.backend.connector.jdbc.datasource.JDBCBackendDataSource; import org.apache.shardingsphere.proxy.backend.connector.jdbc.statement.JDBCBackendStatement; @@ -126,7 +127,7 @@ private ContextManager mockContextManager() { when(metaData.getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.singletonList(transactionRule))); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); - return new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); + return new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext, mock(PersistRepository.class)); } @AfterEach 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 85e03d655834e..baf87a324d583 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 @@ -44,6 +44,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; @@ -111,7 +112,7 @@ void setUp() { when(metaData.getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Arrays.asList(mock(SQLFederationRule.class), transactionRule))); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); - ContextManager contextManager = new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); + ContextManager contextManager = new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext, mock(PersistRepository.class)); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java index 14aed7658d945..2951a46c86e54 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -69,7 +70,7 @@ void restorePreviousContextManager() { @Test void assertInit() { MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); - ProxyContext.init(new ContextManager(metaDataContexts, mock(ComputeNodeInstanceContext.class, RETURNS_DEEP_STUBS))); + ProxyContext.init(new ContextManager(metaDataContexts, mock(ComputeNodeInstanceContext.class, RETURNS_DEEP_STUBS), mock(PersistRepository.class))); assertThat(ProxyContext.getInstance().getContextManager().getStateContext(), is(ProxyContext.getInstance().getContextManager().getStateContext())); assertThat(ProxyContext.getInstance().getContextManager().getStateContext().getCurrentClusterState(), is(ClusterState.OK)); assertThat(ProxyContext.getInstance().getContextManager().getMetaDataContexts(), is(ProxyContext.getInstance().getContextManager().getMetaDataContexts())); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java index 41032471533ad..a2743076f67a2 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult; @@ -27,11 +28,11 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeaderBuilder; @@ -117,6 +118,6 @@ private ContextManager mockContextManager() { mock(RuleMetaData.class), new ConfigurationProperties(new Properties())); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); - return new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); + return new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext, mock(PersistRepository.class)); } } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java index 316347ec114c4..b889c72c71345 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java @@ -37,6 +37,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLQueryBackendHandler; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; @@ -75,7 +76,7 @@ void assertExecuteWithUnknownDatabase() { when(connectionSession.getDatabaseName()).thenReturn("unknown"); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); - ContextManager contextManager = new ContextManager(metaDataContexts, computeNodeInstanceContext); + ContextManager contextManager = new ContextManager(metaDataContexts, computeNodeInstanceContext, mock(PersistRepository.class)); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); assertThrows(UnknownDatabaseException.class, () -> new DistSQLQueryBackendHandler(mock(ExportDatabaseConfigurationStatement.class), connectionSession).execute()); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java index b4ac17556b9c5..37c543c9cd655 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey; import org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType; +import org.apache.shardingsphere.infra.exception.kernel.syntax.InvalidVariableValueException; import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; @@ -33,8 +34,8 @@ import org.apache.shardingsphere.metadata.persist.service.config.global.PropertiesPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; -import org.apache.shardingsphere.infra.exception.kernel.syntax.InvalidVariableValueException; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; import org.junit.jupiter.api.Test; @@ -47,9 +48,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @ExtendWith(AutoMockExtension.class) @StaticMockSettings(ProxyContext.class) @@ -109,7 +110,8 @@ private ContextManager mockContextManager() { when(metaDataPersistService.getPropsService()).thenReturn(mock(PropertiesPersistService.class)); ContextManager result = new ContextManager(MetaDataContextsFactory.create(metaDataPersistService, new ShardingSphereMetaData()), new ComputeNodeInstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), - new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext())); + new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext()), + mock(PersistRepository.class)); return result; } } diff --git a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java index 051917a512982..dda70c3a2289f 100644 --- a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java +++ b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -100,6 +101,6 @@ private ContextManager mockContextManager(final Map