Do not count a deliberate consumer stop as a stream consumption error - #19224
Draft
krishan1390 wants to merge 1 commit into
Draft
Do not count a deliberate consumer stop as a stream consumption error#19224krishan1390 wants to merge 1 commit into
krishan1390 wants to merge 1 commit into
Conversation
…ough OFFLINE or DESTROY transition
krishan1390
marked this pull request as draft
August 12, 2026 11:16
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19224 +/- ##
============================================
+ Coverage 65.78% 66.93% +1.15%
Complexity 1423 1423
============================================
Files 3441 3452 +11
Lines 218303 218550 +247
Branches 34728 34744 +16
============================================
+ Hits 143609 146296 +2687
+ Misses 63119 60564 -2555
- Partials 11575 11690 +115
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:
|
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
RealtimeSegmentDataManager.stop()sets a stop flag and then interrupts the consumer thread. Helix reaches this method on two paths:CONSUMINGtoOFFLINEandCONSUMINGtoDROPPED, throughoffloadSegment. A rebalance, a server shutdown, a table disable, or a table delete causes these transitions.CONSUMINGtoONLINE, while the replica still consumes.A consumer waits inside the stream fetch for most of its life. The interrupt therefore arrives inside
fetchMessages. Kafka wraps it in an uncheckedInterruptExceptionwith anInterruptedExceptioncause.consumeLoopdoes not recognize this exception. The generic catch block sends it tohandleTransientStreamErrors, which does three things:realtimeConsumptionExceptionsmeter, both global and per table.The loop then exits, because the stop flag is set.
doOffloadcloses the consumer that step 3 built.This has three results:
streamConsumerCreateExceptionsalso increases.An operation that moves or stops partitions across many tables produces a steady trickle of these counts. An alert on the meter reads that trickle as a stream fault.
#15660 already finds this case. It uses the result only to lower the log level from WARN to DEBUG. The meter increment, the sleep, and the consumer rebuild stay.
catchupToFinalOffsetsets_shouldStopback to false before it consumes again. A condition on_shouldStoptherefore cannot cover the catch-up path.Fix
A new field
_stoppingrecords the stop.stop()sets it, and nothing clears it. It survives the reset insidecatchupToFinalOffset.A new method
isDeliberateStopInterruptreturns true when_stoppingis set and the cause chain holds anInterruptedExceptionor aClosedByInterruptException. The second type covers NIO-based clients.consumeLoopcalls this method for each exception before it callshandleTransientStreamErrors. On a match it writes one log line and leaves the loop.handleTransientStreamErrorsnow holds only the code for real errors. The old_shouldStopbranch is unreachable after this change, so this change removes it.Behavior after the change
A deliberate stop adds no count, no sleep, and no new consumer.
catchupToFinalOffsetreturns false and the replica downloads the segment. This is the same result as before, without five retries first.A real stream error keeps the old behavior. It still increments the meter, sleeps, and builds a new consumer.
One log line changes level. A transient error that is not an interrupt now writes WARN during a stop. It wrote DEBUG before.
Tests
RealtimeConsumerStopTestis new. It uses a real table data manager, a real consumer thread, and the realoffloadSegmentcall that the Helix state model makes. The test supplies the stream through theStreamConsumerFactoryextension point. The consumer is then always insidefetchMessageswhen the interrupt arrives.The class holds three tests:
Without the fix, the first two tests fail. They record 1 and 6 unwanted counts.
🤖 Generated with Claude Code