-
Notifications
You must be signed in to change notification settings - Fork 14.6k
KAFKA-16926: Optimize BeginQuorumEpoch heartbeat #20318
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: trunk
Are you sure you want to change the base?
Conversation
A label of 'needs-attention' was automatically added to this PR in order to raise the |
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.
@TaiJuWu thanks for your patch
beginQuorumEpochTimer.update(currentTimeMs); | ||
for (Map.Entry<ReplicaKey, Long> entry : lastFetchRequestMs.entrySet()) { | ||
if (beginQuorumEpochTimer.currentTimeMs() - entry.getValue() >= beginQuorumEpochTimeoutMs) { | ||
replicaKeys.add(ReplicaKey.of(entry.getKey().id(), entry.getKey().directoryId().orElse(NO_DIRECTORY_ID))); |
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.
how about replicaKeys.add(entry.getKey());
?
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.
Fixed.
.voterKeys() | ||
.stream() | ||
.filter(key -> key.id() != quorum.localIdOrThrow()) | ||
.filter(key -> !needToSendBeginQuorumRequestNode.contains(key.id())) |
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 are we only checking id
? The unique key is actually composed of both id
and directory id
, right?
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 have updated the code and add a new method equivalentTo
to check two replicaKey because the directions can be empty before KIP-853.``
After 4.0 we can assume all node have directoryID, so I rewrite test and use replicaKey.
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.
Thanks for the patch @TaiJuWu, I left some comment below.
private final Timer beginQuorumEpochTimer; | ||
private final int beginQuorumEpochTimeoutMs; | ||
private final KafkaRaftMetrics kafkaRaftMetrics; | ||
private final Map<ReplicaKey, Long> lastFetchRequestMs = new HashMap<>(); |
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.
This could be replaced with ReplicaState#lastFetchTimestamp, right?
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.
fix, thanks.
Set<ReplicaKey> replicaKeys = new HashSet<>(); | ||
beginQuorumEpochTimer.update(currentTimeMs); | ||
for (Map.Entry<ReplicaKey, Long> entry : lastFetchRequestMs.entrySet()) { | ||
if (beginQuorumEpochTimer.currentTimeMs() - entry.getValue() >= beginQuorumEpochTimeoutMs) { |
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.
From the code above at KafkaRaftClient#L3059,
.filter(key -> !needToSendBeginQuorumRequest.contains(key))
I think the condition should be changed to:
if (beginQuorumEpochTimer.currentTimeMs() - entry.getValue() >= beginQuorumEpochTimeoutMs) { | |
if (beginQuorumEpochTimer.currentTimeMs() - entry.getValue() < beginQuorumEpochTimeoutMs) { |
and we should rename the method to skipSendBeginQuorumRequestNodes
.
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 also use needToSendBeginQuorumRequest
and change filter condition because positive logic is easier to understand.
53eb81c
to
f67e5bd
Compare
Instead of sending out BeginQuorum requests to every voter on a cadence,
we can save on some requests by only sending to those which have not
fetched within the BeginQuorumEpoch timeout.