samratdotcom opened a new pull request, #21238:
URL: https://github.com/apache/kafka/pull/21238

   ### Summary
   Fixes a bug where the `high-watermark` metric in 
[KafkaRaftMetrics](cci:2://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/main/java/org/apache/kafka/raft/internals/KafkaRaftMetrics.java:37:0-288:1)
 temporarily reports `-1` when a Raft node transitions to the 
[Leader](cci:1://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/main/java/org/apache/kafka/raft/QuorumState.java:853:4-855:5)
 state.
   
   ### Detail
   Previously, `QuorumState.transitionToLeader` initialized the new 
[LeaderState](cci:2://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/main/java/org/apache/kafka/raft/LeaderState.java:62:0-1152:1)
 with an empty high watermark. This caused the metric to drop to `-1` until the 
first follower fetch updated it. This change updates 
[QuorumState](cci:2://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/main/java/org/apache/kafka/raft/QuorumState.java:83:0-933:1)
 to pass the existing high watermark (from the previous 
[Follower](cci:1://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/main/java/org/apache/kafka/raft/QuorumState.java:837:4-839:5)
 or 
[Candidate](cci:1://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/main/java/org/apache/kafka/raft/QuorumState.java:865:4-867:5)
 state) to the 
[LeaderState](cci:2://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/main/java/org/apache/kafka/raft/LeaderState.java:62:0-1152:1),
 preserving 
 monotonicity.
   
   ### Tests
   *   **Updated**: 
[KafkaRaftMetricsTest](cci:2://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/test/java/org/apache/kafka/raft/internals/KafkaRaftMetricsTest.java:48:0-530:1)
 to assert the correct high watermark value (e.g., `5`) instead of `-1`.
   *   **Updated**: 
[QuorumStateTest](cci:2://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/test/java/org/apache/kafka/raft/QuorumStateTest.java:51:0-2678:1)
 
([testHighWatermarkRetained](cci:1://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/test/java/org/apache/kafka/raft/QuorumStateTest.java:193:4-230:5))
 to verify the high watermark is preserved on transition.
   *   **Updated**: 
[LeaderStateTest](cci:2://file:///Users/samratrohit/Downloads/Projects/kafka/raft/src/test/java/org/apache/kafka/raft/LeaderStateTest.java:49:0-875:1)
 to match the updated constructor signature.
   *   Verified that all tests pass with `./gradlew raft:test`.
   
   ### Committer Checklist (Excluded from Commit Message)
   - [x] Verify that tests pass.
   - [x] 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?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to