-
Notifications
You must be signed in to change notification settings - Fork 14.9k
KAFKA-19212: Correct the unclean leader election metric calculation for 3.9 #21134
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
base: 3.9
Are you sure you want to change the base?
Conversation
|
@mmatloka thanks for this patch. Do you have time to add an integration test to reproduce this bug? |
Hi, I will try to add additional tests |
Hi, I added some additional tests. Could you check them, and if they’re not sufficient, point out where I should add more (I am not fully familiar with this codebase)? |
metadata/src/main/java/org/apache/kafka/metadata/PartitionRegistration.java
Outdated
Show resolved
Hide resolved
| int[] prevIsr = prev != null ? prev.isr : next.replicas; | ||
| if (!PartitionRegistration.electionWasClean(next.leader, prevIsr)) { | ||
| // check if at the same step the partition we are adding to ISR is becoming the leader, don't treat that as unclean election. | ||
| int[] nextAddingReplicas = next.addingReplicas; |
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.
Could someone doublecheck my thinking? AddingReplicas will appear in prev or in next?
|
Thanks for the patch! I've a question:
I'm unsure about this. Going through the original fix, IIUC, it modifies the "unclean" check to be based on |
Hi, actually the good question is what events actually lead to the situation where adding replica becomes the leader in one step. One situation is probably when it is recovering. However, what we saw in practice, that the situation was probably(?) result of some partition re-assign (probably performed by Confluent SBC actually, new cluster, completely healthy, idle, nothing happening, suddenly adding partition becomes the leader and metrics show unclean election. maybe manual reassign could try to simulate this 🤔 ). Do the partition re-assign cause the leader go through recovering state? |
This is attempt of backport #19590 specific for Kafka 3.9. Copying description from that PR:
"""
The current ElectionWasClean checks if the new leader is in the previous
ISR. However, there is a corner case in the partition reassignment. The
partition reassignment can change the partition replicas. If the new
preferred leader (the first one in the new replicas) is the last one to
join ISR, this preferred leader will be elected in the same partition
change.
For example: In the previous state, the partition is Leader: 0,
Replicas (2,1,0), ISR (1,0), Adding(2), removing(0). Then replica 2
joins the ISR. The new partition would be like: Leader: 2, Replicas
(2,1), ISR(1,2). The new leader 2 is not in the previous ISR (1,0) but
it is still a clean election.
"""
The original fix depends on ELR, however, AFAIK ELR's are valid for Kafka 4.0 and 4.1, not for 3.9. I prepared a simpler fix for 3.9 (we have encountered such problem under 3.9, and Confluent confirmed it is an issue).
Note: this is my first Apache contribution, I signed the ICLA, I read the contributing guidelines, sorry if I did something incorrectly :)
Let me also mention author of the original fix for 4.x - @CalvinConfluent
Thank you!