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 37ea7f8040f Remove useless codes on StorageNodeNodePath and StorageUnitNodePath (#34892) 37ea7f8040f is described below commit 37ea7f8040f61fdbff39a9673dfdb7a2a236f82f Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Wed Mar 5 22:42:21 2025 +0800 Remove useless codes on StorageNodeNodePath and StorageUnitNodePath (#34892) --- .../node/path/type/metadata/storage/StorageNodeNodePath.java | 9 +++------ .../node/path/type/metadata/storage/StorageUnitNodePath.java | 9 +++------ .../node/path/type/metadata/storage/StorageNodeNodePathTest.java | 5 +++-- .../node/path/type/metadata/storage/StorageUnitNodePathTest.java | 5 +++-- .../handler/database/datasource/StorageNodeChangedHandler.java | 2 +- .../handler/database/datasource/StorageUnitChangedHandler.java | 2 +- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageNodeNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageNodeNodePath.java index 8f379351b29..f28223b0acc 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageNodeNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageNodeNodePath.java @@ -36,16 +36,13 @@ public final class StorageNodeNodePath implements NodePath { private final String storageNodeName; - public StorageNodeNodePath() { - this(NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER); - } - /** * Create storage node search criteria. * + * @param databaseName database name * @return created search criteria */ - public static NodePathSearchCriteria createStorageNodeSearchCriteria() { - return new NodePathSearchCriteria(new StorageNodeNodePath(), false, true, 2); + public static NodePathSearchCriteria createStorageNodeSearchCriteria(final String databaseName) { + return new NodePathSearchCriteria(new StorageNodeNodePath(databaseName, NodePathPattern.IDENTIFIER), false, true, 1); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageUnitNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageUnitNodePath.java index 1cc6ef78bbd..ad18c72dd2e 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageUnitNodePath.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageUnitNodePath.java @@ -36,16 +36,13 @@ public final class StorageUnitNodePath implements NodePath { private final String storageUnitName; - public StorageUnitNodePath() { - this(NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER); - } - /** * Create storage unit search criteria. * + * @param databaseName database name * @return created search criteria */ - public static NodePathSearchCriteria createStorageUnitSearchCriteria() { - return new NodePathSearchCriteria(new StorageUnitNodePath(), false, true, 2); + public static NodePathSearchCriteria createStorageUnitSearchCriteria(final String databaseName) { + return new NodePathSearchCriteria(new StorageUnitNodePath(databaseName, NodePathPattern.IDENTIFIER), false, true, 1); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageNodeNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageNodeNodePathTest.java index 2bd9219bb53..0f8aeac99c8 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageNodeNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageNodeNodePathTest.java @@ -37,7 +37,8 @@ class StorageNodeNodePathTest { @Test void assertCreateStorageNodeSearchCriteria() { - assertThat(NodePathSearcher.find("/metadata/foo_db/data_sources/nodes/foo_ds", StorageNodeNodePath.createStorageNodeSearchCriteria()), is(Optional.of("foo_ds"))); - assertFalse(NodePathSearcher.find("/xxx/foo_db/data_sources/nodes/foo_ds", StorageNodeNodePath.createStorageNodeSearchCriteria()).isPresent()); + assertThat(NodePathSearcher.find("/metadata/foo_db/data_sources/nodes/foo_ds", StorageNodeNodePath.createStorageNodeSearchCriteria("foo_db")), is(Optional.of("foo_ds"))); + assertFalse(NodePathSearcher.find("/xxx/foo_db/data_sources/nodes/foo_ds", StorageNodeNodePath.createStorageNodeSearchCriteria("foo_db")).isPresent()); + assertFalse(NodePathSearcher.find("/metadata/bar_db/data_sources/nodes/foo_ds", StorageNodeNodePath.createStorageNodeSearchCriteria("foo_db")).isPresent()); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageUnitNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageUnitNodePathTest.java index c932266939b..c197d38c6f4 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageUnitNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/type/metadata/storage/StorageUnitNodePathTest.java @@ -37,7 +37,8 @@ class StorageUnitNodePathTest { @Test void assertCreateStorageUnitSearchCriteria() { - assertThat(NodePathSearcher.find("/metadata/foo_db/data_sources/units/foo_ds", StorageUnitNodePath.createStorageUnitSearchCriteria()), is(Optional.of("foo_ds"))); - assertFalse(NodePathSearcher.find("/xxx/foo_db/data_sources/units/foo_ds", StorageUnitNodePath.createStorageUnitSearchCriteria()).isPresent()); + assertThat(NodePathSearcher.find("/metadata/foo_db/data_sources/units/foo_ds", StorageUnitNodePath.createStorageUnitSearchCriteria("foo_db")), is(Optional.of("foo_ds"))); + assertFalse(NodePathSearcher.find("/xxx/foo_db/data_sources/units/foo_ds", StorageUnitNodePath.createStorageUnitSearchCriteria("foo_db")).isPresent()); + assertFalse(NodePathSearcher.find("/metadata/bar_db/data_sources/units/foo_ds", StorageUnitNodePath.createStorageUnitSearchCriteria("foo_db")).isPresent()); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/datasource/StorageNodeChangedHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/datasource/StorageNodeChangedHandler.java index ea5d96fe644..2ed08a5c486 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/datasource/StorageNodeChangedHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/datasource/StorageNodeChangedHandler.java @@ -43,7 +43,7 @@ public final class StorageNodeChangedHandler implements DatabaseChangedHandler { @Override public void handle(final String databaseName, final DataChangedEvent event) { - Optional<String> storageNodeName = NodePathSearcher.find(event.getKey(), StorageNodeNodePath.createStorageNodeSearchCriteria()); + Optional<String> storageNodeName = NodePathSearcher.find(event.getKey(), StorageNodeNodePath.createStorageNodeSearchCriteria(databaseName)); if (!storageNodeName.isPresent()) { return; } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/datasource/StorageUnitChangedHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/datasource/StorageUnitChangedHandler.java index 1b252743fa1..8bf41ff720d 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/datasource/StorageUnitChangedHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/database/datasource/StorageUnitChangedHandler.java @@ -52,7 +52,7 @@ public final class StorageUnitChangedHandler implements DatabaseChangedHandler { @Override public void handle(final String databaseName, final DataChangedEvent event) { - Optional<String> storageUnitName = NodePathSearcher.find(event.getKey(), StorageUnitNodePath.createStorageUnitSearchCriteria()); + Optional<String> storageUnitName = NodePathSearcher.find(event.getKey(), StorageUnitNodePath.createStorageUnitSearchCriteria(databaseName)); if (!storageUnitName.isPresent()) { return; }