-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-19570: Implement offline migration for streams groups #20288
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -833,19 +833,28 @@ ConsumerGroup getOrMaybeCreateConsumerGroup( | |||||||||
| * Gets or creates a streams group without updating the groups map. | ||||||||||
| * The group will be materialized during the replay. | ||||||||||
| * | ||||||||||
| * If there is an empty classic consumer group of the same name, it will be deleted and a new streams | ||||||||||
| * group. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot's first comment looks correct, we're missing a word here.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||
| * | ||||||||||
| * @param groupId The group ID. | ||||||||||
| * @param records The record list to which the group tombstones are written | ||||||||||
| * if the group is empty and is a classic group. | ||||||||||
| * | ||||||||||
| * @return A StreamsGroup. | ||||||||||
| * | ||||||||||
| * Package private for testing. | ||||||||||
| */ | ||||||||||
| StreamsGroup getOrCreateStreamsGroup( | ||||||||||
| String groupId | ||||||||||
| String groupId, | ||||||||||
| List<CoordinatorRecord> records | ||||||||||
| ) { | ||||||||||
| Group group = groups.get(groupId); | ||||||||||
|
|
||||||||||
| if (group == null) { | ||||||||||
| return new StreamsGroup(logContext, snapshotRegistry, groupId, metrics); | ||||||||||
| } else if (maybeDeleteEmptyClassicGroup(group, records)) { | ||||||||||
|
lucasbru marked this conversation as resolved.
|
||||||||||
| log.info("[GroupId {}] Converted the empty classic group to a streams group.", groupId); | ||||||||||
| return new StreamsGroup(logContext, snapshotRegistry, groupId, metrics); | ||||||||||
| } else { | ||||||||||
| return castToStreamsGroup(group); | ||||||||||
| } | ||||||||||
|
|
@@ -1871,7 +1880,7 @@ private CoordinatorResult<StreamsGroupHeartbeatResult, CoordinatorRecord> stream | |||||||||
| boolean isJoining = memberEpoch == 0; | ||||||||||
| StreamsGroup group; | ||||||||||
| if (isJoining) { | ||||||||||
| group = getOrCreateStreamsGroup(groupId); | ||||||||||
| group = getOrCreateStreamsGroup(groupId, records); | ||||||||||
| throwIfStreamsGroupIsFull(group); | ||||||||||
| } else { | ||||||||||
| group = getStreamsGroupOrThrow(groupId); | ||||||||||
|
|
@@ -6066,7 +6075,7 @@ public CoordinatorResult<Void, CoordinatorRecord> classicGroupJoin( | |||||||||
| // classicGroupJoinToConsumerGroup takes the join requests to non-empty consumer groups. | ||||||||||
| // The empty consumer groups should be converted to classic groups in classicGroupJoinToClassicGroup. | ||||||||||
| return classicGroupJoinToConsumerGroup((ConsumerGroup) group, context, request, responseFuture); | ||||||||||
| } else if (group.type() == CONSUMER || group.type() == CLASSIC) { | ||||||||||
| } else if (group.type() == CONSUMER || group.type() == CLASSIC || group.type() == STREAMS && group.isEmpty()) { | ||||||||||
| return classicGroupJoinToClassicGroup(context, request, responseFuture); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a comment to state the groups accepted by classicGroupJoinToClassicGroup here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||
| } else { | ||||||||||
| // Group exists but it's not a consumer group | ||||||||||
|
|
@@ -6107,6 +6116,8 @@ CoordinatorResult<Void, CoordinatorRecord> classicGroupJoinToClassicGroup( | |||||||||
| ClassicGroup group; | ||||||||||
| if (maybeDeleteEmptyConsumerGroup(groupId, records)) { | ||||||||||
| log.info("[GroupId {}] Converted the empty consumer group to a classic group.", groupId); | ||||||||||
| } else if (maybeDeleteEmptyStreamsGroup(groupId, records)) { | ||||||||||
| log.info("[GroupId {}] Converted the empty streams group to a classic group.", groupId); | ||||||||||
| } | ||||||||||
| boolean isNewGroup = !groups.containsKey(groupId); | ||||||||||
| try { | ||||||||||
|
|
@@ -8398,6 +8409,13 @@ private static boolean isEmptyConsumerGroup(Group group) { | |||||||||
| return group != null && group.type() == CONSUMER && group.isEmpty(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @return true if the group is an empty streams group. | ||||||||||
| */ | ||||||||||
| private static boolean isEmptyStreamsGroup(Group group) { | ||||||||||
| return group != null && group.type() == STREAMS && group.isEmpty(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Write tombstones for the group if it's empty and is a classic group. | ||||||||||
| * | ||||||||||
|
|
@@ -8435,6 +8453,26 @@ private boolean maybeDeleteEmptyConsumerGroup(String groupId, List<CoordinatorRe | |||||||||
| } | ||||||||||
| return false; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Delete and write tombstones for the group if it's empty and is a streams group. | ||||||||||
| * | ||||||||||
| * @param groupId The group id to be deleted. | ||||||||||
| * @param records The list of records to delete the group. | ||||||||||
| * | ||||||||||
| * @return true if the group is an empty streams group. | ||||||||||
| */ | ||||||||||
| private boolean maybeDeleteEmptyStreamsGroup(String groupId, List<CoordinatorRecord> records) { | ||||||||||
| Group group = groups.get(groupId, Long.MAX_VALUE); | ||||||||||
| if (isEmptyStreamsGroup(group)) { | ||||||||||
| // Add tombstones for the previous streams group. The tombstones won't actually be | ||||||||||
| // replayed because its coordinator result has a non-null appendFuture. | ||||||||||
| createGroupTombstoneRecords(group, records); | ||||||||||
| removeGroup(groupId); | ||||||||||
| return true; | ||||||||||
| } | ||||||||||
| return false; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Checks whether the given protocol type or name in the request is inconsistent with the group's. | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is incomplete - it ends abruptly with 'a new streams' without completing the sentence. Should be 'a new streams group will be created.'