Skip to content

Commit c2b2a7e

Browse files
authored
Add NewNodePathGenerator and NodePathEntity to process node path (#34735)
* 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
1 parent 449db05 commit c2b2a7e

File tree

108 files changed

+754
-1313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+754
-1313
lines changed

features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/deliver/ReadwriteSplittingQualifiedDataSourceChangedSubscriber.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.google.common.eventbus.Subscribe;
2121
import lombok.Setter;
2222
import org.apache.shardingsphere.mode.deliver.DeliverEventSubscriber;
23-
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
23+
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
2424
import org.apache.shardingsphere.mode.node.path.node.storage.QualifiedDataSourceNodePath;
2525
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
2626

@@ -39,6 +39,6 @@ public final class ReadwriteSplittingQualifiedDataSourceChangedSubscriber implem
3939
*/
4040
@Subscribe
4141
public void delete(final QualifiedDataSourceDeletedEvent event) {
42-
repository.delete(new NodePathGenerator(new QualifiedDataSourceNodePath()).getPath(event.getQualifiedDataSource()));
42+
repository.delete(NewNodePathGenerator.generatePath(new QualifiedDataSourceNodePath(event.getQualifiedDataSource()), false));
4343
}
4444
}

kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
2626
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
2727
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
28-
import org.apache.shardingsphere.mode.node.path.statistics.job.StatisticsJobNodePath;
28+
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
29+
import org.apache.shardingsphere.mode.node.path.statistics.StatisticsJobNodePath;
2930
import org.apache.shardingsphere.mode.manager.ContextManager;
3031
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
3132

