【Kafka】broker -副本与ISR设计

kafka把分区的所有副本均匀地分配到所有broker上,并从这些副本中挑选一个作为leader副本对外提供服务,而其他副本被称为follower副本,只能被动地向leader副本请求数据,从而保持与leader副本的同步:

所谓isr,就是Kafka集群动态维护的一组同步副本集合,每个topic分区都有自己的isr列表,isr中的所有副本都与leader保持同步状态,而producer写入的一条Kafka 消息只有被isr中的所有副本都接收到,才被视为“已提交”状态,由此可见,若isr中有n个副本,那么该分区最多可以忍受n-1个副本崩溃而不丢失已提交消息。

1.follower副本同步:

follower副本只做一件事情:向leader副本请求数据。

如何界定同步:

0.9.0.0版本之前:落后消息数+时间

0.9.0.0版本之后:由于慢以及进程卡壳导致的滞后–即follower副本落后leader副本的时间间隔,replica.lag.time.max.ms默认是10秒。如果一个follower副本落后leader的时间持续性地超过了这个参数值,那么该follower副本就是不同步的。

### Kafka Acknowledgment Modes Explained In Apache Kafka, the producer sends messages to brokers and expects an acknowledgment (ack) from them. There are three main ack modes that dictate how acknowledgments work: #### 0: No Acknowledgment Required When setting `acks=0`, the producer does not wait for any acknowledgment from the broker after sending a message. This mode offers the highest throughput but provides no guarantee that the message has been successfully written to the log[^1]. ```python producer.send('topic', key=b'key', value=b'value').add_callback( lambda resp: print(f'Successfully sent message at offset {resp.offset}') ).add_errback(lambda err: print(f'Message delivery failed due to error: {err}')) ``` This example demonstrates sending without waiting for acknowledgment. #### 1: Wait for Leader Acknowledgment Setting `acks=1` means the producer waits until it receives an acknowledgment only from the leader partition replica. Once this happens, the leader considers the write successful even if followers have yet to replicate data. While offering better reliability than `acks=0`, some risk remains as unreplicated writes can be lost upon leader failure. #### All (-1): Wait for Full Replication Acknowledgment By configuring `acks=all` or `-1`, producers ensure all in-sync replicas acknowledge receipt before considering send operations complete. Although slower compared with other settings, this option guarantees maximum durability since committed records will remain available despite potential failures affecting fewer than half of configured ISR nodes.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值