TheR1sing3un commented on code in PR #6100:
URL: https://github.com/apache/rocketmq/pull/6100#discussion_r1113850833
##########
broker/src/main/java/org/apache/rocketmq/broker/controller/ReplicasManager.java:
##########
@@ -322,35 +438,150 @@ private boolean registerBrokerToController() {
}
}
+ /**
+ * Send GetNextBrokerRequest to controller for getting next assigning
brokerId in this broker-set
+ * @return next brokerId in this broker-set
+ */
+ private Long getNextBrokerId() {
+ try {
+ GetNextBrokerIdResponseHeader nextBrokerIdResp =
this.brokerOuterAPI.getNextBrokerId(this.brokerConfig.getBrokerClusterName(),
this.brokerConfig.getBrokerName(), this.controllerLeaderAddress);
+ return nextBrokerIdResp.getNextBrokerId();
+ } catch (Exception e) {
+ LOGGER.error("fail to get next broker id from controller", e);
+ return null;
+ }
+ }
+
+ /**
+ * Create temp metadata file in local file system, records the brokerId
and registerCheckCode
+ * @param brokerId the brokerId that is expected to be assigned
+ * @return whether the temp meta file is created successfully
+ */
+
+ private boolean createTempMetadataFile(Long brokerId) {
+ // generate register check code, format like that:
$ipAddress;$timestamp
+ String registerCheckCode = this.localAddress + ";" +
System.currentTimeMillis();
+ try {
+
this.tempBrokerMetadata.updateAndPersist(brokerConfig.getBrokerClusterName(),
brokerConfig.getBrokerName(), brokerId, registerCheckCode);
+ return true;
+ } catch (Exception e) {
+ LOGGER.error("update and persist temp broker metadata file
failed", e);
+ this.tempBrokerMetadata.clear();
+ return false;
+ }
+ }
+
+ /**
+ * Send applyBrokerId request to controller
+ * @return whether controller has assigned this brokerId for this broker
+ */
+ private boolean applyBrokerId() {
+ try {
+ ApplyBrokerIdResponseHeader response =
this.brokerOuterAPI.applyBrokerId(brokerConfig.getBrokerClusterName(),
brokerConfig.getBrokerName(),
+ tempBrokerMetadata.getBrokerId(),
tempBrokerMetadata.getRegisterCheckCode(), this.controllerLeaderAddress);
+ return true;
+
+ } catch (Exception e) {
+ LOGGER.error("fail to apply broker id: {}", e,
tempBrokerMetadata.getBrokerId());
+ return false;
+ }
+ }
Review Comment:
> response whether to determine?
`BrokerOuterAPI` will judge this response if successful.
--
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]