Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename GlobalNodePath #34255

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public final class DatabaseMetaDataNodePath {

private static final String TABLES_NODE = "tables";

private static final String ACTIVE_VERSION = "active_version";
private static final String VERSIONS_NODE = "versions";

private static final String VERSIONS = "versions";
private static final String ACTIVE_VERSION_NODE = "active_version";

private static final String IDENTIFIER_PATTERN = "([\\w\\-]+)";

Expand Down Expand Up @@ -101,7 +101,7 @@ public static String getTablesPath(final String databaseName, final String schem
* @return version path
*/
public static String getVersionPath(final String rulePath, final String activeVersion) {
return rulePath.replace(ACTIVE_VERSION, VERSIONS) + "/" + activeVersion;
return rulePath.replace(ACTIVE_VERSION_NODE, VERSIONS_NODE) + "/" + activeVersion;
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.metadata.persist.node;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
* Global node path.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class GlobalNodePath {

private static final String RULE_NODE = "rules";

private static final String PROPS_NODE = "props";

private static final String VERSIONS_NODE = "versions";

private static final String ACTIVE_VERSION_NODE = "active_version";

/**
* Get global rule root path.
*
* @return global rule root path
*/
public static String getRuleRootPath() {
return String.join("/", "", RULE_NODE);
}

/**
* Get global rule path.
*
* @param ruleName rule name
* @return global rule path
*/
public static String getRulePath(final String ruleName) {
return String.join("/", getRuleRootPath(), ruleName);
}

/**
* Get global rule versions path.
*
* @param ruleName rule name
* @return global rule versions path
*/
public static String getRuleVersionsPath(final String ruleName) {
return String.join("/", getRulePath(ruleName), VERSIONS_NODE);
}

/**
* Get global rule version path.
*
* @param ruleName rule name
* @param version version
* @return global rule version path
*/
public static String getRuleVersionPath(final String ruleName, final String version) {
return String.join("/", getRuleVersionsPath(ruleName), version);
}

/**
* Get global rule active version path.
*
* @param ruleName rule name
* @return global rule active version path
*/
public static String getRuleActiveVersionPath(final String ruleName) {
return String.join("/", getRulePath(ruleName), ACTIVE_VERSION_NODE);
}

/**
* Get properties path.
*
* @return properties path
*/
public static String getPropsRootPath() {
return String.join("/", "", PROPS_NODE);
}

/**
* Get properties versions path.
*
* @return properties versions path
*/
public static String getPropsVersionsPath() {
return String.join("/", getPropsRootPath(), VERSIONS_NODE);
}

/**
* Get properties version path.
*
* @param version version
* @return properties version path
*/
public static String getPropsVersionPath(final String version) {
return String.join("/", getPropsVersionsPath(), version);
}

/**
* Get properties active version path.
*
* @return properties active version path
*/
public static String getPropsActiveVersionPath() {
return String.join("/", getPropsRootPath(), ACTIVE_VERSION_NODE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.metadata.persist.node.GlobalNode;
import org.apache.shardingsphere.metadata.persist.node.GlobalNodePath;
import org.apache.shardingsphere.metadata.persist.service.config.RepositoryTuplePersistService;
import org.apache.shardingsphere.metadata.persist.service.version.MetaDataVersionPersistService;
import org.apache.shardingsphere.mode.spi.PersistRepository;
Expand Down Expand Up @@ -57,7 +57,7 @@ public GlobalRulePersistService(final PersistRepository repository, final MetaDa
* @return global rule configurations
*/
public Collection<RuleConfiguration> load() {
return new RepositoryTupleSwapperEngine().swapToRuleConfigurations(repositoryTuplePersistService.load(GlobalNode.getGlobalRuleRootNode()));
return new RepositoryTupleSwapperEngine().swapToRuleConfigurations(repositoryTuplePersistService.load(GlobalNodePath.getRuleRootPath()));
}

/**
Expand All @@ -67,7 +67,7 @@ public Collection<RuleConfiguration> load() {
* @return global rule configuration
*/
public Optional<RuleConfiguration> load(final String ruleTypeName) {
return new RepositoryTupleSwapperEngine().swapToRuleConfiguration(ruleTypeName, repositoryTuplePersistService.load(GlobalNode.getGlobalRuleNode(ruleTypeName)));
return new RepositoryTupleSwapperEngine().swapToRuleConfiguration(ruleTypeName, repositoryTuplePersistService.load(GlobalNodePath.getRulePath(ruleTypeName)));
}

/**
Expand All @@ -87,13 +87,13 @@ public void persist(final Collection<RuleConfiguration> globalRuleConfigs) {
private Collection<MetaDataVersion> persistTuples(final Collection<RepositoryTuple> repositoryTuples) {
Collection<MetaDataVersion> result = new LinkedList<>();
for (RepositoryTuple each : repositoryTuples) {
List<String> versions = metaDataVersionPersistService.getVersions(GlobalNode.getGlobalRuleVersionsNode(each.getKey()));
List<String> versions = metaDataVersionPersistService.getVersions(GlobalNodePath.getRuleVersionsPath(each.getKey()));
String nextActiveVersion = versions.isEmpty() ? MetaDataVersion.DEFAULT_VERSION : String.valueOf(Integer.parseInt(versions.get(0)) + 1);
repository.persist(GlobalNode.getGlobalRuleVersionNode(each.getKey(), nextActiveVersion), each.getValue());
if (Strings.isNullOrEmpty(repository.query(GlobalNode.getGlobalRuleActiveVersionNode(each.getKey())))) {
repository.persist(GlobalNode.getGlobalRuleActiveVersionNode(each.getKey()), MetaDataVersion.DEFAULT_VERSION);
repository.persist(GlobalNodePath.getRuleVersionPath(each.getKey(), nextActiveVersion), each.getValue());
if (Strings.isNullOrEmpty(repository.query(GlobalNodePath.getRuleActiveVersionPath(each.getKey())))) {
repository.persist(GlobalNodePath.getRuleActiveVersionPath(each.getKey()), MetaDataVersion.DEFAULT_VERSION);
}
result.add(new MetaDataVersion(GlobalNode.getGlobalRuleNode(each.getKey()), repository.query(GlobalNode.getGlobalRuleActiveVersionNode(each.getKey())), nextActiveVersion));
result.add(new MetaDataVersion(GlobalNodePath.getRulePath(each.getKey()), repository.query(GlobalNodePath.getRuleActiveVersionPath(each.getKey())), nextActiveVersion));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.metadata.persist.node.GlobalNode;
import org.apache.shardingsphere.metadata.persist.node.GlobalNodePath;
import org.apache.shardingsphere.metadata.persist.service.version.MetaDataVersionPersistService;
import org.apache.shardingsphere.mode.spi.PersistRepository;

Expand All @@ -45,7 +45,7 @@ public final class PropertiesPersistService {
* @return properties
*/
public Properties load() {
String yamlContent = repository.query(GlobalNode.getPropsVersionNode(getActiveVersion()));
String yamlContent = repository.query(GlobalNodePath.getPropsVersionPath(getActiveVersion()));
return Strings.isNullOrEmpty(yamlContent) ? new Properties() : YamlEngine.unmarshal(yamlContent, Properties.class);
}

Expand All @@ -55,16 +55,16 @@ public Properties load() {
* @param props properties
*/
public void persist(final Properties props) {
List<String> versions = metaDataVersionPersistService.getVersions(GlobalNode.getPropsVersionsNode());
List<String> versions = metaDataVersionPersistService.getVersions(GlobalNodePath.getPropsVersionsPath());
String nextActiveVersion = versions.isEmpty() ? MetaDataVersion.DEFAULT_VERSION : String.valueOf(Integer.parseInt(versions.get(0)) + 1);
repository.persist(GlobalNode.getPropsVersionNode(nextActiveVersion), YamlEngine.marshal(props));
repository.persist(GlobalNodePath.getPropsVersionPath(nextActiveVersion), YamlEngine.marshal(props));
if (Strings.isNullOrEmpty(getActiveVersion())) {
repository.persist(GlobalNode.getPropsActiveVersionNode(), MetaDataVersion.DEFAULT_VERSION);
repository.persist(GlobalNodePath.getPropsActiveVersionPath(), MetaDataVersion.DEFAULT_VERSION);
}
metaDataVersionPersistService.switchActiveVersion(Collections.singleton(new MetaDataVersion(GlobalNode.getPropsRootNode(), getActiveVersion(), nextActiveVersion)));
metaDataVersionPersistService.switchActiveVersion(Collections.singleton(new MetaDataVersion(GlobalNodePath.getPropsRootPath(), getActiveVersion(), nextActiveVersion)));
}

private String getActiveVersion() {
return repository.query(GlobalNode.getPropsActiveVersionNode());
return repository.query(GlobalNodePath.getPropsActiveVersionPath());
}
}
Loading
Loading