Skip to content

Commit

Permalink
Add NewNodePathGenerator and NodePathEntity to process node path (#34735
Browse files Browse the repository at this point in the history
)

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path

* Add NewNodePathGenerator and NodePathEntity to process node path
  • Loading branch information
terrymanu authored Feb 21, 2025
1 parent 449db05 commit c2b2a7e
Show file tree
Hide file tree
Showing 108 changed files with 754 additions and 1,313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.common.eventbus.Subscribe;
import lombok.Setter;
import org.apache.shardingsphere.mode.deliver.DeliverEventSubscriber;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.node.storage.QualifiedDataSourceNodePath;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;

Expand All @@ -39,6 +39,6 @@ public final class ReadwriteSplittingQualifiedDataSourceChangedSubscriber implem
*/
@Subscribe
public void delete(final QualifiedDataSourceDeletedEvent event) {
repository.delete(new NodePathGenerator(new QualifiedDataSourceNodePath()).getPath(event.getQualifiedDataSource()));
repository.delete(NewNodePathGenerator.generatePath(new QualifiedDataSourceNodePath(event.getQualifiedDataSource()), false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.mode.node.path.statistics.job.StatisticsJobNodePath;
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.statistics.StatisticsJobNodePath;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;

Expand Down Expand Up @@ -68,7 +69,7 @@ public void initialize() {

private CoordinatorRegistryCenter createRegistryCenter(final ModeConfiguration modeConfig) {
ClusterPersistRepositoryConfiguration repositoryConfig = (ClusterPersistRepositoryConfiguration) modeConfig.getRepository();
String namespace = repositoryConfig.getNamespace() + new StatisticsJobNodePath().getRootPath();
String namespace = repositoryConfig.getNamespace() + NewNodePathGenerator.generatePath(new StatisticsJobNodePath(), false);
CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(getZookeeperConfiguration(repositoryConfig, namespace));
result.init();
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.yaml.config.swapper.resource.YamlDataSourceConfigurationSwapper;
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.metadata.storage.StorageUnitNodePath;
import org.apache.shardingsphere.mode.node.path.version.VersionNodePath;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
Expand Down Expand Up @@ -56,7 +56,7 @@ public DataSourceUnitPersistService(final PersistRepository repository) {
* @return data source pool properties map
*/
public Map<String, DataSourcePoolProperties> load(final String databaseName) {
Collection<String> childrenKeys = repository.getChildrenKeys(new StorageUnitNodePath(databaseName).getRootPath());
Collection<String> childrenKeys = repository.getChildrenKeys(NewNodePathGenerator.generatePath(new StorageUnitNodePath(databaseName, null), false));
return childrenKeys.stream().collect(Collectors.toMap(each -> each, each -> load(databaseName, each), (a, b) -> b, () -> new LinkedHashMap<>(childrenKeys.size(), 1F)));
}

Expand All @@ -69,7 +69,7 @@ public Map<String, DataSourcePoolProperties> load(final String databaseName) {
*/
@SuppressWarnings("unchecked")
public DataSourcePoolProperties load(final String databaseName, final String dataSourceName) {
VersionNodePath versionNodePath = new NodePathGenerator(new StorageUnitNodePath(databaseName)).getVersion(dataSourceName);
VersionNodePath versionNodePath = NewNodePathGenerator.generateVersionPath(new StorageUnitNodePath(databaseName, dataSourceName));
int activeVersion = Integer.parseInt(repository.query(versionNodePath.getActiveVersionPath()));
String dataSourceContent = repository.query(versionNodePath.getVersionPath(activeVersion));
return yamlDataSourceConfigurationSwapper.swapToDataSourcePoolProperties(YamlEngine.unmarshal(dataSourceContent, Map.class));
Expand All @@ -83,7 +83,7 @@ public DataSourcePoolProperties load(final String databaseName, final String dat
*/
public void persist(final String databaseName, final Map<String, DataSourcePoolProperties> dataSourcePropsMap) {
for (Entry<String, DataSourcePoolProperties> entry : dataSourcePropsMap.entrySet()) {
VersionNodePath versionNodePath = new NodePathGenerator(new StorageUnitNodePath(databaseName)).getVersion(entry.getKey());
VersionNodePath versionNodePath = NewNodePathGenerator.generateVersionPath(new StorageUnitNodePath(databaseName, entry.getKey()));
metaDataVersionPersistService.persist(versionNodePath, YamlEngine.marshal(yamlDataSourceConfigurationSwapper.swapToMap(entry.getValue())));
}
}
Expand All @@ -95,6 +95,6 @@ public void persist(final String databaseName, final Map<String, DataSourcePoolP
* @param dataSourceName data source name
*/
public void delete(final String databaseName, final String dataSourceName) {
repository.delete(new NodePathGenerator(new StorageUnitNodePath(databaseName)).getPath(dataSourceName));
repository.delete(NewNodePathGenerator.generatePath(new StorageUnitNodePath(databaseName, dataSourceName), false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.mode.metadata.persist.config.RepositoryTuplePersistService;
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.config.database.item.DatabaseRuleItem;
import org.apache.shardingsphere.mode.node.path.metadata.rule.DatabaseRuleItemNodePath;
import org.apache.shardingsphere.mode.node.path.metadata.rule.DatabaseRuleNodePath;
import org.apache.shardingsphere.mode.node.tuple.RepositoryTuple;
import org.apache.shardingsphere.mode.node.tuple.YamlRepositoryTupleSwapperEngine;
Expand Down Expand Up @@ -68,7 +67,8 @@ public DatabaseRulePersistService(final PersistRepository repository) {
* @return configurations
*/
public Collection<RuleConfiguration> load(final String databaseName) {
return yamlRepositoryTupleSwapperEngine.swapToRuleConfigurations(repositoryTuplePersistService.load(new DatabaseRuleNodePath(databaseName).getRootPath()));
return yamlRepositoryTupleSwapperEngine.swapToRuleConfigurations(
repositoryTuplePersistService.load(NewNodePathGenerator.generatePath(new DatabaseRuleNodePath(databaseName, null, null), false)));
}

/**
Expand All @@ -91,11 +91,11 @@ public Collection<MetaDataVersion> persist(final String databaseName, final Coll

private Collection<MetaDataVersion> persistDataNodes(final String databaseName, final String ruleType, final Collection<RepositoryTuple> repositoryTuples) {
Collection<MetaDataVersion> result = new LinkedList<>();
NodePathGenerator nodePathGenerator = new NodePathGenerator(new DatabaseRuleItemNodePath(databaseName, ruleType));
for (RepositoryTuple each : repositoryTuples) {
DatabaseRuleItem databaseRuleItem = new DatabaseRuleItem(each.getKey());
int nextVersion = metaDataVersionPersistService.persist(nodePathGenerator.getVersion(databaseRuleItem), each.getValue());
result.add(new MetaDataVersion(nodePathGenerator.getPath(databaseRuleItem), Math.max(MetaDataVersion.INIT_VERSION, nextVersion - 1)));
DatabaseRuleNodePath databaseRuleNodePath = new DatabaseRuleNodePath(databaseName, ruleType, databaseRuleItem);
int nextVersion = metaDataVersionPersistService.persist(NewNodePathGenerator.generateVersionPath(databaseRuleNodePath), each.getValue());
result.add(new MetaDataVersion(NewNodePathGenerator.generatePath(databaseRuleNodePath, false), Math.max(MetaDataVersion.INIT_VERSION, nextVersion - 1)));
}
return result;
}
Expand All @@ -107,7 +107,7 @@ private Collection<MetaDataVersion> persistDataNodes(final String databaseName,
* @param ruleType rule type
*/
public void delete(final String databaseName, final String ruleType) {
repository.delete(new NodePathGenerator(new DatabaseRuleNodePath(databaseName)).getPath(ruleType));
repository.delete(NewNodePathGenerator.generatePath(new DatabaseRuleNodePath(databaseName, ruleType, null), false));
}

/**
Expand All @@ -133,7 +133,7 @@ public Collection<MetaDataVersion> delete(final String databaseName, final Colle
private Collection<MetaDataVersion> delete(final String databaseName, final String ruleType, final Collection<RepositoryTuple> repositoryTuples) {
Collection<MetaDataVersion> result = new LinkedList<>();
for (RepositoryTuple each : repositoryTuples) {
String toBeDeletedKey = new NodePathGenerator(new DatabaseRuleItemNodePath(databaseName, ruleType)).getPath(new DatabaseRuleItem(each.getKey()));
String toBeDeletedKey = NewNodePathGenerator.generatePath(new DatabaseRuleNodePath(databaseName, ruleType, new DatabaseRuleItem(each.getKey())), false);
repository.delete(toBeDeletedKey);
result.add(new MetaDataVersion(toBeDeletedKey));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.mode.metadata.persist.config.RepositoryTuplePersistService;
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.config.global.GlobalRuleNodePath;
import org.apache.shardingsphere.mode.node.path.version.VersionNodePath;
import org.apache.shardingsphere.mode.node.tuple.RepositoryTuple;
import org.apache.shardingsphere.mode.node.tuple.YamlRepositoryTupleSwapperEngine;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
Expand Down Expand Up @@ -58,7 +57,7 @@ public GlobalRulePersistService(final PersistRepository repository, final MetaDa
* @return global rule configurations
*/
public Collection<RuleConfiguration> load() {
return yamlRepositoryTupleSwapperEngine.swapToRuleConfigurations(repositoryTuplePersistService.load(new GlobalRuleNodePath().getRootPath()));
return yamlRepositoryTupleSwapperEngine.swapToRuleConfigurations(repositoryTuplePersistService.load(NewNodePathGenerator.generatePath(new GlobalRuleNodePath(null), false)));
}

/**
Expand All @@ -68,7 +67,7 @@ public Collection<RuleConfiguration> load() {
* @return global rule configuration
*/
public Optional<RuleConfiguration> load(final String ruleType) {
return yamlRepositoryTupleSwapperEngine.swapToRuleConfiguration(ruleType, repositoryTuplePersistService.load(new NodePathGenerator(new GlobalRuleNodePath()).getPath(ruleType)));
return yamlRepositoryTupleSwapperEngine.swapToRuleConfiguration(ruleType, repositoryTuplePersistService.load(NewNodePathGenerator.generatePath(new GlobalRuleNodePath(ruleType), false)));
}

/**
Expand All @@ -84,8 +83,7 @@ public void persist(final Collection<RuleConfiguration> globalRuleConfigs) {

private void persistTuples(final Collection<RepositoryTuple> tuples) {
for (RepositoryTuple each : tuples) {
VersionNodePath versionNodePath = new NodePathGenerator(new GlobalRuleNodePath()).getVersion(each.getKey());
metaDataVersionPersistService.persist(versionNodePath, each.getValue());
metaDataVersionPersistService.persist(NewNodePathGenerator.generateVersionPath(new GlobalRuleNodePath(each.getKey())), each.getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.config.global.GlobalPropertiesNodePath;
import org.apache.shardingsphere.mode.node.path.version.VersionNodePath;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
Expand All @@ -46,12 +46,12 @@ public final class PropertiesPersistService {
*/
public Properties load() {
return loadActiveVersion()
.map(optional -> YamlEngine.unmarshal(repository.query(new NodePathGenerator(new GlobalPropertiesNodePath()).getVersion(null).getVersionPath(optional)), Properties.class))
.map(optional -> YamlEngine.unmarshal(repository.query(NewNodePathGenerator.generateVersionPath(new GlobalPropertiesNodePath()).getVersionPath(optional)), Properties.class))
.orElse(new Properties());
}

private Optional<Integer> loadActiveVersion() {
String value = repository.query(new NodePathGenerator(new GlobalPropertiesNodePath()).getVersion(null).getActiveVersionPath());
String value = repository.query(NewNodePathGenerator.generateVersionPath(new GlobalPropertiesNodePath()).getActiveVersionPath());
return Strings.isNullOrEmpty(value) ? Optional.empty() : Optional.of(Integer.parseInt(value));
}

Expand All @@ -61,7 +61,7 @@ private Optional<Integer> loadActiveVersion() {
* @param props properties
*/
public void persist(final Properties props) {
VersionNodePath versionNodePath = new NodePathGenerator(new GlobalPropertiesNodePath()).getVersion(null);
VersionNodePath versionNodePath = NewNodePathGenerator.generateVersionPath(new GlobalPropertiesNodePath());
metaDataVersionPersistService.persist(versionNodePath, YamlEngine.marshal(props));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
import org.apache.shardingsphere.infra.metadata.database.schema.manager.GenericSchemaManager;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.metadata.database.SchemaNodePath;
import org.apache.shardingsphere.mode.node.path.metadata.database.TableNodePath;
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.metadata.database.TableMetadataNodePath;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;

import java.util.Collection;
Expand Down Expand Up @@ -53,7 +52,7 @@ public SchemaMetaDataPersistService(final PersistRepository repository, final Me
* @param schemaName to be added schema name
*/
public void add(final String databaseName, final String schemaName) {
repository.persist(new TableNodePath(databaseName, schemaName).getRootPath(), "");
repository.persist(NewNodePathGenerator.generatePath(new TableMetadataNodePath(databaseName, schemaName, null), false), "");
}

/**
Expand All @@ -63,7 +62,7 @@ public void add(final String databaseName, final String schemaName) {
* @param schemaName to be dropped schema name
*/
public void drop(final String databaseName, final String schemaName) {
repository.delete(new NodePathGenerator(new SchemaNodePath(databaseName)).getPath(schemaName));
repository.delete(NewNodePathGenerator.generatePath(new TableMetadataNodePath(databaseName, schemaName, null), true));
}

/**
Expand Down Expand Up @@ -113,7 +112,7 @@ public void alterByRuleDropped(final String databaseName, final ShardingSphereSc
* @return schemas
*/
public Collection<ShardingSphereSchema> load(final String databaseName) {
return repository.getChildrenKeys(new SchemaNodePath(databaseName).getRootPath()).stream()
return repository.getChildrenKeys(NewNodePathGenerator.generatePath(new TableMetadataNodePath(databaseName, null, null), false)).stream()
.map(each -> new ShardingSphereSchema(each, tableMetaDataPersistService.load(databaseName, each), viewMetaDataPersistService.load(databaseName, each))).collect(Collectors.toList());
}
}
Loading

0 comments on commit c2b2a7e

Please sign in to comment.