This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 0d6e1a9a74f remove attributes node of registry center (#17947)
0d6e1a9a74f is described below

commit 0d6e1a9a74f00d35f4b3ecbc843c1a9710eeba13
Author: Haoran Meng <[email protected]>
AuthorDate: Wed May 25 19:53:37 2022 +0800

    remove attributes node of registry center (#17947)
---
 .../mode/metadata/persist/node/ComputeNode.java    | 31 +++++++---------------
 .../metadata/persist/node/ComputeNodeTest.java     | 21 ++++++---------
 .../watcher/ComputeNodeStateChangedWatcher.java    |  2 +-
 .../ComputeNodeStateChangedWatcherTest.java        | 16 +++++------
 4 files changed, 27 insertions(+), 43 deletions(-)

diff --git 
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNode.java
 
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNode.java
index 23e226e874b..2f62956227c 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNode.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNode.java
@@ -35,8 +35,6 @@ public final class ComputeNode {
     
     private static final String ONLINE_NODE = "online";
     
-    private static final String ATTRIBUTES_NODE = "attributes";
-    
     private static final String LABELS_NODE = "labels";
     
     private static final String PROCESS_TRIGGER = "process_trigger";
@@ -105,7 +103,7 @@ public final class ComputeNode {
      * @return path of compute node instance labels
      */
     public static String getInstanceLabelsNodePath(final String instanceId) {
-        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ATTRIBUTES_NODE, 
instanceId, LABELS_NODE);
+        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, LABELS_NODE, 
instanceId);
     }
     
     /**
@@ -115,16 +113,7 @@ public final class ComputeNode {
      * @return path of compute node xa recovery id
      */
     public static String getInstanceXaRecoveryIdNodePath(final String 
instanceId) {
-        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ATTRIBUTES_NODE, 
instanceId, XA_RECOVERY_ID_NODE);
-    }
-    
-    /**
-     * Get attributes node path.
-     * 
-     * @return attributes node path
-     */
-    public static String getAttributesNodePath() {
-        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ATTRIBUTES_NODE);
+        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, 
XA_RECOVERY_ID_NODE, instanceId);
     }
     
     /**
@@ -143,19 +132,19 @@ public final class ComputeNode {
      * @return worker id path
      */
     public static String getInstanceWorkerIdNodePath(final String instanceId) {
-        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ATTRIBUTES_NODE, 
instanceId, WORKER_ID);
+        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, WORKER_ID, 
instanceId);
     }
     
     /**
-     * Get instance id by status path.
+     * Get instance id by compute node path.
      * 
-     * @param attributesPath attributes path
+     * @param computeNodePath compute node path
      * @return instance id
      */
