Copilot commented on code in PR #20730:
URL: https://github.com/apache/kafka/pull/20730#discussion_r2444698192
##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/StreamsGroupMember.java:
##########
@@ -254,42 +254,38 @@ public Builder
updateWith(StreamsGroupCurrentMemberAssignmentValue record) {
setPreviousMemberEpoch(record.previousMemberEpoch());
setState(MemberState.fromValue(record.state()));
setAssignedTasks(
- new TasksTuple(
- assignmentFromTaskIds(record.activeTasks()),
- assignmentFromTaskIds(record.standbyTasks()),
- assignmentFromTaskIds(record.warmupTasks())
+ TasksTupleWithEpochs.fromCurrentAssignmentRecord(
+ record.activeTasks(),
+ record.standbyTasks(),
+ record.warmupTasks(),
+ record.memberEpoch()
)
);
setTasksPendingRevocation(
- new TasksTuple(
-
assignmentFromTaskIds(record.activeTasksPendingRevocation()),
-
assignmentFromTaskIds(record.standbyTasksPendingRevocation()),
-
assignmentFromTaskIds(record.warmupTasksPendingRevocation())
+ TasksTupleWithEpochs.fromCurrentAssignmentRecord(
+ record.activeTasksPendingRevocation(),
+ record.standbyTasksPendingRevocation(),
+ record.warmupTasksPendingRevocation(),
+ record.memberEpoch()
)
);
return this;
}
- private static Map<String, Set<Integer>> assignmentFromTaskIds(
- List<StreamsGroupCurrentMemberAssignmentValue.TaskIds>
topicPartitionsList
- ) {
- return topicPartitionsList.stream().collect(Collectors.toMap(
-
StreamsGroupCurrentMemberAssignmentValue.TaskIds::subtopologyId,
- taskIds -> Set.copyOf(taskIds.partitions())));
- }
-
public static Builder withDefaults(String memberId) {
return new Builder(memberId)
.setRebalanceTimeoutMs(-1)
.setTopologyEpoch(-1)
.setInstanceId(null)
.setRackId(null)
+ .setClientId("")
+ .setClientHost("")
.setProcessId("")
.setClientTags(Collections.emptyMap())
.setState(MemberState.STABLE)
.setMemberEpoch(0)
- .setAssignedTasks(TasksTuple.EMPTY)
- .setTasksPendingRevocation(TasksTuple.EMPTY)
+ .setAssignedTasks(TasksTupleWithEpochs.EMPTY)
+ .setTasksPendingRevocation(TasksTupleWithEpochs.EMPTY)
.setUserEndpoint(null);
}
Review Comment:
The `withDefaults` method now sets `clientId` and `clientHost` to empty
strings (lines 281-282), which was not done previously. This appears to be an
unrelated change that should be documented in the PR description or moved to a
separate commit, as it's not directly related to epoch tracking.
##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/TasksTupleWithEpochs.java:
##########
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.coordinator.group.streams;
+
+import
org.apache.kafka.coordinator.group.generated.StreamsGroupCurrentMemberAssignmentValue;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * An immutable tuple containing active, standby and warm-up tasks with
assignment epochs.
+ * <p>
+ * Active tasks include epoch information to support fencing of zombie commits.
+ * Standby and warmup tasks do not have epochs as they don't commit offsets.
+ *
+ * @param activeTasksWithEpochs Active tasks with their assignment epochs.
+ * The outer map key is the subtopology ID, the
inner map key is the partition ID,
+ * and the inner map value is the assignment
epoch.
+ * @param standbyTasks Standby tasks.
+ * The key of the map is the subtopology ID, and
the value is the set of partition IDs.
+ * @param warmupTasks Warm-up tasks.
+ * The key of the map is the subtopology ID, and
the value is the set of partition IDs.
+ */
+public record TasksTupleWithEpochs(Map<String, Map<Integer, Integer>>
activeTasksWithEpochs,
+ Map<String, Set<Integer>> standbyTasks,
+ Map<String, Set<Integer>> warmupTasks) {
+
+ public TasksTupleWithEpochs {
+ activeTasksWithEpochs =
deepUnmodifiableMapOfMaps(Objects.requireNonNull(activeTasksWithEpochs));
+ standbyTasks =
Collections.unmodifiableMap(Objects.requireNonNull(standbyTasks));
+ warmupTasks =
Collections.unmodifiableMap(Objects.requireNonNull(warmupTasks));
+ }
Review Comment:
The standbyTasks and warmupTasks maps are made unmodifiable at the outer
level, but their inner Set values remain mutable. Consider using
`deepUnmodifiableMapOfSets` similar to how `deepUnmodifiableMapOfMaps` is used
for activeTasksWithEpochs to ensure complete immutability.
##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/TasksTuple.java:
##########
@@ -172,8 +148,10 @@ public static TasksTuple fromHeartbeatRequest(final
List<StreamsGroupHeartbeatRe
*
* Example:
* [subtopologyID1-0, subtopologyID1-1, subtopologyID2-0, subtopologyID2-1]
+ *
+ * Package-private to allow TasksTupleWithEpochs to use it.
Review Comment:
Corrected comment formatting: should start with asterisk for proper Javadoc.
--
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]