This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 d65c0ce Use status type as node name for compute_nodes (#12461)
d65c0ce is described below
commit d65c0ce567f73d539f4183ac05783b01934f0434
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Sep 16 00:22:29 2021 +0800
Use status type as node name for compute_nodes (#12461)
* Refactor ClusterInstance
* Use status type as node name for compute_nodes
---
.../cluster/coordinator/ClusterInstance.java | 6 ++--
.../lock/service/LockRegistryService.java | 5 +--
...RegistryService.java => ComputeNodeStatus.java} | 24 +++------------
...RegistryService.java => StorageNodeStatus.java} | 24 +++------------
.../registry/status/node/StatusNode.java | 36 +++++++++++++++-------
.../service/InstanceStatusRegistryService.java | 10 +++++-
.../watcher/TerminalStateChangedWatcher.java | 3 +-
.../registry/status/node/StatusNodeTest.java | 3 +-
8 files changed, 52 insertions(+), 59 deletions(-)
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterInstance.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterInstance.java
index b96419f..9cc467b 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterInstance.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterInstance.java
@@ -17,7 +17,9 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator;
+import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.utils.IpUtils;
import java.lang.management.ManagementFactory;
@@ -25,6 +27,7 @@ import java.lang.management.ManagementFactory;
/**
* Cluster instance.
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public final class ClusterInstance {
@@ -34,9 +37,6 @@ public final class ClusterInstance {
private String id;
- private ClusterInstance() {
- }
-
/**
* Init cluster instance.
*
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/service/LockRegistryService.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/service/LockRegistryService.java
index 8d74fe5..b5f4b9f 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/service/LockRegistryService.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/service/LockRegistryService.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.service;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterInstance;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ComputeNodeStatus;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.node.StatusNode;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
@@ -111,11 +112,11 @@ public final class LockRegistryService {
}
private boolean checkAck(final String lockName, final String ackValue,
final long timeoutMilliseconds) {
- Collection<String> instanceIds =
repository.getChildrenKeys(StatusNode.getComputeNodesPath());
+ Collection<String> onlineInstanceIds =
repository.getChildrenKeys(StatusNode.getComputeNodePath(ComputeNodeStatus.ONLINE));
long checkMilliseconds = timeoutMilliseconds;
while (checkMilliseconds > 0) {
long start = System.currentTimeMillis();
- if (check(instanceIds, lockName, ackValue)) {
+ if (check(onlineInstanceIds, lockName, ackValue)) {
return true;
}
try {
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/ComputeNodeStatus.java
similarity index 52%
copy from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
copy to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/ComputeNodeStatus.java
index c28ec7a..e1711ca 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/ComputeNodeStatus.java
@@ -15,28 +15,12 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.service;
-
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.node.StatusNode;
-import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status;
/**
- * Instance status registry service.
+ * Compute node status.
*/
-@RequiredArgsConstructor
-public final class InstanceStatusRegistryService {
-
- private final ClusterPersistRepository repository;
+public enum ComputeNodeStatus {
- /**
- * Register instance online.
- *
- * @param instanceId instance ID
- */
- public void registerInstanceOnline(final String instanceId) {
- repository.persist(StatusNode.getStorageNodePath(), "");
- repository.persist(StatusNode.getPrimaryNodesPath(), "");
- repository.persistEphemeral(StatusNode.getComputeNodePath(instanceId),
"");
- }
+ ONLINE, CIRCUIT_BREAKER
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/StorageNodeStatus.java
similarity index 52%
copy from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
copy to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/StorageNodeStatus.java
index c28ec7a..242e166 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/StorageNodeStatus.java
@@ -15,28 +15,12 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.service;
-
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.node.StatusNode;
-import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status;
/**
- * Instance status registry service.
+ * Storage node status.
*/
-@RequiredArgsConstructor
-public final class InstanceStatusRegistryService {
-
- private final ClusterPersistRepository repository;
+public enum StorageNodeStatus {
- /**
- * Register instance online.
- *
- * @param instanceId instance ID
- */
- public void registerInstanceOnline(final String instanceId) {
- repository.persist(StatusNode.getStorageNodePath(), "");
- repository.persist(StatusNode.getPrimaryNodesPath(), "");
- repository.persistEphemeral(StatusNode.getComputeNodePath(instanceId),
"");
- }
+ DISABLE, PRIMARY
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
index fd27126..de05c3a 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
@@ -20,6 +20,8 @@ package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import com.google.common.base.Joiner;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ComputeNodeStatus;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.StorageNodeStatus;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.schema.ClusterSchema;
import java.util.Optional;
@@ -45,11 +47,32 @@ public final class StatusNode {
/**
* Get compute node path.
*
+ * @param status compute node status
+ * @return compute node path
+ */
+ public static String getComputeNodePath(final ComputeNodeStatus status) {
+ return Joiner.on("/").join("", ROOT_NODE, COMPUTE_NODE,
status.name().toLowerCase());
+ }
+
+ /**
+ * Get compute node path.
+ *
+ * @param status compute node status
* @param instanceId instance id
* @return compute node path
*/
- public static String getComputeNodePath(final String instanceId) {
- return Joiner.on("/").join("", ROOT_NODE, COMPUTE_NODE, instanceId);
+ public static String getComputeNodePath(final ComputeNodeStatus status,
final String instanceId) {
+ return Joiner.on("/").join("", ROOT_NODE, COMPUTE_NODE,
status.name().toLowerCase(), instanceId);
+ }
+
+ /**
+ * Get storage node path.
+ *
+ * @param status storage node status
+ * @return storage node path
+ */
+ public static String getStorageNodePath(final StorageNodeStatus status) {
+ return Joiner.on("/").join("", ROOT_NODE, STORAGE_NODE,
status.name().toLowerCase());
}
/**
@@ -139,15 +162,6 @@ public final class StatusNode {
}
/**
- * Get proxy nodes path.
- *
- * @return proxy nodes path
- */
- public static String getComputeNodesPath() {
- return Joiner.on("/").join("", ROOT_NODE, COMPUTE_NODE);
- }
-
- /**
* Get privilege node path.
*
* @return privilege node path
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
index c28ec7a..fc55756 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/service/InstanceStatusRegistryService.java
@@ -18,6 +18,8 @@
package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.service;
import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ComputeNodeStatus;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.StorageNodeStatus;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.node.StatusNode;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
@@ -35,8 +37,14 @@ public final class InstanceStatusRegistryService {
* @param instanceId instance ID
*/
public void registerInstanceOnline(final String instanceId) {
+ for (ComputeNodeStatus each : ComputeNodeStatus.values()) {
+ repository.persist(StatusNode.getComputeNodePath(each), "");
+ }
+ for (StorageNodeStatus each : StorageNodeStatus.values()) {
+ repository.persist(StatusNode.getStorageNodePath(each), "");
+ }
+
repository.persistEphemeral(StatusNode.getComputeNodePath(ComputeNodeStatus.ONLINE,
instanceId), "");
repository.persist(StatusNode.getStorageNodePath(), "");
repository.persist(StatusNode.getPrimaryNodesPath(), "");
- repository.persistEphemeral(StatusNode.getComputeNodePath(instanceId),
"");
}
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/TerminalStateChangedWatcher.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/TerminalStateChangedWatcher.java
index dab33e6..3951e06 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/TerminalStateChangedWatcher.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/TerminalStateChangedWatcher.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import org.apache.shardingsphere.infra.state.StateEvent;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ComputeNodeStatus;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ResourceState;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.node.StatusNode;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
@@ -35,7 +36,7 @@ public final class TerminalStateChangedWatcher implements
GovernanceWatcher<Stat
@Override
public Collection<String> getWatchingKeys() {
- return Collections.singleton(StatusNode.getComputeNodesPath());
+ return
Collections.singleton(StatusNode.getComputeNodePath(ComputeNodeStatus.CIRCUIT_BREAKER));
}
@Override
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
index d6c6df8..7d522a2 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
@@ -17,6 +17,7 @@
package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.node;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ComputeNodeStatus;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.schema.ClusterSchema;
import org.junit.Test;
@@ -30,7 +31,7 @@ public final class StatusNodeTest {
@Test
public void assertGetProxyNodePath() {
- assertThat(StatusNode.getComputeNodePath("testId"),
is("/status/compute_nodes/testId"));
+ assertThat(StatusNode.getComputeNodePath(ComputeNodeStatus.ONLINE,
"testId"), is("/status/compute_nodes/online/testId"));
}
@Test