From 3b6a5e21377d713a79db18740d88aec041ddf46c Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Mon, 6 Jan 2025 22:36:22 +0800 Subject: [PATCH] Refactor DatabaseMetaDataNodePath (#34273) --- .../metadata/persist/node/DatabaseMetaDataNodePath.java | 4 ++-- .../metadata/persist/node/GlobalNodePath.java | 8 ++++---- .../metadata/persist/node/ProcessNodePath.java | 4 ++-- .../persist/node/QualifiedDataSourceNodePath.java | 4 ++-- .../metadata/persist/node/ReservationNodePath.java | 4 ++-- .../metadata/persist/node/ShardingSphereDataNodePath.java | 4 ++-- .../metadata/persist/node/StatesNodePath.java | 8 ++++---- .../persist/node/ShardingSphereDataNodePathTest.java | 2 +- .../statistics/collect/StatisticsCollectJobWorker.java | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/DatabaseMetaDataNodePath.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/DatabaseMetaDataNodePath.java index 9f0b1c2ac015f..45bb1dc955fe3 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/DatabaseMetaDataNodePath.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/DatabaseMetaDataNodePath.java @@ -30,7 +30,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class DatabaseMetaDataNodePath { - private static final String ROOT_NODE = "metadata"; + private static final String ROOT_NODE = "/metadata"; private static final String SCHEMAS_NODE = "schemas"; @@ -48,7 +48,7 @@ public final class DatabaseMetaDataNodePath { * @return meta data root path */ public static String getRootPath() { - return String.join("/", "", ROOT_NODE); + return ROOT_NODE; } /** diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/GlobalNodePath.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/GlobalNodePath.java index f67fe564f210f..c4ddc1a56f5fe 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/GlobalNodePath.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/GlobalNodePath.java @@ -26,9 +26,9 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class GlobalNodePath { - private static final String RULE_NODE = "rules"; + private static final String RULE_NODE = "/rules"; - private static final String PROPS_NODE = "props"; + private static final String PROPS_NODE = "/props"; private static final String VERSIONS_NODE = "versions"; @@ -40,7 +40,7 @@ public final class GlobalNodePath { * @return global rule root path */ public static String getRuleRootPath() { - return String.join("/", "", RULE_NODE); + return RULE_NODE; } /** @@ -90,7 +90,7 @@ public static String getRuleActiveVersionPath(final String ruleName) { * @return properties path */ public static String getPropsRootPath() { - return String.join("/", "", PROPS_NODE); + return PROPS_NODE; } /** diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePath.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePath.java index 316df9d13ad51..a5d78f39fd880 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePath.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ProcessNodePath.java @@ -26,7 +26,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ProcessNodePath { - private static final String ROOT_NODE = "execution_nodes"; + private static final String ROOT_NODE = "/execution_nodes"; /** * Get process ID root path. @@ -35,7 +35,7 @@ public final class ProcessNodePath { * @return process ID root path */ public static String getRootPath(final String processId) { - return String.join("/", "", ROOT_NODE, processId); + return String.join("/", ROOT_NODE, processId); } /** diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/QualifiedDataSourceNodePath.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/QualifiedDataSourceNodePath.java index f0745c2be0aa4..48655c5bb5fc4 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/QualifiedDataSourceNodePath.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/QualifiedDataSourceNodePath.java @@ -31,7 +31,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class QualifiedDataSourceNodePath { - private static final String ROOT_NODE = "nodes"; + private static final String ROOT_NODE = "/nodes"; private static final String QUALIFIED_DATA_SOURCES_NODE = "qualified_data_sources"; @@ -43,7 +43,7 @@ public final class QualifiedDataSourceNodePath { * @return qualified data source root path */ public static String getRootPath() { - return String.join("/", "", ROOT_NODE, QUALIFIED_DATA_SOURCES_NODE); + return String.join("/", ROOT_NODE, QUALIFIED_DATA_SOURCES_NODE); } /** diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ReservationNodePath.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ReservationNodePath.java index 45f7494b74604..6b080cf124193 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ReservationNodePath.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ReservationNodePath.java @@ -26,7 +26,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ReservationNodePath { - private static final String ROOT_NODE = "reservation"; + private static final String ROOT_NODE = "/reservation"; private static final String WORKER_ID_NODE = "worker_id"; @@ -37,6 +37,6 @@ public final class ReservationNodePath { * @return worker id reservation path */ public static String getWorkerIdReservationPath(final int workerId) { - return String.join("/", "", ROOT_NODE, WORKER_ID_NODE, String.valueOf(workerId)); + return String.join("/", ROOT_NODE, WORKER_ID_NODE, String.valueOf(workerId)); } } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ShardingSphereDataNodePath.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ShardingSphereDataNodePath.java index 9389ad711f9c7..b3105b2c2d71b 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ShardingSphereDataNodePath.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/ShardingSphereDataNodePath.java @@ -30,7 +30,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ShardingSphereDataNodePath { - private static final String ROOT_NODE = "statistics"; + private static final String ROOT_NODE = "/statistics"; private static final String DATABASES_NODE = "databases"; @@ -46,7 +46,7 @@ public final class ShardingSphereDataNodePath { * @return database root path */ public static String getDatabasesRootPath() { - return String.join("/", "", ROOT_NODE, DATABASES_NODE); + return String.join("/", ROOT_NODE, DATABASES_NODE); } /** diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/StatesNodePath.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/StatesNodePath.java index d290740244ae8..9b4139ed10910 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/StatesNodePath.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/node/StatesNodePath.java @@ -30,7 +30,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class StatesNodePath { - private static final String ROOT_NODE = "states"; + private static final String ROOT_NODE = "/states"; private static final String CLUSTER_STATE_NODE = "cluster_state"; @@ -42,7 +42,7 @@ public final class StatesNodePath { * @return cluster state path */ public static String getClusterStatePath() { - return String.join("/", "", ROOT_NODE, CLUSTER_STATE_NODE); + return String.join("/", ROOT_NODE, CLUSTER_STATE_NODE); } /** @@ -51,7 +51,7 @@ public static String getClusterStatePath() { * @return listener assisted node path */ public static String getListenerAssistedNodePath() { - return String.join("/", "", ROOT_NODE, LISTENER_ASSISTED_NODE); + return String.join("/", ROOT_NODE, LISTENER_ASSISTED_NODE); } /** @@ -73,6 +73,6 @@ public static Optional findDatabaseNameByListenerAssistedNodePath(final * @return database name listener assisted node path */ public static String getDatabaseNameListenerAssistedNodePath(final String databaseName) { - return String.join("/", "", ROOT_NODE, LISTENER_ASSISTED_NODE, databaseName); + return String.join("/", ROOT_NODE, LISTENER_ASSISTED_NODE, databaseName); } } diff --git a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ShardingSphereDataNodePathTest.java b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ShardingSphereDataNodePathTest.java index 626a486e14dee..cebc1cf9b6fd8 100644 --- a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ShardingSphereDataNodePathTest.java +++ b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/ShardingSphereDataNodePathTest.java @@ -133,6 +133,6 @@ void assertGetRowUniqueKeyUniqueKeyNotFoundScenario() { @Test void assertGetJobPath() { - assertThat(ShardingSphereDataNodePath.getJobPath(), is("statistics/job")); + assertThat(ShardingSphereDataNodePath.getJobPath(), is("/statistics/job")); } } diff --git a/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java b/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java index fa9537cc306d3..68edee5853898 100644 --- a/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java +++ b/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java @@ -68,7 +68,7 @@ public void initialize() { private CoordinatorRegistryCenter createRegistryCenter(final ModeConfiguration modeConfig) { ClusterPersistRepositoryConfiguration repositoryConfig = (ClusterPersistRepositoryConfiguration) modeConfig.getRepository(); - String namespace = String.join("/", repositoryConfig.getNamespace(), ShardingSphereDataNodePath.getJobPath()); + String namespace = repositoryConfig.getNamespace() + ShardingSphereDataNodePath.getJobPath(); CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(getZookeeperConfiguration(repositoryConfig, namespace)); result.init(); return result;