This is an automated email from the ASF dual-hosted git repository.

zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new e383088483c Move data source state manager to StateContext (#31439)
e383088483c is described below

commit e383088483cbb9b98e3a720a9be0b4fae479bbe0
Author: Haoran Meng <[email protected]>
AuthorDate: Fri May 31 13:09:50 2024 +0800

    Move data source state manager to StateContext (#31439)
    
    * Move data source state manager to StateContext
    
    * Move data source state manager to StateContext
    
    * Move data source state manager to StateContext
    
    * Move data source state manager to StateContext
    
    * Move data source state manager to StateContext
---
 .../impl/proxy/ProxyMetaDataInfoExporterTest.java  |  2 +
 .../impl/proxy/ProxyStateExporterTest.java         | 15 +---
 .../PrometheusPluginLifecycleServiceTest.java      |  2 +-
 ...eadwriteSplittingStorageUnitStatusExecutor.java |  4 +-
 .../driver/state/DriverStateContextTest.java       |  2 -
 .../mode/manager/ContextManager.java               |  4 +-
 .../mode/metadata/MetaDataContextsFactory.java     |  8 +--
 .../mode/service/PersistServiceFacade.java         |  4 ++
 .../QualifiedDataSourceStatePersistService.java}   | 22 +++---
 .../shardingsphere/mode/state/StateContext.java    | 82 ++++++++++++++++++++++
 ...ceStatus.java => QualifiedDataSourceState.java} |  4 +-
 .../yaml/YamlQualifiedDataSourceStatusSwapper.java | 10 +--
 .../mode/manager/ContextManagerTest.java           |  2 +-
 .../mode/state/StateContextTest.java               |  6 +-
 .../cluster/ClusterContextManagerBuilder.java      |  7 +-
 .../storage/event/StorageNodeChangedEvent.java     |  6 +-
 .../watcher/QualifiedDataSourceChangedWatcher.java | 10 +--
 ...va => QualifiedDataSourceStateServiceTest.java} |  6 +-
 ...=> QualifiedDataSourceStateSubscriberTest.java} |  2 +-
 .../subscriber/StateChangedSubscriberTest.java     |  4 +-
 .../StandaloneContextManagerBuilder.java           |  2 +-
 .../ProxyDatabaseConnectionManagerTest.java        |  2 +-
 .../backend/connector/ProxySQLExecutorTest.java    |  3 +-
 .../proxy/backend/context/ProxyContextTest.java    |  2 +-
 .../DatabaseAdminQueryBackendHandlerTest.java      |  3 +-
 .../ral/QueryableRALBackendHandlerTest.java        |  2 +-
 .../ral/updatable/SetDistVariableExecutorTest.java |  2 +-
 .../FrontDatabaseProtocolTypeFactoryTest.java      |  2 +-
 .../frontend/state/impl/OKProxyStateTest.java      |  2 +-
 .../PostgreSQLCommandExecuteEngineTest.java        |  2 +-
 .../pipeline/core/util/PipelineContextUtils.java   |  3 +-
 31 files changed, 155 insertions(+), 72 deletions(-)

diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java
index 7008ec312e0..64ce8e8f02a 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java
@@ -25,6 +25,7 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.Met
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
@@ -76,6 +77,7 @@ class ProxyMetaDataInfoExporterTest {
     
     private ContextManager mockContextManager() {
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
+        
when(database.getResourceMetaData()).thenReturn(mock(ResourceMetaData.class));
         
when(database.getResourceMetaData().getStorageUnits()).thenReturn(Collections.singletonMap("ds_0",
 mock(StorageUnit.class)));
         
when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
 "FIXTURE"));
         ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
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 f2fc0fcdaf0..0824357c6a9 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
@@ -22,20 +22,12 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeM
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
-import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
-import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
-import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
-import org.apache.shardingsphere.infra.lock.LockContext;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.state.instance.InstanceStateContext;
-import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
 import org.apache.shardingsphere.mode.manager.ContextManager;
-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;
@@ -82,9 +74,8 @@ class ProxyStateExporterTest {
     
     private ContextManager mockContextManager() {
         MetaDataContexts metaDataContexts = 
MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new 
ShardingSphereMetaData());
-        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, mock(PersistRepository.class));
+        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+        when(result.getMetaDataContexts()).thenReturn(metaDataContexts);
+        return result;
     }
 }
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 be934e12108..a836f3380d5 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
@@ -74,6 +74,6 @@ class PrometheusPluginLifecycleServiceTest {
         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, mock(PersistRepository.class));
+        return new ContextManager(metaDataContexts, 
computeNodeInstanceContext, mock(PersistRepository.class), false);
     }
 }
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 f8dcce5ec9c..0b526395485 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
@@ -28,7 +28,6 @@ import 
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.MissingReq
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
 import org.apache.shardingsphere.mode.manager.ContextManager;
