kafka如何处理不同批次的订购?

How does kafka handle ordering of different batch?

在kafka关于重试的文档中,它说:

Allowing retries without setting max.in.flight.requests.per.connection to 1 will potentially change the ordering of records because if two batches are sent to a single partition, and the first fails and is retried but the second succeeds, then the records in the second batch may appear first.

根据段落,如果将两个批次发送到同一个分区,kafka 可以提交第二个批次而第一个批次失败。
但这似乎与卡夫卡关于在同一分区中订购的保证相矛盾。因为通常如果一个批次失败了,后面的批次都应该失败,否则怎么保证顺序呢?另外kafka如何保证producer发送的batch的顺序和broker接收的顺序一致

所以我的问题是:kafka如何保证不同批次(同一分区)的排序,或者它只是不保证。

how does kafka guarantee the ordering of different batch (of same partition) or it just does not guarantee.

通过设置

保证分区内的顺序
  • retries=0
  • retries>0max.in.flight.requests.per.connection=1.

如果将重试次数增加到大于 0,则配置 max.in.flight.requests.per.connection 生效,默认为 5in-flight 请求意味着最多可以有 5 个生产者请求尚未被代理确认。

如文档中引用的段落所述,您的批次 B1、B2、B3、B4、B5 都可以并行发送。如果发送 B3 失败并且重试次数 > 0,则它可能会在 B5 之后写入代理。