且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Kafka:隔离级别影响

更新时间:2023-09-24 10:02:34

首先,isolation.level 设置仅对消费者产生影响,前提是它消费的主题包含使用事务性写入的记录制作人.

First, the isolation.level setting only has an impact on the consumer if the topics it's consuming from contains records written using a transactional producer.

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

If so, if it's set to read_uncommitted, the consumer will simply read everything including aborted transactions. That is the default.

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

When set to read_committed, the consumer will only be able to read records from committed transactions (in addition to records not part of transactions). It also means that in order to keep ordering, if a transaction is in-flight the consumer will not be able to consume records that are part of that transation. Basically the broker will only allow the consumer to read up to the Last Stable Offset (LSO). When the transation is committed (or aborted), the broker will update the LSO and the consumer will receive the new records.

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

If you don't tolerate duplicates or records from aborted transactions, then you should use read_committed. As you hinted this creates a small delay in consuming as records are only visible once transactions are committed. The impact mostly depends on the sizes of your transactions, ie how often you commit.