chickenchickenlove commented on code in PR #23855:
URL: https://github.com/apache/kafka/pull/23855#discussion_r4411100599


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/StreamsTopology.java:
##########
@@ -128,6 +131,178 @@ public static StreamsTopology 
fromHeartbeatRequest(StreamsGroupHeartbeatRequestD
         return new StreamsTopology(topology.epoch(), subtopologyMap);
     }
 
+    /**
+     * Checks whether the request describes this topology without converting 
or modifying it.
+     * Subtopologies are matched by ID. Copartition groups and their topic 
indexes are compared
+     * without regard to order, but duplicate occurrences must still match. 
All other lists
+     * retain their order-sensitive comparison, including the topic lists 
referenced by indexes.
+     *
+     * @param topology The topology supplied in the heartbeat request.
+     * @return Whether the request matches this topology.
+     */
+    public boolean matches(StreamsGroupHeartbeatRequestData.Topology topology) 
{
+        if (topologyEpoch != topology.epoch() || subtopologies.size() != 
topology.subtopologies().size()) {
+            return false;
+        }
+        for (int i = 0; i < topology.subtopologies().size(); i++) {
+            StreamsGroupHeartbeatRequestData.Subtopology requested = 
topology.subtopologies().get(i);
+            Subtopology current = subtopologies.get(requested.subtopologyId());
+            if (current == null || !matchesSubtopology(current, requested)) {
+                return false;
+            }
+
+            // Do not let repeated IDs match one stored subtopology while 
omitting another.

Review Comment:
   Thanks for your suggestion. it is much better. 
   I've addressed it.
   
   One more things I want to say is that `matches()` will return `false` if the 
request contains duplicate subtopology IDs. This prevents a request from 
matching the same stored subtopology multiple times while omitting another.



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