You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "RongtongJin (via GitHub)" <gi...@apache.org> on 2023/03/16 00:06:32 UTC

[GitHub] [rocketmq] RongtongJin commented on a diff in pull request #6345: [ISSUE #6344] queueOffsets in topicQueueTable rollback when master changes to master in ha mode

RongtongJin commented on code in PR #6345:
URL: https://github.com/apache/rocketmq/pull/6345#discussion_r1137904857


##########
broker/src/main/java/org/apache/rocketmq/broker/controller/ReplicasManager.java:
##########
@@ -308,20 +313,25 @@ public void changeToSlave(final String newMasterAddress, final int newMasterEpoc
                 this.haService.changeToSlave(newMasterAddress, newMasterEpoch, brokerControllerId);
 
                 this.brokerController.getTopicConfigManager().getDataVersion().nextVersion(newMasterEpoch);
+                registerBrokerWhenRoleChange();
+            }
+        }
+    }
 
-                this.executorService.submit(() -> {
-                    // Register broker to name-srv
-                    try {
-                        this.brokerController.registerBrokerAll(true, false, this.brokerController.getBrokerConfig().isForceRegister());
-                    } catch (final Throwable e) {
-                        LOGGER.error("Error happen when register broker to name server, Failed to change broker to slave", e);
-                        return;
-                    }
+    public void registerBrokerWhenRoleChange() {
+        String currentRole = this.brokerController.getMessageStoreConfig().getBrokerRole().equals(BrokerRole.SLAVE) ? "slave" : "master";
 
-                    LOGGER.info("Change broker [id:{}][address:{}] to slave, newMasterBrokerId:{}, newMasterAddress:{}, newMasterEpoch:{}", this.brokerControllerId, this.brokerAddress, newMasterBrokerId, newMasterAddress, newMasterEpoch);
-                });
+        this.executorService.submit(() -> {
+            // Register broker to name-srv
+            try {
+                this.brokerController.registerBrokerAll(true, false, this.brokerController.getBrokerConfig().isForceRegister());
+            } catch (final Throwable e) {
+                LOGGER.error("Error happen when register broker to name-srv, Failed to change broker to {}", currentRole, e);
+                return;
             }
-        }
+            LOGGER.info("Change broker [id:{}][address:{}] to {}, newMasterBrokerId:{}, newMasterAddress:{}, newMasterEpoch:{}, syncStateSetEpoch:{}",
+                this.brokerControllerId, this.brokerAddress, currentRole, this.masterBrokerId, this.masterAddress, this.masterEpoch, this.syncStateSetEpoch);
+        });

Review Comment:
   这个应该放上面,不是很适合放该方法中



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

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