rocketmq-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (ROCKETMQ-243) BrokerData#selectBrokerAddr() picks the 1st element in the list of addresses
Date Wed, 12 Jul 2017 03:19:00 GMT

    [ https://issues.apache.org/jira/browse/ROCKETMQ-243?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16083361#comment-16083361
] 

ASF GitHub Bot commented on ROCKETMQ-243:
-----------------------------------------

Github user vsair commented on a diff in the pull request:

    https://github.com/apache/incubator-rocketmq/pull/130#discussion_r126856546
  
    --- 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 --
    
    why not use values to construct list directly?


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

Mime
View raw message