You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/02/07 17:40:51 UTC
(shardingsphere) branch master updated: Refactor PropertiesPersistService (#34599)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 27092c3169b Refactor PropertiesPersistService (#34599)
27092c3169b is described below
commit 27092c3169b9e1fa28392139b06f53c97ffabac4
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Feb 8 01:40:46 2025 +0800
Refactor PropertiesPersistService (#34599)
---
.../config/global/PropertiesPersistService.java | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java
index 735631ade8e..11c20ae8492 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
import org.apache.shardingsphere.mode.node.path.config.GlobalPropertiesNodePath;
-import org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
import java.util.Collections;
@@ -45,9 +44,8 @@ public final class PropertiesPersistService {
* @return properties
*/
public Properties load() {
- VersionNodePathGenerator versionNodePathGenerator = GlobalPropertiesNodePath.getVersionNodePathGenerator();
- Integer activeVersion = getActiveVersion(versionNodePathGenerator);
- String yamlContent = repository.query(versionNodePathGenerator.getVersionPath(null == activeVersion ? 0 : activeVersion));
+ Integer activeVersion = getActiveVersion();
+ String yamlContent = repository.query(GlobalPropertiesNodePath.getVersionNodePathGenerator().getVersionPath(null == activeVersion ? 0 : activeVersion));
return Strings.isNullOrEmpty(yamlContent) ? new Properties() : YamlEngine.unmarshal(yamlContent, Properties.class);
}
@@ -57,18 +55,16 @@ public final class PropertiesPersistService {
* @param props properties
*/
public void persist(final Properties props) {
- VersionNodePathGenerator versionNodePathGenerator = GlobalPropertiesNodePath.getVersionNodePathGenerator();
- int nextActiveVersion = metaDataVersionPersistService.getNextVersion(versionNodePathGenerator.getVersionsPath());
- repository.persist(versionNodePathGenerator.getVersionPath(nextActiveVersion), YamlEngine.marshal(props));
- if (null == getActiveVersion(versionNodePathGenerator)) {
- repository.persist(versionNodePathGenerator.getActiveVersionPath(), String.valueOf(MetaDataVersion.DEFAULT_VERSION));
+ int nextActiveVersion = metaDataVersionPersistService.getNextVersion(GlobalPropertiesNodePath.getVersionNodePathGenerator().getVersionsPath());
+ repository.persist(GlobalPropertiesNodePath.getVersionNodePathGenerator().getVersionPath(nextActiveVersion), YamlEngine.marshal(props));
+ if (null == getActiveVersion()) {
+ repository.persist(GlobalPropertiesNodePath.getVersionNodePathGenerator().getActiveVersionPath(), String.valueOf(MetaDataVersion.DEFAULT_VERSION));
}
- metaDataVersionPersistService
- .switchActiveVersion(Collections.singleton(new MetaDataVersion(GlobalPropertiesNodePath.getRootPath(), getActiveVersion(versionNodePathGenerator), nextActiveVersion)));
+ metaDataVersionPersistService.switchActiveVersion(Collections.singleton(new MetaDataVersion(GlobalPropertiesNodePath.getRootPath(), getActiveVersion(), nextActiveVersion)));
}
- private Integer getActiveVersion(final VersionNodePathGenerator versionNodePathGenerator) {
- String value = repository.query(versionNodePathGenerator.getActiveVersionPath());
+ private Integer getActiveVersion() {
+ String value = repository.query(GlobalPropertiesNodePath.getVersionNodePathGenerator().getActiveVersionPath());
return Strings.isNullOrEmpty(value) ? null : Integer.parseInt(value);
}
}