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 8d617656fee Spilt DataSourceNodePathGenerator and 
DataSourceNodePathParser (#34689)
8d617656fee is described below

commit 8d617656feef8fae6cbf07fb4160149a6668c0dc
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Feb 16 02:23:47 2025 +0800

    Spilt DataSourceNodePathGenerator and DataSourceNodePathParser (#34689)
---
 .../database/DataSourceUnitPersistService.java     | 12 ++--
 .../storage/DataSourceNodePathGenerator.java       | 71 +---------------------
 .../metadata/storage/DataSourceNodePathParser.java | 59 ++----------------
 .../storage/StorageNodeNodePathGenerator.java      | 63 +++++++++++++++++++
 .../storage/StorageNodeNodePathParser.java         | 59 ++++++++++++++++++
 .../storage/StorageUnitNodePathGenerator.java      | 63 +++++++++++++++++++
 .../storage/StorageUnitNodePathParser.java         | 59 ++++++++++++++++++
 .../storage/DataSourceNodePathGeneratorTest.java   | 40 +-----------
 .../storage/DataSourceNodePathParserTest.java      | 33 +---------
 .../storage/StorageNodeNodePathGeneratorTest.java  | 44 ++++++++++++++
 ...est.java => StorageNodeNodePathParserTest.java} | 27 ++------
 .../storage/StorageUnitNodePathGeneratorTest.java  | 44 ++++++++++++++
 ...est.java => StorageUnitNodePathParserTest.java} | 27 ++------
 .../database/metadata/MetaDataChangedHandler.java  | 12 ++--
 14 files changed, 365 insertions(+), 248 deletions(-)

diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/database/DataSourceUnitPersistService.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/database/DataSourceUnitPersistService.java
index a88cae7c833..9db416da925 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/database/DataSourceUnitPersistService.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/database/DataSourceUnitPersistService.java
@@ -21,7 +21,7 @@ import 
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePo
 import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
 import 
org.apache.shardingsphere.infra.yaml.config.swapper.resource.YamlDataSourceConfigurationSwapper;
 import 
org.apache.shardingsphere.mode.metadata.persist.version.MetaDataVersionPersistService;
-import 
org.apache.shardingsphere.mode.node.path.metadata.storage.DataSourceNodePathGenerator;
+import 
org.apache.shardingsphere.mode.node.path.metadata.storage.StorageUnitNodePathGenerator;
 import 
org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator;
 import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
 
