Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing the right cleanup policy in Kafka configuration

Tags:

apache-kafka

I am using kafka_2.10-0.10.0.1. I created the topics with 1 partitions. I know that the default cleanup policy is "delete". I want to keep all the records in the topic all the time (without deleting any record). What's the right way : make "log.cleaner.enable=false" or "log.cleanup.policy=compact"?

like image 789
DaliMidou Avatar asked Jan 29 '18 14:01

DaliMidou


People also ask

What is Kafka cleanup policy?

Kafka Log Cleanup PoliciesKafka stores messages for a set amount of time and purge messages older than the retention period.

What is the default value of Kafka topic property cleanup policy?

cleanup. The default policy ("delete") will discard old segments when their retention time or size limit has been reached.

What are the strategies used by Kafka to clean up its old log segments?

Delete and Compact Both: We can specify both delete and compact values for the cleanup. policy configuration at the same time. In this case, the log is compacted, but the cleanup process also follows the retention time or size limit settings.

How do you set retention policy in Kafka?

The 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.


1 Answers

Topics have broker-wide configs that apply by default to any topic that doesn't have a config, but topics can also have topic-specific configs that override or complement broker-wide topic configs.

Broker-wide topic configs are set in your service.properties file. Topic specific configs are set using the bin/kafka-topics.sh script or AdminClient if you are using Java.

The relevant broker-wide config for you is log.retention.ms and the equivalent topic-specific config is retention.ms. If you set log.retention.ms to -1, all topics without this the retention.ms config will have an infinite retention period. Likewise, if you set -1 for retention.ms on a specific topic, it will have an infinite retention period.

To set retention.ms on a new topic:

bin/kafka-topics.sh --zookeeper zk_host:port/chroot --create --topic my_topic_name
  --partitions 20 --replication-factor 3 --config retention.ms=-1

You can also modify an existing topic to set retention.ms to -1:

> bin/kafka-configs.sh --zookeeper zk_host:port/chroot --entity-type topics --entity-name my_topic_name --alter --add-config retention.ms=-1

See the full list of topic-specific configs here: https://kafka.apache.org/documentation/#topicconfigs and more about topic operations: https://kafka.apache.org/documentation/#basic_ops

like image 108
Dmitry Minkovsky Avatar answered Sep 19 '22 11:09

Dmitry Minkovsky