Fix false StreamDataLoss on transactional Kafka topics - #19161
Open
swaminathanmanish wants to merge 1 commit into
Open
Fix false StreamDataLoss on transactional Kafka topics#19161swaminathanmanish wants to merge 1 commit into
swaminathanmanish wants to merge 1 commit into
Conversation
An offset gap between the requested startOffset and the first returned record was treated as data loss under read_uncommitted. Transactional producers write commit/abort control records that occupy offsets but are never delivered to the consumer, so a healthy contiguous stream legitimately has gaps, raising false StreamDataLoss alerts. Only flag data loss when the requested startOffset is below the broker's log start offset (beginningOffsets), i.e. records at/after startOffset were actually deleted via retention or truncation. When the log start offset cannot be determined, default to no data loss to avoid false positives. Applied to both kafka-3.0 and kafka-4.0, with unit tests covering transactional gaps, real truncation, contiguous batches, read_committed, and lookup failure. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19161 +/- ##
============================================
- Coverage 65.81% 65.79% -0.02%
Complexity 1423 1423
============================================
Files 3441 3441
Lines 218320 218328 +8
Branches 34737 34739 +2
============================================
- Hits 143677 143650 -27
- Misses 63075 63100 +25
- Partials 11568 11578 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
swaminathanmanish
marked this pull request as ready for review
August 7, 2026 13:20
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes false StreamDataLoss alerts caused by Kafka transactional control-record offset gaps.
Changes:
- Confirms loss using Kafka’s log start offset.
- Adds five regression scenarios for Kafka 3.0 and 4.0.
- Preserves fast paths for contiguous and
read_committedconsumption.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
pinot-kafka-3.0/.../KafkaPartitionLevelConsumer.java |
Refines data-loss detection. |
pinot-kafka-3.0/.../KafkaPartitionLevelConsumerDataLossTest.java |
Adds regression coverage. |
pinot-kafka-4.0/.../KafkaPartitionLevelConsumer.java |
Refines data-loss detection. |
pinot-kafka-4.0/.../KafkaPartitionLevelConsumerDataLossTest.java |
Adds regression coverage. |
| // read_committed we never flag loss because aborted-record gaps are always expected. | ||
| boolean hasDataLoss = false; | ||
| if (!_isReadCommitted && firstOffset > startOffset) { | ||
| hasDataLoss = getLogStartOffset(timeoutMs) > startOffset; |
| // read_committed we never flag loss because aborted-record gaps are always expected. | ||
| boolean hasDataLoss = false; | ||
| if (!_isReadCommitted && firstOffset > startOffset) { | ||
| hasDataLoss = getLogStartOffset(timeoutMs) > startOffset; |
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.
Problem
Real-time tables ingesting from transactional Kafka topics raise false
StreamDataLossalerts.KafkaPartitionLevelConsumerflagged data loss whenever thefirst returned record offset was greater than the requested
startOffset(underread_uncommitted):Transactional producers write commit/abort control records that consume offsets in
the log but are never delivered to the consumer. A perfectly healthy, contiguous stream
of user records therefore has offset gaps, which this check misread as data loss.
Fix
Only report data loss when the requested
startOffsetis actually below the broker'slog start offset (
Consumer.beginningOffsets) — i.e. records at/afterstartOffsetwere genuinely deleted by retention or truncation:
hot path or under
read_committed.transient broker hiccup can't manufacture a false alert.
// TODO: fetch earliest offset from topiccomment.Applied to both
pinot-kafka-3.0andpinot-kafka-4.0.Tests
New
KafkaPartitionLevelConsumerDataLossTestin each module (Mockito harness mirroringKafkaPartitionLevelConsumerSeekTest), 5 cases each:logStart <= startOffset)startOffsetbelow log start (real truncation)beginningOffsetsis never called)read_committedgap (never called)beginningOffsetslookup failsVerified the tests fail against the old code (the two false-positive cases flip to
true) and pass with the fix.checkstyleandspotlessclean on both modules.