@@ -55,7 +55,7 @@ public final class DataSourceUnitPersistService {
      * @return data source pool properties map
      */
     public Map<String, DataSourcePoolProperties> load(final String 
databaseName) {
-        Collection<String> childrenKeys = 
repository.getChildrenKeys(DataSourceNodePathGenerator.getStorageUnitsPath(databaseName));
+        Collection<String> childrenKeys = 
repository.getChildrenKeys(StorageUnitNodePathGenerator.getRootPath(databaseName));
         return childrenKeys.stream().collect(Collectors.toMap(each -> each, 
each -> load(databaseName, each), (a, b) -> b, () -> new 
LinkedHashMap<>(childrenKeys.size(), 1F)));
     }
     
@@ -68,8 +68,8 @@ public final class DataSourceUnitPersistService {
      */
     @SuppressWarnings("unchecked")
     public DataSourcePoolProperties load(final String databaseName, final 
String dataSourceName) {
-        int activeVersion = 
Integer.parseInt(repository.query(DataSourceNodePathGenerator.getStorageUnitVersion(databaseName,
 dataSourceName).getActiveVersionPath()));
-        String dataSourceContent = 
repository.query(DataSourceNodePathGenerator.getStorageUnitVersion(databaseName,
 dataSourceName).getVersionPath(activeVersion));
+        int activeVersion = 
Integer.parseInt(repository.query(StorageUnitNodePathGenerator.getVersion(databaseName,
 dataSourceName).getActiveVersionPath()));
+        String dataSourceContent = 
repository.query(StorageUnitNodePathGenerator.getVersion(databaseName, 
dataSourceName).getVersionPath(activeVersion));
         return 
yamlDataSourceConfigurationSwapper.swapToDataSourcePoolProperties(YamlEngine.unmarshal(dataSourceContent,
 Map.class));
     }
     
@@ -81,7 +81,7 @@ public final class DataSourceUnitPersistService {
      */
     public void persist(final String databaseName, final Map<String, 
DataSourcePoolProperties> dataSourcePropsMap) {
         for (Entry<String, DataSourcePoolProperties> entry : 
dataSourcePropsMap.entrySet()) {
-            VersionNodePathGenerator versionNodePathGenerator = 
DataSourceNodePathGenerator.getStorageUnitVersion(databaseName, entry.getKey());
+            VersionNodePathGenerator versionNodePathGenerator = 
StorageUnitNodePathGenerator.getVersion(databaseName, entry.getKey());
             metaDataVersionPersistService.persist(versionNodePathGenerator, 
YamlEngine.marshal(yamlDataSourceConfigurationSwapper.swapToMap(entry.getValue())));
         }
     }
@@ -93,6 +93,6 @@ public final class DataSourceUnitPersistService {
      * @param dataSourceName data source name
      */
     public void delete(final String databaseName, final String dataSourceName) 
{
-        
repository.delete(DataSourceNodePathGenerator.getStorageUnitPath(databaseName, 
dataSourceName));
+        
repository.delete(StorageUnitNodePathGenerator.getStorageUnitPath(databaseName, 
dataSourceName));
     }
 }
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathGenerator.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathGenerator.java
index 1a2150ef969..c7145b53707 100644
--- 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathGenerator.java
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathGenerator.java
@@ -20,7 +20,6 @@ package 
org.apache.shardingsphere.mode.node.path.metadata.storage;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.mode.node.path.metadata.DatabaseNodePathGenerator;
-import 
org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator;
 
 /**
  * Data source node path generator.
@@ -30,81 +29,13 @@ public final class DataSourceNodePathGenerator {
     
     private static final String DATA_SOURCES_NODE = "data_sources";
     
-    private static final String NODES_NODE = "nodes";
-    
-    private static final String UNITS_NODE = "units";
-    
     /**
      * Get data source root path.
      *
      * @param databaseName database name
      * @return data source root path
      */
-    public static String getDataSourceRootPath(final String databaseName) {
+    public static String getRootPath(final String databaseName) {
         return String.join("/", DatabaseNodePathGenerator.getRootPath(), 
databaseName, DATA_SOURCES_NODE);
     }
-    
-    /**
-     * Get storage units path.
-     *
-     * @param databaseName database name
-     * @return storage units path
-     */
-    public static String getStorageUnitsPath(final String databaseName) {
-        return String.join("/", getDataSourceRootPath(databaseName), 
UNITS_NODE);
-    }
-    
-    /**
-     * Get storage nodes path.
-     *
-     * @param databaseName database name
-     * @return storage nodes path
-     */
-    public static String getStorageNodesPath(final String databaseName) {
-        return String.join("/", getDataSourceRootPath(databaseName), 
NODES_NODE);
-    }
-    
-    /**
-     * Get storage unit path.
-     *
-     * @param databaseName database name
-     * @param storageUnitName storage unit name
-     * @return storage unit path
-     */
-    public static String getStorageUnitPath(final String databaseName, final 
String storageUnitName) {
-        return String.join("/", getStorageUnitsPath(databaseName), 
storageUnitName);
-    }
-    
-    /**
-     * Get storage node path.
-     *
-     * @param databaseName database name
-     * @param storageNodeName storage node name
-     * @return storage node path
-     */
-    public static String getStorageNodePath(final String databaseName, final 
String storageNodeName) {
-        return String.join("/", getStorageNodesPath(databaseName), 
storageNodeName);
-    }
-    
-    /**
-     * Get storage unit version node path generator.
-     *
-     * @param databaseName database name
-     * @param storageUnitName storage unit name
-     * @return storage unit version node path generator
-     */
-    public static VersionNodePathGenerator getStorageUnitVersion(final String 
databaseName, final String storageUnitName) {
-        return new VersionNodePathGenerator(String.join("/", 
getStorageUnitsPath(databaseName), storageUnitName));
-    }
-    
-    /**
-     * Get storage node version node path generator.
-     *
-     * @param databaseName database name
-     * @param storageNodeName storage node name
-     * @return storage node version node path generator
-     */
-    public static VersionNodePathGenerator getStorageNodeVersion(final String 
databaseName, final String storageNodeName) {
-        return new VersionNodePathGenerator(String.join("/", 
getStorageNodesPath(databaseName), storageNodeName));
-    }
 }
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParser.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParser.java
index a46797ec6b0..1b35e9c307f 100644
--- 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParser.java
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParser.java
@@ -20,10 +20,7 @@ package 
org.apache.shardingsphere.mode.node.path.metadata.storage;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.mode.node.path.NodePathPattern;
-import org.apache.shardingsphere.mode.node.path.version.VersionNodePathParser;
 
-import java.util.Optional;
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
@@ -32,61 +29,15 @@ import java.util.regex.Pattern;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class DataSourceNodePathParser {
     
-    private static final VersionNodePathParser STORAGE_UNITS_VERSION_PARSER =
-            new VersionNodePathParser(String.join("/", 
DataSourceNodePathGenerator.getStorageUnitsPath(NodePathPattern.IDENTIFIER), 
NodePathPattern.IDENTIFIER));
-    
-    private static final VersionNodePathParser STORAGE_NODES_VERSION_PARSER =
-            new VersionNodePathParser(String.join("/", 
DataSourceNodePathGenerator.getStorageNodesPath(NodePathPattern.IDENTIFIER), 
NodePathPattern.IDENTIFIER));
-    
-    /**
-     * Find storage unit name by storage unit path.
-     *
-     * @param path path
-     * @return found storage unit name
-     */
-    public static Optional<String> findStorageUnitNameByStorageUnitPath(final 
String path) {
-        Pattern pattern = 
Pattern.compile(DataSourceNodePathGenerator.getStorageUnitPath(NodePathPattern.IDENTIFIER,
 NodePathPattern.IDENTIFIER) + "$", Pattern.CASE_INSENSITIVE);
-        Matcher matcher = pattern.matcher(path);
-        return matcher.find() ? Optional.of(matcher.group(2)) : 
Optional.empty();
-    }
+    private static final Pattern PATTERN = 
Pattern.compile(DataSourceNodePathGenerator.getRootPath(NodePathPattern.IDENTIFIER)
 + "?", Pattern.CASE_INSENSITIVE);
     
     /**
-     * Find storage node name by storage node path.
+     * Is data source path.
      *
      * @param path path
-     * @return found storage unit name
-     */
-    public static Optional<String> findStorageNodeNameByStorageNodePath(final 
String path) {
-        Pattern pattern = 
Pattern.compile(DataSourceNodePathGenerator.getStorageNodePath(NodePathPattern.IDENTIFIER,
 NodePathPattern.IDENTIFIER) + "$", Pattern.CASE_INSENSITIVE);
-        Matcher matcher = pattern.matcher(path);
-        return matcher.find() ? Optional.of(matcher.group(2)) : 
Optional.empty();
-    }
-    
-    /**
-     * Is data source root path.
-     *
-     * @param path path
-     * @return is data source root path or not
-     */
-    public static boolean isDataSourceRootPath(final String path) {
-        return 
Pattern.compile(DataSourceNodePathGenerator.getDataSourceRootPath(NodePathPattern.IDENTIFIER)
 + "?", Pattern.CASE_INSENSITIVE).matcher(path).find();
-    }
-    
-    /**
-     * Get storage unit version unit path parser.
-     *
-     * @return storage unit version node path parser
-     */
-    public static VersionNodePathParser getStorageUnitVersion() {
-        return STORAGE_UNITS_VERSION_PARSER;
-    }
-    
-    /**
-     * Get storage node version node path parser.
-     *
-     * @return storage node version node path parser
+     * @return is data source path or not
      */
-    public static VersionNodePathParser getStorageNodeVersion() {
-        return STORAGE_NODES_VERSION_PARSER;
+    public static boolean isDataSourcePath(final String path) {
+        return PATTERN.matcher(path).find();
     }
 }
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathGenerator.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathGenerator.java
new file mode 100644
index 00000000000..07353a9b7cd
--- /dev/null
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathGenerator.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.node.path.metadata.storage;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator;
+
+/**
+ * Storage node node path generator.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StorageNodeNodePathGenerator {
+    
+    private static final String NODES_NODE = "nodes";
+    
+    /**
+     * Get storage node root path.
+     *
+     * @param databaseName database name
+     * @return storage node root path
+     */
+    public static String getRootPath(final String databaseName) {
+        return String.join("/", 
DataSourceNodePathGenerator.getRootPath(databaseName), NODES_NODE);
+    }
+    
+    /**
+     * Get storage node path.
+     *
+     * @param databaseName database name
+     * @param storageNodeName storage node name
+     * @return storage node path
+     */
+    public static String getStorageNodePath(final String databaseName, final 
String storageNodeName) {
+        return String.join("/", getRootPath(databaseName), storageNodeName);
+    }
+    
+    /**
+     * Get storage node version node path generator.
+     *
+     * @param databaseName database name
+     * @param storageNodeName storage node name
+     * @return storage node version node path generator
+     */
+    public static VersionNodePathGenerator getVersion(final String 
databaseName, final String storageNodeName) {
+        return new VersionNodePathGenerator(String.join("/", 
getRootPath(databaseName), storageNodeName));
+    }
+}
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathParser.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathParser.java
new file mode 100644
index 00000000000..abed4fd52a6
--- /dev/null
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathParser.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.node.path.metadata.storage;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.mode.node.path.NodePathPattern;
+import org.apache.shardingsphere.mode.node.path.version.VersionNodePathParser;
+
+import java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Storage node node path parser.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StorageNodeNodePathParser {
+    
+    private static final Pattern PATTERN = 
Pattern.compile(StorageNodeNodePathGenerator.getStorageNodePath(NodePathPattern.IDENTIFIER,
 NodePathPattern.IDENTIFIER) + "$", Pattern.CASE_INSENSITIVE);
+    
+    private static final VersionNodePathParser VERSION_PARSER =
+            new VersionNodePathParser(String.join("/", 
StorageNodeNodePathGenerator.getRootPath(NodePathPattern.IDENTIFIER), 
NodePathPattern.IDENTIFIER));
+    
+    /**
+     * Find storage node name.
+     *
+     * @param path path
+     * @return found storage node name
+     */
+    public static Optional<String> findStorageNodeName(final String path) {
+        Matcher matcher = PATTERN.matcher(path);
+        return matcher.find() ? Optional.of(matcher.group(2)) : 
Optional.empty();
+    }
+    
+    /**
+     * Get storage node version node path parser.
+     *
+     * @return storage node version node path parser
+     */
+    public static VersionNodePathParser getVersion() {
+        return VERSION_PARSER;
+    }
+}
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathGenerator.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathGenerator.java
new file mode 100644
index 00000000000..a7a5fe30e1f
--- /dev/null
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathGenerator.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.node.path.metadata.storage;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator;
+
+/**
+ * Storage unit node path generator.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StorageUnitNodePathGenerator {
+    
+    private static final String UNITS_NODE = "units";
+    
+    /**
+     * Get storage unit root path.
+     *
+     * @param databaseName database name
+     * @return storage unit root path
+     */
+    public static String getRootPath(final String databaseName) {
+        return String.join("/", 
DataSourceNodePathGenerator.getRootPath(databaseName), UNITS_NODE);
+    }
+    
+    /**
+     * Get storage unit path.
+     *
+     * @param databaseName database name
+     * @param storageUnitName storage unit name
+     * @return storage unit path
+     */
+    public static String getStorageUnitPath(final String databaseName, final 
String storageUnitName) {
+        return String.join("/", getRootPath(databaseName), storageUnitName);
+    }
+    
+    /**
+     * Get storage unit version node path generator.
+     *
+     * @param databaseName database name
+     * @param storageUnitName storage unit name
+     * @return storage unit version node path generator
+     */
+    public static VersionNodePathGenerator getVersion(final String 
databaseName, final String storageUnitName) {
+        return new VersionNodePathGenerator(String.join("/", 
getRootPath(databaseName), storageUnitName));
+    }
+}
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathParser.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathParser.java
new file mode 100644
index 00000000000..7ffece7b773
--- /dev/null
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathParser.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.node.path.metadata.storage;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.mode.node.path.NodePathPattern;
+import org.apache.shardingsphere.mode.node.path.version.VersionNodePathParser;
+
+import java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Storage unit node path parser.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StorageUnitNodePathParser {
+    
+    private static final Pattern PATTERN = 
Pattern.compile(StorageUnitNodePathGenerator.getStorageUnitPath(NodePathPattern.IDENTIFIER,
 NodePathPattern.IDENTIFIER) + "$", Pattern.CASE_INSENSITIVE);
+    
+    private static final VersionNodePathParser VERSION_PARSER =
+            new VersionNodePathParser(String.join("/", 
StorageUnitNodePathGenerator.getRootPath(NodePathPattern.IDENTIFIER), 
NodePathPattern.IDENTIFIER));
+    
+    /**
+     * Find storage unit name.
+     *
+     * @param path path
+     * @return found storage unit name
+     */
+    public static Optional<String> findStorageUnitName(final String path) {
+        Matcher matcher = PATTERN.matcher(path);
+        return matcher.find() ? Optional.of(matcher.group(2)) : 
Optional.empty();
+    }
+    
+    /**
+     * Get storage unit version unit path parser.
+     *
+     * @return storage unit version node path parser
+     */
+    public static VersionNodePathParser getVersion() {
+        return VERSION_PARSER;
+    }
+}
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathGeneratorTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathGeneratorTest.java
index 303716814ca..e58fa0d27e8 100644
--- 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathGeneratorTest.java
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathGeneratorTest.java
@@ -25,43 +25,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 class DataSourceNodePathGeneratorTest {
     
     @Test
-    void assertGetDataSourceRootPath() {
-        
assertThat(DataSourceNodePathGenerator.getDataSourceRootPath("foo_db"), 
is("/metadata/foo_db/data_sources"));
-    }
-    
-    @Test
-    void assertGetStorageUnitsPath() {
-        assertThat(DataSourceNodePathGenerator.getStorageUnitsPath("foo_db"), 
is("/metadata/foo_db/data_sources/units"));
-    }
-    
-    @Test
-    void assertGetStorageNodesPath() {
-        assertThat(DataSourceNodePathGenerator.getStorageNodesPath("foo_db"), 
is("/metadata/foo_db/data_sources/nodes"));
-    }
-    
-    @Test
-    void assertGetStorageUnitPath() {
-        assertThat(DataSourceNodePathGenerator.getStorageUnitPath("foo_db", 
"foo_ds"), is("/metadata/foo_db/data_sources/units/foo_ds"));
-    }
-    
-    @Test
-    void assertGetStorageNodePath() {
-        assertThat(DataSourceNodePathGenerator.getStorageNodePath("foo_db", 
"foo_ds"), is("/metadata/foo_db/data_sources/nodes/foo_ds"));
-    }
-    
-    @Test
-    void assertGetStorageUnitVersion() {
-        assertThat(DataSourceNodePathGenerator.getStorageUnitVersion("foo_db", 
"foo_ds").getActiveVersionPath(),
-                
is("/metadata/foo_db/data_sources/units/foo_ds/active_version"));
-        assertThat(DataSourceNodePathGenerator.getStorageUnitVersion("foo_db", 
"foo_ds").getVersionsPath(), 
is("/metadata/foo_db/data_sources/units/foo_ds/versions"));
-        assertThat(DataSourceNodePathGenerator.getStorageUnitVersion("foo_db", 
"foo_ds").getVersionPath(0), 
is("/metadata/foo_db/data_sources/units/foo_ds/versions/0"));
-    }
-    
-    @Test
-    void assertGetStorageNodeVersion() {
-        assertThat(DataSourceNodePathGenerator.getStorageNodeVersion("foo_db", 
"foo_ds").getActiveVersionPath(),
-                
is("/metadata/foo_db/data_sources/nodes/foo_ds/active_version"));
-        assertThat(DataSourceNodePathGenerator.getStorageNodeVersion("foo_db", 
"foo_ds").getVersionsPath(), 
is("/metadata/foo_db/data_sources/nodes/foo_ds/versions"));
-        assertThat(DataSourceNodePathGenerator.getStorageNodeVersion("foo_db", 
"foo_ds").getVersionPath(0), 
is("/metadata/foo_db/data_sources/nodes/foo_ds/versions/0"));
+    void assertGetRootPath() {
+        assertThat(DataSourceNodePathGenerator.getRootPath("foo_db"), 
is("/metadata/foo_db/data_sources"));
     }
 }
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
index 123d8fb6e7f..584c99771de 100644
--- 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
@@ -19,41 +19,12 @@ package 
org.apache.shardingsphere.mode.node.path.metadata.storage;
 
 import org.junit.jupiter.api.Test;
 
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class DataSourceNodePathParserTest {
     
     @Test
-    void assertFindStorageUnitNameByStorageUnitPath() {
-        Optional<String> actual = 
DataSourceNodePathParser.findStorageUnitNameByStorageUnitPath("/metadata/foo_db/data_sources/units/foo_ds");
-        assertTrue(actual.isPresent());
-        assertThat(actual.get(), is("foo_ds"));
-    }
-    
-    @Test
-    void assertFindStorageUnitNameByStorageUnitPathIfNotFound() {
-        
assertFalse(DataSourceNodePathParser.findStorageUnitNameByStorageUnitPath("/xxx/foo_db/data_sources/units/foo_ds").isPresent());
-    }
-    
-    @Test
-    void assertFindStorageNodeNameByStorageNodePath() {
-        Optional<String> actual = 
DataSourceNodePathParser.findStorageNodeNameByStorageNodePath("/metadata/foo_db/data_sources/nodes/foo_ds");
-        assertTrue(actual.isPresent());
-        assertThat(actual.get(), is("foo_ds"));
-    }
-    
-    @Test
-    void assertFindStorageNodeNameByStorageNodePathIfNotFound() {
-        
assertFalse(DataSourceNodePathParser.findStorageNodeNameByStorageNodePath("/xxx/foo_db/data_sources/nodes/foo_ds").isPresent());
-    }
-    
-    @Test
-    void assertIsDataSourceRootPath() {
-        
assertTrue(DataSourceNodePathParser.isDataSourceRootPath("/metadata/foo_db/data_sources/foo_ds"));
+    void assertIsDataSourcePath() {
+        
assertTrue(DataSourceNodePathParser.isDataSourcePath("/metadata/foo_db/data_sources/foo_ds"));
     }
 }
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathGeneratorTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathGeneratorTest.java
new file mode 100644
index 00000000000..0236c7c8af0
--- /dev/null
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathGeneratorTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.node.path.metadata.storage;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class StorageNodeNodePathGeneratorTest {
+    
+    @Test
+    void assertGetRootPath() {
+        assertThat(StorageNodeNodePathGenerator.getRootPath("foo_db"), 
is("/metadata/foo_db/data_sources/nodes"));
+    }
+    
+    @Test
+    void assertGetStorageNodePath() {
+        assertThat(StorageNodeNodePathGenerator.getStorageNodePath("foo_db", 
"foo_ds"), is("/metadata/foo_db/data_sources/nodes/foo_ds"));
+    }
+    
+    @Test
+    void assertGetVersion() {
+        assertThat(StorageNodeNodePathGenerator.getVersion("foo_db", 
"foo_ds").getActiveVersionPath(),
+                
is("/metadata/foo_db/data_sources/nodes/foo_ds/active_version"));
+        assertThat(StorageNodeNodePathGenerator.getVersion("foo_db", 
"foo_ds").getVersionsPath(), 
is("/metadata/foo_db/data_sources/nodes/foo_ds/versions"));
+        assertThat(StorageNodeNodePathGenerator.getVersion("foo_db", 
"foo_ds").getVersionPath(0), 
is("/metadata/foo_db/data_sources/nodes/foo_ds/versions/0"));
+    }
+}
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathParserTest.java
similarity index 52%
copy from 
mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
copy to 
mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathParserTest.java
index 123d8fb6e7f..9007ae98862 100644
--- 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageNodeNodePathParserTest.java
@@ -26,34 +26,17 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-class DataSourceNodePathParserTest {
+class StorageNodeNodePathParserTest {
     
     @Test
-    void assertFindStorageUnitNameByStorageUnitPath() {
-        Optional<String> actual = 
DataSourceNodePathParser.findStorageUnitNameByStorageUnitPath("/metadata/foo_db/data_sources/units/foo_ds");
+    void assertFindStorageNodeName() {
+        Optional<String> actual = 
StorageNodeNodePathParser.findStorageNodeName("/metadata/foo_db/data_sources/nodes/foo_ds");
         assertTrue(actual.isPresent());
         assertThat(actual.get(), is("foo_ds"));
     }
     
     @Test
-    void assertFindStorageUnitNameByStorageUnitPathIfNotFound() {
-        
assertFalse(DataSourceNodePathParser.findStorageUnitNameByStorageUnitPath("/xxx/foo_db/data_sources/units/foo_ds").isPresent());
-    }
-    
-    @Test
-    void assertFindStorageNodeNameByStorageNodePath() {
-        Optional<String> actual = 
DataSourceNodePathParser.findStorageNodeNameByStorageNodePath("/metadata/foo_db/data_sources/nodes/foo_ds");
-        assertTrue(actual.isPresent());
-        assertThat(actual.get(), is("foo_ds"));
-    }
-    
-    @Test
-    void assertFindStorageNodeNameByStorageNodePathIfNotFound() {
-        
assertFalse(DataSourceNodePathParser.findStorageNodeNameByStorageNodePath("/xxx/foo_db/data_sources/nodes/foo_ds").isPresent());
-    }
-    
-    @Test
-    void assertIsDataSourceRootPath() {
-        
assertTrue(DataSourceNodePathParser.isDataSourceRootPath("/metadata/foo_db/data_sources/foo_ds"));
+    void assertFindStorageNodeNameIfNotFound() {
+        
assertFalse(StorageNodeNodePathParser.findStorageNodeName("/xxx/foo_db/data_sources/nodes/foo_ds").isPresent());
     }
 }
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathGeneratorTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathGeneratorTest.java
new file mode 100644
index 00000000000..937e936acfd
--- /dev/null
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathGeneratorTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.node.path.metadata.storage;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class StorageUnitNodePathGeneratorTest {
+    
+    @Test
+    void assertGetRootPath() {
+        assertThat(StorageUnitNodePathGenerator.getRootPath("foo_db"), 
is("/metadata/foo_db/data_sources/units"));
+    }
+    
+    @Test
+    void assertGetStorageUnitPath() {
+        assertThat(StorageUnitNodePathGenerator.getStorageUnitPath("foo_db", 
"foo_ds"), is("/metadata/foo_db/data_sources/units/foo_ds"));
+    }
+    
+    @Test
+    void assertGetVersion() {
+        assertThat(StorageUnitNodePathGenerator.getVersion("foo_db", 
"foo_ds").getActiveVersionPath(),
+                
is("/metadata/foo_db/data_sources/units/foo_ds/active_version"));
+        assertThat(StorageUnitNodePathGenerator.getVersion("foo_db", 
"foo_ds").getVersionsPath(), 
is("/metadata/foo_db/data_sources/units/foo_ds/versions"));
+        assertThat(StorageUnitNodePathGenerator.getVersion("foo_db", 
"foo_ds").getVersionPath(0), 
is("/metadata/foo_db/data_sources/units/foo_ds/versions/0"));
+    }
+}
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathParserTest.java
similarity index 52%
copy from 
mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
copy to 
mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathParserTest.java
index 123d8fb6e7f..2f682e9b79c 100644
--- 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceNodePathParserTest.java
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/storage/StorageUnitNodePathParserTest.java
@@ -26,34 +26,17 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-class DataSourceNodePathParserTest {
+class StorageUnitNodePathParserTest {
     
     @Test
-    void assertFindStorageUnitNameByStorageUnitPath() {
-        Optional<String> actual = 
DataSourceNodePathParser.findStorageUnitNameByStorageUnitPath("/metadata/foo_db/data_sources/units/foo_ds");
+    void assertFindStorageUnitName() {
+        Optional<String> actual = 
StorageUnitNodePathParser.findStorageUnitName("/metadata/foo_db/data_sources/units/foo_ds");
         assertTrue(actual.isPresent());
         assertThat(actual.get(), is("foo_ds"));
     }
     
     @Test
-    void assertFindStorageUnitNameByStorageUnitPathIfNotFound() {
-        
assertFalse(DataSourceNodePathParser.findStorageUnitNameByStorageUnitPath("/xxx/foo_db/data_sources/units/foo_ds").isPresent());
-    }
-    
-    @Test
-    void assertFindStorageNodeNameByStorageNodePath() {
-        Optional<String> actual = 
DataSourceNodePathParser.findStorageNodeNameByStorageNodePath("/metadata/foo_db/data_sources/nodes/foo_ds");
-        assertTrue(actual.isPresent());
-        assertThat(actual.get(), is("foo_ds"));
-    }
-    
-    @Test
-    void assertFindStorageNodeNameByStorageNodePathIfNotFound() {
-        
assertFalse(DataSourceNodePathParser.findStorageNodeNameByStorageNodePath("/xxx/foo_db/data_sources/nodes/foo_ds").isPresent());
-    }
-    
-    @Test
-    void assertIsDataSourceRootPath() {
-        
assertTrue(DataSourceNodePathParser.isDataSourceRootPath("/metadata/foo_db/data_sources/foo_ds"));
+    void assertFindStorageUnitNameIfNotFound() {
+        
assertFalse(StorageUnitNodePathParser.findStorageUnitName("/xxx/foo_db/data_sources/units/foo_ds").isPresent());
     }
 }
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/metadata/MetaDataChangedHandler.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/metadata/MetaDataChangedHandler.java
index cb9fd5f1028..4b0016df430 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/metadata/MetaDataChangedHandler.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/metadata/MetaDataChangedHandler.java
@@ -29,6 +29,8 @@ import 
org.apache.shardingsphere.mode.node.path.metadata.database.SchemaNodePath
 import 
org.apache.shardingsphere.mode.node.path.metadata.database.TableNodePathParser;
 import 
org.apache.shardingsphere.mode.node.path.metadata.database.ViewNodePathParser;
 import 
org.apache.shardingsphere.mode.node.path.metadata.storage.DataSourceNodePathParser;
+import 
org.apache.shardingsphere.mode.node.path.metadata.storage.StorageNodeNodePathParser;
+import 
org.apache.shardingsphere.mode.node.path.metadata.storage.StorageUnitNodePathParser;
 
 import java.util.Optional;
 
@@ -78,7 +80,7 @@ public final class MetaDataChangedHandler {
             handleViewChanged(databaseName, schemaName.get(), event);
             return true;
         }
-        if (DataSourceNodePathParser.isDataSourceRootPath(eventKey)) {
+        if (DataSourceNodePathParser.isDataSourcePath(eventKey)) {
             handleDataSourceChanged(databaseName, event);
             return true;
         }
@@ -118,20 +120,20 @@ public final class MetaDataChangedHandler {
     }
     
     private void handleDataSourceChanged(final String databaseName, final 
DataChangedEvent event) {
-        Optional<String> storageUnitName = 
DataSourceNodePathParser.getStorageUnitVersion().findIdentifierByActiveVersionPath(event.getKey(),
 2);
+        Optional<String> storageUnitName = 
StorageUnitNodePathParser.getVersion().findIdentifierByActiveVersionPath(event.getKey(),
 2);
         boolean isActiveVersion = true;
         if (!storageUnitName.isPresent()) {
-            storageUnitName = 
DataSourceNodePathParser.findStorageUnitNameByStorageUnitPath(event.getKey());
+            storageUnitName = 
StorageUnitNodePathParser.findStorageUnitName(event.getKey());
             isActiveVersion = false;
         }
         if (storageUnitName.isPresent()) {
             handleStorageUnitChanged(databaseName, event, 
storageUnitName.get(), isActiveVersion);
             return;
         }
-        Optional<String> storageNodeName = 
DataSourceNodePathParser.getStorageNodeVersion().findIdentifierByActiveVersionPath(event.getKey(),
 2);
+        Optional<String> storageNodeName = 
StorageNodeNodePathParser.getVersion().findIdentifierByActiveVersionPath(event.getKey(),
 2);
         isActiveVersion = true;
         if (!storageNodeName.isPresent()) {
-            storageNodeName = 
DataSourceNodePathParser.findStorageNodeNameByStorageNodePath(event.getKey());
+            storageNodeName = 
StorageNodeNodePathParser.findStorageNodeName(event.getKey());
             isActiveVersion = false;
         }
         if (storageNodeName.isPresent()) {


Reply via email to