Skip to content

KAFKA-19474: Move WARN log on log truncation below HWM #20106

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 2 commits into from
Jul 9, 2025

Conversation

gaurav-narula
Copy link
Contributor

@gaurav-narula gaurav-narula commented Jul 4, 2025

#5608 introduced a regression where the check for targetOffset < log.highWatermark
to emit a WARN log was made incorrectly after truncating the log.

This change moves the check for targetOffset < log.highWatermark to
UnifiedLog#truncateTo and ensures we emit a WARN log on truncation
below the replica's HWM by both the ReplicaFetcherThread and
ReplicaAlterLogDirsThread

Reviewers: Jun Rao junrao@gmail.com, Chia-Ping Tsai
chia7712@gmail.com

@github-actions github-actions bot added triage PRs from the community core Kafka Broker small Small PRs labels Jul 4, 2025
@gaurav-narula
Copy link
Contributor Author

gaurav-narula commented Jul 4, 2025

Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaurav-narula : Thanks for the PR. LGTM. Will wait for the CI to complete.

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaurav-narula nice find. one small comment is left. PTAL

@@ -166,12 +166,12 @@ class ReplicaFetcherThread(name: String,
val partition = replicaMgr.getPartitionOrException(tp)
val log = partition.localLogOrException

partition.truncateTo(offsetTruncationState.offset, isFuture = false)

if (offsetTruncationState.offset < log.highWatermark)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this log could be moved into UnifiedLog#truncateTo. UnifiedLog#truncateTo already logs if the target offset is larger than or equal to end offset, so adding another log for this case seems to make sense. Additionally, ReplicaAlterLogDirsThread could issue the same warning if the log is moved to UnifiedLog#truncateTo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've moved the log inside UnifiedLog#truncateTo.

Although users might be able to disambiguate between the two cases using the thread name (ReplicaAlterLogDirsThread vs ReplicaFetcherThread), I felt it's perhaps better to disambiguate between a future/non-future replica in the log statement

Moves the check for `offsetTruncationState.offset < log.highWatermark`
before truncating the log as truncation might update the HWM thereby
leading to an incorrect condition evaluation.
@github-actions github-actions bot added the storage Pull requests that target the storage module label Jul 7, 2025
Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaurav-narula : Thanks for the updated PR. LGTM too.

@chia7712
Copy link
Member

chia7712 commented Jul 8, 2025

@gaurav-narula could you please tweak the PR description according to the latest updates?

@gaurav-narula
Copy link
Contributor Author

@chia7712 Updated. PTAL again.

@chia7712 chia7712 merged commit 36b9bb9 into apache:trunk Jul 9, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-approved core Kafka Broker small Small PRs storage Pull requests that target the storage module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants