Skip to content

Conversation

@samratdotcom
Copy link

@samratdotcom samratdotcom commented Jan 2, 2026

Summary

Fixes a bug where the high-watermark metric in KafkaRaftMetrics temporarily reports -1 when a Raft node transitions to the Leader state.

Detail

Previously, QuorumState.transitionToLeader initialized the new LeaderState with an empty high watermark. This caused the metric to drop to -1 until the first follower fetch updated it. This change updates QuorumState to pass the existing high watermark (from the previous Follower or Candidate state) to the LeaderState, preserving monotonicity.

Tests

  • Updated: KafkaRaftMetricsTest to assert the correct high watermark value (e.g., 5) instead of -1.
  • Updated: QuorumStateTest (testHighWatermarkRetained) to verify the high watermark is preserved on transition.
  • Updated: LeaderStateTest to match the updated constructor signature.
  • Verified that all tests pass with ./gradlew raft:test.

Committer Checklist (Excluded from Commit Message)

  • Verify that tests pass.
  • Verify that checkstyle passes.

NOTE TO MAINTAINERS:
I am currently unable to create a JIRA ticket due to the public signup restrictions on the ASF JIRA portal. Could a maintainer please help create a ticket for this issue?

@github-actions github-actions bot added triage PRs from the community kraft labels Jan 2, 2026
@chia7712
Copy link
Member

chia7712 commented Jan 2, 2026

@samratdotcom thanks for this patch. Would you mind removing the unrelated changes?

@samratdotcom samratdotcom force-pushed the fix-high-watermark branch 4 times, most recently from 30e4ed4 to 1b1f40e Compare January 2, 2026 13:46
@github-actions github-actions bot added tests Test fixes (including flaky tests) small Small PRs labels Jan 2, 2026
Updated LeaderState and QuorumState to preserve high watermark during transition to Leader. Updated tests to assert correct behavior.
@samratdotcom
Copy link
Author

Hi @chia7712 ,
Review feedback addressed: I've removed all unrelated whitespace and formatting changes. The diff now contains only the necessary logic for the high-watermark fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved kraft small Small PRs tests Test fixes (including flaky tests) triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants