Skip to content

Commit

Permalink
Rename ManagerServiceFacade to MetaDataContextManager
Browse files Browse the repository at this point in the history
  • Loading branch information
menghaoranss committed May 28, 2024
1 parent edefb06 commit d345d66
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
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.ManagerServiceFacade;
import org.apache.shardingsphere.mode.service.MetaDataContextManager;
import org.apache.shardingsphere.mode.service.PersistServiceFacade;
import org.apache.shardingsphere.mode.service.manager.ConfigurationManagerService;
import org.apache.shardingsphere.mode.service.manager.ConfigurationManager;
import org.apache.shardingsphere.mode.spi.PersistRepository;
import org.apache.shardingsphere.mode.state.StateContext;

Expand All @@ -71,7 +71,7 @@ public final class ContextManager implements AutoCloseable {

private final PersistServiceFacade persistServiceFacade;

private final ManagerServiceFacade managerServiceFacade;
private final MetaDataContextManager metaDataContextManager;

private final PersistRepository repository;

Expand All @@ -80,7 +80,7 @@ public ContextManager(final MetaDataContexts metaDataContexts, final ComputeNode
this.computeNodeInstanceContext = computeNodeInstanceContext;
this.repository = repository;
persistServiceFacade = new PersistServiceFacade(repository, computeNodeInstanceContext.getModeConfiguration(), this);
managerServiceFacade = new ManagerServiceFacade(this.metaDataContexts, computeNodeInstanceContext, persistServiceFacade);
metaDataContextManager = new MetaDataContextManager(this.metaDataContexts, computeNodeInstanceContext, persistServiceFacade);
executorEngine = ExecutorEngine.createExecutorEngineWithSize(metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE));
stateContext = new StateContext();
}
Expand Down Expand Up @@ -170,12 +170,12 @@ public void refreshTableMetaData(final ShardingSphereDatabase database) {

private MetaDataContexts createMetaDataContexts(final ShardingSphereDatabase database) throws SQLException {
MetaDataPersistService metaDataPersistService = persistServiceFacade.getMetaDataPersistService();
ConfigurationManagerService configurationManagerService = managerServiceFacade.getConfigurationManagerService();
ConfigurationManager configurationManager = metaDataContextManager.getConfigurationManager();
Map<String, DataSourcePoolProperties> dataSourcePoolPropsFromRegCenter = metaDataPersistService.getDataSourceUnitService().load(database.getName());
SwitchingResource switchingResource = new ResourceSwitchManager().alterStorageUnit(database.getResourceMetaData(), dataSourcePoolPropsFromRegCenter);
metaDataContexts.get().getMetaData().getDatabases().putAll(configurationManagerService.renewDatabase(database, switchingResource));
metaDataContexts.get().getMetaData().getDatabases().putAll(configurationManager.renewDatabase(database, switchingResource));
Collection<RuleConfiguration> ruleConfigs = metaDataPersistService.getDatabaseRulePersistService().load(database.getName());
Map<String, ShardingSphereDatabase> changedDatabases = configurationManagerService.createChangedDatabases(database.getName(), false, switchingResource, ruleConfigs);
Map<String, ShardingSphereDatabase> changedDatabases = configurationManager.createChangedDatabases(database.getName(), false, switchingResource, ruleConfigs);
ConfigurationProperties props = new ConfigurationProperties(metaDataPersistService.getPropsService().load());
Collection<RuleConfiguration> globalRuleConfigs = metaDataPersistService.getGlobalRuleService().load();
RuleMetaData changedGlobalMetaData = new RuleMetaData(GlobalRulesBuilder.buildRules(globalRuleConfigs, changedDatabases, props));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@
import lombok.Getter;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.service.manager.ConfigurationManagerService;
import org.apache.shardingsphere.mode.service.manager.ResourceMetaDataManagerService;
import org.apache.shardingsphere.mode.service.manager.ShardingSphereDatabaseManagerService;
import org.apache.shardingsphere.mode.service.manager.ConfigurationManager;
import org.apache.shardingsphere.mode.service.manager.ResourceMetaDataManager;
import org.apache.shardingsphere.mode.service.manager.ShardingSphereDatabaseManager;

import java.util.concurrent.atomic.AtomicReference;

/**
* Context manager service facade.
* Meta data context manager..
*/
@Getter
public class ManagerServiceFacade {
public class MetaDataContextManager {

private final ShardingSphereDatabaseManagerService databaseManagerService;
private final ShardingSphereDatabaseManager databaseManager;

private final ConfigurationManagerService configurationManagerService;
private final ConfigurationManager configurationManager;

private final ResourceMetaDataManagerService resourceMetaDataManagerService;
private final ResourceMetaDataManager resourceMetaDataManager;

public ManagerServiceFacade(final AtomicReference<MetaDataContexts> metaDataContexts, final ComputeNodeInstanceContext computeNodeInstanceContext,
final PersistServiceFacade persistServiceFacade) {
databaseManagerService = new ShardingSphereDatabaseManagerService(metaDataContexts);
configurationManagerService = new ConfigurationManagerService(metaDataContexts, computeNodeInstanceContext, persistServiceFacade);
resourceMetaDataManagerService = new ResourceMetaDataManagerService(metaDataContexts, persistServiceFacade);
public MetaDataContextManager(final AtomicReference<MetaDataContexts> metaDataContexts, final ComputeNodeInstanceContext computeNodeInstanceContext,
final PersistServiceFacade persistServiceFacade) {
databaseManager = new ShardingSphereDatabaseManager(metaDataContexts);
configurationManager = new ConfigurationManager(metaDataContexts, computeNodeInstanceContext, persistServiceFacade);
resourceMetaDataManager = new ResourceMetaDataManager(metaDataContexts, persistServiceFacade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
*/
@RequiredArgsConstructor
@Slf4j
public final class ConfigurationManagerService {
public final class ConfigurationManager {

private final AtomicReference<MetaDataContexts> metaDataContexts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
import java.util.concurrent.atomic.AtomicReference;

/**
* Resource meta data context manager.
* Resource meta data manager.
*/
@RequiredArgsConstructor
public final class ResourceMetaDataManagerService {
public final class ResourceMetaDataManager {

private final AtomicReference<MetaDataContexts> metaDataContexts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* ShardingSphere database context manager.
*/
@RequiredArgsConstructor
public final class ShardingSphereDatabaseManagerService {
public final class ShardingSphereDatabaseManager {

private final AtomicReference<MetaDataContexts> metaDataContexts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void renew(final AlterRuleItemEvent event) {
RuleConfiguration currentRuleConfig = processor.findRuleConfiguration(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName));
synchronized (this) {
processor.changeRuleItemConfiguration(event, currentRuleConfig, processor.swapRuleItemConfiguration(event, yamlContent));
contextManager.getManagerServiceFacade().getConfigurationManagerService().alterRuleConfiguration(databaseName, currentRuleConfig);
contextManager.getMetaDataContextManager().getConfigurationManager().alterRuleConfiguration(databaseName, currentRuleConfig);
}
}

Expand All @@ -75,7 +75,7 @@ public void renew(final DropRuleItemEvent event) {
RuleConfiguration currentRuleConfig = processor.findRuleConfiguration(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName));
synchronized (this) {
processor.dropRuleItemConfiguration(event, currentRuleConfig);
contextManager.getManagerServiceFacade().getConfigurationManagerService().dropRuleConfiguration(databaseName, currentRuleConfig);
contextManager.getMetaDataContextManager().getConfigurationManager().dropRuleConfiguration(databaseName, currentRuleConfig);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,41 +131,41 @@ void assertRenewMetaDataContexts() {

@Test
void assertAddDatabase() {
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().addDatabase("new_db");
contextManager.getMetaDataContextManager().getResourceMetaDataManager().addDatabase("new_db");
verify(metaDataContexts.getMetaData()).addDatabase(eq("new_db"), any(DatabaseType.class), any(ConfigurationProperties.class));
}

@Test
void assertAddExistedDatabase() {
when(metaDataContexts.getMetaData().containsDatabase("foo_db")).thenReturn(true);
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().addDatabase("foo_db");
contextManager.getMetaDataContextManager().getResourceMetaDataManager().addDatabase("foo_db");
verify(metaDataContexts.getMetaData(), times(0)).addDatabase(eq("foo_db"), any(DatabaseType.class), any(ConfigurationProperties.class));
}

@Test
void assertDropDatabase() {
when(metaDataContexts.getMetaData().getDatabase("foo_db").getName()).thenReturn("foo_db");
when(metaDataContexts.getMetaData().containsDatabase("foo_db")).thenReturn(true);
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().dropDatabase("foo_db");
contextManager.getMetaDataContextManager().getResourceMetaDataManager().dropDatabase("foo_db");
verify(metaDataContexts.getMetaData()).dropDatabase("foo_db");
}

@Test
void assertDropNotExistedDatabase() {
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().dropDatabase("not_existed_db");
contextManager.getMetaDataContextManager().getResourceMetaDataManager().dropDatabase("not_existed_db");
verify(metaDataContexts.getMetaData(), times(0)).dropDatabase("not_existed_db");
}

@Test
void assertAddSchema() {
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().addSchema("foo_db", "bar_schema");
contextManager.getMetaDataContextManager().getResourceMetaDataManager().addSchema("foo_db", "bar_schema");
verify(metaDataContexts.getMetaData().getDatabase("foo_db")).addSchema(anyString(), any(ShardingSphereSchema.class));
}

@Test
void assertAddExistedSchema() {
when(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").containsSchema("foo_schema")).thenReturn(true);
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().addSchema("foo_db", "foo_schema");
contextManager.getMetaDataContextManager().getResourceMetaDataManager().addSchema("foo_db", "foo_schema");
verify(metaDataContexts.getMetaData().getDatabase("foo_db"), times(0)).addSchema(anyString(), any(ShardingSphereSchema.class));
}

Expand All @@ -176,7 +176,7 @@ void assertAlterSchemaForTableAltered() {
when(metaDataContexts.getMetaData().getDatabase("foo_db").getSchema("foo_schema")).thenReturn(toBeAlteredSchema);
ShardingSphereColumn toBeChangedColumn = new ShardingSphereColumn("foo_col", Types.VARCHAR, false, false, false, true, false, false);
ShardingSphereTable toBeChangedTable = new ShardingSphereTable("foo_tbl", Collections.singleton(toBeChangedColumn), Collections.emptyList(), Collections.emptyList());
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().alterSchema("foo_db", "foo_schema", toBeChangedTable, null);
contextManager.getMetaDataContextManager().getResourceMetaDataManager().alterSchema("foo_db", "foo_schema", toBeChangedTable, null);
ShardingSphereTable table = contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getSchema("foo_schema").getTables().get("foo_tbl");
assertThat(table.getColumnValues().size(), is(1));
assertTrue(table.containsColumn("foo_col"));
Expand All @@ -188,7 +188,7 @@ void assertAlterSchemaForViewAltered() {
when(metaDataContexts.getMetaData().getDatabase("foo_db").getSchemas()).thenReturn(Collections.singletonMap("foo_schema", toBeAlteredSchema));
when(metaDataContexts.getMetaData().getDatabase("foo_db").getSchema("foo_schema")).thenReturn(toBeAlteredSchema);
ShardingSphereView toBeChangedView = new ShardingSphereView("foo_view", "select `foo_view`.`foo_view`.`id` AS `id` from `foo_view`.`foo_view`");
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().alterSchema("foo_db", "foo_schema", null, toBeChangedView);
contextManager.getMetaDataContextManager().getResourceMetaDataManager().alterSchema("foo_db", "foo_schema", null, toBeChangedView);
ShardingSphereView view = contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getSchema("foo_schema").getView("foo_view");
assertThat(view.getName(), is("foo_view"));
assertThat(view.getViewDefinition(), is("select `foo_view`.`foo_view`.`id` AS `id` from `foo_view`.`foo_view`"));
Expand All @@ -197,14 +197,14 @@ void assertAlterSchemaForViewAltered() {
@Test
void assertAlterSchemaForTableDropped() {
when(metaDataContexts.getMetaData().getDatabase("foo_db").getSchemas()).thenReturn(Collections.singletonMap("foo_schema", createToBeAlteredSchema()));
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().alterSchema("foo_db", "foo_schema", "foo_tbl", null);
contextManager.getMetaDataContextManager().getResourceMetaDataManager().alterSchema("foo_db", "foo_schema", "foo_tbl", null);
assertFalse(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getSchema("foo_schema").getTables().containsKey("foo_tbl"));
}

@Test
void assertAlterSchemaForViewDropped() {
when(metaDataContexts.getMetaData().getDatabase("foo_db").getSchemas()).thenReturn(Collections.singletonMap("foo_schema", createToBeAlteredSchema()));
contextManager.getManagerServiceFacade().getResourceMetaDataManagerService().alterSchema("foo_db", "foo_schema", "foo_view", null);
contextManager.getMetaDataContextManager().getResourceMetaDataManager().alterSchema("foo_db", "foo_schema", "foo_view", null);
assertFalse(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getSchema("foo_schema").getViews().containsKey("foo_view"));
}

Expand Down Expand Up @@ -236,7 +236,7 @@ void assertGetDatabase() {

@Test
void assertAlterProperties() {
contextManager.getManagerServiceFacade().getConfigurationManagerService().alterProperties(PropertiesBuilder.build(new Property("foo", "foo_value")));
contextManager.getMetaDataContextManager().getConfigurationManager().alterProperties(PropertiesBuilder.build(new Property("foo", "foo_value")));
assertThat(contextManager.getMetaDataContexts().getMetaData().getProps().getProps().getProperty("foo"), is("foo_value"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void renew(final RegisterStorageUnitEvent event) {
.getActiveVersionByFullPath(event.getActiveVersionKey()))) {
return;
}
contextManager.getManagerServiceFacade().getConfigurationManagerService().registerStorageUnit(event.getDatabaseName(),
contextManager.getMetaDataContextManager().getConfigurationManager().registerStorageUnit(event.getDatabaseName(),
contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService().load(event.getDatabaseName(), event.getStorageUnitName()));
}

Expand All @@ -62,7 +62,7 @@ public void renew(final AlterStorageUnitEvent event) {
.getActiveVersionByFullPath(event.getActiveVersionKey()))) {
return;
}
contextManager.getManagerServiceFacade().getConfigurationManagerService().alterStorageUnit(
contextManager.getMetaDataContextManager().getConfigurationManager().alterStorageUnit(
event.getDatabaseName(), contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService().load(event.getDatabaseName(), event.getStorageUnitName()));
}

Expand All @@ -76,7 +76,7 @@ public void renew(final UnregisterStorageUnitEvent event) {
if (!contextManager.getMetaDataContexts().getMetaData().containsDatabase(event.getDatabaseName())) {
return;
}
contextManager.getManagerServiceFacade().getConfigurationManagerService().unregisterStorageUnit(event.getDatabaseName(), event.getStorageUnitName());
contextManager.getMetaDataContextManager().getConfigurationManager().unregisterStorageUnit(event.getDatabaseName(), event.getStorageUnitName());
}

/**
Expand All @@ -91,7 +91,7 @@ public synchronized void renew(final AlterGlobalRuleConfigurationEvent event) {
return;
}
contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().load(event.getRuleSimpleName())
.ifPresent(optional -> contextManager.getManagerServiceFacade().getConfigurationManagerService().alterGlobalRuleConfiguration(optional));
.ifPresent(optional -> contextManager.getMetaDataContextManager().getConfigurationManager().alterGlobalRuleConfiguration(optional));

}

Expand All @@ -106,6 +106,6 @@ public synchronized void renew(final AlterPropertiesEvent event) {
.getActiveVersionByFullPath(event.getActiveVersionKey()))) {
return;
}
contextManager.getManagerServiceFacade().getConfigurationManagerService().alterProperties(contextManager.getPersistServiceFacade().getMetaDataPersistService().getPropsService().load());
contextManager.getMetaDataContextManager().getConfigurationManager().alterProperties(contextManager.getPersistServiceFacade().getMetaDataPersistService().getPropsService().load());
}
}
Loading

0 comments on commit d345d66

Please sign in to comment.