lianetm commented on code in PR #15511:
URL: https://github.com/apache/kafka/pull/15511#discussion_r1521745679


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/MembershipManagerImpl.java:
##########
@@ -508,9 +508,30 @@ private void 
processAssignmentReceived(ConsumerGroupHeartbeatResponseData.Assign
      */
     private void replaceTargetAssignmentWithNewAssignment(
             ConsumerGroupHeartbeatResponseData.Assignment assignment) {
-        currentTargetAssignment.clear();
+
+        // Return if the same as current assignment; comparison without 
creating a new collection
+        if (currentTargetAssignment != null) {
+            // check if the new assignment is different from the current 
target assignment
+            if (currentTargetAssignment.partitions.size() == 
assignment.topicPartitions().size() &&
+                assignment.topicPartitions().stream().allMatch(
+                    tp -> 
currentTargetAssignment.partitions.containsKey(tp.topicId()) &&
+                        
currentTargetAssignment.partitions.get(tp.topicId()).size() == 
tp.partitions().size() &&
+                        
currentTargetAssignment.partitions.get(tp.topicId()).containsAll(tp.partitions())))
 {
+                return;
+            }
+        }
+
+        // Bump local epoch and replace assignment
+        long nextLocalEpoch;
+        if (currentTargetAssignment == null) {
+            nextLocalEpoch = 0;
+        } else {
+            nextLocalEpoch = currentTargetAssignment.localEpoch + 1;
+        }

Review Comment:
   Is there a reason why we need to compute epochs on the client here? The 
server is the one bumping the epochs whenever it computes a new assignment for 
a member. I was expecting that we just keep a `LocalAssignment` that will 
contain the partitions and epoch the broker sent on the 
`ConsumerGroupHeartbeatResponseData`



-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to