Kafka Topic InvalidCleanupPolicyException

The cleanup policy is invalid.

Understanding Kafka Topics

Apache Kafka is a distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications. At the heart of Kafka is the concept of a topic, which is a category or feed name to which records are published. Topics in Kafka are partitioned and replicated across multiple brokers to ensure fault tolerance and scalability.

Identifying the Symptom: InvalidCleanupPolicyException

While working with Kafka topics, you might encounter an error message like InvalidCleanupPolicyException. This exception indicates that there is an issue with the configuration of the topic's cleanup policy. The cleanup policy determines how Kafka manages log segments for a topic, and an invalid setting can disrupt normal operations.

What You Might Observe

When this exception occurs, you may notice that your Kafka topic is not behaving as expected. For instance, messages might not be deleted or compacted according to your configurations, leading to potential storage issues or data retention problems.

Explaining the Issue: Invalid Cleanup Policy

The InvalidCleanupPolicyException is thrown when the cleanup policy for a Kafka topic is set to an unrecognized value. Kafka supports two primary cleanup policies:

  • Delete: This policy removes old log segments when they exceed a certain retention period or size.
  • Compact: This policy retains the latest record for each key, effectively compacting the log.

If the cleanup policy is set to anything other than delete or compact, Kafka will throw this exception.

Common Misconfigurations

Developers often encounter this issue when they accidentally mistype the cleanup policy or attempt to use a custom policy that Kafka does not recognize. It's crucial to ensure that the policy is correctly specified in the topic configuration.

Steps to Fix the InvalidCleanupPolicyException

To resolve this issue, follow these steps to correctly configure the cleanup policy for your Kafka topic:

Step 1: Verify Current Configuration

First, check the current configuration of your Kafka topic to identify the incorrect cleanup policy setting. You can use the following command to describe the topic:

kafka-topics.sh --describe --topic <your_topic_name> --bootstrap-server <broker_address>

Look for the cleanup.policy configuration in the output.

Step 2: Update the Cleanup Policy

If the cleanup policy is incorrect, update it to a valid value. Use the following command to set the cleanup policy to either delete or compact:

kafka-configs.sh --alter --entity-type topics --entity-name <your_topic_name> --add-config cleanup.policy=delete

or

kafka-configs.sh --alter --entity-type topics --entity-name <your_topic_name> --add-config cleanup.policy=compact

Step 3: Validate the Changes

After updating the configuration, describe the topic again to ensure that the changes have been applied successfully:

kafka-topics.sh --describe --topic <your_topic_name> --bootstrap-server <broker_address>

Verify that the cleanup.policy is now set to a valid value.

Additional Resources

For more information on Kafka topic configurations, you can refer to the official Kafka Documentation. Additionally, the Topic Configurations section provides detailed explanations of all available configurations.

By following these steps, you should be able to resolve the InvalidCleanupPolicyException and ensure that your Kafka topics are configured correctly for optimal performance.

Never debug

Kafka Topic

manually again

Let Dr. Droid create custom investigation plans for your infrastructure.

Book Demo
Automate Debugging for
Kafka Topic
See how Dr. Droid creates investigation plans for your infrastructure.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid