kang-hl commented on code in PR #7188:
URL: https://github.com/apache/rocketmq/pull/7188#discussion_r1303727884
##########
namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java:
##########
@@ -334,28 +328,42 @@ public RegisterBrokerResult registerBroker(
}
}
- for (Map.Entry<String, TopicConfig> entry :
tcTable.entrySet()) {
- if (registerFirst ||
this.isTopicConfigChanged(clusterName, brokerAddr,
- topicConfigWrapper.getDataVersion(), brokerName,
- entry.getValue().getTopicName())) {
- final TopicConfig topicConfig = entry.getValue();
- if (isPrimeSlave) {
+ if (registerFirst ||
this.isBrokerTopicConfigChanged(clusterName, brokerAddr,
topicConfigWrapper.getDataVersion())) {
+ if (isPrimeSlave) {
+ for (TopicConfig topicConfig : tcTable.values()) {
// Wipe write perm for prime slave
topicConfig.setPerm(topicConfig.getPerm() &
(~PermName.PERM_WRITE));
+ this.createAndUpdateQueueData(brokerName,
topicConfig);
+ }
+ } else {
+ for (TopicConfig topicConfig : tcTable.values()) {
+ this.createAndUpdateQueueData(brokerName,
topicConfig);
}
- this.createAndUpdateQueueData(brokerName,
topicConfig);
}
- }
- if (this.isBrokerTopicConfigChanged(clusterName,
brokerAddr, topicConfigWrapper.getDataVersion()) || registerFirst) {
//the topicQueueMappingInfoMap should never be null,
but can be empty
for (Map.Entry<String, TopicQueueMappingInfo> entry :
topicQueueMappingInfoMap.entrySet()) {
- if
(!topicQueueMappingInfoTable.containsKey(entry.getKey())) {
- topicQueueMappingInfoTable.put(entry.getKey(),
new HashMap<>());
- }
+ Map<String, TopicQueueMappingInfo>
topicQueueMappingInfo =
ConcurrentHashMapUtils.computeIfAbsent((ConcurrentHashMap<String, Map<String,
TopicQueueMappingInfo>>) topicQueueMappingInfoTable, entry.getKey(), k -> new
HashMap<>());
//Note asset brokerName equal
entry.getValue().getBname()
//here use the mappingDetail.bname
-
topicQueueMappingInfoTable.get(entry.getKey()).put(entry.getValue().getBname(),
entry.getValue());
+ TopicQueueMappingInfo value = entry.getValue();
+ topicQueueMappingInfo.put(value.getBname(), value);
+ }
+ } else {
+ if (isPrimeSlave) {
+ for (TopicConfig topicConfig : tcTable.values()) {
+ if (this.isTopicConfigChanged(false,
brokerName, topicConfig.getTopicName())) {
+ // Wipe write perm for prime slave
+ topicConfig.setPerm(topicConfig.getPerm()
& (~PermName.PERM_WRITE));
+ this.createAndUpdateQueueData(brokerName,
topicConfig);
+ }
+ }
+ } else {
Review Comment:
Moving `if` unrelated to the loop outside of the loop will result in better
performance
--
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]