我们可以在断电的情况下丢失 kafka 消息吗?
Can we lose kafka message in case of poweroff?
我有一个关于 Kafka 进程如何失败的理论问题。
假设我们只有 1 个分区和 2 个消费者。我知道不太可能有这种情况,但它是一个例子,我真的很想更好地理解它。我启用了自动提交和一点提交间隔。
分区是:
P: M1, M2, M3
其中 M1、M2 和 M3 是具有偏移量 (1, 2, 3) 的消息。
假设如下:
T1: M1, M2 - failed
T2: M3
这意味着worker(线程)1得到了M1并成功处理了它,但是它在处理M2时失败了。例如,关机或某些硬件问题。但它在失败之前提交了偏移量 2(顺便说一句——这可能吗?)。线程 2 得到 M3,成功处理它并提交偏移量 3。
结果我们丢失了 M2 消息。
问题——这可能吗?如果问题很明显,请提前致歉。
引自this优秀文章:
Before beginning the discussion on consistency and availability, keep
in mind that these guarantees hold as long as you are producing to one
partition and consuming from one partition. All guarantees are off
if you are reading from the same partition using two consumers or
writing to the same partition using two producers.
因此,对于两个消费者,您不能指望访问在处理过程中丢失的消息。但是,如果您坚持使用一个消费者并使用 "at least once message delivery" 模式,那么:
For at least
once delivery, the consumer reads data from a partition, processes the
message, and then commits the offset of the message it has processed.
In this case, the consumer could crash between processing the message
and committing the offset and when the consumer restarts it will
process the message again. This leads to duplicate messages in
downstream systems but no data loss.
Kafka 至少保证消息传递一次。但您永远不会丢失消息。
你说的情况永远不会发生。它不能提交偏移量,除非它读取消息。您已打开自动提交。这只是说您将在每个固定的时间间隔内提交偏移量。这并不意味着偏移量会在不阅读消息的情况下向前移动。 Kafka 保证。
我有一个关于 Kafka 进程如何失败的理论问题。 假设我们只有 1 个分区和 2 个消费者。我知道不太可能有这种情况,但它是一个例子,我真的很想更好地理解它。我启用了自动提交和一点提交间隔。
分区是:
P: M1, M2, M3
其中 M1、M2 和 M3 是具有偏移量 (1, 2, 3) 的消息。
假设如下:
T1: M1, M2 - failed
T2: M3
这意味着worker(线程)1得到了M1并成功处理了它,但是它在处理M2时失败了。例如,关机或某些硬件问题。但它在失败之前提交了偏移量 2(顺便说一句——这可能吗?)。线程 2 得到 M3,成功处理它并提交偏移量 3。
结果我们丢失了 M2 消息。 问题——这可能吗?如果问题很明显,请提前致歉。
引自this优秀文章:
Before beginning the discussion on consistency and availability, keep in mind that these guarantees hold as long as you are producing to one partition and consuming from one partition. All guarantees are off if you are reading from the same partition using two consumers or writing to the same partition using two producers.
因此,对于两个消费者,您不能指望访问在处理过程中丢失的消息。但是,如果您坚持使用一个消费者并使用 "at least once message delivery" 模式,那么:
For at least once delivery, the consumer reads data from a partition, processes the message, and then commits the offset of the message it has processed. In this case, the consumer could crash between processing the message and committing the offset and when the consumer restarts it will process the message again. This leads to duplicate messages in downstream systems but no data loss.
Kafka 至少保证消息传递一次。但您永远不会丢失消息。
你说的情况永远不会发生。它不能提交偏移量,除非它读取消息。您已打开自动提交。这只是说您将在每个固定的时间间隔内提交偏移量。这并不意味着偏移量会在不阅读消息的情况下向前移动。 Kafka 保证。