Apache Kafka messages got archived - is it possible to retrieve the messages

Viewed 26

We are using Apache Kafka and we process more than 30 million messages per day. We have an retention policy of "30" days. However, before 30 days, our messages got archived.

Is there a way we could retrieve the deleted messages? Is it possible to reset the "start index" to older index to retrieve the data through query?

What other options do we have?

If we have "disk backup", could we use that for retrieving the data?

Thank You

2 Answers

I'm assuming your messages got deleted by the Kafka cluster here.

In general, no - if the records got deleted due to duration / size related policies, then they have been removed.

Theoretically, if you have access to backups you might move the Kafka data-log files to server directory, but the behaviour is undefined. Trying that with a fresh cluster with infinite size/time policies (so nothing gets purged instantly) might work and let you consume again.

In my experience, until the general availability of Tiered Storage, there is no free/easy way to recover data (via the Kafka Consumer protocol).

For example, you can use some Kafka Connect Sink connector to write to some external, more persistent storage. Then, would you want to write a job that scrapes that data? Sure, you could have a SQL database table of STRING topic, INT timestamp, BLOB key, BLOB value, and maybe track "consumer offsets" separately from that? If you use that design, then Kafka doesn't really seem useful, as you'd be reimplementing various parts of it when you could've just added more storage to the Kafka cluster.

Is it possible to reset the "start index" to older index to retrieve the data through query?

That is what auto.offset.reset=earliest will do, or kafka-consumer-groups --reset-offsets --to-earliest

have "disk backup", could we use that

With caution, maybe. For example - you can copy old broker log segments into a server, but then there aren't any tools I know of that will retroactively discover the new "low watermark" of each topic (maybe the broker finds this upon restart, I haven't tested). You'd need to copy this data for each broker manually, I believe, since the replicas wouldn't know about old segments (again, maybe after a full cluster restart, they might).
Plus, the consumer offsets would already be reading way past that data, unless you stop all consumers and reset them.

I'm also not sure what happens if you had gaps in the segment files. E.g. your current oldest segment is N and you copy N-2, but not N-1... You might then run into an error or the consumer will simply apply auto.offset.reset policy, and seek to the next available offset or to the very end of the topic

Related