Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test whether log compaction is working or not in Kafka?

I have made the changes in server.properties file in Kafka 0.8.1.1 i.e. added log.cleaner.enable=true and also enabled cleanup.policy=compact while creating the topic. Now when I am testing it, I pushed the following messages to the topic with following (Key, Message).

  • Offset: 1 - (123, abc);
  • Offset: 2 - (234, def);
  • Offset: 3 - (345, ghi);
  • Offset: 4 - (123, changed)

Now I pushed the 4th message with a same key as an earlier input, but changed the message. Here log compaction should come into picture. And using Kafka tool, I can see all the 4 offsets in the topic. How can I know whether log compaction is working or not? Should the earlier message be deleted, or the log compaction is working fine as the new message has been pushed. Does it have to do anything with the log.retention.hours or topic.log.retention.hours or log.retention.size configurations? What is the role of these configs in log compaction. P.S. - I have thoroughly gone through the Apache Documentation, but still it is not clear.

like image 676
tanmayghosh2507 Avatar asked Dec 15 '15 05:12

tanmayghosh2507


People also ask

How do you trigger log compaction in Kafka?

There are multiple ways in which you can achieve compaction for your data logs: Method 1: Using the Traditional Method of Discarding Old Data. Method 2: Storing Old Logs in the Compressed Format. Method 3: Kafka Log Compaction, A Hybrid Approach.

What is compacted Kafka topic?

What is a Log Compacted Topics. Kafka documentation says: Log compaction is a mechanism to give finer-grained per-record retention, rather than the coarser-grained time-based retention. The idea is to selectively remove records where we have a more recent update with the same primary key.

What is Max compaction lag MS?

max.compaction.lag.ms :-It is max delay between the time when a message is written and when it becomes eligible for compaction. This overwrites the min. cleanable.


2 Answers

even though this question is a few months old, I just came across it doing research for my own question. I had created a minimal example for seeing how compaction works with Java, maybe it is helpful for you too:

https://gist.github.com/anonymous/f78184eaeec3ee82b15182aec24a432a

Furthermore, consulting the documentation, I used the following configuration on a topic level for compaction to kick in as quickly as possible:

min.cleanable.dirty.ratio=0.01
cleanup.policy=compact
segment.ms=100
delete.retention.ms=100

When run, this class shows that compaction works - there is only ever one message with the same key on the topic.

With the appropriate settings, this would be reproducible on command line.

like image 130
Jannixx Avatar answered Sep 23 '22 18:09

Jannixx


Actually, the log compaction is visible only when the number of logs reaches to a very high count eg 1 million. So, if you have that much data, it's good. Otherwise, using configuration changes, you can reduce this limit to say 100 messages, and then you can see that out of the messages with the same keys, only the latest message will be there, the previous one will be deleted. It is better to use log compaction if you have full snapshot of your data everytime, otherwise you may loose the previous logs with the same associated key, which might be useful.

like image 27
tanmayghosh2507 Avatar answered Sep 20 '22 18:09

tanmayghosh2507