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

[GitHub] [dubbo] fsx379 edited a comment on issue #7897: 使用curator 订阅多注册中心(使用zookeeper)的问题讨论

fsx379 edited a comment on issue #7897:
URL: https://github.com/apache/dubbo/issues/7897#issuecomment-894147835


   在CuratorZookeeperClient中,对于create/delete/getchildren/checkExists代码,调用client增删改查前,是否可以加入isConnected() 判断,如果没有连接成功,直接抛出一个异常,然后操作就结束了。
   (1)由于抛出了异常,上层 FailbackRegistry 捕获并定期重试create\delete 等;(参考zkClientWrapper写法)
   (2)client重试连接,交给curator框架自动重试;
   
   不知道这么改有什么风险
   
   ```
       @Override
       public void createPersistent(String path) {
           try {
               if(!this.isConnected()){
                   throw new IllegalStateException("Zookeeper is not connected yet!");
               }
               client.create().forPath(path);
           } catch (NodeExistsException e) {
           } catch (Exception e) {
               throw new IllegalStateException(e.getMessage(), e);
           }
       }
   
       public boolean checkExists(String path) {
           try {
               if(!this.isConnected()){
                   throw new IllegalStateException("Zookeeper is not connected yet!");
               }
               if (client.checkExists().forPath(path) != null) {
                   return true;
               }
           } catch (Exception e) {
           }
           return false;
       }
   ```
   
   第二,在类初始化过程中,在 client.start() 之后,增加 一个卡点,防止zk异步告知connected之前,就开始做create等操作,导致打印异常日志。
   
   ```
   public CuratorZookeeperClient(URL url) {
           super(url);
           try {
               int timeout = url.getParameter(Constants.TIMEOUT_KEY, 5000);
              ........
               client.start();
             //add check
               try{
                   listenableFutureTask = ListenableFutureTask.create(new Callable<Boolean>() {
                       @Override
                       public Boolean call(){
                           try {
                               if (client.checkExists().forPath("/dubbo") != null) {
                                   return true;
                               }
                           } catch (Exception e) {
                           }
                           return false;
                       }
                   });
                   listenableFutureTask.get(timeout, TimeUnit.MILLISECONDS);
               }catch (Exception e){}
           } catch (Exception e) {
               throw new IllegalStateException(e.getMessage(), e);
           }
       }
   ```


-- 
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@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org