定义(definition)
副本是在topic分区这个层级上定义的,它是只能追加写消息的日志 (AOF)
角色(role)
领导者副本(Leader Replica) 只能有一个
追随者副本(Follower Replica) 可有多个
副本机制有什么好处?(what are the benefits of replicas)
1. 数据持久化
2. 提供高伸缩性
3. 改善数据的局部性
因为kafka只有Leader Replica对外提供读写服务,所以2,3两点不满足。
副本如何同步?(how to synchronize Leader-Follower Replicas)
![](https://img.haomeiwen.com/i13379180/7295d87285ffeb1a.png)
当生产者设置 acks = all 时,表示在ISR(In-Sync Replicas)中所有的副本都需收到消息后才返回。可确保消息的强一致性,但会降低吞吐量。当生产者设置 acks = 1 时, 表示只要Leader收到消息后就返回,基本可以确保消息的最终一致性,提升kafka写入消息的吞吐量。
![](https://img.haomeiwen.com/i13379180/b540cdfa539c2eeb.png)
![](https://img.haomeiwen.com/i13379180/028820102ecef77c.png)
![](https://img.haomeiwen.com/i13379180/c9ed929a204c0242.png)
网友评论