jsancio commented on code in PR #20318:
URL: https://github.com/apache/kafka/pull/20318#discussion_r2449033478
##########
raft/src/main/java/org/apache/kafka/raft/LeaderState.java:
##########
@@ -188,6 +188,19 @@ public void resetBeginQuorumEpochTimer(long currentTimeMs)
{
beginQuorumEpochTimer.reset(beginQuorumEpochTimeoutMs);
}
+ // Leader don't need to send begin quorum requests to replicas which have
fetched recently.
+ public Set<ReplicaKey> needToSendBeginQuorumRequests(long currentTimeMs) {
Review Comment:
This returns the local replica which is a bit odd based on the name of the
method and the description of the method.
The commit works because the local replica is filtered
[here](https://github.com/apache/kafka/pull/20318/files#diff-1da15c51e641ea46ea5c86201ab8f21cfee9e7c575102a39c7bae0d5ffd7de39R3038):
`.filter(key -> key.id() != quorum.localIdOrThrow())`
How about changing this implementation so that it doesn't return the local
replica.
##########
raft/src/main/java/org/apache/kafka/raft/LeaderState.java:
##########
@@ -188,6 +188,19 @@ public void resetBeginQuorumEpochTimer(long currentTimeMs)
{
beginQuorumEpochTimer.reset(beginQuorumEpochTimeoutMs);
}
+ // Leader don't need to send begin quorum requests to replicas which have
fetched recently.
+ public Set<ReplicaKey> needToSendBeginQuorumRequests(long currentTimeMs) {
+ Set<ReplicaKey> replicaKeys = new HashSet<>();
+ beginQuorumEpochTimer.update(currentTimeMs);
+ for (ReplicaState state : voterStates.values()) {
+ if (currentTimeMs - state.lastFetchTimestamp >=
beginQuorumEpochTimeoutMs
+ || !state.hasAcknowledgedLeader) {
Review Comment:
Is `hasAcknowledgeLeader` redundant? Meaning if
`!state.hasAcknowledgeLeader` is true, then `currentTimeMs -
state.lastFetchTimestamp >= beginQuorumEpochTimeoutMs` is always true, no?
##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -3029,13 +3029,15 @@ private long maybeSendBeginQuorumEpochRequests(
)
);
- timeUntilNextBeginQuorumSend = maybeSendRequest(
+ Set<ReplicaKey> needToSendBeginQuorumRequests =
state.needToSendBeginQuorumRequests(currentTimeMs);
+ timeUntilNextBeginQuorumSend = maybeSendRequests(
currentTimeMs,
voters
.voterKeys()
.stream()
.filter(key -> key.id() != quorum.localIdOrThrow())
- .collect(Collectors.toSet()),
+ .filter(needToSendBeginQuorumRequests::contains)
+ .collect(Collectors.toUnmodifiableSet()),
Review Comment:
I think you can clean up and make this implementation more efficient by not
calling `voters.voterKeys` and instead leverage the replica keys returned by
`state.needToSendBeginQuorumRequests(currentTimeMs)`.
##########
raft/src/main/java/org/apache/kafka/raft/LeaderState.java:
##########
@@ -188,6 +188,18 @@ public void resetBeginQuorumEpochTimer(long currentTimeMs)
{
beginQuorumEpochTimer.reset(beginQuorumEpochTimeoutMs);
}
+ public Set<ReplicaKey> needToSendBeginQuorumRequests(long currentTimeMs) {
Review Comment:
Please make this a Java Doc. That means that you should add a general
description, `@param` and `@return`.
--
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]