Xavier Léauté created KAFKA-21657:
-------------------------------------

             Summary: KRaft observers busy-poll when no voter responds
                 Key: KAFKA-21657
                 URL: https://issues.apache.org/jira/browse/KAFKA-21657
             Project: Kafka
          Issue Type: Bug
          Components: kraft
    Affects Versions: 4.3.2, 4.2.2, 4.4.0, 4.1.2, 4.0.2, 3.9.2, 3.9.1
            Reporter: Xavier Léauté
            Assignee: Xavier Léauté


When an observer (e.g. a broker) gets no response from any voter, the KRaft I/O 
thread busy-loops: {{KafkaRaftClient.poll()}} computes a poll timeout of 0 on 
every iteration until a leader responds. This happens in two states.

*Follower*
{{maybeSendFetchToBestNode()}} returns {{min(backoffMs, 
state.remainingFetchTimeMs(currentTimeMs))}}. Only a successful fetch resets 
the fetch timer, so once the fetch timeout expires the result is always 0. 
Voters transition to prospective when the fetch timeout expires. Observers have 
had no such transition since KAFKA-19354 removed the observer's fetch-timeout 
branch, so they stay in the follower state and spin.

*Unattached*
An observer that starts up unattached ({{QuorumState.initialize()}}) gets a 
finite election timeout ({{randomElectionTimeoutMs()}}). Later transitions to 
unattached give observers {{Long.MAX_VALUE}}. {{pollUnattachedCommon()}} 
returns {{min(fetchBackoffMs, state.remainingElectionTimeMs(currentTimeMs))}}, 
so once the election timeout expires the result is always 0. Observers never 
act on the election timeout.

*Impact*
A busy loop on the raft I/O thread while the controller quorum is unavailable. 
Profiles show it as a significant share of broker CPU in 
{{FollowerState.leaderNode}}, {{VoterSet.isVoter}} and 
{{RequestManager.hasAnyInflightRequest}}.

*Proposed fix*
Bound the poll timeout by the fetch and election timeouts only on the voter 
paths ({{pollFollowerAsVoter}}, {{pollUnattachedAsVoter}}), since only voters 
act on them. Observers then wait for the in-flight fetch or the bootstrap 
server backoff.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to