jsancio commented on code in PR #22505:
URL: https://github.com/apache/kafka/pull/22505#discussion_r3437394890


##########
raft/src/main/java/org/apache/kafka/raft/UnattachedState.java:
##########
@@ -87,6 +87,11 @@ public int epoch() {
         return epoch;
     }
 
+    @Override
+    public LeaderAndEpoch leaderAndEpoch() {
+        return new LeaderAndEpoch(leaderId, epoch);

Review Comment:
   It could be empty but not necessarily. Because of KIP-853, a follower may 
know the leader id but not the leader's endpoints. When we implemented KIP-853, 
I updated the Java Doc for this state. It now reads:
   ```java
     /**
      * A replica is "unattached" when it doesn't know the leader or the 
leader's endpoint.
      *
      * Typically, a replica doesn't know the leader if the KRaft topic is 
undergoing an election cycle.
      *
      * It is also possible for a replica to be unattached if it doesn't know 
the leader's endpoint.
      * This typically happens when a replica starts up and the known leader id 
is not part of the local
      * voter set. In that case, during startup the replica transitions to 
unattached instead of
      * transitioning to follower. The unattached replica discovers the leader 
and leader's endpoint
      * either through random Fetch requests to the bootstrap servers or 
through BeginQuorumEpoch
      * request from the leader.
      */
   ```
   
   I used Unattached for this state instead of Follower state. To me the key 
invariants are that Followers fetch from the leader and unattached fetch from 
the bootstrap servers.
   
   Regard the leader id. One key invariant of kraft is that nodes can never 
"forget" the voted id (the replica for which they voted in a given epoc) or the 
leader id of an epoch. The main reason for this invariant is so that replicas 
do not vote for different replicas in the same epoch. This is needed so that 
for a given epoch the leader is stable if a leader was elected.
   
   The kraft implementation has one small annoyance that it forgets the voted 
id when it becomes a follower. This is the reason why replica cannot forget the 
leader id when they become follower. I hope to fix this voted id issue soon: 
https://issues.apache.org/jira/browse/KAFKA-16213



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

Reply via email to