@@ -68,7 +69,7 @@ public void initialize() {
6869

6970
private CoordinatorRegistryCenter createRegistryCenter(final ModeConfiguration modeConfig) {
7071
ClusterPersistRepositoryConfiguration repositoryConfig = (ClusterPersistRepositoryConfiguration) modeConfig.getRepository();
71-
String namespace = repositoryConfig.getNamespace() + new StatisticsJobNodePath().getRootPath();
72+
String namespace = repositoryConfig.getNamespace() + NewNodePathGenerator.generatePath(new StatisticsJobNodePath(), false);
7273
CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(getZookeeperConfiguration(repositoryConfig, namespace));
7374
result.init();
7475
return result;

mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/database/DataSourceUnitPersistService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
2222
import org.apache.shardingsphere.infra.yaml.config.swapper.resource.YamlDataSourceConfigurationSwapper;
2323
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
24-
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
24+
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
2525
import org.apache.shardingsphere.mode.node.path.metadata.storage.StorageUnitNodePath;
2626
import org.apache.shardingsphere.mode.node.path.version.VersionNodePath;
2727
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
@@ -56,7 +56,7 @@ public DataSourceUnitPersistService(final PersistRepository repository) {
5656
* @return data source pool properties map
5757
*/
5858
public Map<String, DataSourcePoolProperties> load(final String databaseName) {
59-
Collection<String> childrenKeys = repository.getChildrenKeys(new StorageUnitNodePath(databaseName).getRootPath());
59+
Collection<String> childrenKeys = repository.getChildrenKeys(NewNodePathGenerator.generatePath(new StorageUnitNodePath(databaseName, null), false));
6060
return childrenKeys.stream().collect(Collectors.toMap(each -> each, each -> load(databaseName, each), (a, b) -> b, () -> new LinkedHashMap<>(childrenKeys.size(), 1F)));
6161
}
6262

@@ -69,7 +69,7 @@ public Map<String, DataSourcePoolProperties> load(final String databaseName) {
6969
*/
7070
@SuppressWarnings("unchecked")
7171
public DataSourcePoolProperties load(final String databaseName, final String dataSourceName) {
72-
VersionNodePath versionNodePath = new NodePathGenerator(new StorageUnitNodePath(databaseName)).getVersion(dataSourceName);
72+
VersionNodePath versionNodePath = NewNodePathGenerator.generateVersionPath(new StorageUnitNodePath(databaseName, dataSourceName));
7373
int activeVersion = Integer.parseInt(repository.query(versionNodePath.getActiveVersionPath()));
7474
String dataSourceContent = repository.query(versionNodePath.getVersionPath(activeVersion));
7575
return yamlDataSourceConfigurationSwapper.swapToDataSourcePoolProperties(YamlEngine.unmarshal(dataSourceContent, Map.class));
@@ -83,7 +83,7 @@ public DataSourcePoolProperties load(final String databaseName, final String dat
8383
*/
8484
public void persist(final String databaseName, final Map<String, DataSourcePoolProperties> dataSourcePropsMap) {
8585
for (Entry<String, DataSourcePoolProperties> entry : dataSourcePropsMap.entrySet()) {
86-
VersionNodePath versionNodePath = new NodePathGenerator(new StorageUnitNodePath(databaseName)).getVersion(entry.getKey());
86+
VersionNodePath versionNodePath = NewNodePathGenerator.generateVersionPath(new StorageUnitNodePath(databaseName, entry.getKey()));
8787
metaDataVersionPersistService.persist(versionNodePath, YamlEngine.marshal(yamlDataSourceConfigurationSwapper.swapToMap(entry.getValue())));
8888
}
8989
}
@@ -95,6 +95,6 @@ public void persist(final String databaseName, final Map<String, DataSourcePoolP
9595
* @param dataSourceName data source name
9696
*/
9797
public void delete(final String databaseName, final String dataSourceName) {
98-
repository.delete(new NodePathGenerator(new StorageUnitNodePath(databaseName)).getPath(dataSourceName));
98+
repository.delete(NewNodePathGenerator.generatePath(new StorageUnitNodePath(databaseName, dataSourceName), false));
9999
}
100100
}

mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/database/DatabaseRulePersistService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
2424
import org.apache.shardingsphere.mode.metadata.persist.config.RepositoryTuplePersistService;
2525
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
26-
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
26+
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
2727
import org.apache.shardingsphere.mode.node.path.config.database.item.DatabaseRuleItem;
28-
import org.apache.shardingsphere.mode.node.path.metadata.rule.DatabaseRuleItemNodePath;
2928
import org.apache.shardingsphere.mode.node.path.metadata.rule.DatabaseRuleNodePath;
3029
import org.apache.shardingsphere.mode.node.tuple.RepositoryTuple;
3130
import org.apache.shardingsphere.mode.node.tuple.YamlRepositoryTupleSwapperEngine;
@@ -68,7 +67,8 @@ public DatabaseRulePersistService(final PersistRepository repository) {
6867
* @return configurations
6968
*/
7069
public Collection<RuleConfiguration> load(final String databaseName) {
71-
return yamlRepositoryTupleSwapperEngine.swapToRuleConfigurations(repositoryTuplePersistService.load(new DatabaseRuleNodePath(databaseName).getRootPath()));
70+
return yamlRepositoryTupleSwapperEngine.swapToRuleConfigurations(
71+
repositoryTuplePersistService.load(NewNodePathGenerator.generatePath(new DatabaseRuleNodePath(databaseName, null, null), false)));
7272
}
7373

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

9292
private Collection<MetaDataVersion> persistDataNodes(final String databaseName, final String ruleType, final Collection<RepositoryTuple> repositoryTuples) {
9393
Collection<MetaDataVersion> result = new LinkedList<>();
94-
NodePathGenerator nodePathGenerator = new NodePathGenerator(new DatabaseRuleItemNodePath(databaseName, ruleType));
9594
for (RepositoryTuple each : repositoryTuples) {
9695
DatabaseRuleItem databaseRuleItem = new DatabaseRuleItem(each.getKey());
97-
int nextVersion = metaDataVersionPersistService.persist(nodePathGenerator.getVersion(databaseRuleItem), each.getValue());
98-
result.add(new MetaDataVersion(nodePathGenerator.getPath(databaseRuleItem), Math.max(MetaDataVersion.INIT_VERSION, nextVersion - 1)));
96+
DatabaseRuleNodePath databaseRuleNodePath = new DatabaseRuleNodePath(databaseName, ruleType, databaseRuleItem);
97+
int nextVersion = metaDataVersionPersistService.persist(NewNodePathGenerator.generateVersionPath(databaseRuleNodePath), each.getValue());
98+
result.add(new MetaDataVersion(NewNodePathGenerator.generatePath(databaseRuleNodePath, false), Math.max(MetaDataVersion.INIT_VERSION, nextVersion - 1)));
9999
}
100100
return result;
101101
}
@@ -107,7 +107,7 @@ private Collection<MetaDataVersion> persistDataNodes(final String databaseName,
107107
* @param ruleType rule type
108108
*/
109109
public void delete(final String databaseName, final String ruleType) {
110-
repository.delete(new NodePathGenerator(new DatabaseRuleNodePath(databaseName)).getPath(ruleType));
110+
repository.delete(NewNodePathGenerator.generatePath(new DatabaseRuleNodePath(databaseName, ruleType, null), false));
111111
}
112112

113113
/**
@@ -133,7 +133,7 @@ public Collection<MetaDataVersion> delete(final String databaseName, final Colle
133133
private Collection<MetaDataVersion> delete(final String databaseName, final String ruleType, final Collection<RepositoryTuple> repositoryTuples) {
134134
Collection<MetaDataVersion> result = new LinkedList<>();
135135
for (RepositoryTuple each : repositoryTuples) {
136-
String toBeDeletedKey = new NodePathGenerator(new DatabaseRuleItemNodePath(databaseName, ruleType)).getPath(new DatabaseRuleItem(each.getKey()));
136+
String toBeDeletedKey = NewNodePathGenerator.generatePath(new DatabaseRuleNodePath(databaseName, ruleType, new DatabaseRuleItem(each.getKey())), false);
137137
repository.delete(toBeDeletedKey);
138138
result.add(new MetaDataVersion(toBeDeletedKey));
139139
}

mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/GlobalRulePersistService.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
2323
import org.apache.shardingsphere.mode.metadata.persist.config.RepositoryTuplePersistService;
2424
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
25-
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
25+
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
2626
import org.apache.shardingsphere.mode.node.path.config.global.GlobalRuleNodePath;
27-
import org.apache.shardingsphere.mode.node.path.version.VersionNodePath;
2827
import org.apache.shardingsphere.mode.node.tuple.RepositoryTuple;
2928
import org.apache.shardingsphere.mode.node.tuple.YamlRepositoryTupleSwapperEngine;
3029
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
@@ -58,7 +57,7 @@ public GlobalRulePersistService(final PersistRepository repository, final MetaDa
5857
* @return global rule configurations
5958
*/
6059
public Collection<RuleConfiguration> load() {
61-
return yamlRepositoryTupleSwapperEngine.swapToRuleConfigurations(repositoryTuplePersistService.load(new GlobalRuleNodePath().getRootPath()));
60+
return yamlRepositoryTupleSwapperEngine.swapToRuleConfigurations(repositoryTuplePersistService.load(NewNodePathGenerator.generatePath(new GlobalRuleNodePath(null), false)));
6261
}
6362

6463
/**
@@ -68,7 +67,7 @@ public Collection<RuleConfiguration> load() {
6867
* @return global rule configuration
6968
*/
7069
public Optional<RuleConfiguration> load(final String ruleType) {
71-
return yamlRepositoryTupleSwapperEngine.swapToRuleConfiguration(ruleType, repositoryTuplePersistService.load(new NodePathGenerator(new GlobalRuleNodePath()).getPath(ruleType)));
70+
return yamlRepositoryTupleSwapperEngine.swapToRuleConfiguration(ruleType, repositoryTuplePersistService.load(NewNodePathGenerator.generatePath(new GlobalRuleNodePath(ruleType), false)));
7271
}
7372

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

8584
private void persistTuples(final Collection<RepositoryTuple> tuples) {
8685
for (RepositoryTuple each : tuples) {
87-
VersionNodePath versionNodePath = new NodePathGenerator(new GlobalRuleNodePath()).getVersion(each.getKey());
88-
metaDataVersionPersistService.persist(versionNodePath, each.getValue());
86+
metaDataVersionPersistService.persist(NewNodePathGenerator.generateVersionPath(new GlobalRuleNodePath(each.getKey())), each.getValue());
8987
}
9088
}
9189
}

mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import lombok.RequiredArgsConstructor;
2222
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
2323
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
24-
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
24+
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
2525
import org.apache.shardingsphere.mode.node.path.config.global.GlobalPropertiesNodePath;
2626
import org.apache.shardingsphere.mode.node.path.version.VersionNodePath;
2727
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
@@ -46,12 +46,12 @@ public final class PropertiesPersistService {
4646
*/
4747
public Properties load() {
4848
return loadActiveVersion()
49-
.map(optional -> YamlEngine.unmarshal(repository.query(new NodePathGenerator(new GlobalPropertiesNodePath()).getVersion(null).getVersionPath(optional)), Properties.class))
49+
.map(optional -> YamlEngine.unmarshal(repository.query(NewNodePathGenerator.generateVersionPath(new GlobalPropertiesNodePath()).getVersionPath(optional)), Properties.class))
5050
.orElse(new Properties());
5151
}
5252

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

@@ -61,7 +61,7 @@ private Optional<Integer> loadActiveVersion() {
6161
* @param props properties
6262
*/
6363
public void persist(final Properties props) {
64-
VersionNodePath versionNodePath = new NodePathGenerator(new GlobalPropertiesNodePath()).getVersion(null);
64+
VersionNodePath versionNodePath = NewNodePathGenerator.generateVersionPath(new GlobalPropertiesNodePath());
6565
metaDataVersionPersistService.persist(versionNodePath, YamlEngine.marshal(props));
6666
}
6767
}

mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/SchemaMetaDataPersistService.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
import org.apache.shardingsphere.infra.metadata.database.schema.manager.GenericSchemaManager;
2121
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
2222
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
23-
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
24-
import org.apache.shardingsphere.mode.node.path.metadata.database.SchemaNodePath;
25-
import org.apache.shardingsphere.mode.node.path.metadata.database.TableNodePath;
23+
import org.apache.shardingsphere.mode.node.path.NewNodePathGenerator;
24+
import org.apache.shardingsphere.mode.node.path.metadata.database.TableMetadataNodePath;
2625
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
2726

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

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

6968
/**
@@ -113,7 +112,7 @@ public void alterByRuleDropped(final String databaseName, final ShardingSphereSc
113112
* @return schemas
114113
*/
115114
public Collection<ShardingSphereSchema> load(final String databaseName) {
116-
return repository.getChildrenKeys(new SchemaNodePath(databaseName).getRootPath()).stream()
115+
return repository.getChildrenKeys(NewNodePathGenerator.generatePath(new TableMetadataNodePath(databaseName, null, null), false)).stream()
117116
.map(each -> new ShardingSphereSchema(each, tableMetaDataPersistService.load(databaseName, each), viewMetaDataPersistService.load(databaseName, each))).collect(Collectors.toList());
118117
}
119118
}

0 commit comments

Comments
 (0)