-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 will be created. | ||
| * | ||
| * @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)) { | ||
| 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,11 @@ 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()) { | ||
| // classicGroupJoinToClassicGroup accepts: | ||
| // - classic groups | ||
| // - empty streams groups | ||
| // - empty consumer groups | ||
| 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 +6120,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 +8413,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 +8457,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. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.