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


##########
broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java:
##########
@@ -1766,36 +1767,63 @@ public synchronized void 
registerIncrementBrokerData(List<TopicConfig> topicConf
     }
 
     public synchronized void registerBrokerAll(final boolean checkOrderConfig, 
boolean oneway, boolean forceRegister) {
+        ConcurrentMap<String, TopicConfig> topicConfigMap = 
this.getTopicConfigManager().getTopicConfigTable();
+        ConcurrentHashMap<String, TopicConfig> topicConfigTable = new 
ConcurrentHashMap<>();
 
-        TopicConfigAndMappingSerializeWrapper topicConfigWrapper = new 
TopicConfigAndMappingSerializeWrapper();
+        for (TopicConfig topicConfig : topicConfigMap.values()) {
+            if 
(!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
+                || 
!PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
+                topicConfigTable.put(topicConfig.getTopicName(),
+                    new TopicConfig(topicConfig.getTopicName(), 
topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
+                        topicConfig.getPerm() & 
getBrokerConfig().getBrokerPermission()));
+            } else {
+                topicConfigTable.put(topicConfig.getTopicName(), topicConfig);
+            }
 
-        
topicConfigWrapper.setDataVersion(this.getTopicConfigManager().getDataVersion());
-        
topicConfigWrapper.setTopicConfigTable(this.getTopicConfigManager().getTopicConfigTable());
+            if (this.brokerConfig.isEnableSplitRegistration()
+                && topicConfigTable.size() >= 
this.brokerConfig.getSplitRegistrationSize()
+                && needRegister(forceRegister)) {

Review Comment:
   There is no need to determine needRegister here



##########
common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java:
##########
@@ -396,6 +396,10 @@ public class BrokerConfig extends BrokerIdentity {
 
     private boolean enableMixedMessageType = false;
 
+    private boolean enableSplitRegistration = false;

Review Comment:
   Just a reminder to the users that this switch cannot be used together with 
deleteTopicWithBrokerRegistration, otherwise there will be a loss of routing.



##########
broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java:
##########
@@ -1766,36 +1767,63 @@ public synchronized void 
registerIncrementBrokerData(List<TopicConfig> topicConf
     }
 
     public synchronized void registerBrokerAll(final boolean checkOrderConfig, 
boolean oneway, boolean forceRegister) {
+        ConcurrentMap<String, TopicConfig> topicConfigMap = 
this.getTopicConfigManager().getTopicConfigTable();
+        ConcurrentHashMap<String, TopicConfig> topicConfigTable = new 
ConcurrentHashMap<>();
 
-        TopicConfigAndMappingSerializeWrapper topicConfigWrapper = new 
TopicConfigAndMappingSerializeWrapper();
+        for (TopicConfig topicConfig : topicConfigMap.values()) {
+            if 
(!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
+                || 
!PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
+                topicConfigTable.put(topicConfig.getTopicName(),
+                    new TopicConfig(topicConfig.getTopicName(), 
topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
+                        topicConfig.getPerm() & 
getBrokerConfig().getBrokerPermission()));
+            } else {
+                topicConfigTable.put(topicConfig.getTopicName(), topicConfig);
+            }
 
-        
topicConfigWrapper.setDataVersion(this.getTopicConfigManager().getDataVersion());
-        
topicConfigWrapper.setTopicConfigTable(this.getTopicConfigManager().getTopicConfigTable());
+            if (this.brokerConfig.isEnableSplitRegistration()
+                && topicConfigTable.size() >= 
this.brokerConfig.getSplitRegistrationSize()
+                && needRegister(forceRegister)) {
+                TopicConfigAndMappingSerializeWrapper topicConfigWrapper = 
buildSerializeWrapper(topicConfigTable);
+                doRegisterBrokerAll(checkOrderConfig, oneway, 
topicConfigWrapper);
+                topicConfigTable.clear();
+            }
+        }
 
-        
topicConfigWrapper.setTopicQueueMappingInfoMap(this.getTopicQueueMappingManager().getTopicQueueMappingTable().entrySet().stream().map(
-            entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), 
TopicQueueMappingDetail.cloneAsMappingInfo(entry.getValue()))
-        ).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
+        Map<String, TopicQueueMappingInfo> topicQueueMappingInfoMap = 
this.getTopicQueueMappingManager().getTopicQueueMappingTable().entrySet().stream()
+            .map(entry -> new 
AbstractMap.SimpleImmutableEntry<>(entry.getKey(), 
TopicQueueMappingDetail.cloneAsMappingInfo(entry.getValue())))
+            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
 
-        if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
-            || 
!PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
-            ConcurrentHashMap<String, TopicConfig> topicConfigTable = new 
ConcurrentHashMap<>();
-            for (TopicConfig topicConfig : 
topicConfigWrapper.getTopicConfigTable().values()) {
-                TopicConfig tmp =
-                    new TopicConfig(topicConfig.getTopicName(), 
topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
-                        topicConfig.getPerm() & 
this.brokerConfig.getBrokerPermission(), topicConfig.getTopicSysFlag());
-                topicConfigTable.put(topicConfig.getTopicName(), tmp);
-            }
-            topicConfigWrapper.setTopicConfigTable(topicConfigTable);
+        TopicConfigAndMappingSerializeWrapper topicConfigWrapper = 
buildSerializeWrapper(topicConfigTable, topicQueueMappingInfoMap);
+        if (this.brokerConfig.isEnableSplitRegistration() || 
needRegister(forceRegister)) {
+            doRegisterBrokerAll(checkOrderConfig, oneway, topicConfigWrapper);
         }
+    }
 
-        if (forceRegister || 
needRegister(this.brokerConfig.getBrokerClusterName(),
+    private boolean needRegister(final boolean forceRegister) {
+        return forceRegister || 
needRegister(this.brokerConfig.getBrokerClusterName(),
             this.getBrokerAddr(),
             this.brokerConfig.getBrokerName(),
             this.brokerConfig.getBrokerId(),
             this.brokerConfig.getRegisterBrokerTimeoutMills(),
-            this.brokerConfig.isInBrokerContainer())) {
-            doRegisterBrokerAll(checkOrderConfig, oneway, topicConfigWrapper);
+            this.brokerConfig.isInBrokerContainer());
+    }
+
+    private TopicConfigAndMappingSerializeWrapper buildSerializeWrapper(final 
ConcurrentMap<String, TopicConfig> topicConfigTable) {
+        return buildSerializeWrapper(topicConfigTable, Maps.newHashMap());
+    }
+
+    private TopicConfigAndMappingSerializeWrapper buildSerializeWrapper(

Review Comment:
   It would be better move these two methods to TopicConfigManager



-- 
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-unsubscr...@rocketmq.apache.org

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

Reply via email to