You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by zh...@apache.org on 2022/06/15 11:50:07 UTC
[rocketmq] branch 5.0.0-beta-dledger-controller updated: Polish the logic of change to master (#4464)
This is an automated email from the ASF dual-hosted git repository.
zhoubo pushed a commit to branch 5.0.0-beta-dledger-controller
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/5.0.0-beta-dledger-controller by this push:
new fd804d9a9 Polish the logic of change to master (#4464)
fd804d9a9 is described below
commit fd804d9a95346b005e8c62c6f275e4bb710e1a53
Author: rongtong <ji...@163.com>
AuthorDate: Wed Jun 15 19:50:00 2022 +0800
Polish the logic of change to master (#4464)
---
.../broker/hacontroller/ReplicasManager.java | 25 +++++++++++++---------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/broker/src/main/java/org/apache/rocketmq/broker/hacontroller/ReplicasManager.java b/broker/src/main/java/org/apache/rocketmq/broker/hacontroller/ReplicasManager.java
index c11129ca7..d4ac86760 100644
--- a/broker/src/main/java/org/apache/rocketmq/broker/hacontroller/ReplicasManager.java
+++ b/broker/src/main/java/org/apache/rocketmq/broker/hacontroller/ReplicasManager.java
@@ -163,8 +163,6 @@ public class ReplicasManager {
if (newMasterEpoch > this.masterEpoch) {
LOGGER.info("Begin to change to master, brokerName:{}, replicas:{}, new Epoch:{}", this.brokerConfig.getBrokerName(), this.localAddress, newMasterEpoch);
- // Change record
- this.masterAddress = this.localAddress;
this.masterEpoch = newMasterEpoch;
// Change sync state set
@@ -172,17 +170,24 @@ public class ReplicasManager {
newSyncStateSet.add(this.localAddress);
changeSyncStateSet(newSyncStateSet, syncStateSetEpoch);
- // Handle the slave synchronise
- handleSlaveSynchronize(BrokerRole.SYNC_MASTER);
+ if (this.localAddress.equals(masterAddress) && brokerController.getBrokerConfig().getBrokerId() == MixAll.MASTER_ID) {
+ LOGGER.warn("The broker role is already master");
+ } else {
+ // Change record
+ this.masterAddress = this.localAddress;
- // Notify ha service, change to master
- this.haService.changeToMaster(newMasterEpoch);
+ // Handle the slave synchronise
+ handleSlaveSynchronize(BrokerRole.SYNC_MASTER);
- this.brokerController.getBrokerConfig().setBrokerId(MixAll.MASTER_ID);
- this.brokerController.getMessageStoreConfig().setBrokerRole(BrokerRole.SYNC_MASTER);
- this.brokerController.changeSpecialServiceStatus(true);
+ // Notify ha service, change to master
+ this.haService.changeToMaster(newMasterEpoch);
- schedulingCheckSyncStateSet();
+ this.brokerController.getBrokerConfig().setBrokerId(MixAll.MASTER_ID);
+ this.brokerController.getMessageStoreConfig().setBrokerRole(BrokerRole.SYNC_MASTER);
+ this.brokerController.changeSpecialServiceStatus(true);
+
+ schedulingCheckSyncStateSet();
+ }
this.executorService.submit(() -> {
// Register broker to name-srv