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/19 06:46:40 UTC
(shardingsphere) branch master updated: Add WorkerIDNodePath and ProcessNodePath (#34715)
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 0697712da3a Add WorkerIDNodePath and ProcessNodePath (#34715)
0697712da3a is described below
commit 0697712da3adbf5e5ad403081a4a7f4bc4783683
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Feb 19 14:46:34 2025 +0800
Add WorkerIDNodePath and ProcessNodePath (#34715)
* Add WorkerIDNodePath
* Add ProcessNodePath
---
.../ExecutionNodePath.java} | 12 ++++--------
.../{state => execution/process}/ProcessNodePath.java | 12 +++++++-----
.../mode/node/path/reservation/ReservationNodePath.java | 2 +-
.../workerid/WorkerIDNodePath.java} | 16 ++++++++--------
.../ExecutionNodePathTest.java} | 6 +++---
.../process}/ProcessNodePathTest.java | 2 +-
.../node/path/reservation/ReservationNodePathTest.java | 4 ++--
.../workerid/WorkerIDNodePathTest.java} | 6 +++---
.../process/ClusterProcessPersistCoordinator.java | 2 +-
.../persist/service/ClusterProcessPersistService.java | 2 +-
.../cluster/workerid/ReservationPersistService.java | 4 ++--
11 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePath.java
similarity index 76%
copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java
copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePath.java
index 17fb5a245a0..e9133b7edd8 100644
--- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java
+++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePath.java
@@ -15,23 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.node.path.state;
+package org.apache.shardingsphere.mode.node.path.execution;
-import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.node.path.NodePath;
/**
- * Process node path generator.
+ * Execution node path.
*/
-@RequiredArgsConstructor
-public final class ProcessNodePath implements NodePath {
+public final class ExecutionNodePath implements NodePath {
private static final String ROOT_NODE = "/execution_nodes";
- private final String processId;
-
@Override
public String getRootPath() {
- return String.join("/", ROOT_NODE, processId);
+ return ROOT_NODE;
}
}
diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePath.java
similarity index 72%
copy from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java
copy to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePath.java
index 17fb5a245a0..9734f1c8922 100644
--- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java
+++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePath.java
@@ -15,23 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.node.path.state;
+package org.apache.shardingsphere.mode.node.path.execution.process;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.node.path.NodePath;
+import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
+import org.apache.shardingsphere.mode.node.path.execution.ExecutionNodePath;
/**
- * Process node path generator.
+ * Process node path.
*/
@RequiredArgsConstructor
public final class ProcessNodePath implements NodePath {
- private static final String ROOT_NODE = "/execution_nodes";
-
private final String processId;
+ private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ExecutionNodePath());
+
@Override
public String getRootPath() {
- return String.join("/", ROOT_NODE, processId);
+ return String.join("/", nodePathGenerator.getPath(processId));
}
}
diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePath.java
index 445c1543b0f..3798fc41af3 100644
--- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePath.java
+++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePath.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.mode.node.path.NodePath;
*/
public final class ReservationNodePath implements NodePath {
- private static final String ROOT_NODE = "/reservation/worker_id";
+ private static final String ROOT_NODE = "/reservation";
@Override
public String getRootPath() {
diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java
similarity index 63%
rename from mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java
rename to mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java
index 17fb5a245a0..d21328f2fbc 100644
--- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePath.java
+++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePath.java
@@ -15,23 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.node.path.state;
+package org.apache.shardingsphere.mode.node.path.reservation.workerid;
-import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.node.path.NodePath;
+import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
+import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath;
/**
- * Process node path generator.
+ * Worker ID node path.
*/
-@RequiredArgsConstructor
-public final class ProcessNodePath implements NodePath {
+public final class WorkerIDNodePath implements NodePath {
- private static final String ROOT_NODE = "/execution_nodes";
+ private static final String ROOT_NODE = "worker_id";
- private final String processId;
+ private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath());
@Override
public String getRootPath() {
- return String.join("/", ROOT_NODE, processId);
+ return String.join("/", nodePathGenerator.getPath(ROOT_NODE));
}
}
diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePathTest.java
similarity index 83%
copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java
copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePathTest.java
index 79502d4a3db..59a74a56559 100644
--- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java
+++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/ExecutionNodePathTest.java
@@ -15,17 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.node.path.state;
+package org.apache.shardingsphere.mode.node.path.execution;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class ProcessNodePathTest {
+class ExecutionNodePathTest {
@Test
void assertGetRootPath() {
- assertThat(new ProcessNodePath("foo_process_id").getRootPath(), is("/execution_nodes/foo_process_id"));
+ assertThat(new ExecutionNodePath().getRootPath(), is("/execution_nodes"));
}
}
diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePathTest.java
similarity index 94%
copy from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java
copy to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePathTest.java
index 79502d4a3db..c64632f8388 100644
--- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java
+++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/execution/process/ProcessNodePathTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.node.path.state;
+package org.apache.shardingsphere.mode.node.path.execution.process;
import org.junit.jupiter.api.Test;
diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePathTest.java
index 75ac97497d5..9f316e03228 100644
--- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePathTest.java
+++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/ReservationNodePathTest.java
@@ -25,7 +25,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
class ReservationNodePathTest {
@Test
- void assertGetWorkerIdReservationPath() {
- assertThat(new ReservationNodePath().getRootPath(), is("/reservation/worker_id"));
+ void assertGetRootPath() {
+ assertThat(new ReservationNodePath().getRootPath(), is("/reservation"));
}
}
diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java
similarity index 83%
rename from mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java
rename to mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java
index 79502d4a3db..612bd8b3c0c 100644
--- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/state/ProcessNodePathTest.java
+++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/reservation/workerid/WorkerIDNodePathTest.java
@@ -15,17 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.node.path.state;
+package org.apache.shardingsphere.mode.node.path.reservation.workerid;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class ProcessNodePathTest {
+class WorkerIDNodePathTest {
@Test
void assertGetRootPath() {
- assertThat(new ProcessNodePath("foo_process_id").getRootPath(), is("/execution_nodes/foo_process_id"));
+ assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id"));
}
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/process/ClusterProcessPersistCoordinator.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/process/ClusterProcessPersistCoordinator.java
index 2db5a4a780a..830d2d086cc 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/process/ClusterProcessPersistCoordinator.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/coordinator/process/ClusterProcessPersistCoordinator.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.executor.sql.process.yaml.swapper.YamlPro
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator;
-import org.apache.shardingsphere.mode.node.path.state.ProcessNodePath;
+import org.apache.shardingsphere.mode.node.path.execution.process.ProcessNodePath;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
import java.util.Collection;
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java
index 647844ca44f..2671431ed6b 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator;
-import org.apache.shardingsphere.mode.node.path.state.ProcessNodePath;
+import org.apache.shardingsphere.mode.node.path.execution.process.ProcessNodePath;
import org.apache.shardingsphere.mode.persist.service.ProcessPersistService;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ReservationPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ReservationPersistService.java
index ceaee1f6a1e..1acbd4f60fb 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ReservationPersistService.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ReservationPersistService.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.mode.manager.cluster.workerid;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
-import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath;
+import org.apache.shardingsphere.mode.node.path.reservation.workerid.WorkerIDNodePath;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterRepositoryPersistException;
@@ -43,7 +43,7 @@ public final class ReservationPersistService {
public Optional<Integer> reserveWorkerId(final Integer preselectedWorkerId, final String instanceId) {
try {
return repository.persistExclusiveEphemeral(
- new NodePathGenerator(new ReservationNodePath()).getPath(preselectedWorkerId), instanceId) ? Optional.of(preselectedWorkerId) : Optional.empty();
+ new NodePathGenerator(new WorkerIDNodePath()).getPath(preselectedWorkerId), instanceId) ? Optional.of(preselectedWorkerId) : Optional.empty();
} catch (final ClusterRepositoryPersistException ignore) {
return Optional.empty();
}