-import 
org.apache.shardingsphere.mode.storage.service.QualifiedDataSourceStatusService;
 import 
org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingDataSourceType;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.statement.AlterReadwriteSplittingStorageUnitStatusStatement;
 import 
org.apache.shardingsphere.readwritesplitting.exception.ReadwriteSplittingRuleExceptionIdentifier;
@@ -77,8 +76,7 @@ public final class 
AlterReadwriteSplittingStorageUnitStatusExecutor
     
     private void updateStatus(final ContextManager contextManager, final 
AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement) {
         DataSourceState status = sqlStatement.isEnable() ? 
DataSourceState.ENABLED : DataSourceState.DISABLED;
-        new QualifiedDataSourceStatusService(contextManager.getRepository())
-                .changeStatus(database.getName(), sqlStatement.getRuleName(), 
sqlStatement.getStorageUnitName(), status);
+        
contextManager.getPersistServiceFacade().getQualifiedDataSourceStatePersistService().updateState(database.getName(),
 sqlStatement.getRuleName(), sqlStatement.getStorageUnitName(), status);
     }
     
     @Override
diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java
index e164b600a18..0fef4b94fff 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java
@@ -32,7 +32,6 @@ import 
org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
 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.state.StateContext;
 import org.apache.shardingsphere.traffic.rule.TrafficRule;
 import org.apache.shardingsphere.transaction.rule.TransactionRule;
 import org.junit.jupiter.api.BeforeEach;
@@ -70,7 +69,6 @@ class DriverStateContextTest {
                 mock(MetaDataPersistService.class), new 
ShardingSphereMetaData(databases, mock(ResourceMetaData.class), 
globalRuleMetaData, new ConfigurationProperties(new Properties())));
         
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
         
when(contextManager.getComputeNodeInstanceContext().getInstance().getState()).thenReturn(new
 InstanceStateContext());
