Copilot commented on code in PR #20760: URL: https://github.com/apache/kafka/pull/20760#discussion_r2455529803
########## 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.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 = Collections.unmodifiableMap(Objects.requireNonNull(activeTasksWithEpochs)); + standbyTasks = Collections.unmodifiableMap(Objects.requireNonNull(standbyTasks)); + warmupTasks = Collections.unmodifiableMap(Objects.requireNonNull(warmupTasks)); Review Comment: The unmodifiable maps created in the compact constructor only make the outer map unmodifiable, but the inner Map<Integer, Integer> for activeTasksWithEpochs and Set<Integer> for standby/warmup tasks remain mutable. Consider creating deep unmodifiable copies to ensure true immutability. ```suggestion Objects.requireNonNull(activeTasksWithEpochs); Objects.requireNonNull(standbyTasks); Objects.requireNonNull(warmupTasks); activeTasksWithEpochs = Collections.unmodifiableMap( activeTasksWithEpochs.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> Collections.unmodifiableMap(new HashMap<>(e.getValue())) )) ); standbyTasks = Collections.unmodifiableMap( standbyTasks.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> Collections.unmodifiableSet(new HashSet<>(e.getValue())) )) ); warmupTasks = Collections.unmodifiableMap( warmupTasks.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> Collections.unmodifiableSet(new HashSet<>(e.getValue())) )) ); ``` ########## streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/SmokeTestDriverIntegrationTest.java: ########## @@ -210,5 +216,16 @@ public void shouldWorkWithRebalance( throw new AssertionError(driver.exception()); } assertTrue(driver.result().passed(), driver.result().result()); + + // The one extra record is a record that the driver produces to flush suppress + final int expectedRecords = numKeys * maxRecordsPerKey + 1; + + // We check that we did no have to reprocess any records, which would indicate a bug since everything + // runs locally in this test. + assertEquals(expectedRecords, numDataRecordsProcessed, + String.format("It seems we had to reprocess records, with %d processed records expected, but %d records processed.", Review Comment: The assertion message format is backwards - it states 'expected, but actual' when the actual parameters to assertEquals are (expected, actual). The message should say 'expected %d records but processed %d records' to match the parameter order. ```suggestion String.format("It seems we had to reprocess records, expected %d records but processed %d records.", ``` -- 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]
