jt2594838 commented on code in PR #19021:
URL: https://github.com/apache/iotdb/pull/19021#discussion_r4384527435


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusSubscriptionSetupHandler.java:
##########
@@ -195,111 +195,129 @@ private static void onNewRegionCreated(
         allSubscriptions.size(),
         serverImpl.getSearchIndex());
 
-    for (final Map.Entry<String, java.util.Set<String>> groupEntry : 
allSubscriptions.entrySet()) {
-      final String consumerGroupId = groupEntry.getKey();
-      final boolean isTableModel = 
SubscriptionAgent.consumer().isTableModel(consumerGroupId);
-      for (final String topicName : groupEntry.getValue()) {
-        if (!isConsensusBasedTopic(topicName, isTableModel)) {
+    for (final String consumerGroupId : allSubscriptions.keySet()) {
+      // Serialize binding with metadata repair and its rollback. Re-read the 
group's topics after
+      // acquiring the lock so an unsubscribe while this callback was waiting 
cannot be undone.
+      SubscriptionAgent.consumer()
+          .executeWithConsumerGroupLock(
+              consumerGroupId,
+              () ->
+                  bindNewRegionForConsumerGroup(
+                      consumerGroupId, groupId, serverImpl, commitManager));
+    }
+  }
+
+  private static void bindNewRegionForConsumerGroup(
+      final String consumerGroupId,
+      final ConsensusGroupId groupId,
+      final IoTConsensusServerImpl serverImpl,
+      final ConsensusSubscriptionCommitManager commitManager) {
+    final boolean isTableModel = 
SubscriptionAgent.consumer().isTableModel(consumerGroupId);
+    for (final String topicName :
+        
SubscriptionAgent.consumer().getTopicNamesSubscribedByConsumerGroup(consumerGroupId))
 {
+      if (!isConsensusBasedTopic(topicName, isTableModel)) {
+        continue;
+      }
+      if (SubscriptionAgent.broker()
+          .hasConsensusQueueForRegion(consumerGroupId, topicName, 
groupId.toString())) {
+        continue;
+      }
+      try {
+        final Map<String, TopicConfig> topicConfigs =
+            SubscriptionAgent.topic()
+                .getTopicConfigs(java.util.Collections.singleton(topicName), 
isTableModel);

Review Comment:
   Mind the import



-- 
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]

Reply via email to