8000 KAFKA-19163: Avoid deleting groups with pending transactional offsets by arvi18 · Pull Request #7 · coderabbit-test/kafka · GitHub
[go: up one dir, main page]

Skip to content

KAFKA-19163: Avoid deleting groups with pending transactional offsets #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter 8000

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
KAFKA-19163: Avoid deleting groups with pending transactional offsets
When a group has pending transactional offsets but no committed offsets,
we can accidentally delete it while cleaning up expired offsets. Add a
check to avoid this case.
  • Loading branch information
squah-confluent committed Apr 16, 2025
commit 3c0cbb09f36d72a31188026a92783eba250f214c
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ public boolean cleanupExpiredOffsets(String groupId, List<CoordinatorRecord> rec
TimelineHashMap<String, TimelineHashMap<Integer, OffsetAndMetadata>> offsetsByTopic =
offsets.offsetsByGroup.get(groupId);
if (offsetsByTopic == null) {
return true;
return !openTransactionsByGroup.containsKey(groupId);
}

// We expect the group to exist.
Expand Down
7559
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,42 @@ public void testCleanupExpiredOffsetsWithDeletedPendingTransactionalOffsets() {
assertEquals(expectedRecords, records);
}

@Test
public void testCleanupExpiredOffsetsWithPendingTransactionalOffsetsOnly() {
GroupMetadataManager groupMetadataManager = mock(GroupMetadataManager.class);
Group group = mock(Group.class);

OffsetMetadataManagerTestContext context = new OffsetMetadataManagerTestContext.Builder()
.withGroupMetadataManager(groupMetadataManager)
.withOffsetsRetentionMinutes(1)
.build();

long commitTimestamp = context.time.milliseconds();

context.commitOffset("group-id", "foo", 0, 100L, 0, commitTimestamp);
context.commitOffset(10L, "group-id", "foo", 1, 101L, 0, commitTimestamp + 500);

context.time.sleep(Duration.ofMinutes(1).toMillis());

when(groupMetadataManager.group("group-id")).thenReturn(group);
when(group.offsetExpirationCondition()).thenReturn(Optional.of(
new OffsetExpirationConditionImpl(offsetAndMetadata -> offsetAndMetadata.commitTimestampMs)));
when(group.isSubscribedToTopic("foo")).thenReturn(false);

// foo-0 is expired, but the group is not deleted beacuse it has pending transactional offset commits.
List<CoordinatorRecord> expectedRecords = List.of(
GroupCoordinatorRecordHelpers.newOffsetCommitTombstoneRecord("group-id", "foo", 0)
);
List<CoordinatorRecord> records = new ArrayList<>();
assertFalse(context.cleanupExpiredOffsets("group-id", records));
assertEquals(expectedRecords, records);

// No offsets are expired, and the group is still not deleted because it has pending transactional offset commits.
records = new ArrayList<>();
assertFalse(context.cleanupExpiredOffsets("group-id", records));
assertEquals(List.of(), records);
}

private static OffsetFetchResponseData.OffsetFetchResponsePartitions mkOffsetPartitionResponse(
int partition,
long offset,
Expand Down
0