KAFKA-17676: Fix NPE when starting tasks after config topic compaction#21368
Open
ayalamark-afk wants to merge 1 commit intoapache:trunkfrom
Open
KAFKA-17676: Fix NPE when starting tasks after config topic compaction#21368ayalamark-afk wants to merge 1 commit intoapache:trunkfrom
ayalamark-afk wants to merge 1 commit intoapache:trunkfrom
Conversation
76cb8fe to
e862341
Compare
…ecovery This commit adds three fixes for the NPE/task failure issues caused when task configs are lost due to connect-configs topic compaction: Fix 1: Leader periodic check for inconsistent connectors (processInconsistentConnectors) - Leader checks configState.inconsistentConnectors() on each tick - Automatically triggers reconfigureConnectorTasksWithRetry() for any connector with incomplete task configs - This proactively recovers connectors before tasks fail to start Fix 2: Auto-recovery in startTask() when task config is missing - Checks if taskConfig is null before attempting to start task - If connector is running, calls requestTaskReconfiguration() to regenerate configs - Throws ConnectException so task will be retried after configs are regenerated - This provides fallback recovery if periodic check misses the issue Fix 3: Proper cleanup in removeConnectorConfig() - When connector is deleted, also tombstone all task configs and commit record - Prevents orphaned task configs that could cause issues when connector is recreated - Original code only tombstoned connector config and target state These fixes ensure Kafka Connect can automatically recover from task config loss due to topic compaction without manual intervention.
e862341 to
8a4e1d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix for KAFKA-17676 - NullPointerException when starting tasks after the connect-configs topic has been compacted.
Problem
When the connect-configs topic gets compacted, two scenarios can cause NPE crashes:
Incomplete task configs due to compaction: Task config records get compacted leaving an incomplete set, but
connectorTaskCountsis still updated, causing NPE when trying to start tasks without configs.Missing connector config: Connector config records can be removed by compaction even though the connector is still active. The fix for KAFKA-16838 assumes that if a connector config is missing, the connector was deleted, and ignores task configs. This causes an NPE when trying to start tasks:
java.lang.NullPointerException: Cannot invoke "java.util.Map.size()" because "inputMap" is null
at org.apache.kafka.connect.runtime.TaskConfig.
at org.apache.kafka.connect.runtime.Worker.startTask
Solution
Two fixes in
processTasksCommitRecord:Fix 1: Only update
connectorTaskCountswhen we actually apply task configsconnectorTaskCounts.put()inside the else blockFix 2: Handle compacted connector configs gracefully
Both fixes are needed to fully address NPE crashes when starting tasks after config topic compaction.