You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/10/29 03:25:30 UTC

[GitHub] [shardingsphere] zjcnb opened a new issue #13345: CuratorCache.start() method used not right in CuratorZookeeperRepository

zjcnb opened a new issue #13345:
URL: https://github.com/apache/shardingsphere/issues/13345


   Hi community,
   
   version: master branch
   
   I think CuratorCache.start() method used not right in CuratorZookeeperRepository. So as to cause the first key set to monitor cannot receive zookeeper event notification 
   
   `Old code:`
   ```
     @Override
       public void watch(final String key, final DataChangedEventListener listener) {
           String path = key + PATH_SEPARATOR;
           if (!caches.containsKey(path)) {
               addCacheData(key);
               CuratorCache cache = caches.get(path);
               CuratorCacheListener curatorCacheListener = CuratorCacheListener.builder()
                   .forTreeCache(client, (framework, treeCacheListener) -> {
                       Type changedType = getChangedType(treeCacheListener.getType());
                       if (Type.IGNORED != changedType) {
                           System.out.println("treeCacheListener.getData().getPath() is :" + treeCacheListener.getData().getPath());
                           listener.onChange(new DataChangedEvent(treeCacheListener.getData().getPath(), 
                                   new String(treeCacheListener.getData().getData(), StandardCharsets.UTF_8), changedType));
                       }
                   }).build();
               cache.listenable().addListener(curatorCacheListener);
           }
       }
       
       private void addCacheData(final String cachePath) {
           CuratorCache cache = CuratorCache.build(client, cachePath);
           try {
               cache.start();
               // CHECKSTYLE:OFF
           } catch (final Exception ex) {
               // CHECKSTYLE:ON
               CuratorZookeeperExceptionHandler.handleException(ex);
           }
           caches.put(cachePath + PATH_SEPARATOR, cache);
       }
   ```
   
   `Old result:`
   ```
   treeCacheListener.getData().getPath() is :/metadata
   treeCacheListener.getData().getPath() is :/rules
   treeCacheListener.getData().getPath() is :/metadata/database_discovery_db
   treeCacheListener.getData().getPath() is :/props
   treeCacheListener.getData().getPath() is :/status/compute_nodes
   treeCacheListener.getData().getPath() is :/lock/locks
   treeCacheListener.getData().getPath() is :/metadata/database_discovery_db/schema
   treeCacheListener.getData().getPath() is :/metadata/database_discovery_db/rules
   treeCacheListener.getData().getPath() is :/metadata/database_discovery_db/dataSources
   treeCacheListener.getData().getPath() is :/status/compute_nodes/online
   treeCacheListener.getData().getPath() is :/status/compute_nodes/online/192.168.5.69@3307
   ```
   
   `New code:`
   ```
    @Override
       public void watch(final String key, final DataChangedEventListener listener) {
           String path = key + PATH_SEPARATOR;
           if (!caches.containsKey(path)) {
               addCacheData(key);
               CuratorCache cache = caches.get(path);
               CuratorCacheListener curatorCacheListener = CuratorCacheListener.builder()
                   .forTreeCache(client, (framework, treeCacheListener) -> {
                       Type changedType = getChangedType(treeCacheListener.getType());
                       if (Type.IGNORED != changedType) {
                           System.out.println("treeCacheListener.getData().getPath() is :" + treeCacheListener.getData().getPath());
                           listener.onChange(new DataChangedEvent(treeCacheListener.getData().getPath(),
                                   new String(treeCacheListener.getData().getData(), StandardCharsets.UTF_8), changedType));
                       }
                   }).build();
               cache.listenable().addListener(curatorCacheListener);
               start(cache);
           }
       }
       
       public void start(CuratorCache cache) {
           try {
               cache.start();
               // CHECKSTYLE:OFF
           } catch (final Exception ex) {
               // CHECKSTYLE:ON
               CuratorZookeeperExceptionHandler.handleException(ex);
           }
       }
       
       private void addCacheData(final String cachePath) {
           CuratorCache cache = CuratorCache.build(client, cachePath);
           caches.put(cachePath + PATH_SEPARATOR, cache);
       }
   ```
   
   `New result:`
   ```
   treeCacheListener.getData().getPath() is :/status/storage_nodes
   treeCacheListener.getData().getPath() is :/metadata
   treeCacheListener.getData().getPath() is :/rules
   treeCacheListener.getData().getPath() is :/props
   treeCacheListener.getData().getPath() is :/status/compute_nodes
   treeCacheListener.getData().getPath() is :/lock/locks
   treeCacheListener.getData().getPath() is :/status/storage_nodes/primary
   treeCacheListener.getData().getPath() is :/metadata/database_discovery_db
   treeCacheListener.getData().getPath() is :/status/compute_nodes/online
   treeCacheListener.getData().getPath() is :/status/storage_nodes/primary/database_discovery_db.pr_ds
   treeCacheListener.getData().getPath() is :/metadata/database_discovery_db/schema
   treeCacheListener.getData().getPath() is :/metadata/database_discovery_db/rules
   treeCacheListener.getData().getPath() is :/metadata/database_discovery_db/dataSources
   treeCacheListener.getData().getPath() is :/status/compute_nodes/online/192.168.5.69@3307
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] menghaoranss closed issue #13345: CuratorCache.start() method used not right in CuratorZookeeperRepository

Posted by GitBox <gi...@apache.org>.
menghaoranss closed issue #13345:
URL: https://github.com/apache/shardingsphere/issues/13345


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org