TaiJuWu commented on code in PR #20318:
URL: https://github.com/apache/kafka/pull/20318#discussion_r2450832720
##########
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:
Good suggestion, fixed it.
##########
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:
You are right, this is like guard code instead of necessary.
##########
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:
Fixed it.
--
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]