You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/08/09 15:25:23 UTC

[GitHub] [rocketmq] mxsm commented on a diff in pull request #4798: [ISSUE #4791] Add elect master command for admin CLI

mxsm commented on code in PR #4798:
URL: https://github.com/apache/rocketmq/pull/4798#discussion_r941482729


##########
controller/src/main/java/org/apache/rocketmq/controller/impl/manager/ReplicasInfoManager.java:
##########
@@ -160,25 +161,30 @@ public ControllerResult<ElectMasterResponseHeader> electMaster(
             // First, check whether the master is still active
             final String oldMaster = syncStateInfo.getMasterAddress();
             if (StringUtils.isNoneEmpty(oldMaster) && brokerAlivePredicate.test(brokerInfo.getClusterName(), oldMaster)) {
-                String err = String.format("The old master %s is still alive, not need to elect new master for broker %s", oldMaster, brokerInfo.getBrokerName());
-                log.warn("{}", err);
-                result.setCodeAndRemark(ResponseCode.CONTROLLER_INVALID_REQUEST, err);
-                return result;
+
+                if (StringUtils.isBlank(assignBrokerAddress) || StringUtils.equals(oldMaster, assignBrokerAddress)) {
+                    String err = String.format("The old master %s is still alive, not need to elect new master for broker %s", oldMaster, brokerInfo.getBrokerName());
+                    log.warn("{}", err);
+                    result.setCodeAndRemark(ResponseCode.CONTROLLER_INVALID_REQUEST, err);
+                    return result;
+                }
             }
 
             // Try elect a master in syncStateSet
             if (syncStateSet.size() > 1) {
-                boolean electSuccess = tryElectMaster(result, brokerName, syncStateSet, candidate ->
-                    !candidate.equals(syncStateInfo.getMasterAddress()) && brokerAlivePredicate.test(brokerInfo.getClusterName(), candidate));
+                boolean electSuccess = tryElectMaster(result, brokerName, assignBrokerAddress, syncStateSet, candidate ->
+                    (StringUtils.isEmpty(assignBrokerAddress) ? !StringUtils.equals(candidate, syncStateInfo.getMasterAddress()) : true)

Review Comment:
   Redundant check, I remove it



-- 
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: dev-unsubscribe@rocketmq.apache.org

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