1、follower发送fetch请求到leader,leader无数据更新时,加入时间轮(100ms)延迟调度 给follower发送空响应 (节约网络资源)
2、leader有数据更新时,会唤醒 时间轮马上执行给follower发送空响应
follower接收到空响应后会继续向leader 发送fetch请求
KafkaApi.handle case ApiKeys.FETCH => handleFetchRequest(request)
replicaManager.fetchMessages
def fetchMessages(timeout: Long,
replicaId: Int,
fetchMinBytes: Int,
fetchMaxBytes: Int,
hardMaxBytesLimit: Boolean,
fetchInfos: Seq[(TopicAndPartition, PartitionFetchInfo)],
quota: ReplicaQuota = UnboundedQuota,
responseCallback: Seq[(TopicAndPartition, FetchResponsePartitionData)] => Unit) {
val isFromFollower = replicaId >= 0
val fetchOnlyFromLeader: Boolean = replicaId != Request.DebuggingConsumerId
val fetchOnlyCommitted: Boolean = ! Request.isValidBrokerId<