rocketMQ 4.5.1 No route info of this topic

心无私天地宽
  • 503

rocketMQ 版本

4.5.1

集群配置

2m-2s

出现问题

客户端偶而出现:No route info of this topic

其他信息

  1. topic 是有创建的,客户端出现这种情况是偶发
  2. 在 rocketMQ namesrv 源码可以看到。当 pickupTopicRouteData 方法返回的值为 null 时,会返回刚才的报错信息给客户端

    public class DefaultRequestProcessor {
    public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx,
         RemotingCommand request) throws RemotingCommandException {
         final RemotingCommand response = RemotingCommand.createResponseCommand(null);
         final GetRouteInfoRequestHeader requestHeader =
             (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class);
    
         TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic());
    
         if (topicRouteData != null) {
             if (this.namesrvController.getNamesrvConfig().isOrderMessageEnable()) {
                 String orderTopicConf =
                     this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG,
                         requestHeader.getTopic());
                 topicRouteData.setOrderTopicConf(orderTopicConf);
             }
    
             byte[] content = topicRouteData.encode();
             response.setBody(content);
             response.setCode(ResponseCode.SUCCESS);
             response.setRemark(null);
             return response;
         }
    
         response.setCode(ResponseCode.TOPIC_NOT_EXIST);
         response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic()
             + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL));
         return response;
     }
    }
  3. 什么情况下 pickupTopicRouteData 会返回 null?

    public class RouteInfoManager {
    public TopicRouteData pickupTopicRouteData(final String topic) {
         TopicRouteData topicRouteData = new TopicRouteData();
         boolean foundQueueData = false;
         boolean foundBrokerData = false;
         Set<String> brokerNameSet = new HashSet<String>();
         List<BrokerData> brokerDataList = new LinkedList<BrokerData>();
         topicRouteData.setBrokerDatas(brokerDataList);
    
         HashMap<String, List<String>> filterServerMap = new HashMap<String, List<String>>();
         topicRouteData.setFilterServerTable(filterServerMap);
    
         try {
             try {
                 this.lock.readLock().lockInterruptibly();
                 List<QueueData> queueDataList = this.topicQueueTable.get(topic);
                 if (queueDataList != null) {
                     topicRouteData.setQueueDatas(queueDataList);
                     foundQueueData = true;
    
                     Iterator<QueueData> it = queueDataList.iterator();
                     while (it.hasNext()) {
                         QueueData qd = it.next();
                         brokerNameSet.add(qd.getBrokerName());
                     }
    
                     for (String brokerName : brokerNameSet) {
                         BrokerData brokerData = this.brokerAddrTable.get(brokerName);
                         if (null != brokerData) {
                             BrokerData brokerDataClone = new BrokerData(brokerData.getCluster(), brokerData.getBrokerName(), (HashMap<Long, String>) brokerData
                                 .getBrokerAddrs().clone());
                             brokerDataList.add(brokerDataClone);
                             foundBrokerData = true;
                             for (final String brokerAddr : brokerDataClone.getBrokerAddrs().values()) {
                                 List<String> filterServerList = this.filterServerTable.get(brokerAddr);
                                 filterServerMap.put(brokerAddr, filterServerList);
                             }
                         }
                     }
                 }
             } finally {
                 this.lock.readLock().unlock();
             }
         } catch (Exception e) {
             log.error("pickupTopicRouteData Exception", e);
         }
    
         log.debug("pickupTopicRouteData {} {}", topic, topicRouteData);
    
         if (foundBrokerData && foundQueueData) {
             return topicRouteData;
         }
    
         return null;
     }
    }

从代码,可以看到, 当 foundBrokerData && foundQueueData 值为 false 时,会返回 null.

  1. 什么情况 foundBrokerData OR foundQueueDatanull
    从代码看,加锁失败! 或者方法执行失败会返回 null。 但是, 方法执行失败,这个根本不可能,也就是只能是加锁失败了。
  2. 什么时候加锁会失败???????
回复
阅读 366
1 个回答

无语了:

同事连了 3 个 namesrv。 而其中 1个 namesrv 不在 集群中。
所以服务在启动的时候,可能会连接到 不在 集群中的 namesrv

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