log.retention.hours
is a property of a broker which is used as a default value when a topic is created. When you change configurations of currently running topic using kafka-topics.sh
, you should specify a topic-level property.
A topic-level property for log retention time is retention.ms
.
From Topic-level configuration in Kafka 0.8.1 documentation:
- Property: retention.ms
- Default: 7 days
- Server Default Property: log.retention.minutes
- Description: This configuration controls the maximum time we will retain a log before we will discard old log segments to free up space if we are using the "delete" retention policy. This represents an SLA on how soon consumers must read their data.
So the correct command depends on the version. Up to 0.8.2 (although docs still show its use up to 0.10.1) use kafka-topics.sh --alter
and after 0.10.2 (or perhaps from 0.9.0 going forward) use kafka-configs.sh --alter
$ bin/kafka-topics.sh --zookeeper zk.yoursite.com --alter --topic as-access --config retention.ms=86400000
You can check whether the configuration is properly applied with the following command.
$ bin/kafka-topics.sh --describe --zookeeper zk.yoursite.com --topic as-access
Then you will see something like below.
Topic:as-access PartitionCount:3 ReplicationFactor:3 Configs:retention.ms=86400000
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…