首页 > 解决方案 > 设置配置保留.ms=3600000 仍然没有从 Kafka 中删除数据

问题描述

我已通过以下命令设置了retention.ms=3600000,但1小时后磁盘上仍有大量数据。由于大量数据传入 Kafka,我的磁盘已满。

./bin/kafka-topics.sh --zookeeper zookeeper:2181 --alter --topic topic_1 --config retention.ms=3600000

描述命令

 ./bin/kafka-topics.sh --zookeeper zookeeper:2181 --describe --topics-with-overrides
    Topic:__consumer_offsets        PartitionCount:50       ReplicationFactor:3     Configs:segment.bytes=104857600,cleanup.policy=compact,compression.type=producer
    Topic:topic_1    PartitionCount:3        ReplicationFactor:3     Configs:retention.ms=3600000
    Topic:topic_2    PartitionCount:3        ReplicationFactor:3     Configs:retention.ms=3600000
    Topic:topic_3    PartitionCount:3        ReplicationFactor:3     Configs:retention.ms=3600000,retention.bytes=104857600

谁能给出建议,为什么kafka在1小时后不删除数据。?

标签: apache-kafkaretention

解决方案


从 describe 命令结果来看,主题保留策略设置为compact启用日志压缩而不是删除,并将保留每个键的最新数据。要删除所有超过保留期的数据,您需要将保留策略设置为delete

./bin/kafka-topics.sh --zookeeper zookeeper:2181 --alter --topic topic_1 --config cleanup.policy=delete

推荐阅读