-    public static String getInstanceIdByAttributes(final String 
attributesPath) {
-        Pattern pattern = Pattern.compile(getAttributesNodePath() + 
"/([\\S]+)" + "(/status|/worker_id|/labels|/xa_recovery_id)$", 
Pattern.CASE_INSENSITIVE);
-        Matcher matcher = pattern.matcher(attributesPath);
-        return matcher.find() ? matcher.group(1) : "";
+    public static String getInstanceIdByComputeNode(final String 
computeNodePath) {
+        Pattern pattern = Pattern.compile(getComputeNodePath() + 
"(/status|/worker_id|/labels|/xa_recovery_id)" + "/([\\S]+)$", 
Pattern.CASE_INSENSITIVE);
+        Matcher matcher = pattern.matcher(computeNodePath);
+        return matcher.find() ? matcher.group(2) : "";
     }
     
     /**
@@ -165,7 +154,7 @@ public final class ComputeNode {
      * @return instance status node path
      */
     public static String getInstanceStatusNodePath(final String instanceId) {
-        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ATTRIBUTES_NODE, 
instanceId, STATUS_NODE);
+        return String.join("/", "", ROOT_NODE, COMPUTE_NODE, STATUS_NODE, 
instanceId);
     }
     
     /**
diff --git 
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNodeTest.java
 
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNodeTest.java
index 703e24c5cb2..235be7674c5 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNodeTest.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNodeTest.java
@@ -56,34 +56,29 @@ public final class ComputeNodeTest {
     
     @Test
     public void assertGetInstanceLabelsNodePath() {
-        assertThat(ComputeNode.getInstanceLabelsNodePath("127.0.0.1@3307"), 
is("/nodes/compute_nodes/attributes/127.0.0.1@3307/labels"));
-    }
-    
-    @Test
-    public void assertGetAttributesNodePath() {
-        assertThat(ComputeNode.getAttributesNodePath(), 
is("/nodes/compute_nodes/attributes"));
+        assertThat(ComputeNode.getInstanceLabelsNodePath("127.0.0.1@3307"), 
is("/nodes/compute_nodes/labels/127.0.0.1@3307"));
     }
     
     @Test
     public void assertGetInstanceWorkerIdNodePath() {
-        assertThat(ComputeNode.getInstanceWorkerIdNodePath("127.0.0.1@3307"), 
is("/nodes/compute_nodes/attributes/127.0.0.1@3307/worker_id"));
+        assertThat(ComputeNode.getInstanceWorkerIdNodePath("127.0.0.1@3307"), 
is("/nodes/compute_nodes/worker_id/127.0.0.1@3307"));
     }
     
     @Test
-    public void assertGetInstanceIdByAttributes() {
-        
assertThat(ComputeNode.getInstanceIdByAttributes("/nodes/compute_nodes/attributes/127.0.0.1@3307/status"),
 is("127.0.0.1@3307"));
-        
assertThat(ComputeNode.getInstanceIdByAttributes("/nodes/compute_nodes/attributes/127.0.0.1@3308/worker_id"),
 is("127.0.0.1@3308"));
-        
assertThat(ComputeNode.getInstanceIdByAttributes("/nodes/compute_nodes/attributes/127.0.0.1@3309/labels"),
 is("127.0.0.1@3309"));
+    public void assertGetInstanceIdByComuteNodePath() {
+        
assertThat(ComputeNode.getInstanceIdByComputeNode("/nodes/compute_nodes/status/127.0.0.1@3307"),
 is("127.0.0.1@3307"));
+        
assertThat(ComputeNode.getInstanceIdByComputeNode("/nodes/compute_nodes/worker_id/127.0.0.1@3308"),
 is("127.0.0.1@3308"));
+        
assertThat(ComputeNode.getInstanceIdByComputeNode("/nodes/compute_nodes/labels/127.0.0.1@3309"),
 is("127.0.0.1@3309"));
     }
     
     @Test
     public void assertGetInstanceStatusNodePath() {
-        assertThat(ComputeNode.getInstanceStatusNodePath("127.0.0.1@3307"), 
is("/nodes/compute_nodes/attributes/127.0.0.1@3307/status"));
+        assertThat(ComputeNode.getInstanceStatusNodePath("127.0.0.1@3307"), 
is("/nodes/compute_nodes/status/127.0.0.1@3307"));
     }
     
     @Test
     public void assertGetInstanceXaRecoveryIdNodePath() {
-        
assertThat(ComputeNode.getInstanceXaRecoveryIdNodePath("127.0.0.1@3307"), 
is("/nodes/compute_nodes/attributes/127.0.0.1@3307/xa_recovery_id"));
+        
assertThat(ComputeNode.getInstanceXaRecoveryIdNodePath("127.0.0.1@3307"), 
is("/nodes/compute_nodes/xa_recovery_id/127.0.0.1@3307"));
     }
     
     @Test
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/compute/watcher/ComputeNodeStateChangedWatcher.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/compute/watcher/ComputeNodeStateChan
 [...]
index f2f75ae4a03..fc56ba6e0f5 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/compute/watcher/ComputeNodeStateChangedWatcher.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/compute/watcher/ComputeNodeStateChangedWatcher.java
@@ -60,7 +60,7 @@ public final class ComputeNodeStateChangedWatcher implements 
GovernanceWatcher<G
     
     @Override
     public Optional<GovernanceEvent> createGovernanceEvent(final 
DataChangedEvent event) {
-        String instanceId = 
ComputeNode.getInstanceIdByAttributes(event.getKey());
+        String instanceId = 
ComputeNode.getInstanceIdByComputeNode(event.getKey());
         if (!Strings.isNullOrEmpty(instanceId)) {
             if 
(event.getKey().equals(ComputeNode.getInstanceStatusNodePath(instanceId))) {
                 Collection<String> status = 
Strings.isNullOrEmpty(event.getValue()) ? new ArrayList<>() : 
YamlEngine.unmarshal(event.getValue(), Collection.class);
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/compute/watcher/ComputeNodeStateChangedWatcherTest.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/compute/watcher/ComputeNodeState
 [...]
index 640f90bec18..a5504b71e8a 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/compute/watcher/ComputeNodeStateChangedWatcherTest.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/compute/watcher/ComputeNodeStateChangedWatcherTest.java
@@ -37,8 +37,8 @@ import static org.junit.Assert.assertTrue;
 public final class ComputeNodeStateChangedWatcherTest {
     
     @Test
-    public void assertCreateEventWhenEnabled() {
-        Optional<GovernanceEvent> actual = new 
ComputeNodeStateChangedWatcher().createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/attributes/127.0.0.1@3307/status",
+    public void assertCreateEventWhenDisabled() {
+        Optional<GovernanceEvent> actual = new 
ComputeNodeStateChangedWatcher().createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/status/127.0.0.1@3307",
                 
YamlEngine.marshal(Arrays.asList(ComputeNodeStatus.CIRCUIT_BREAK.name())), 
Type.ADDED));
         assertTrue(actual.isPresent());
         assertThat(((StateEvent) actual.get()).getStatus(), 
is(Arrays.asList(ComputeNodeStatus.CIRCUIT_BREAK.name())));
@@ -46,9 +46,9 @@ public final class ComputeNodeStateChangedWatcherTest {
     }
     
     @Test
-    public void assertCreateEventWhenDisabled() {
+    public void assertCreateEventWhenDEnabled() {
         Optional<GovernanceEvent> actual = new ComputeNodeStateChangedWatcher()
-                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/attributes/127.0.0.1@3307/status", "", 
Type.UPDATED));
+                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/status/127.0.0.1@3307", "", 
Type.UPDATED));
         assertTrue(actual.isPresent());
         assertTrue(((StateEvent) actual.get()).getStatus().isEmpty());
         assertThat(((StateEvent) actual.get()).getInstanceId(), 
is("127.0.0.1@3307"));
@@ -57,7 +57,7 @@ public final class ComputeNodeStateChangedWatcherTest {
     @Test
     public void assertCreateAddWorkerIdEvent() {
         Optional<GovernanceEvent> actual = new ComputeNodeStateChangedWatcher()
-                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/attributes/127.0.0.1@3307/worker_id", 
"123", Type.ADDED));
+                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/worker_id/127.0.0.1@3307", "123", 
Type.ADDED));
         assertTrue(actual.isPresent());
         assertThat(((WorkerIdEvent) actual.get()).getWorkerId(), is(123L));
         assertThat(((WorkerIdEvent) actual.get()).getInstanceId(), 
is("127.0.0.1@3307"));
@@ -66,7 +66,7 @@ public final class ComputeNodeStateChangedWatcherTest {
     @Test
     public void assertCreateUpdateWorkerIdEvent() {
         Optional<GovernanceEvent> actual = new ComputeNodeStateChangedWatcher()
-                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/attributes/127.0.0.1@3307/worker_id", 
"123", Type.UPDATED));
+                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/worker_id/127.0.0.1@3307", "123", 
Type.UPDATED));
         assertTrue(actual.isPresent());
         assertThat(((WorkerIdEvent) actual.get()).getWorkerId(), is(123L));
         assertThat(((WorkerIdEvent) actual.get()).getInstanceId(), 
is("127.0.0.1@3307"));
@@ -75,7 +75,7 @@ public final class ComputeNodeStateChangedWatcherTest {
     @Test
     public void assertCreateAddLabelEvent() {
         Optional<GovernanceEvent> actual = new ComputeNodeStateChangedWatcher()
-                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/attributes/127.0.0.1@3307/labels",
+                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/labels/127.0.0.1@3307",
                         YamlEngine.marshal(Arrays.asList("label_1", 
"label_2")), Type.ADDED));
         assertTrue(actual.isPresent());
         assertThat(((LabelsEvent) actual.get()).getLabels(), 
is(Arrays.asList("label_1", "label_2")));
@@ -85,7 +85,7 @@ public final class ComputeNodeStateChangedWatcherTest {
     @Test
     public void assertCreateUpdateLabelsEvent() {
         Optional<GovernanceEvent> actual = new ComputeNodeStateChangedWatcher()
-                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/attributes/127.0.0.1@3307/labels",
+                .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/labels/127.0.0.1@3307",
                         YamlEngine.marshal(Arrays.asList("label_1", 
"label_2")), Type.UPDATED));
         assertTrue(actual.isPresent());
         assertThat(((LabelsEvent) actual.get()).getLabels(), 
is(Arrays.asList("label_1", "label_2")));

Reply via email to