MM2: Implement Fault Tolerance for Log Truncation and Topic Reset #21349
+38
−8
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.
This Pull Request implements two key fault tolerance features within MirrorMaker's
MirrorSourceTaskto enhance data integrity in mission-critical deployments.The changes address the risk of silent data loss (truncation) and service disruption (topic reset).
1. Log Truncation Detection (Fail-Fast)
Problem: Kafka's retention policies can delete log segments, causing MM2's consumer to lose its expected offset and silently skip data.
Solution (in MirrorSourceTask.java):
An in-memory map tracks the last processed offset for each partition. If the newly polled offset is greater than the last processed offset + 1, a data gap is confirmed.
ConnectExceptionwith a CRITICAL log message, forcing a Fail-Fast stop and preventing further silent data loss.2. Graceful Topic Reset Handling (Auto-Recovery)
Problem: Deleting and recreating the source topic resets its offset to 0. MM2's stored offset is now invalid.
Solution (in MirrorSourceTask.java):
The logic detects if the newly polled offset is less than the last processed offset (indicating a log reset/topic recreation).
3. Environment Fix (MirrorUtils.java)
Problem: Single-node Connect deployments fail due to Kafka 4.0.0's strict default replication factor of 3 for internal topics.
Solution (in MirrorUtils.java):
The
createCompactedTopicmethod is modified to explicitly setreplicationFactor = 1, ensuring compatibility with single-broker testing environments.