在ReplicaManager.makeFollowers
函数中,对于成为Follower的broker,需要执行这么一段代码:
val partitionsToMakeFollowerWithLeaderAndOffset = partitionsToMakeFollower.map(partition =>
new TopicAndPartition(partition) -> BrokerAndInitialOffset(
leaders.find(_.id == partition.leaderReplicaIdOpt.get).get,
partition.getReplica().get.logEndOffset.messageOffset)).toMap
replicaFetcherManager.addFetcherForPartitions(partitionsToMakeFollowerWithLeaderAndOffset)
这段代码首先获取Follower对应的(leader,leo),之后调用addFetcherForPartitions将这些partition纳入replicaFetcherManager的管理下,并不断同步leader中的log到follower中。
这里贴一下addFetcherForPartitions
的代码:
def addFetcherForPartitions(partitionAndOffsets: Map[TopicAndPartition, BrokerAndInitialOffset]) {
map