简体   繁体   English

如果 ISR 小于复制因子并且生产者 acks 设置为 all,那么生产者会等待多少个 acks?

[英]If ISR is less than replication factor and producer acks are set to all, How many acks will the producer wait for?

  • RF = 3 , ISR = 3 , acks = all >>> sent successfully RF = 3 , ISR = 3 , acks = all >>> 发送成功
  • RF = 3 , ISR = 2 , acks = all >>> sent successfully RF = 3 , ISR = 2 , acks = all >>> 发送成功
  • RF = 3 , ISR = 1 , acks = all >>> sent successfully RF = 3 , ISR = 1 , acks = all >>> 发送成功
  • RF = 3 , ISR = 1 , acks = all , min.isr.replicas = 3 >>> sent successfully ! RF = 3 , ISR = 1 , acks = all , min.isr.replicas = 3 >>> 发送成功!

So, If replication factor is 4, ISR is 3 and producer acks are set to all, How many acks will the producer wait for?那么,如果复制因子为 4,ISR 为 3,并且生产者确认设置为全部,生产者将等待多少确认? I tried different scenarios, What should be the real behavior?我尝试了不同的场景,真正的行为应该是什么?

If you set acks=all broker which is the partition leader will wait all in-sync-replicas to replicate the data.如果您设置acks=all代理,它是分区领导者将等待所有同步副本复制数据。 In-sync-replica is a replica which is not far behind the partition leader. In-sync-replica 是一个分区领导者不远的副本。

What I mean by not far behind: In Kafka when a message is sent to a topic-partition (firstly message is received and stored in leader) and if replication factor for this topic is greater than 1, then replica broker(s) send fetch request(s) to leader broker and this data is replicated to other broker(s).我的意思是紧随其后:在 Kafka 中,当消息发送到主题分区时(首先接收消息并将其存储在领导者中)并且如果该主题的复制因子大于 1,则副本代理发送获取向领导代理发出请求,并将此数据复制到其他代理。 If replica.lag.time.max.ms is passed from last caught up, replica is considered as out-of-sync and removed from ISR list.如果replica.lag.time.max.ms是从上次赶上开始传递的, replica.lag.time.max.ms副本视为不同步并从 ISR 列表中删除。 (It is still a replica and fetch messages but leader broker doesn't wait it until catch up and became an in-sync-replica again) (它仍然是一个副本并获取消息,但领导代理不会等到它赶上并再次成为同步副本)

From Kafka docs:来自 Kafka 文档:

Configuration parameter replica.lag.time.max.ms now refers not just to the time passed since last fetch request from replica, but also to time since the replica last caught up.配置参数 replica.lag.time.max.ms 现在不仅指自上次从副本获取请求以来经过的时间,还指自副本上次赶上以来的时间。 Replicas that are still fetching messages from leaders but did not catch up to the latest messages in replica.lag.time.max.ms will be considered out of sync.仍在从领导者获取消息但没有赶上 replica.lag.time.max.ms 中的最新消息的副本将被视为不同步。

There is also min.insync.replicas parameter in broker config.代理配置中还有min.insync.replicas参数。 It specifies minimum number of in-sync-replicas to continue sending message when acks=all .它指定在acks=all时继续发送消息的最小同步副本数。

min.insync.replicas: When a producer sets acks to "all" (or "-1"), min.insync.replicas specifies the minimum number of replicas that must acknowledge a write for the write to be considered successful. min.insync.replicas:当生产者将 acks 设置为“全部”(或“-1”)时,min.insync.replicas 指定必须确认写入才能将写入视为成功的最小副本数。 If this minimum cannot be met, then the producer will raise an exception (either NotEnoughReplicas or NotEnoughReplicasAfterAppend).如果无法满足此最小值,则生产者将引发异常(NotEnoughReplicas 或 NotEnoughReplicasAfterAppend)。 When used together, min.insync.replicas and acks allow you to enforce greater durability guarantees.当一起使用时,min.insync.replicas 和 acks 允许您强制执行更大的持久性保证。 A typical scenario would be to create a topic with a replication factor of 3, set min.insync.replicas to 2, and produce with acks of "all".一个典型的场景是创建一个复制因子为 3 的主题,将 min.insync.replicas 设置为 2,并使用“all”的 acks 进行生产。 This will ensure that the producer raises an exception if a majority of replicas do not receive a write.如果大多数副本没有收到写入,这将确保生产者引发异常。


If replication factor is 4, ISR is 3 and producer acks are set to all, How many acks will the producer wait for?如果复制因子为 4,ISR 为 3,并且生产者 acks 设置为 all,那么生产者将等待多少个 acks?

Answer : Broker which is topic-partition leader will wait 3 other brokers in ISR list to replicate the data and send acknowledgement.:作为主题分区领导者的 Broker 将等待 ISR 列表中的其他 3 个 Broker 复制数据并发送确认。 If number of replicas in ISR list is less than min.insync.replicas then your producer get an exception and cannot produce the data.如果 ISR 列表中的副本数小于min.insync.replicas那么您的生产者会收到异常并且无法生成数据。

Note: You can check current replica and ISR list with command below.注意:您可以使用以下命令检查当前副本和 ISR 列表。

bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic myTopic --describe

When it comes to the acks setting the replication factor of the topic itself only plays an implicit role.当涉及到acks设置主题本身的replication factor ,它只起到隐含的作用。 As written in the Broker Configuration documentation and cited below the min.insync.replicas defines the minimum number of successful replications broker-wide before it is seen as a successful write.正如 Broker Configuration文档中所写并在下面引用的那样, min.insync.replicas定义了在被视为成功写入之前,代理范围内成功复制的最小数量。

min.insync.replicas: When a producer sets acks to "all" (or "-1"), min.insync.replicas specifies the minimum number of replicas that must acknowledge a write for the write to be considered successful . min.insync.replicas:当生产者将 acks 设置为“全部”(或“-1”)时,min.insync.replicas 指定必须确认写入才能将写入视为成功的最小副本数 If this minimum cannot be met, then the producer will raise an exception (either NotEnoughReplicas or NotEnoughReplicasAfterAppend).如果无法满足此最小值,则生产者将引发异常(NotEnoughReplicas 或 NotEnoughReplicasAfterAppend)。 When used together, min.insync.replicas and acks allow you to enforce greater durability guarantees.当一起使用时,min.insync.replicas 和 acks 允许您强制执行更大的持久性保证。 A typical scenario would be to create a topic with a replication factor of 3, set min.insync.replicas to 2, and produce with acks of "all".一个典型的场景是创建一个复制因子为 3 的主题,将 min.insync.replicas 设置为 2,并使用“all”的 acks 进行生产。 This will ensure that the producer raises an exception if a majority of replicas do not receive a write.如果大多数副本没有收到写入,这将确保生产者引发异常。

Type: int类型:int

Default: 1默认值:1

Valid Values: [1,...]有效值:[1,...]

Importance: high重要性:高

Update Mode: cluster-wide更新模式:集群范围

To answer your conrete question: If replication factor is 4, and min.insync.replicas is 3 and producer acks are set to all, then the producer will wait for 3 acknowledgments within the cluster before it is seen as a successful write.回答您的具体问题:如果replication factor为 4,并且min.insync.replicas为 3 并且生产者acks设置为全部,那么生产者将在集群内等待 3 次确认,然后才会被视为成功写入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM