当前位置: 代码迷 >> 综合 >> Kafka配置offsets.retention.minutes和log.retention.minutes的区别
  详细解决方案

Kafka配置offsets.retention.minutes和log.retention.minutes的区别

热度:43   发布时间:2024-03-06 12:48:28.0

前言

在Kafka中,我们可能会发现两个与retention相关的配置:

  • log.retention.minutes
  • offsets.retention.minutes

那么它们之前的差别是什么呢?

定义

首先让我们看看它们在官方文档中的定义

名称 描述 类型 默认值 有效值 重要性
log.retention.minutes The number of minutes to keep a log file before deleting it (in minutes), secondary to log.retention.ms property. If not set, the value in log.retention.hours is used
在删除日志文件之前保留日志文件的分钟数(以分钟为单位),优先级弱于 log.retention.ms。 如果未设置,则使用log.retention.hours中的值
int null   高
offsets.retention.minutes Log retention window in minutes for offsets topic
主题偏移量日志文的保留时长(分钟)
int 1440 [1,...] 高

两者的差别

log.retention.minutes设定的是消息日志的保留时长,而offsets.retention.minutes则是记录topic的偏移量日志的保留时长。

偏移量是指向消费者已消耗的最新消息的指针。 比如,你消费了10条消息,那么偏移量将移动10个位置。 这个偏移量会被记录到日志中,以便我们下次消费时知道应该从哪个offset开始继续消费。
而offsets.retention.minutes允许我们将偏移量重置,即它会清除过期的记录主题偏移量的日志,一旦记录主题偏移量的日志被清楚,我们将不知道之前消费到具体哪个offset。这个设置并不会影响消息日志的保留时间。

比如我们将offsets.retention.minutes设为10,即十分钟。然后最后一次主题A的消费偏移量是100,十分钟内继续消费,讲会从101开始继续消费,但是十分钟内我们没有继续消费,该记录主题A的消费偏移量100的日志将会被清除,也就是下次继续消费主题A的消息时,我们不知道上一次消费哪里了(注意,主题A所存储的消息依旧在broker上,并没有被删除), 在这种情况下,将会根据auto.offset.reset 的设置,读取最早(smallest)/最晚(largest)的消息。

一般来说,记录topic的偏移量日志的保留时长需要设置的比消息日志的保留时长更大。

  相关解决方案