TheR1sing3un commented on code in PR #6100:
URL: https://github.com/apache/rocketmq/pull/6100#discussion_r1113843544
##########
broker/src/main/java/org/apache/rocketmq/broker/controller/ReplicasManager.java:
##########
@@ -296,24 +347,89 @@ private void handleSlaveSynchronize(final BrokerRole
role) {
}
}
+ private boolean brokerElect() {
+ // Broker try to elect itself as a master in broker set.
+ try {
+ ElectMasterResponseHeader tryElectResponse =
this.brokerOuterAPI.brokerElect(this.controllerLeaderAddress,
this.brokerConfig.getBrokerClusterName(),
+ this.brokerConfig.getBrokerName(), this.brokerId);
+ final String masterAddress = tryElectResponse.getMasterAddress();
+ final Long masterBrokerId = tryElectResponse.getMasterBrokerId();
+ if (StringUtils.isEmpty(masterAddress) || masterBrokerId == null) {
+ LOGGER.warn("Now no master in broker set");
+ return false;
+ }
+
+ if (masterBrokerId.equals(this.brokerId)) {
+ changeToMaster(tryElectResponse.getMasterEpoch(),
tryElectResponse.getSyncStateSetEpoch());
+ } else {
+ changeToSlave(masterAddress,
tryElectResponse.getMasterEpoch(), tryElectResponse.getMasterBrokerId());
+ }
+ brokerController.setIsolated(false);
+ return true;
+ } catch (Exception e) {
+ LOGGER.error("Failed to try elect", e);
+ return false;
+ }
+ }
+
+ public void sendHeartbeatToController() {
+ final List<String> controllerAddresses =
this.getAvailableControllerAddresses();
+ for (String controllerAddress : controllerAddresses) {
+ if (StringUtils.isNotEmpty(controllerAddress)) {
+ this.brokerOuterAPI.sendHeartbeatToController(
+ controllerAddress,
+ this.brokerConfig.getBrokerClusterName(),
+ this.localAddress,
+ this.brokerConfig.getBrokerName(),
+ this.brokerId,
Review Comment:
> How about `this.localAddress` rename `this.brokerAddress`?
done~
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]