Skip to content

Commit

Permalink
Remove ModeContextManager
Browse files Browse the repository at this point in the history
  • Loading branch information
menghaoranss committed May 23, 2024
1 parent 4982c65 commit 3c6b3d0
Show file tree
Hide file tree
Showing 43 changed files with 102 additions and 767 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.state.instance.InstanceStateContext;
Expand Down Expand Up @@ -83,7 +82,7 @@ private ContextManager mockContextManager() {
MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData());
ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null),
mock(ModeContextManager.class), mock(LockContext.class), new EventBusContext());
mock(LockContext.class), new EventBusContext());
return new ContextManager(metaDataContexts, computeNodeInstanceContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
Expand Down Expand Up @@ -72,7 +71,7 @@ private ContextManager mockContextManager() {
MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData());
ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null),
mock(ModeContextManager.class), mock(LockContext.class), new EventBusContext());
mock(LockContext.class), new EventBusContext());
return new ContextManager(metaDataContexts, computeNodeInstanceContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private ShardingRule createShardingRule() {
ruleConfig.getTables().add(nonCacheableTableSharding);
ruleConfig.setShardingCache(new ShardingCacheConfiguration(100, new ShardingCacheOptionsConfiguration(true, 0, 0)));
return new ShardingRule(ruleConfig, Maps.of("ds_0", new MockedDataSource(), "ds_1", new MockedDataSource()),
new ComputeNodeInstanceContext(mock(ComputeNodeInstance.class), props -> 0, null, null, null, null));
new ComputeNodeInstanceContext(mock(ComputeNodeInstance.class), props -> 0, null, null, null));
}

private TimestampServiceRule createTimeServiceRule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator;
import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.state.instance.InstanceState;
Expand Down Expand Up @@ -52,8 +51,6 @@ public final class ComputeNodeInstanceContext {

private final ModeConfiguration modeConfiguration;

private final ModeContextManager modeContextManager;

@SuppressWarnings("rawtypes")
private final LockContext lockContext;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator;
import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.state.instance.InstanceState;
Expand All @@ -42,8 +41,6 @@ class ComputeNodeInstanceContextTest {

private final ModeConfiguration modeConfig = new ModeConfiguration("Standalone", null);

private final ModeContextManager modeContextManager = mock(ModeContextManager.class);

private final LockContext lockContext = mock(LockContext.class);

private final EventBusContext eventBusContext = new EventBusContext();
Expand All @@ -53,7 +50,7 @@ void assertUpdateComputeNodeState() {
InstanceMetaData instanceMetaData = mock(InstanceMetaData.class);
when(instanceMetaData.getId()).thenReturn("foo_instance_id");
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(
new ComputeNodeInstance(instanceMetaData), mock(WorkerIdGenerator.class), modeConfig, modeContextManager, lockContext, eventBusContext);
new ComputeNodeInstance(instanceMetaData), mock(WorkerIdGenerator.class), modeConfig, lockContext, eventBusContext);
InstanceState actual = context.getInstance().getState().getCurrentState();
assertThat(actual, is(InstanceState.OK));
context.updateStatus(instanceMetaData.getId(), InstanceState.CIRCUIT_BREAK.name());
Expand All @@ -68,14 +65,14 @@ void assertUpdateComputeNodeState() {
void assertGetWorkerId() {
ComputeNodeInstance computeNodeInstance = mock(ComputeNodeInstance.class);
when(computeNodeInstance.getWorkerId()).thenReturn(0);
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(computeNodeInstance, mock(WorkerIdGenerator.class), modeConfig, modeContextManager, lockContext, eventBusContext);
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(computeNodeInstance, mock(WorkerIdGenerator.class), modeConfig, lockContext, eventBusContext);
assertThat(context.getWorkerId(), is(0));
}

@Test
void assertGenerateWorkerId() {
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), modeConfig, modeContextManager, lockContext, eventBusContext);
new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), modeConfig, lockContext, eventBusContext);
assertThat(context.generateWorkerId(new Properties()), is(0));
}

