-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-10199: Add task updater metrics, part 2 #13300
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 all commits
7c76c4f
d1af2c0
ab94cad
19aa9bf
d335f59
5db70a3
9b8531b
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 |
|---|---|---|
|
|
@@ -457,15 +457,9 @@ public long restore(final Map<TaskId, Task> tasks) { | |
| // small batches; this can be optimized in the future, e.g. wait longer for larger batches. | ||
| final TaskId taskId = changelogs.get(partition).stateManager.taskId(); | ||
| try { | ||
| final Task task = tasks.get(taskId); | ||
| final ChangelogMetadata changelogMetadata = changelogs.get(partition); | ||
| final int restored = restoreChangelog(changelogMetadata); | ||
| if (restored > 0 || changelogMetadata.state().equals(ChangelogState.COMPLETED)) { | ||
| final Task task = tasks.get(taskId); | ||
| if (task != null) { | ||
| task.clearTaskTimeout(); | ||
| } | ||
| } | ||
| totalRestored += restored; | ||
| totalRestored += restoreChangelog(task, changelogMetadata); | ||
| } catch (final TimeoutException timeoutException) { | ||
| tasks.get(taskId).maybeInitTaskTimeoutOrThrow( | ||
| time.milliseconds(), | ||
|
|
@@ -642,7 +636,7 @@ private void bufferChangelogRecords(final ChangelogMetadata changelogMetadata, f | |
| * | ||
| * @return number of records restored | ||
| */ | ||
| private int restoreChangelog(final ChangelogMetadata changelogMetadata) { | ||
| private int restoreChangelog(final Task task, final ChangelogMetadata changelogMetadata) { | ||
| final ProcessorStateManager stateManager = changelogMetadata.stateManager; | ||
| final StateStoreMetadata storeMetadata = changelogMetadata.storeMetadata; | ||
| final TopicPartition partition = storeMetadata.changelogPartition(); | ||
|
|
@@ -662,6 +656,8 @@ private int restoreChangelog(final ChangelogMetadata changelogMetadata) { | |
| changelogMetadata.bufferedRecords.clear(); | ||
| } | ||
|
|
||
| task.maybeRecordRestored(time, records.size()); | ||
|
|
||
| final Long currentOffset = storeMetadata.offset(); | ||
| log.trace("Restored {} records from changelog {} to store {}, end offset is {}, current offset is {}", | ||
| numRecords, partition, storeName, recordEndOffset(changelogMetadata.restoreEndOffset), currentOffset); | ||
|
|
@@ -694,6 +690,10 @@ private int restoreChangelog(final ChangelogMetadata changelogMetadata) { | |
| } | ||
| } | ||
|
|
||
| if (numRecords > 0 || changelogMetadata.state().equals(ChangelogState.COMPLETED)) { | ||
| task.clearTaskTimeout(); | ||
| } | ||
|
|
||
| return numRecords; | ||
| } | ||
|
|
||
|
|
@@ -857,7 +857,7 @@ private void initializeChangelogs(final Map<TaskId, Task> tasks, | |
| } | ||
| } | ||
|
|
||
| // try initialize limit offsets for standby tasks for the first time | ||
| // try initializing limit offsets for standby tasks for the first time | ||
| if (!committedOffsets.isEmpty()) { | ||
| updateLimitOffsetsForStandbyChangelogs(committedOffsets); | ||
| } | ||
|
|
@@ -875,7 +875,7 @@ private void initializeChangelogs(final Map<TaskId, Task> tasks, | |
| } | ||
|
|
||
| // prepare newly added partitions of the restore consumer by setting their starting position | ||
| prepareChangelogs(newPartitionsToRestore); | ||
| prepareChangelogs(tasks, newPartitionsToRestore); | ||
| } | ||
|
|
||
| private void addChangelogsToRestoreConsumer(final Set<TopicPartition> partitions) { | ||
|
|
@@ -930,7 +930,8 @@ private void resumeChangelogsFromRestoreConsumer(final Collection<TopicPartition | |
| log.debug("Resumed partitions {} from the restore consumer", partitions); | ||
| } | ||
|
|
||
| private void prepareChangelogs(final Set<ChangelogMetadata> newPartitionsToRestore) { | ||
| private void prepareChangelogs(final Map<TaskId, Task> tasks, | ||
| final Set<ChangelogMetadata> newPartitionsToRestore) { | ||
| // separate those who do not have the current offset loaded from checkpoint | ||
| final Set<TopicPartition> newPartitionsWithoutStartOffset = new HashSet<>(); | ||
|
|
||
|
|
@@ -986,6 +987,14 @@ private void prepareChangelogs(final Set<ChangelogMetadata> newPartitionsToResto | |
| } catch (final Exception e) { | ||
| throw new StreamsException("State restore listener failed on batch restored", e); | ||
| } | ||
|
|
||
| final TaskId taskId = changelogs.get(partition).stateManager.taskId(); | ||
| final StreamTask task = (StreamTask) tasks.get(taskId); | ||
| // if the log is truncated between when we get the log end offset and when we get the | ||
| // consumer position, then it's possible that the difference become negative and there's actually | ||
| // no records to restore; in this case we just initialize the sensor to zero | ||
| final long recordsToRestore = Math.max(changelogMetadata.restoreEndOffset - startOffset, 0L); | ||
|
Member
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. Why do we need to apply
Contributor
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. Not very compelling reasons, I just want to make sure we do not start with a negative number, but I cannot think of a case that it could be negative.
Contributor
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. I've added a comment to cover the very edge case when it could become negative. |
||
| task.initRemainingRecordsToRestore(time, recordsToRestore); | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
Why do we remove this
nullcheck?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.
I pondered on the code and I think it should not be
nullever? Please correct me if I'm wrong.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.
@mjsax LMK what do you think? I may lack some background here.
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.
Was just wondering. It seemed to be unrelated to this PR, and so I just assumed there must be a reason for having the
nullcheck.