This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 d52b2c0e9c8 Refactor ContextManager (#36621)
d52b2c0e9c8 is described below
commit d52b2c0e9c87a2c423cae07a4daecf54b5063b26
Author: Haoran Meng <[email protected]>
AuthorDate: Fri Sep 19 10:28:12 2025 +0800
Refactor ContextManager (#36621)
---
.../metrics/prometheus/PrometheusPluginLifecycleServiceTest.java | 4 ++--
.../org/apache/shardingsphere/mode/manager/ContextManager.java | 8 ++------
.../mode/manager/cluster/ClusterContextManagerBuilder.java | 4 +++-
.../mode/manager/standalone/StandaloneContextManagerBuilder.java | 4 +++-
.../test/it/data/pipeline/core/util/PipelineContextUtils.java | 2 +-
5 files changed, 11 insertions(+), 11 deletions(-)
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 9d8c9e7ec11..8c33cc27fd1 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
@@ -27,7 +27,7 @@ import
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatist
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
-import org.apache.shardingsphere.mode.exclusive.ExclusiveOperatorContext;
+import org.apache.shardingsphere.mode.exclusive.ExclusiveOperatorEngine;
import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.mode.manager.standalone.workerid.StandaloneWorkerIdGenerator;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -74,6 +74,6 @@ class PrometheusPluginLifecycleServiceTest {
ComputeNodeInstanceContext computeNodeInstanceContext = new
ComputeNodeInstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), new
ModeConfiguration("Standalone", null), new EventBusContext());
computeNodeInstanceContext.init(new StandaloneWorkerIdGenerator());
- return new ContextManager(metaDataContexts,
computeNodeInstanceContext, mock(PersistRepository.class),
mock(ExclusiveOperatorContext.class));
+ return new ContextManager(metaDataContexts,
computeNodeInstanceContext, mock(PersistRepository.class),
mock(ExclusiveOperatorEngine.class));
}
}
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 08c47de4b15..fdfee62fe5a 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
@@ -39,7 +39,6 @@ import
org.apache.shardingsphere.infra.metadata.database.schema.manager.GenericS
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.statistics.builder.ShardingSphereStatisticsFactory;
import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder;
-import org.apache.shardingsphere.mode.exclusive.ExclusiveOperatorContext;
import org.apache.shardingsphere.mode.exclusive.ExclusiveOperatorEngine;
import
org.apache.shardingsphere.mode.manager.listener.ContextManagerLifecycleListenerFactory;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -74,20 +73,17 @@ public final class ContextManager implements AutoCloseable {
private final MetaDataContextManager metaDataContextManager;
- private final ExclusiveOperatorContext exclusiveOperatorContext;
-
private final ExclusiveOperatorEngine exclusiveOperatorEngine;
public ContextManager(final MetaDataContexts metaDataContexts, final
ComputeNodeInstanceContext computeNodeInstanceContext,
- final PersistRepository repository, final
ExclusiveOperatorContext exclusiveOperatorContext) {
+ final PersistRepository repository, final
ExclusiveOperatorEngine exclusiveOperatorEngine) {
this.metaDataContexts = metaDataContexts;
this.computeNodeInstanceContext = computeNodeInstanceContext;
- this.exclusiveOperatorContext = exclusiveOperatorContext;
+ this.exclusiveOperatorEngine = exclusiveOperatorEngine;
executorEngine =
ExecutorEngine.createExecutorEngineWithSize(metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE));
metaDataContextManager = new MetaDataContextManager(metaDataContexts,
computeNodeInstanceContext, repository);
persistServiceFacade = new PersistServiceFacade(repository,
computeNodeInstanceContext.getModeConfiguration(), metaDataContextManager);
stateContext = new
StateContext(persistServiceFacade.getStateService().load());
- exclusiveOperatorEngine = new
ExclusiveOperatorEngine(exclusiveOperatorContext);
ContextManagerLifecycleListenerFactory.getListeners(this).forEach(each
-> each.onInitialized(this));
}
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 e72c3533e03..204628590eb 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
@@ -27,6 +27,7 @@ import
org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.mode.deliver.DeliverEventSubscriber;
import org.apache.shardingsphere.mode.deliver.DeliverEventSubscriberRegistry;
+import org.apache.shardingsphere.mode.exclusive.ExclusiveOperatorEngine;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.builder.ContextManagerBuilder;
import
org.apache.shardingsphere.mode.manager.builder.ContextManagerBuilderParameter;
@@ -58,8 +59,9 @@ public final class ClusterContextManagerBuilder implements
ContextManagerBuilder
ComputeNodeInstanceContext computeNodeInstanceContext = new
ComputeNodeInstanceContext(new ComputeNodeInstance(param.getInstanceMetaData(),
param.getLabels()), modeConfig, eventBusContext);
ClusterPersistRepository repository =
getClusterPersistRepository(config, computeNodeInstanceContext);
computeNodeInstanceContext.init(new
ClusterWorkerIdGenerator(repository, param.getInstanceMetaData().getId()));
+ ExclusiveOperatorEngine exclusiveOperatorEngine = new
ExclusiveOperatorEngine(new ClusterExclusiveOperatorContext(repository));
MetaDataContexts metaDataContexts = new MetaDataContextsFactory(new
MetaDataPersistFacade(repository), computeNodeInstanceContext).create(param);
- ContextManager result = new ContextManager(metaDataContexts,
computeNodeInstanceContext, repository, new
ClusterExclusiveOperatorContext(repository));
+ ContextManager result = new ContextManager(metaDataContexts,
computeNodeInstanceContext, repository, exclusiveOperatorEngine);
registerOnline(computeNodeInstanceContext, param, result);
new
DeliverEventSubscriberRegistry(result.getComputeNodeInstanceContext().getEventBusContext()).register(createDeliverEventSubscribers(repository));
return result;
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 3a2e2df2d38..fa29d3a79d2 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
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
+import org.apache.shardingsphere.mode.exclusive.ExclusiveOperatorEngine;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.builder.ContextManagerBuilder;
import
org.apache.shardingsphere.mode.manager.builder.ContextManagerBuilderParameter;
@@ -47,8 +48,9 @@ public final class StandaloneContextManagerBuilder implements
ContextManagerBuil
computeNodeInstanceContext.init(new StandaloneWorkerIdGenerator());
StandalonePersistRepository repository = TypedSPILoader.getService(
StandalonePersistRepository.class, null == repositoryConfig ?
null : repositoryConfig.getType(), null == repositoryConfig ? new Properties()
: repositoryConfig.getProps());
+ ExclusiveOperatorEngine exclusiveOperatorEngine = new
ExclusiveOperatorEngine(new StandaloneExclusiveOperatorContext());
MetaDataContexts metaDataContexts = new MetaDataContextsFactory(new
MetaDataPersistFacade(repository), computeNodeInstanceContext).create(param);
- return new ContextManager(metaDataContexts,
computeNodeInstanceContext, repository, new
StandaloneExclusiveOperatorContext());
+ return new ContextManager(metaDataContexts,
computeNodeInstanceContext, repository, exclusiveOperatorEngine);
}
@Override
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 f7ffb933a15..103f80d0895 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
@@ -114,7 +114,7 @@ public final class PipelineContextUtils {
MetaDataContexts metaDataContexts =
renewMetaDataContexts(contextManager.getMetaDataContexts(), new
MetaDataPersistFacade(persistRepository, true));
PipelineContextManager.putContext(contextKey,
new ContextManager(metaDataContexts,
contextManager.getComputeNodeInstanceContext(),
contextManager.getPersistServiceFacade().getRepository(),
- contextManager.getExclusiveOperatorContext()));
+ contextManager.getExclusiveOperatorEngine()));
}
@SneakyThrows({ReflectiveOperationException.class, SQLException.class})