Expand All @@ -84,7 +81,7 @@ void assertUpdateLabel() {
InstanceMetaData instanceMetaData = mock(InstanceMetaData.class);
when(instanceMetaData.getId()).thenReturn("foo_instance_id");
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(
new ComputeNodeInstance(instanceMetaData), mock(WorkerIdGenerator.class), modeConfig, modeContextManager, lockContext, eventBusContext);
new ComputeNodeInstance(instanceMetaData), mock(WorkerIdGenerator.class), modeConfig, lockContext, eventBusContext);
Collection<String> expected = Arrays.asList("label_1", "label_2");
context.updateLabel("foo_instance_id", expected);
Collection<String> actual = context.getInstance().getLabels();
Expand All @@ -94,32 +91,32 @@ void assertUpdateLabel() {
@Test
void assertGetInstance() {
ComputeNodeInstance expected = new ComputeNodeInstance(mock(InstanceMetaData.class));
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(expected, mock(WorkerIdGenerator.class), modeConfig, modeContextManager, lockContext, eventBusContext);
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(expected, mock(WorkerIdGenerator.class), modeConfig, lockContext, eventBusContext);
ComputeNodeInstance actual = context.getInstance();
assertThat(actual, is(expected));
}

@Test
void assertGetState() {
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), modeConfig, modeContextManager, lockContext, eventBusContext);
new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), modeConfig, lockContext, eventBusContext);
assertNotNull(context.getInstance().getState());
}

@Test
void assertGetModeConfiguration() {
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), modeConfig, modeContextManager, lockContext, eventBusContext);
new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), modeConfig, lockContext, eventBusContext);
assertThat(context.getModeConfiguration(), is(modeConfig));
}

@Test
void assertIsCluster() {
ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), modeConfig, modeContextManager, lockContext, eventBusContext);
new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), modeConfig, lockContext, eventBusContext);
assertFalse(context.isCluster());
ComputeNodeInstanceContext clusterContext = new ComputeNodeInstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class),
new ModeConfiguration("Cluster", null), modeContextManager, lockContext, eventBusContext);
new ModeConfiguration("Cluster", null), lockContext, eventBusContext);
assertTrue(clusterContext.isCluster());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import org.apache.shardingsphere.distsql.statement.rdl.rule.database.DatabaseRuleDefinitionStatement;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.config.rule.decorator.RuleConfigurationDecorator;
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.service.MetaDataManagerPersistService;

import java.util.Collection;
import java.util.LinkedHashMap;
Expand All @@ -49,10 +49,10 @@ public final class AlterDatabaseRuleOperator implements DatabaseRuleOperator {
@SuppressWarnings("unchecked")
public Collection<MetaDataVersion> operate(final DatabaseRuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) {
RuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement);
ModeContextManager modeContextManager = contextManager.getComputeNodeInstanceContext().getModeContextManager();
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getMetaDataManagerPersistService();
RuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(toBeAlteredRuleConfig);
modeContextManager.removeRuleConfigurationItem(database.getName(), toBeDroppedRuleConfig);
return modeContextManager.alterRuleConfiguration(database.getName(), decorateRuleConfiguration(database, toBeAlteredRuleConfig));
metaDataManagerPersistService.removeRuleConfigurationItem(database.getName(), toBeDroppedRuleConfig);
return metaDataManagerPersistService.alterRuleConfiguration(database.getName(), decorateRuleConfiguration(database, toBeAlteredRuleConfig));
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import org.apache.shardingsphere.distsql.statement.rdl.rule.database.DatabaseRuleDefinitionStatement;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.config.rule.decorator.RuleConfigurationDecorator;
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.service.MetaDataManagerPersistService;

import java.util.Collection;
import java.util.LinkedHashMap;
Expand All @@ -49,8 +49,8 @@ public final class CreateDatabaseRuleOperator implements DatabaseRuleOperator {
@SuppressWarnings("unchecked")
public Collection<MetaDataVersion> operate(final DatabaseRuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) {
RuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(sqlStatement);
ModeContextManager modeContextManager = contextManager.getComputeNodeInstanceContext().getModeContextManager();
return modeContextManager.alterRuleConfiguration(database.getName(), decorateRuleConfiguration(database, toBeCreatedRuleConfig));
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getMetaDataManagerPersistService();
return metaDataManagerPersistService.alterRuleConfiguration(database.getName(), decorateRuleConfiguration(database, toBeCreatedRuleConfig));
}

@SuppressWarnings("unchecked")
Expand Down
Loading

0 comments on commit 3c6b3d0

Please sign in to comment.