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/11/09 03:54:14 UTC

[GitHub] [dubbo] chickenlj edited a comment on issue #6443: 支持直连模式下,在连接不可用时的快速失败

chickenlj edited a comment on issue #6443:
URL: https://github.com/apache/dubbo/issues/6443#issuecomment-963792264


   我有一些疑问或需要确认的点,不论是直连或非直连模式,如果采用默认配置 `lazy="true"` `send.reconnect=true`,会发生什么行为:
   
   第一次 request 时会执行链接建立,此时
   * 如果建立链接成功。一切正常运行
   * 如果建立链接失败。首先 request 调用会以 RemotingException 终止;而 LazyConnectExchangeClient 的状态如下:
   ```java
   class LazyConnectExchangeClient {
       private boolean initialState = true;
       private Client client = null // 因为 client 创建以 RemotingException 终止了
   
     // 后续每次请求都会尝试 client 建连(client=null)。请求之所以会到这里是因为 isConnected() 始终指示调用者可用
     private void initClient() throws RemotingException {
           if (client != null) {
               return;
           }
           if (logger.isInfoEnabled()) {
               logger.info("Lazy connect to " + url);
           }
           connectLock.lock();
           try {
               if (client != null) {
                   return;
               }
               this.client = Exchangers.connect(url, requestHandler);
           } finally {
               connectLock.unlock();
           }
       }
       
     // 始终返回 initialState = true,告诉外围链接可用,实际上上一次建连失败了
      public boolean isConnected() {
           if (client == null) {
               return initialState; 
           } else {
               return client.isConnected();
           }
      }
   }
   ```
   
   我认为 LazyConnectExchangeClient 正常工作的情况应该是,第一次请求时尝试主动建连,后续依赖 ReconnectTask 建连,而不是一直重复建连。这意味着 LazyConnectExchangeClient 需要增加更多状态,可能的改法是:
   * 第一次 request 尝试建立 client 链接,此时无论如何 client 实例都要生成,并根据client状态告知此次request结果,如决策是否抛出 RemotingException
   * 后续 request。理论上来说后续 request 在 client 可用之前不会进来,因为此时 isConnected 能准确的反映 LazyClient 的连接状态。不论因为什么原因(如外围没做连接管理的高可用策略),如果 request 进入了一个当前不可用的 LazyClient,则可以依据 client 的状态快速失败(另一个选择是始终尝试建立链接,但我认为这样不太好)。


-- 
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