-
Notifications
You must be signed in to change notification settings - Fork 15.3k
KAFKA-20116: Forwad task-(end)-offset to task assignor (5/5) #22644
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
+443
−25
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
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
65 changes: 65 additions & 0 deletions
65
...ordinator/src/main/java/org/apache/kafka/coordinator/group/streams/MemberTaskOffsets.java
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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * 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.common.message.StreamsGroupHeartbeatRequestData; | ||
| import org.apache.kafka.coordinator.group.streams.assignor.TaskId; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * The latest per-task cumulative changelog offsets and end-offsets that a member reported in its heartbeat. | ||
| * <p> | ||
| * These values are transient telemetry that the assignor uses to estimate task lag (for warm-up promotion). | ||
| * Per KIP-1071 they are <b>not</b> persisted to the {@code __consumer_offsets} topic ("not persisted, as they are | ||
| * constantly changing"); they are held in memory on the group coordinator and re-reported by the member on the | ||
| * task-offset interval. | ||
| * | ||
| * @param taskOffsets Cumulative changelog offsets per task. | ||
| * @param taskEndOffsets Cumulative changelog end-offsets per task. | ||
| */ | ||
| public record MemberTaskOffsets(Map<TaskId, Long> taskOffsets, Map<TaskId, Long> taskEndOffsets) { | ||
|
|
||
| public static final MemberTaskOffsets EMPTY = new MemberTaskOffsets(Map.of(), Map.of()); | ||
|
|
||
| /** | ||
| * Returns a copy of these offsets updated with the values reported in a heartbeat. Task offsets and task | ||
| * end-offsets are reported independently: a {@code null} list means "unchanged since the last heartbeat", so the | ||
| * corresponding map is retained from this instance even when the other one is updated. | ||
| * | ||
| * @param reportedTaskOffsets The reported task offsets, or {@code null} if unchanged. | ||
| * @param reportedTaskEndOffsets The reported task end-offsets, or {@code null} if unchanged. | ||
| */ | ||
| public MemberTaskOffsets update( | ||
| final List<StreamsGroupHeartbeatRequestData.TaskOffset> reportedTaskOffsets, | ||
| final List<StreamsGroupHeartbeatRequestData.TaskOffset> reportedTaskEndOffsets | ||
| ) { | ||
| return new MemberTaskOffsets( | ||
| reportedTaskOffsets == null ? taskOffsets : toTaskIdMap(reportedTaskOffsets), | ||
| reportedTaskEndOffsets == null ? taskEndOffsets : toTaskIdMap(reportedTaskEndOffsets) | ||
| ); | ||
| } | ||
|
|
||
| private static Map<TaskId, Long> toTaskIdMap(final List<StreamsGroupHeartbeatRequestData.TaskOffset> taskOffsets) { | ||
| return taskOffsets.stream().collect(Collectors.toMap( | ||
| taskOffset -> new TaskId(taskOffset.subtopologyId(), taskOffset.partition()), | ||
| StreamsGroupHeartbeatRequestData.TaskOffset::offset | ||
| )); | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
If they are transient, we may want to discuss whether using timeline data structures is the correct approach here. Those are usually backed by persisted records.
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.
Ah. Good catch.