Skip to content

Commit

Permalink
Remove old meta data structure code (#30469)
Browse files Browse the repository at this point in the history
* Remove old meta data structure code

* Fix ci

* Fix ci

* Fix ci

* Fix ci

* Fix checkstyle

* Fix e2e-sql

* Fix bug

* Remove code
  • Loading branch information
zhaojinchao95 authored Mar 18, 2024
1 parent bd2977d commit 37da1d3
Show file tree
Hide file tree
Showing 126 changed files with 1,465 additions and 7,001 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
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.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
import org.apache.shardingsphere.test.mock.StaticMockSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
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.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
import org.apache.shardingsphere.test.mock.StaticMockSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;

class NewYamlBroadcastRuleConfigurationSwapperTest {
class YamlBroadcastDataNodeRuleConfigurationSwapperTest {

private final YamlBroadcastDataNodeRuleConfigurationSwapper swapper = new YamlBroadcastDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;

class NewYamlEncryptRuleConfigurationSwapperTest {
class YamlEncryptDataNodeRuleConfigurationSwapperTest {

private final YamlEncryptDataNodeRuleConfigurationSwapper swapper = new YamlEncryptDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;

class NewYamlMaskRuleConfigurationSwapperTest {
class YamlMaskDataNodeRuleConfigurationSwapperTest {

private final YamlMaskDataNodeRuleConfigurationSwapper swapper = new YamlMaskDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;

class NewYamlReadwriteSplittingRuleConfigurationSwapperTest {
class YamlReadwriteSplittingDataNodeRuleConfigurationSwapperTest {

private final YamlReadwriteSplittingDataNodeRuleConfigurationSwapper swapper = new YamlReadwriteSplittingDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;

class NewYamlShadowRuleConfigurationSwapperTest {
class YamlShadowDataNodeRuleConfigurationSwapperTest {

private final YamlShadowDataNodeRuleConfigurationSwapper swapper = new YamlShadowDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class NewYamlShardingRuleConfigurationSwapperTest {
class YamlShardingDataNodeRuleConfigurationSwapperTest {

private final YamlShardingDataNodeRuleConfigurationSwapper swapper = new YamlShardingDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import java.util.Optional;

/**
* TODO Rename YamlConfigurationSwapper when metadata structure adjustment completed. #25485
* YAML configuration swapper.
* YAML data node configuration swapper.
*
* @param <T> type of swapped object
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

// TODO Rename YamlAuthorityRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
class NewYamlAuthorityRuleConfigurationSwapperTest {
class YamlAuthorityDataNodeRuleConfigurationSwapperTest {

private final YamlAuthorityDataNodeRuleConfigurationSwapper swapper = new YamlAuthorityDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

// TODO Rename YamlGlobalClockRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
class NewYamlGlobalClockRuleConfigurationSwapperTest {
class YamlGlobalClockDataNodeRuleConfigurationSwapperTest {

private final YamlGlobalClockDataNodeRuleConfigurationSwapper swapper = new YamlGlobalClockDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

// TODO Rename YamlLoggingRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
class NewYamlLoggingRuleConfigurationSwapperTest {
class YamlLoggingDataNodeRuleConfigurationSwapperTest {

private final YamlLoggingDataNodeRuleConfigurationSwapper swapper = new YamlLoggingDataNodeRuleConfigurationSwapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder;
import org.apache.shardingsphere.metadata.persist.MetaDataBasedPersistService;
import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;

import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -64,12 +65,12 @@ public static ShardingSphereDatabase create(final String databaseName, final Met
* @param instanceContext instance context
* @return databases
*/
public static Map<String, ShardingSphereDatabase> create(final MetaDataBasedPersistService persistService, final Map<String, DatabaseConfiguration> databaseConfigMap,
public static Map<String, ShardingSphereDatabase> create(final MetaDataPersistService persistService, final Map<String, DatabaseConfiguration> databaseConfigMap,
final ConfigurationProperties props, final InstanceContext instanceContext) {
return createDatabases(persistService, databaseConfigMap, DatabaseTypeEngine.getProtocolType(databaseConfigMap, props), props, instanceContext);
}

private static Map<String, ShardingSphereDatabase> createDatabases(final MetaDataBasedPersistService persistService, final Map<String, DatabaseConfiguration> databaseConfigMap,
private static Map<String, ShardingSphereDatabase> createDatabases(final MetaDataPersistService persistService, final Map<String, DatabaseConfiguration> databaseConfigMap,
final DatabaseType protocolType, final ConfigurationProperties props, final InstanceContext instanceContext) {
Map<String, ShardingSphereDatabase> result = new ConcurrentHashMap<>(databaseConfigMap.size(), 1F);
for (Entry<String, DatabaseConfiguration> entry : databaseConfigMap.entrySet()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.Properties;

/**
* TODO replace the old implementation after meta data refactor completed
* Abstract meta data persist service.
*/
public interface MetaDataBasedPersistService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
import java.util.stream.Collectors;

/**
* Meta data persist service.
* New meta data persist service.
*/
@Getter
public final class MetaDataPersistService implements MetaDataBasedPersistService {

private final PersistRepository repository;

private final MetaDataVersionPersistService metaDataVersionPersistService;

private final DataSourceUnitPersistService dataSourceUnitService;

private final DataSourceNodePersistService dataSourceNodeService;
Expand All @@ -66,31 +68,34 @@ public final class MetaDataPersistService implements MetaDataBasedPersistService

private final PropertiesPersistService propsService;

private final MetaDataVersionPersistService metaDataVersionPersistService;

private final ShardingSphereDataPersistService shardingSphereDataPersistService;

public MetaDataPersistService(final PersistRepository repository) {
this.repository = repository;
metaDataVersionPersistService = new MetaDataVersionPersistService(repository);
dataSourceUnitService = new DataSourceUnitPersistService(repository);
dataSourceNodeService = new DataSourceNodePersistService(repository);
databaseMetaDataService = new DatabaseMetaDataPersistService(repository);
databaseMetaDataService = new DatabaseMetaDataPersistService(repository, metaDataVersionPersistService);
databaseRulePersistService = new DatabaseRulePersistService(repository);
globalRuleService = new GlobalRulePersistService(repository);
propsService = new PropertiesPersistService(repository);
metaDataVersionPersistService = new MetaDataVersionPersistService(repository);
shardingSphereDataPersistService = new ShardingSphereDataPersistService(repository);
}

/**
* Persist global rule configurations.
*
* @param globalRuleConfigs global rule configurations
* @param props properties
*/
@Override
public void persistGlobalRuleConfiguration(final Collection<RuleConfiguration> globalRuleConfigs, final Properties props) {
globalRuleService.persist(globalRuleConfigs);
propsService.persist(props);
}

@Override
public void persistConfigurations(final String databaseName, final DatabaseConfiguration databaseConfigs,
final Map<String, DataSource> dataSources, final Collection<ShardingSphereRule> rules) {
public void persistConfigurations(final String databaseName, final DatabaseConfiguration databaseConfigs, final Map<String, DataSource> dataSources, final Collection<ShardingSphereRule> rules) {
Map<String, DataSourcePoolProperties> propsMap = getDataSourcePoolPropertiesMap(databaseConfigs);
if (propsMap.isEmpty() && databaseConfigs.getRuleConfigurations().isEmpty()) {
databaseMetaDataService.addDatabase(databaseName);
Expand All @@ -100,11 +105,6 @@ public void persistConfigurations(final String databaseName, final DatabaseConfi
}
}

private Map<String, DataSourcePoolProperties> getDataSourcePoolPropertiesMap(final DatabaseConfiguration databaseConfigs) {
return databaseConfigs.getStorageUnits().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
}

@SuppressWarnings({"unchecked", "rawtypes"})
private Collection<RuleConfiguration> decorateRuleConfigs(final String databaseName, final Map<String, DataSource> dataSources, final Collection<ShardingSphereRule> rules) {
Collection<RuleConfiguration> result = new LinkedList<>();
Expand All @@ -116,6 +116,11 @@ private Collection<RuleConfiguration> decorateRuleConfigs(final String databaseN
return result;
}

private Map<String, DataSourcePoolProperties> getDataSourcePoolPropertiesMap(final DatabaseConfiguration databaseConfigs) {
return databaseConfigs.getStorageUnits().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
}

@Override
public Map<String, DataSourceConfiguration> loadDataSourceConfigurations(final String databaseName) {
return dataSourceUnitService.load(databaseName).entrySet().stream().collect(Collectors.toMap(Entry::getKey,
Expand Down
Loading

0 comments on commit 37da1d3

Please sign in to comment.