KAFKA-17676: Fix NPE when starting tasks after config topic compaction #21368
+52
−11
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.