-        when(contextManager.getStateContext()).thenReturn(new StateContext());
     }
     
     private Map<String, ShardingSphereDatabase> mockDatabases() {
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 a6af4feacf1..88be4c316a3 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
@@ -75,14 +75,14 @@ public final class ContextManager implements AutoCloseable {
     
     private final PersistRepository repository;
     
-    public ContextManager(final MetaDataContexts metaDataContexts, final 
ComputeNodeInstanceContext computeNodeInstanceContext, final PersistRepository 
repository) {
+    public ContextManager(final MetaDataContexts metaDataContexts, final 
ComputeNodeInstanceContext computeNodeInstanceContext, final PersistRepository 
repository, final boolean force) {
         this.metaDataContexts = new AtomicReference<>(metaDataContexts);
         this.computeNodeInstanceContext = computeNodeInstanceContext;
         this.repository = repository;
         persistServiceFacade = new PersistServiceFacade(repository, 
computeNodeInstanceContext.getModeConfiguration(), this);
+        stateContext = new 
StateContext(this.metaDataContexts.get().getMetaData(), 
persistServiceFacade.getQualifiedDataSourceStatePersistService().loadStates(), 
force);
         metaDataContextManager = new 
MetaDataContextManager(this.metaDataContexts, computeNodeInstanceContext, 
persistServiceFacade);
         executorEngine = 
ExecutorEngine.createExecutorEngineWithSize(metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE));
-        stateContext = new StateContext();
     }
     
     /**
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 a1217a72202..aa0431f6e72 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
@@ -50,7 +50,7 @@ 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.ContextManagerBuilderParameter;
-import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceState;
 
 import javax.sql.DataSource;
 import java.sql.SQLException;
@@ -95,7 +95,7 @@ public final class MetaDataContextsFactory {
      * @throws SQLException SQL exception
      */
     public static MetaDataContexts create(final MetaDataPersistService 
persistService, final ContextManagerBuilderParameter param,
-                                          final ComputeNodeInstanceContext 
computeNodeInstanceContext, final Map<String, QualifiedDataSourceStatus> 
statusMap) throws SQLException {
+                                          final ComputeNodeInstanceContext 
computeNodeInstanceContext, final Map<String, QualifiedDataSourceState> 
statusMap) throws SQLException {
         boolean isDatabaseMetaDataExisted = 
!persistService.getDatabaseMetaDataService().loadAllDatabaseNames().isEmpty();
         Map<String, DatabaseConfiguration> effectiveDatabaseConfigs = 
isDatabaseMetaDataExisted
                 ? 
createEffectiveDatabaseConfigurations(getDatabaseNames(computeNodeInstanceContext,
 param.getDatabaseConfigs(), persistService), param.getDatabaseConfigs(), 
persistService)
@@ -155,7 +155,7 @@ public final class MetaDataContextsFactory {
         }
     }
     
-    private static void checkDataSourceStates(final Map<String, 
DatabaseConfiguration> databaseConfigs, final Map<String, 
QualifiedDataSourceStatus> statusMap, final boolean force) {
+    private static void checkDataSourceStates(final Map<String, 
DatabaseConfiguration> databaseConfigs, final Map<String, 
QualifiedDataSourceState> statusMap, final boolean force) {
         Map<String, DataSourceState> storageDataSourceStates = 
getStorageDataSourceStates(statusMap);
         databaseConfigs.forEach((key, value) -> {
             if (!value.getStorageUnits().isEmpty()) {
@@ -164,7 +164,7 @@ public final class MetaDataContextsFactory {
         });
     }
     
-    private static Map<String, DataSourceState> 
getStorageDataSourceStates(final Map<String, QualifiedDataSourceStatus> 
statusMap) {
+    private static Map<String, DataSourceState> 
getStorageDataSourceStates(final Map<String, QualifiedDataSourceState> 
statusMap) {
         Map<String, DataSourceState> result = new HashMap<>(statusMap.size(), 
1F);
         statusMap.forEach((key, value) -> {
             List<String> values = Splitter.on(".").splitToList(key);
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 3c63b6d4391..17ba7def416 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
@@ -26,6 +26,7 @@ import 
org.apache.shardingsphere.mode.service.persist.ComputeNodePersistService;
 import 
org.apache.shardingsphere.mode.service.persist.MetaDataManagerPersistService;
 import org.apache.shardingsphere.mode.service.persist.PersistServiceBuilder;
 import org.apache.shardingsphere.mode.service.persist.ProcessPersistService;
+import 
org.apache.shardingsphere.mode.service.persist.QualifiedDataSourceStatePersistService;
 import 
org.apache.shardingsphere.mode.service.pojo.ShardingSphereSchemaDataAlteredPOJO;
 import org.apache.shardingsphere.mode.spi.PersistRepository;
 import org.apache.shardingsphere.mode.state.StatePersistService;
@@ -46,10 +47,13 @@ public final class PersistServiceFacade {
     
     private final ProcessPersistService processPersistService;
     
+    private final QualifiedDataSourceStatePersistService 
qualifiedDataSourceStatePersistService;
+    
     public PersistServiceFacade(final PersistRepository repository, final 
ModeConfiguration modeConfiguration, final ContextManager contextManager) {
         metaDataPersistService = new MetaDataPersistService(repository);
         computeNodePersistService = new ComputeNodePersistService(repository);
         statePersistService = new StatePersistService(repository);
+        qualifiedDataSourceStatePersistService = new 
QualifiedDataSourceStatePersistService(repository);
         PersistServiceBuilder persistServiceBuilder = 
TypedSPILoader.getService(PersistServiceBuilder.class, 
modeConfiguration.getType());
         metaDataManagerPersistService = 
persistServiceBuilder.buildMetaDataManagerPersistService(contextManager);
         processPersistService = 
persistServiceBuilder.buildProcessPersistService(repository);
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/QualifiedDataSourceStatusService.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/service/persist/QualifiedDataSourceStatePersistService.java
similarity index 79%
rename from 
mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/QualifiedDataSourceStatusService.java
rename to 
mode/core/src/main/java/org/apache/shardingsphere/mode/service/persist/QualifiedDataSourceStatePersistService.java
index d02e0d4e18b..c87370660d8 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/QualifiedDataSourceStatusService.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/service/persist/QualifiedDataSourceStatePersistService.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.mode.storage.service;
+package org.apache.shardingsphere.mode.service.persist;
 
 import com.google.common.base.Strings;
 import lombok.RequiredArgsConstructor;
@@ -23,7 +23,7 @@ import 
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSou
 import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
 import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
 import org.apache.shardingsphere.mode.spi.PersistRepository;
-import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceState;
 import org.apache.shardingsphere.mode.storage.node.QualifiedDataSourceNode;
 import 
org.apache.shardingsphere.mode.storage.yaml.YamlQualifiedDataSourceStatus;
 import 
org.apache.shardingsphere.mode.storage.yaml.YamlQualifiedDataSourceStatusSwapper;
@@ -33,21 +33,21 @@ import java.util.HashMap;
 import java.util.Map;
 
 /**
- * Qualified data source status service.
+ * Qualified data source state persist service.
  */
 @RequiredArgsConstructor
-public final class QualifiedDataSourceStatusService {
+public final class QualifiedDataSourceStatePersistService {
     
     private final PersistRepository repository;
     
     /**
-     * Load qualified data source status.
+     * Load qualified data source states.
      *
-     * @return qualified data source status
+     * @return qualified data source states
      */
-    public Map<String, QualifiedDataSourceStatus> loadStatus() {
+    public Map<String, QualifiedDataSourceState> loadStates() {
         Collection<String> qualifiedDataSourceNodes = 
repository.getChildrenKeys(QualifiedDataSourceNode.getRootPath());
-        Map<String, QualifiedDataSourceStatus> result = new 
HashMap<>(qualifiedDataSourceNodes.size(), 1F);
+        Map<String, QualifiedDataSourceState> result = new 
HashMap<>(qualifiedDataSourceNodes.size(), 1F);
         qualifiedDataSourceNodes.forEach(each -> {
             String yamlContent = 
repository.query(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(new 
QualifiedDataSource(each)));
             if (!Strings.isNullOrEmpty(yamlContent)) {
@@ -58,15 +58,15 @@ public final class QualifiedDataSourceStatusService {
     }
     
     /**
-     * Change qualified data source status.
+     * Update qualified data source state.
      *
      * @param databaseName database name
      * @param groupName group name
      * @param storageUnitName storage unit name
      * @param dataSourceState data source state
      */
-    public void changeStatus(final String databaseName, final String 
groupName, final String storageUnitName, final DataSourceState dataSourceState) 
{
-        QualifiedDataSourceStatus status = new 
QualifiedDataSourceStatus(dataSourceState);
+    public void updateState(final String databaseName, final String groupName, 
final String storageUnitName, final DataSourceState dataSourceState) {
+        QualifiedDataSourceState status = new 
QualifiedDataSourceState(dataSourceState);
         
repository.persist(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(
                 new QualifiedDataSource(databaseName, groupName, 
storageUnitName)), YamlEngine.marshal(new 
YamlQualifiedDataSourceStatusSwapper().swapToYamlConfiguration(status)));
     }
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java
index 32b7c685c41..57f788f8a35 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java
@@ -17,16 +17,88 @@
 
 package org.apache.shardingsphere.mode.state;
 
+import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
+import lombok.extern.slf4j.Slf4j;
+import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource;
 import org.apache.shardingsphere.infra.state.cluster.ClusterState;
+import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
+import 
org.apache.shardingsphere.infra.state.datasource.exception.UnavailableDataSourceException;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceState;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * State context.
  */
+@Slf4j
 public final class StateContext {
     
     private final AtomicReference<ClusterState> currentClusterState = new 
AtomicReference<>(ClusterState.OK);
     
+    private final Map<String, DataSourceState> dataSourceStates = new 
ConcurrentHashMap<>();
+    
+    public StateContext(final ShardingSphereMetaData metaData, final 
Map<String, QualifiedDataSourceState> qualifiedDataSourceStates, final boolean 
force) {
+        initDataSourceState(metaData, convert(qualifiedDataSourceStates), 
force);
+    }
+    
+    private void initDataSourceState(final ShardingSphereMetaData metaData, 
final Map<String, DataSourceState> storageDataSourceStates, final boolean 
force) {
+        metaData.getDatabases().forEach((key, value) -> {
+            if (value.getResourceMetaData() != null && 
!value.getResourceMetaData().getStorageUnits().isEmpty()) {
+                initDataSourceState(key, 
value.getResourceMetaData().getStorageUnits(), storageDataSourceStates, force);
+            }
+        });
+    }
+    
+    private void initDataSourceState(final String databaseName, final 
Map<String, StorageUnit> storageUnits, final Map<String, DataSourceState> 
storageDataSourceStates, final boolean force) {
+        storageUnits.forEach((key, value) -> initDataSourceState(databaseName, 
storageDataSourceStates, key, value.getDataSource(), force));
+    }
+    
+    private void initDataSourceState(final String databaseName, final 
Map<String, DataSourceState> storageDataSourceStates, final String 
actualDataSourceName, final DataSource dataSource,
+                                     final boolean force) {
+        DataSourceState storageState = 
storageDataSourceStates.get(getCacheKey(databaseName, actualDataSourceName));
+        if (DataSourceState.DISABLED == storageState) {
+            dataSourceStates.put(getCacheKey(databaseName, 
actualDataSourceName), storageState);
+        } else {
+            checkState(databaseName, actualDataSourceName, dataSource, force);
+        }
+    }
+    
+    private static Map<String, DataSourceState> convert(final Map<String, 
QualifiedDataSourceState> qualifiedDataSourceStates) {
+        Map<String, DataSourceState> result = new 
HashMap<>(qualifiedDataSourceStates.size(), 1F);
+        qualifiedDataSourceStates.forEach((key, value) -> {
+            List<String> values = Splitter.on(".").splitToList(key);
+            Preconditions.checkArgument(3 == values.size(), "Illegal data 
source of storage node.");
+            String databaseName = values.get(0);
+            String dataSourceName = values.get(2);
+            result.put(databaseName + "." + dataSourceName, 
DataSourceState.valueOf(value.getStatus().name()));
+        });
+        return result;
+    }
+    
+    private void checkState(final String databaseName, final String 
actualDataSourceName, final DataSource dataSource, final boolean force) {
+        try (Connection ignored = dataSource.getConnection()) {
+            dataSourceStates.put(getCacheKey(databaseName, 
actualDataSourceName), DataSourceState.ENABLED);
+        } catch (final SQLException ex) {
+            ShardingSpherePreconditions.checkState(force, () -> new 
UnavailableDataSourceException(actualDataSourceName, ex));
+            log.error("Data source unavailable, ignored with the -f 
parameter.", ex);
+        }
+    }
+    
+    private String getCacheKey(final String databaseName, final String 
dataSourceName) {
+        return databaseName + "." + dataSourceName;
+    }
+    
     /**
      * Get current cluster state.
      * 
@@ -44,4 +116,14 @@ public final class StateContext {
     public void switchCurrentClusterState(final ClusterState state) {
         currentClusterState.set(state);
     }
+    
+    /**
+     * Update data source state.
+     *
+     * @param qualifiedDataSource qualified data source
+     * @param dataSourceState data source state
+     */
+    public void updateDataSourceState(final QualifiedDataSource 
qualifiedDataSource, final DataSourceState dataSourceState) {
+        
dataSourceStates.put(getCacheKey(qualifiedDataSource.getDatabaseName(), 
qualifiedDataSource.getDataSourceName()), dataSourceState);
+    }
 }
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceStatus.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceState.java
similarity index 93%
rename from 
mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceStatus.java
rename to 
mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceState.java
index 2c9a9d2abc6..c7401ce5159 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceStatus.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceState.java
@@ -22,11 +22,11 @@ import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
 
 /**
- * Qualified data source status.
+ * Qualified data source state.
  */
 @RequiredArgsConstructor
 @Getter
-public final class QualifiedDataSourceStatus {
+public final class QualifiedDataSourceState {
     
     private final DataSourceState status;
 }
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatusSwapper.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatusSwapper.java
index 4db8d95033b..f75545cdff8 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatusSwapper.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatusSwapper.java
@@ -19,22 +19,22 @@ package org.apache.shardingsphere.mode.storage.yaml;
 
 import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
 import 
org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
-import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceState;
 
 /**
  * YAML qualified data source status swapper.
  */
-public final class YamlQualifiedDataSourceStatusSwapper implements 
YamlConfigurationSwapper<YamlQualifiedDataSourceStatus, 
QualifiedDataSourceStatus> {
+public final class YamlQualifiedDataSourceStatusSwapper implements 
YamlConfigurationSwapper<YamlQualifiedDataSourceStatus, 
QualifiedDataSourceState> {
     
     @Override
-    public YamlQualifiedDataSourceStatus swapToYamlConfiguration(final 
QualifiedDataSourceStatus data) {
+    public YamlQualifiedDataSourceStatus swapToYamlConfiguration(final 
QualifiedDataSourceState data) {
         YamlQualifiedDataSourceStatus result = new 
YamlQualifiedDataSourceStatus();
         result.setStatus(data.getStatus().name());
         return result;
     }
     
     @Override
-    public QualifiedDataSourceStatus swapToObject(final 
YamlQualifiedDataSourceStatus yamlConfig) {
-        return new 
QualifiedDataSourceStatus(DataSourceState.valueOf(yamlConfig.getStatus()));
+    public QualifiedDataSourceState swapToObject(final 
YamlQualifiedDataSourceStatus yamlConfig) {
+        return new 
QualifiedDataSourceState(DataSourceState.valueOf(yamlConfig.getStatus()));
     }
 }
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 d689b9de3bb..b6803aa5d65 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
@@ -89,7 +89,7 @@ class ContextManagerTest {
         
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, mock(PersistRepository.class));
+        contextManager = new ContextManager(metaDataContexts, 
computeNodeInstanceContext, mock(PersistRepository.class), false);
     }
     
     private ShardingSphereDatabase mockDatabase() {
diff --git 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java
 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java
index ba42fc43146..03602fabb33 100644
--- 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java
+++ 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java
@@ -17,15 +17,19 @@
 
 package org.apache.shardingsphere.mode.state;
 
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.state.cluster.ClusterState;
 import org.junit.jupiter.api.Test;
 
+import java.util.HashMap;
+
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
 
 class StateContextTest {
     
-    private final StateContext stateContext = new StateContext();
+    private final StateContext stateContext = new 
StateContext(mock(ShardingSphereMetaData.class), new HashMap<>(), false);
     
     @Test
     void assertGetCurrentClusterState() {
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 9c17de92bf4..be9560ee83f 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
@@ -43,8 +43,8 @@ import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositor
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
 import 
org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder;
 import 
org.apache.shardingsphere.mode.repository.cluster.lock.impl.props.DefaultLockTypedProperties;
+import 
org.apache.shardingsphere.mode.service.persist.QualifiedDataSourceStatePersistService;
 import org.apache.shardingsphere.mode.state.StatePersistService;
-import 
org.apache.shardingsphere.mode.storage.service.QualifiedDataSourceStatusService;
 
 import java.sql.SQLException;
 import java.util.Collections;
@@ -64,8 +64,9 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
         ComputeNodeInstanceContext computeNodeInstanceContext = 
buildComputeNodeInstanceContext(modeConfig, param.getInstanceMetaData(), 
repository, eventBusContext);
         repository.init(config, computeNodeInstanceContext);
         MetaDataPersistService metaDataPersistService = new 
MetaDataPersistService(repository);
-        MetaDataContexts metaDataContexts = 
MetaDataContextsFactory.create(metaDataPersistService, param, 
computeNodeInstanceContext, new 
QualifiedDataSourceStatusService(repository).loadStatus());
-        ContextManager result = new ContextManager(metaDataContexts, 
computeNodeInstanceContext, repository);
+        MetaDataContexts metaDataContexts = 
MetaDataContextsFactory.create(metaDataPersistService, param, 
computeNodeInstanceContext,
+                new 
QualifiedDataSourceStatePersistService(repository).loadStates());
+        ContextManager result = new ContextManager(metaDataContexts, 
computeNodeInstanceContext, repository, param.isForce());
         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/registry/status/storage/event/StorageNodeChangedEvent.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java
index c045e408c53..73f8bc70ffc 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java
@@ -19,9 +19,9 @@ package 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
 
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource;
-import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
+import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceState;
 
 /**
  * Storage node changed event.
@@ -32,5 +32,5 @@ public final class StorageNodeChangedEvent implements 
GovernanceEvent {
     
     private final QualifiedDataSource qualifiedDataSource;
     
-    private final QualifiedDataSourceStatus status;
+    private final QualifiedDataSourceState status;
 }
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcher.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcher.java
index f9e923f9317..05cd9c2198f 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcher.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcher.java
@@ -19,16 +19,16 @@ package 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
 
 import com.google.common.base.Strings;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
 import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
+import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
+import org.apache.shardingsphere.mode.event.DataChangedEvent;
+import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceState;
 import org.apache.shardingsphere.mode.storage.node.QualifiedDataSourceNode;
 import 
org.apache.shardingsphere.mode.storage.yaml.YamlQualifiedDataSourceStatus;
 import 
org.apache.shardingsphere.mode.storage.yaml.YamlQualifiedDataSourceStatusSwapper;
-import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -57,7 +57,7 @@ public final class QualifiedDataSourceChangedWatcher 
implements GovernanceWatche
         }
         Optional<QualifiedDataSource> qualifiedDataSource = 
QualifiedDataSourceNode.extractQualifiedDataSource(event.getKey());
         if (qualifiedDataSource.isPresent()) {
-            QualifiedDataSourceStatus status = new 
YamlQualifiedDataSourceStatusSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(),
 YamlQualifiedDataSourceStatus.class));
+            QualifiedDataSourceState status = new 
YamlQualifiedDataSourceStatusSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(),
 YamlQualifiedDataSourceStatus.class));
             return Optional.of(new 
StorageNodeChangedEvent(qualifiedDataSource.get(), status));
         }
         return Optional.empty();
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStatusServiceTest.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStateServiceTest.java
similarity index 87%
rename from 
mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStatusServiceTest.java
rename to 
mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStateServiceTest.java
index e91e6771e40..cbda735fc1f 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStatusServiceTest.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStateServiceTest.java
@@ -18,7 +18,7 @@
 package 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.service;
 
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
-import 
org.apache.shardingsphere.mode.storage.service.QualifiedDataSourceStatusService;
+import 
org.apache.shardingsphere.mode.service.persist.QualifiedDataSourceStatePersistService;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
@@ -32,7 +32,7 @@ import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.when;
 
 @ExtendWith(MockitoExtension.class)
-class QualifiedDataSourceStatusServiceTest {
+class QualifiedDataSourceStateServiceTest {
     
     @Mock
     private ClusterPersistRepository repository;
@@ -41,6 +41,6 @@ class QualifiedDataSourceStatusServiceTest {
     void assertLoadStatus() {
         List<String> disabledDataSources = 
Arrays.asList("replica_query_db.readwrite_ds.replica_ds_0", 
"other_schema.other_ds.other_ds0");
         
when(repository.getChildrenKeys(anyString())).thenReturn(disabledDataSources);
-        assertDoesNotThrow(() -> new 
QualifiedDataSourceStatusService(repository).loadStatus());
+        assertDoesNotThrow(() -> new 
QualifiedDataSourceStatePersistService(repository).loadStates());
     }
 }
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/QualifiedDataSourceStatusSubscriberTest.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/QualifiedDataSourceStateSubscriberTest.java
similarity index 97%
rename from 
mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/QualifiedDataSourceStatusSubscriberTest.java
rename to 
mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/QualifiedDataSourceStateSubscriberTest.java
index c28beba4fab..67a11e39287 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/QualifiedDataSourceStatusSubscriberTest.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/QualifiedDataSourceStateSubscriberTest.java
@@ -29,7 +29,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import static org.mockito.Mockito.verify;
 
 @ExtendWith(MockitoExtension.class)
-class QualifiedDataSourceStatusSubscriberTest {
+class QualifiedDataSourceStateSubscriberTest {
     
     @Mock
     private ClusterPersistRepository repository;
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 f708bbf6c4e..4bd43906024 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
@@ -45,7 +45,7 @@ import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
 import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory;
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
-import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceState;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -112,7 +112,7 @@ class StateChangedSubscriberTest {
     void assertRenewForDisableStateChanged() {
         StaticDataSourceRuleAttribute ruleAttribute = 
mock(StaticDataSourceRuleAttribute.class);
         
when(database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute));
-        StorageNodeChangedEvent event = new StorageNodeChangedEvent(new 
QualifiedDataSource("db.readwrite_ds.ds_0"), new 
QualifiedDataSourceStatus(DataSourceState.DISABLED));
+        StorageNodeChangedEvent event = new StorageNodeChangedEvent(new 
QualifiedDataSource("db.readwrite_ds.ds_0"), new 
QualifiedDataSourceState(DataSourceState.DISABLED));
         subscriber.renew(event);
         verify(ruleAttribute).updateStatus(
                 argThat(qualifiedDataSource -> 
Objects.equals(event.getQualifiedDataSource(), qualifiedDataSource)),
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 5c2b3da39b0..627bd808294 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 final class StandaloneContextManagerBuilder implements 
ContextManagerBuil
         MetaDataPersistService persistService = new 
MetaDataPersistService(repository);
         ComputeNodeInstanceContext computeNodeInstanceContext = 
buildComputeNodeInstanceContext(param, eventBusContext);
         MetaDataContexts metaDataContexts = 
MetaDataContextsFactory.create(persistService, param, 
computeNodeInstanceContext);
-        ContextManager result = new ContextManager(metaDataContexts, 
computeNodeInstanceContext, repository);
+        ContextManager result = new ContextManager(metaDataContexts, 
computeNodeInstanceContext, repository, param.isForce());
         new StandaloneEventSubscriberRegistry(result).register();
         return result;
     }
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 18d70ce4b95..9843da08bc7 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
@@ -127,7 +127,7 @@ class ProxyDatabaseConnectionManagerTest {
         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, mock(PersistRepository.class));
+        return new 
ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class),
 metaData), computeNodeInstanceContext, mock(PersistRepository.class), false);
     }
     
     @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 baf87a324d5..6034968f676 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
@@ -112,7 +112,8 @@ class ProxySQLExecutorTest {
         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, mock(PersistRepository.class));
+        ContextManager contextManager = new 
ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class),
 metaData), computeNodeInstanceContext,
+                mock(PersistRepository.class), false);
         
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 2951a46c86e..0192e9ea99b 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
@@ -70,7 +70,7 @@ class ProxyContextTest {
     @Test
     void assertInit() {
         MetaDataContexts metaDataContexts = 
MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new 
ShardingSphereMetaData());
-        ProxyContext.init(new ContextManager(metaDataContexts, 
mock(ComputeNodeInstanceContext.class, RETURNS_DEEP_STUBS), 
mock(PersistRepository.class)));
+        ProxyContext.init(new ContextManager(metaDataContexts, 
mock(ComputeNodeInstanceContext.class, RETURNS_DEEP_STUBS), 
mock(PersistRepository.class), false));
         
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 a2743076f67..6bf2b32e076 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
@@ -112,12 +112,13 @@ class DatabaseAdminQueryBackendHandlerTest {
     
     private ContextManager mockContextManager() {
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
+        
when(database.getResourceMetaData()).thenReturn(mock(ResourceMetaData.class));
         when(database.getProtocolType()).thenReturn(databaseType);
         
when(ProxyContext.getInstance().getContextManager().getDatabase("foo_db")).thenReturn(database);
         ShardingSphereMetaData metaData = new 
ShardingSphereMetaData(Collections.singletonMap("foo_db", database), 
mock(ResourceMetaData.class),
                 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, mock(PersistRepository.class));
+        return new 
ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class),
 metaData), computeNodeInstanceContext, mock(PersistRepository.class), false);
     }
 }
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 b889c72c713..3a79734a741 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
@@ -76,7 +76,7 @@ class QueryableRALBackendHandlerTest {
         when(connectionSession.getDatabaseName()).thenReturn("unknown");
         ComputeNodeInstanceContext computeNodeInstanceContext = 
mock(ComputeNodeInstanceContext.class);
         
when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class));
-        ContextManager contextManager = new ContextManager(metaDataContexts, 
computeNodeInstanceContext, mock(PersistRepository.class));
+        ContextManager contextManager = new ContextManager(metaDataContexts, 
computeNodeInstanceContext, mock(PersistRepository.class), false);
         
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 37c543c9cd6..256ddc0fd79 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
@@ -111,7 +111,7 @@ class SetDistVariableExecutorTest {
         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()),
-                mock(PersistRepository.class));
+                mock(PersistRepository.class), false);
         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 dda70c3a228..f2e43d6e39a 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
@@ -101,6 +101,6 @@ class FrontDatabaseProtocolTypeFactoryTest {
                 new ShardingSphereMetaData(databases, 
mock(ResourceMetaData.class), mock(RuleMetaData.class), new 
ConfigurationProperties(props)));
         ComputeNodeInstanceContext computeNodeInstanceContext = 
mock(ComputeNodeInstanceContext.class);
         
when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class));
-        return new ContextManager(metaDataContexts, 
computeNodeInstanceContext, mock(PersistRepository.class));
+        return new ContextManager(metaDataContexts, 
computeNodeInstanceContext, mock(PersistRepository.class), false);
     }
 }
diff --git 
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
 
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
index 81f6da4a516..59a607b19bd 100644
--- 
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
+++ 
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
@@ -97,7 +97,7 @@ class OKProxyStateTest {
         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, mock(PersistRepository.class));
+        return new 
ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class),
 metaData), computeNodeInstanceContext, mock(PersistRepository.class), false);
     }
     
     @SuppressWarnings({"unchecked", "SameParameterValue"})
diff --git 
a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
 
b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
index 0d7481105e7..d00bed566e6 100644
--- 
a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
+++ 
b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
@@ -124,7 +124,7 @@ class PostgreSQLCommandExecuteEngineTest {
         ComputeNodeInstanceContext computeNodeInstanceContext = 
mock(ComputeNodeInstanceContext.class);
         
when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class));
         ContextManager contextManager = new 
ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class),
-                new ShardingSphereMetaData()), computeNodeInstanceContext, 
mock(PersistRepository.class));
+                new ShardingSphereMetaData()), computeNodeInstanceContext, 
mock(PersistRepository.class), false);
         
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
         commandExecuteEngine.writeQueryData(channelHandlerContext, 
databaseConnectionManager, queryCommandExecutor, 0);
         verify(resourceLock).doAwait(channelHandlerContext);
diff --git 
a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/util/PipelineContextUtils.java
 
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/util/PipelineContextUtils.java
index 9f4c2847fd6..99b8710e1b4 100644
--- 
a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/util/PipelineContextUtils.java
+++ 
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/util/PipelineContextUtils.java
@@ -110,7 +110,8 @@ public final class PipelineContextUtils {
         ContextManager contextManager = getContextManager(rootConfig);
         ClusterPersistRepository persistRepository = 
getClusterPersistRepository((ClusterPersistRepositoryConfiguration) 
modeConfig.getRepository());
         MetaDataContexts metaDataContexts = 
renewMetaDataContexts(contextManager.getMetaDataContexts(), new 
MetaDataPersistService(persistRepository));
-        PipelineContext pipelineContext = new PipelineContext(modeConfig, new 
ContextManager(metaDataContexts, 
contextManager.getComputeNodeInstanceContext(), 
contextManager.getRepository()));
+        PipelineContext pipelineContext = new PipelineContext(modeConfig, new 
ContextManager(metaDataContexts, contextManager.getComputeNodeInstanceContext(),
+                contextManager.getRepository(), false));
         PipelineContextManager.putContext(contextKey, pipelineContext);
     }
     

Reply via email to