gpt4 book ai didi

apache-kafka - 卡夫卡 : isolation level implications

转载 作者:行者123 更新时间:2023-12-04 23:56:06 25 4
gpt4 key购买 nike

我有一个用例,我需要 100% 的可靠性、幂等性(无重复消息)以及我的 Kafka 分区中的顺序保留。我正在尝试使用事务 API 来设置概念证明来实现这一点。有一个名为“isolation.level”的设置,我很难理解。
在此 article ,他们谈论两个选项之间的区别

There are now two new isolation levels in Kafka consumer:

read_committed: Read both kind of messages that are not part of atransaction and that are, after the transaction is committed.Read_committed consumer uses end offset of a partition, instead ofclient-side buffering. This offset is the first message in thepartition belonging to an open transaction. It is also known as “LastStable Offset” (LSO). A read_committed consumer will only read up tillthe LSO and filter out any transactional messages which have beenaborted.

read_uncommitted: Read all messages in offset order withoutwaiting for transactions to be committed. This option is similar tothe current semantics of a Kafka consumer.


这里的性能含义是显而易见的,但老实说,我正在努力阅读字里行间并理解每个选择的功能含义/风险。好像 read_committed是“更安全”,但我想了解为什么。

最佳答案

一、isolation.level如果消费者从中消费的主题包含使用事务性生产者编写的记录,则设置仅对消费者产生影响。

如果是这样,如果它设置为 read_uncommitted ,消费者将简单地阅读包括中止交易在内的所有内容。这是默认设置。

设置为 read_committed 时,消费者将只能从已提交的事务中读取记录(除了不属于事务的记录)。这也意味着为了保持排序,如果交易正在进行中,消费者将无法消费属于该交易的记录。基本上,代理只允许消费者读取最后一个稳定偏移量 (LSO)。当事务提交(或中止)时,代理将更新 LSO,消费者将收到新记录。

如果您不能容忍中止事务的重复或记录,那么您应该使用 read_committed .正如您所暗示的那样,这会在消费中产生一个小的延迟,因为只有在提交事务后记录才可见。影响主要取决于您的交易规模,即您提交的频率。

关于apache-kafka - 卡夫卡 : isolation level implications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56047968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com