With Kafka 0.8.1.1, how do I change the log retention time while it's running? The documentation says the property is log.retention.hours
, but trying to change it using kafka-topics.sh
returns this error
$ bin/kafka-topics.sh --zookeeper zk.yoursite.com --alter --topic as-access --config topic.log.retention.hours=24 Error while executing topic command requirement failed: Unknown configuration "topic.log.retention.hours". java.lang.IllegalArgumentException: requirement failed: Unknown configuration "topic.log.retention.hours". at scala.Predef$.require(Predef.scala:145) at kafka.log.LogConfig$$anonfun$validateNames$1.apply(LogConfig.scala:138) at kafka.log.LogConfig$$anonfun$validateNames$1.apply(LogConfig.scala:137) at scala.collection.Iterator$class.foreach(Iterator.scala:631) at scala.collection.JavaConversions$JEnumerationWrapper.foreach(JavaConversions.scala:479) at kafka.log.LogConfig$.validateNames(LogConfig.scala:137) at kafka.log.LogConfig$.validate(LogConfig.scala:145) at kafka.admin.TopicCommand$.parseTopicConfigsToBeAdded(TopicCommand.scala:171) at kafka.admin.TopicCommand$$anonfun$alterTopic$1.apply(TopicCommand.scala:95) at kafka.admin.TopicCommand$$anonfun$alterTopic$1.apply(TopicCommand.scala:93) at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:57) at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:43) at kafka.admin.TopicCommand$.alterTopic(TopicCommand.scala:93) at kafka.admin.TopicCommand$.main(TopicCommand.scala:52) at kafka.admin.TopicCommand.main(TopicCommand.scala)
Apache Kafka supports a server-level retention policy that we can tune by configuring exactly one of the three time-based configuration properties: log. retention. hours.
Kafka Topic Retention Message retention is based on time, the size of the message or on both measurements. In most cases, that I'm aware of, using retention based on time is preferred by most companies. For time based retention, the message log retention is based on either hours, minutes or milliseconds.
The default value is 168 hours (seven days). This setting controls the period of time after which Kafka will force the log to roll, even if the segment file is not full. This ensures that the retention process is able to delete or compact old data. The number of hours to keep a log file before deleting it.
If you want to view the configurations for all topic Either you can view these properties log. retention. hours or log.retention.ms in server. properties in kafka config directory.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With