This is an automated email from the ASF dual-hosted git repository.
jsancio pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new f9e0d032747 MINOR; Make granting voter immutable (#13154)
f9e0d032747 is described below
commit f9e0d0327478e882c27a7b090a358ca593e89243
Author: José Armando García Sancio <[email protected]>
AuthorDate: Wed Jan 25 15:52:01 2023 -0800
MINOR; Make granting voter immutable (#13154)
Make LeaderState's grantingVoters field explicitly immutable. The set of
voters that granted their voter to the current leader was already immutable.
This change makes that explicit.
Reviewers: Jason Gustafson <[email protected]>, Mathew Hogan
<mathewdhogan@@users.noreply.github.com>
---
raft/src/main/java/org/apache/kafka/raft/LeaderState.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/raft/src/main/java/org/apache/kafka/raft/LeaderState.java
b/raft/src/main/java/org/apache/kafka/raft/LeaderState.java
index ac0ef1260b9..b5bc607a01f 100644
--- a/raft/src/main/java/org/apache/kafka/raft/LeaderState.java
+++ b/raft/src/main/java/org/apache/kafka/raft/LeaderState.java
@@ -26,6 +26,7 @@ import org.apache.kafka.raft.internals.BatchAccumulator;
import org.slf4j.Logger;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -47,11 +48,11 @@ public class LeaderState<T> implements EpochState {
private final int localId;
private final int epoch;
private final long epochStartOffset;
+ private final Set<Integer> grantingVoters;
private Optional<LogOffsetMetadata> highWatermark;
private final Map<Integer, ReplicaState> voterStates = new HashMap<>();
private final Map<Integer, ReplicaState> observerStates = new HashMap<>();
- private final Set<Integer> grantingVoters = new HashSet<>();
private final Logger log;
private final BatchAccumulator<T> accumulator;
@@ -76,7 +77,7 @@ public class LeaderState<T> implements EpochState {
boolean hasAcknowledgedLeader = voterId == localId;
this.voterStates.put(voterId, new ReplicaState(voterId,
hasAcknowledgedLeader));
}
- this.grantingVoters.addAll(grantingVoters);
+ this.grantingVoters = Collections.unmodifiableSet(new
HashSet<>(grantingVoters));
this.log = logContext.logger(LeaderState.class);
this.accumulator = Objects.requireNonNull(accumulator, "accumulator
must be non-null");
}