[ https://issues.apache.org/jira/browse/ROCKETMQ-243?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16083472#comment-16083472 ]
ASF GitHub Bot commented on ROCKETMQ-243: ----------------------------------------- Github user shroman commented on a diff in the pull request: https://github.com/apache/incubator-rocketmq/pull/130#discussion_r126867179 --- Diff: common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java --- @@ -37,15 +41,21 @@ public BrokerData(String cluster, String brokerName, HashMap<Long, String> broke this.brokerAddrs = brokerAddrs; } + /** + * Selects a (preferably master) broker address from the registered list. + * If the master's address cannot be found, a slave broker address is selected in a random manner. + * + * @return Broker address. + */ public String selectBrokerAddr() { - String value = this.brokerAddrs.get(MixAll.MASTER_ID); - if (null == value) { - for (Map.Entry<Long, String> entry : this.brokerAddrs.entrySet()) { - return entry.getValue(); - } + String addr = this.brokerAddrs.get(MixAll.MASTER_ID); + + if (addr == null) { + List<Long> keys = new ArrayList<Long>(brokerAddrs.keySet()); + return brokerAddrs.get(keys.get(random.nextInt(keys.size()))); --- End diff -- Ok, changed to the list. > BrokerData#selectBrokerAddr() picks the 1st element in the list of addresses > ---------------------------------------------------------------------------- > > Key: ROCKETMQ-243 > URL: https://issues.apache.org/jira/browse/ROCKETMQ-243 > Project: Apache RocketMQ > Issue Type: Improvement > Components: rocketmq-commons > Affects Versions: 4.1.0-incubating > Reporter: Roman Shtykh > Assignee: Roman Shtykh > Priority: Minor > > I wonder if this can cause broker contention. Therefore I propose to pick the > address at least in a random manner. -- This message was sent by Atlassian JIRA (v6.4.14#64029)