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

menghaoran 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 33bd777f70e Refactor CuratorCache build logic (#18363)
33bd777f70e is described below

commit 33bd777f70e915bfcf719d46447d07ffd8315c21
Author: zhaojinchao <[email protected]>
AuthorDate: Wed Jun 15 14:25:48 2022 +0800

    Refactor CuratorCache build logic (#18363)
    
    * Refactor CuratorCache build logic
    
    * Adjust it
---
 .../cluster/zookeeper/CuratorZookeeperRepository.java         | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-prov
 [...]
index dc99c14f00d..61358682878 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java
@@ -228,10 +228,10 @@ public final class CuratorZookeeperRepository implements 
ClusterPersistRepositor
     
     @Override
     public void watch(final String key, final DataChangedEventListener 
listener) {
-        if (!caches.containsKey(key)) {
-            CuratorCache curatorCache = CuratorCache.build(client, key);
-            start(curatorCache);
-            caches.put(key, curatorCache);
+        CuratorCache cache = caches.get(key);
+        if (null == cache) {
+            cache = CuratorCache.build(client, key);
+            caches.put(key, cache);
         }
         CuratorCacheListener curatorCacheListener = 
CuratorCacheListener.builder()
                 .forTreeCache(client, (framework, treeCacheListener) -> {
@@ -241,7 +241,8 @@ public final class CuratorZookeeperRepository implements 
ClusterPersistRepositor
                                 new 
String(treeCacheListener.getData().getData(), StandardCharsets.UTF_8), 
changedType));
                     }
                 }).build();
-        caches.get(key).listenable().addListener(curatorCacheListener);
+        cache.listenable().addListener(curatorCacheListener);
+        start(cache);
     }
     
     private void start(final CuratorCache cache) {

Reply via email to