hachikuji commented on a change in pull request #9881:
URL: https://github.com/apache/kafka/pull/9881#discussion_r556935873



##########
File path: raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java
##########
@@ -325,8 +341,30 @@ private void fireHandleResign() {
     }
 
     @Override
-    public void initialize() throws IOException {
-        quorum.initialize(new OffsetAndEpoch(log.endOffset().offset, 
log.lastFetchedEpoch()));
+    public void initialize(String quorumVoterStrings) throws IOException {

Review comment:
       This is a little awkward given the presence of the voter configuration 
in `RaftConfig`. Perhaps we could let `initialize` take the full config?
   ```java
   public void initialize(RaftConfig config) throws IOException
   ```

##########
File path: raft/src/test/java/org/apache/kafka/raft/RaftEventSimulationTest.java
##########
@@ -753,11 +751,13 @@ void start(int nodeId) {
                 FETCH_TIMEOUT_MS, persistentState.store, time, logContext, 
random);
             Metrics metrics = new Metrics(time);
 
-            Map<Integer, InetSocketAddress> voterConnectionMap = 
voters.stream()
-                .collect(Collectors.toMap(
-                    Function.identity(),
-                    this::nodeAddress
-                ));
+            StringBuilder votersString = new StringBuilder();

Review comment:
       nit: since we have the same code in a couple places, maybe we can factor 
it into a `RaftTestUtil`?

##########
File path: raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java
##########
@@ -325,8 +341,30 @@ private void fireHandleResign() {
     }
 
     @Override
-    public void initialize() throws IOException {
-        quorum.initialize(new OffsetAndEpoch(log.endOffset().offset, 
log.lastFetchedEpoch()));
+    public void initialize(String quorumVoterStrings) throws IOException {
+        List<Node> quorumVoterNodes = 
quorumVoterStringsToNodes(quorumVoterStrings);
+        Set<Integer> quorumVoterIds = 
quorumVoterNodes.stream().map(Node::id).collect(Collectors.toSet());
+        this.requestManager = new RequestManager(quorumVoterIds, 
retryBackoffMs, requestTimeoutMs, random);
+
+        Map<Integer, InetSocketAddress> voterAddresses = 
quorumVoterNodes.stream()
+                .collect(Collectors.toMap(Node::id, node -> new 
InetSocketAddress(node.host(), node.port())));
+        for (Map.Entry<Integer, InetSocketAddress> voterAddressEntry : 
voterAddresses.entrySet()) {
+            channel.updateEndpoint(voterAddressEntry.getKey(), 
voterAddressEntry.getValue());
+        }
+
+        QuorumState quorumState = new QuorumState(
+                nodeId,
+                quorumVoterIds,
+                electionTimeoutMs,
+                fetchTimeoutMs,
+                quorumStateStore,
+                time,
+                logContext,
+                random);
+        quorumState.initialize(new OffsetAndEpoch(log.endOffset().offset, 
log.lastFetchedEpoch()));
+        this.quorum = quorumState;
+        this.kafkaRaftMetrics = new KafkaRaftMetrics(metrics, "raft", quorum);

Review comment:
       Since we are no longer initializing this in the constructor, we might 
need a null check in `close`.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to