squah-confluent commented on code in PR #23220:
URL: https://github.com/apache/kafka/pull/23220#discussion_r3869757997


##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupMetadataManagerCompactionReplayTest.java:
##########
@@ -0,0 +1,786 @@
+/*
+ * 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;
+
+import org.apache.kafka.clients.consumer.ConsumerPartitionAssignor;
+import org.apache.kafka.clients.consumer.internals.ConsumerProtocol;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.message.ConsumerGroupHeartbeatRequestData;
+import org.apache.kafka.common.message.ConsumerGroupHeartbeatResponseData;
+import org.apache.kafka.common.message.JoinGroupRequestData;
+import org.apache.kafka.common.message.JoinGroupResponseData;
+import org.apache.kafka.common.message.LeaveGroupRequestData;
+import org.apache.kafka.common.message.StreamsGroupHeartbeatRequestData;
+import 
org.apache.kafka.common.message.StreamsGroupHeartbeatRequestData.Subtopology;
+import 
org.apache.kafka.common.message.StreamsGroupHeartbeatRequestData.Topology;
+import org.apache.kafka.common.message.StreamsGroupHeartbeatResponseData;
+import org.apache.kafka.common.message.SyncGroupRequestData;
+import org.apache.kafka.common.protocol.ApiMessage;
+import org.apache.kafka.common.record.internal.RecordBatch;
+import org.apache.kafka.common.utils.Utils;
+import org.apache.kafka.common.utils.internals.LogContext;
+import org.apache.kafka.coordinator.common.runtime.CoordinatorMetadataImage;
+import org.apache.kafka.coordinator.common.runtime.CoordinatorRecord;
+import org.apache.kafka.coordinator.common.runtime.MetadataImageBuilder;
+import org.apache.kafka.coordinator.group.api.assignor.GroupAssignment;
+import org.apache.kafka.coordinator.group.metrics.GroupCoordinatorMetrics;
+import org.apache.kafka.coordinator.group.modern.MemberAssignmentImpl;
+import org.apache.kafka.coordinator.group.streams.MockTaskAssignor;
+import org.apache.kafka.coordinator.group.streams.TaskAssignmentTestUtil;
+import 
org.apache.kafka.coordinator.group.streams.TaskAssignmentTestUtil.TaskRole;
+import org.apache.kafka.coordinator.group.streams.TasksTuple;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.OptionalInt;
+import java.util.OptionalLong;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static 
org.apache.kafka.common.requests.JoinGroupRequest.UNKNOWN_MEMBER_ID;
+import static 
org.apache.kafka.common.requests.StreamsGroupHeartbeatRequest.LEAVE_GROUP_MEMBER_EPOCH;
+import static 
org.apache.kafka.coordinator.group.AssignmentTestUtil.mkAssignment;
+import static 
org.apache.kafka.coordinator.group.AssignmentTestUtil.mkTopicAssignment;
+import static 
org.apache.kafka.coordinator.group.StreamsGroupTestUtil.staticHeartbeat;
+import static 
org.apache.kafka.coordinator.group.StreamsGroupTestUtil.staticJoinHeartbeat;
+
+/**
+ * Compaction replay tests for the group coordinator.
+ *
+ * Tests check partition loading after compaction for non-trivial scenarios 
involving offset
+ * commits and member joins/rebalances for an online classic -> consumer 
upgrade and an
+ * offline classic -> streams upgrade. Both tests capture written records, 
compact the
+ * resulting log, and replay records through a new group coordinator shard to 
verify loading.
+ * Multiple contiguous log segments are tested, including prefix and mid-log 
windows.
+ * 

Review Comment:
   This is also a good place to explain why we align compaction to batch 
boundaries instead of simplifying the model.
   
   ```
   ConsumerGroupMemberMetadataKey
   ...
   ConsumerGroupCurrentMemberAssignmentKey, compacted
   --- batch boundary ---
   ConsumerGroupCurrentMemberAssignmentKey = tombstone, compacted
   ConsumerGroupTargetAssignmentMemberKey = tombstone
   ConsumerGroupMemberMetadataKey = tombstone <-- fails
   ```
   
   `ConsumerGroupMemberMetadataKey` initializes the member epoch to 0, while 
the `ConsumerGroupCurrentMemberAssignmentKey` tombstone updates the member 
epoch to `LEAVE_GROUP_MEMBER_EPOCH`. The `ConsumerGroupMemberMetadataKey` 
tombstone expects a member epoch of `LEAVE_GROUP_MEMBER_EPOCH` and not 0, so 
replay fails when the `ConsumerGroupCurrentMemberAssignmentKey` tombstone is 
compacted.
   
   (but in better sentences)
   
   Normally I'd be against putting this kind of low-level detail in a 
class-level javadoc but I can't find another place to put it.



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