gpt4 book ai didi

apache-kafka - 即使在保留时间/大小之后,数据仍然保留在 Kafka 主题中

转载 作者:行者123 更新时间:2023-12-04 00:55:03 25 4
gpt4 key购买 nike

我们设置了log retention hours到 1 小时如下(之前设置为 72H)
使用下面的Kafka命令行工具,我们设置kafka retention.ms1H .我们的目标是清除主题中早于 1H 的数据 - test_topic ,所以我们使用了以下命令:

kafka-configs.sh --alter \
--zookeeper localhost:2181 \
--entity-type topics \
--entity-name topic_test \
--add-config retention.ms=3600000
并且
kafka-topics.sh --zookeeper localhost:2181 --alter \
--topic topic_test \
--config retention.ms=3600000
两个命令都运行没有错误。
但问题在于 Kafka 数据比 1H 还旧并且仍然存在!
实际上没有数据从主题中删除 topic_test分区。我们有 HDP Kafka 集群版本 1.0x 和 ambari
我们不明白为什么关于主题的数据 - topic_test还留着?并且即使在我们按照已经描述的方式运行两个 cli 之后也没有减少
以下 kafka cli 有什么问题?
kafka-configs.sh --alter --zookeeper localhost:2181  --entity-type topics  --entity-name topic_test --add-config retention.ms=3600000

kafka-topics.sh --zookeeper localhost:2181 --alter --topic topic_test --config retention.ms=3600000
来自卡夫卡 server.log我们可以看到以下内容
2020-07-28 14:47:27,394] INFO Processing override for entityPath: topics/topic_test with config: Map(retention.bytes -> 2165441552, retention.ms -> 3600000) (kafka.server.DynamicConfigManager)
[2020-07-28 14:47:27,397] WARN retention.ms for topic topic_test is set to 3600000. It is smaller than message.timestamp.difference.max.ms's value 9223372036854775807. This may result in frequent log rolling. (kafka.server.TopicConfigHandler)
引用 - https://ronnieroller.com/kafka/cheat-sheet

最佳答案

日志清理器仅适用于非事件(有时也称为“旧”或“干净”)段。只要所有数据都适合事件(“脏”、“不干净”)段,其大小由 segment.bytes 定义。大小限制将不会发生清洁。
配置cleanup.policy被描述为:

A string that is either "delete" or "compact" or both. This string designates the retention policy to use on old log segments. The default policy ("delete") will discard old segments when their retention time or size limit has been reached. The "compact" setting will enable log compaction on the topic.


此外, segment.bytes是:

This configuration controls the segment file size for the log. Retention and cleaning is always done a file at a time so a larger segment size means fewer files but less granular control over retention.


配置 segment.ms也可用于引导删除:

This configuration controls the period of time after which Kafka will force the log to roll even if the segment file isn't full to ensure that retention can delete or compact old data.


由于它默认为一周,您可能希望减少它以满足您的需要。
因此,如果要将主题的保留设置为例如您可以设置一小时:
cleanup.policy=delete
retention.ms=3600000
segment.ms=3600000
file.delete.delay.ms=1 (The time to wait before deleting a file from the filesystem)
segment.bytes=1024
注意:我不是指 retention.bytes . segment.bytes如上所述,这是一个非常不同的事情。另外,请注意 log.retention.hours是集群范围的配置。因此,如果您计划为不同的主题设置不同的保留时间,这将解决它。

关于apache-kafka - 即使在保留时间/大小之后,数据仍然保留在 Kafka 主题中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63137084/

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