Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ensure that logs are retained forever in Kafka?

Tags:

apache-kafka

I need to configure Kafka never to delete logs. Looking at their documentation, I see two kinds of parameters that control this:

  • The "log cleaner", described at http://kafka.apache.org/documentation.html#compaction. It seems that setting log.cleaner.enable = false prevents the cleaner from deleting or compacting logs.

  • The "log retention" mechanism, described at http://kafka.apache.org/documentation.html#configuration under log.retention.<time scales>. It seems that setting log.retention.ms = -1 signals infinite retention.

My question is:

What is the relationship between these two mechanisms, are these the only two, and are the above settings necessary and sufficient to prevent logs from ever being deleted?

like image 922
Ryan Reich Avatar asked May 26 '16 00:05

Ryan Reich


People also ask

What is log retention in Kafka?

log.retention.hoursThe most common configuration for how long Kafka will retain messages is by time. The default is specified in the configuration file using the log. retention. hours parameter, and it is set to 168 hours, the equivalent of one week.

How do I change the retention period in Kafka?

Method 1) If your Kafka allow plaintext connections (via port 9092) you can do it getting into a kafka pod. Method 2) You can do it getting into zookeeper pod. You can still use deprecated script kafka-topics.sh to change retention period for a topic.

How long does Kafka persist data?

The Kafka cluster retains all published messages—whether or not they have been consumed—for a configurable period of time. For example if the log retention is set to two days, then for the two days after a message is published it is available for consumption, after which it will be discarded to free up space.


1 Answers

Not sure which version you are using. For me, I use this:

log.retention.hours=2147483647

That's roughly 245,000 years. I believe I tried -1 at some point, but using the max value worked. Perhaps log.retention.ms accepts different values, but regardless -- the second of your configuration options should be sufficient. My guess is neither option is necessary; either would be sufficient. Certainly, the second one is sufficient by itself.

like image 182
David Griffin Avatar answered Sep 21 '22 05:09

David Griffin