Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing kafka retention period during runtime

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) 
like image 825
Foo L Avatar asked Mar 18 '15 17:03

Foo L


People also ask

Can we change retention period in Kafka?

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.

What is retention MS in Kafka?

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.

What is log retention hours in Kafka?

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.

How do you check the retention time of a Kafka topic?

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.


1 Answers

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 
like image 143
Heejin Avatar answered Oct 03 '22 04:10

Heejin