Copilot commented on code in PR #23638:
URL: https://github.com/apache/kafka/pull/23638#discussion_r4603131602


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/StreamsGroupMember.java:
##########
@@ -385,14 +385,15 @@ public StreamsGroupDescribeResponseData.Member 
asStreamsGroupDescribeMember(
                 
.setWarmupTasks(taskIdsFromMap(targetAssignment.warmupTasks()));
         }
 
+        final TasksTupleWithEpochs assignedTasksWithPendingRevocation = 
assignedTasks.merge(tasksPendingRevocation);

Review Comment:
   This unconditionally allocates/merges task structures on every 
`StreamsGroupDescribe` call, even when there are no pending revocations. If 
`merge` is non-trivial, it’s worth short-circuiting (eg, use `assignedTasks` 
directly when `tasksPendingRevocation` is empty) to reduce CPU/allocations for 
describe-heavy clusters.



##########
core/src/test/scala/unit/kafka/server/StreamsGroupDescribeRequestTest.scala:
##########
@@ -44,6 +44,124 @@ import java.lang.{Byte => JByte}
 )
 class StreamsGroupDescribeRequestTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
 
+  @ClusterTest(
+    serverProperties = Array(
+      new ClusterConfigProperty(key = 
GroupCoordinatorConfig.STREAMS_GROUP_INITIAL_REBALANCE_DELAY_MS_CONFIG, value = 
"0"),
+      new ClusterConfigProperty(key = 
GroupCoordinatorConfig.STREAMS_GROUP_ASSIGNOR_OFFLOAD_ENABLE_CONFIG, value = 
"false")
+    )
+  )
+  def testStreamsGroupDescribeIncludesTasksPendingRevocation(): Unit = {
+    createOffsetsTopic()
+    createTopic(topic = "foo", numPartitions = 2)
+
+    val topology = new StreamsGroupHeartbeatRequestData.Topology()
+      .setEpoch(1)
+      .setSubtopologies(List(
+        new StreamsGroupHeartbeatRequestData.Subtopology()
+          .setSubtopologyId("subtopology-1")
+          .setSourceTopics(List("foo").asJava)
+          .setRepartitionSinkTopics(List.empty.asJava)
+          .setRepartitionSourceTopics(List.empty.asJava)
+          .setStateChangelogTopics(List.empty.asJava)
+      ).asJava)
+
+    // Member-1 joins and receives both active tasks.
+    var member1Response: StreamsGroupHeartbeatResponseData = null
+    TestUtils.waitUntilTrue(() => {
+      member1Response = streamsGroupHeartbeat(
+        groupId = "grp",
+        memberId = "member-1",
+        processId = "process-1",
+        rebalanceTimeoutMs = 5 * 60 * 1000,
+        activeTasks = List.empty,
+        standbyTasks = List.empty,
+        warmupTasks = List.empty,
+        topology = topology
+      )
+      member1Response.activeTasks != null &&
+        
member1Response.activeTasks.asScala.flatMap(_.partitions.asScala).toSet == 
Set[Integer](0, 1)
+    }, msg = s"Member-1 did not receive both tasks. Last response 
$member1Response.")
+
+    // Member-2 joins, moving one task to its target assignment.
+    val member2Response = streamsGroupHeartbeat(
+      groupId = "grp",
+      memberId = "member-2",
+      processId = "process-2",
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      activeTasks = List.empty,
+      standbyTasks = List.empty,
+      warmupTasks = List.empty,
+      topology = topology
+    )
+
+    // Member-1 reports that it still owns both tasks and receives a 
revocation request.
+    // Do not acknowledge the reduced assignment: the revoked task is still 
pending.
+    val revocationResponse = streamsGroupHeartbeat(
+      groupId = "grp",
+      memberId = "member-1",
+      memberEpoch = member1Response.memberEpoch,
+      activeTasks = convertTaskIds(member1Response.activeTasks),
+      standbyTasks = List.empty,
+      warmupTasks = List.empty
+    )
+    assertEquals(1, 
revocationResponse.activeTasks.asScala.flatMap(_.partitions.asScala).size)

Review Comment:
   This test assumes member-1 will receive a revocation response immediately 
after member-2 joins. That transition can be asynchronous and may cause test 
flakiness. Consider wrapping the heartbeat that expects revocation (and the 
`activeTasks` size assertion) in `TestUtils.waitUntilTrue` (similar to the 
initial join assertion) so the test waits until the coordinator has entered the 
expected reconciling state and member-1 receives the reduced assignment.



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