Move realtime stream offset fetch out of the ideal-state update lock - #19170
Open
shounakmk219 wants to merge 1 commit into
Open
Move realtime stream offset fetch out of the ideal-state update lock#19170shounakmk219 wants to merge 1 commit into
shounakmk219 wants to merge 1 commit into
Conversation
RealtimeSegmentValidationManager's ensureAllPartitionsConsuming fetched the stream offsets inside the Helix ideal-state update lambda, so on a table with many partitions the offset I/O (which can take minutes) was held under the per-table ideal-state lock and re-run on every ZK CAS retry, stalling concurrent segment commits. Pre-fetch the offsets from a read-only snapshot of the ideal state, outside the lock (preFetchOffsets), and pass them into the package-private ensureAllPartitionsConsuming, whose updater lambda now performs only in-memory ideal-state mutation. Lock hold-time is proportional to the mutation, and the offset fetch runs once regardless of CAS retries. The smallest-offset stream fetch is gated (anyPartitionNeedsSmallestOffset) so it runs only on a reset or when a partition actually needs a new CONSUMING segment. A partition that starts needing repair after the lock-free snapshot is deferred to the next validation run rather than being repaired with substituted start offsets.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19170 +/- ##
============================================
+ Coverage 66.59% 66.62% +0.02%
Complexity 1423 1423
============================================
Files 3443 3443
Lines 218536 218568 +32
Branches 34780 34786 +6
============================================
+ Hits 145538 145621 +83
+ Misses 61273 61231 -42
+ Partials 11725 11716 -9
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
RealtimeSegmentValidationManager(RVM) callsPinotLLCRealtimeSegmentManager.ensureAllPartitionsConsuming, which fetched the stream offsets inside the Helix ideal-state update lambda (HelixHelper.updateIdealState→IdealStateGroupCommit). On a table with many partitions the offset I/O can take minutes, and because it ran inside the updater it (a) held the per-table ideal-state lock for that whole time — stalling concurrent segment commits — and (b) was re-executed on every ZK version-checked CAS retry.This is the follow-up to #19116 (which batched the Kafka fetch): batching shrinks the fetch, this change removes it from the lock entirely.
Fix
ensureAllPartitionsConsumingnow reads a read-only snapshot of the ideal state (HelixHelper.getTableIdealState), does the early enabled/paused check, and calls a new@VisibleForTesting preFetchOffsets(...)to computestreamMetadataListand the per-partition smallest offsets before enteringHelixHelper.updateIdealState.ensureAllPartitionsConsuming(..., preFetchedPartitionIdToSmallestOffset), which mutates the fresh IS from the pre-fetched offsets. No stream I/O runs under the lock, so lock hold-time is proportional to the mutation and the fetch is not repeated on CAS retries.offsetCriteria != null) or whenanyPartitionNeedsSmallestOffset(...)finds a partition whose latest segment has no CONSUMING replica (the only repair path that consults it). Healthy tables fetch nothing.Testing
PinotLLCRealtimeSegmentManagerTest+RealtimeSegmentValidationManagerTest: 57 tests pass, including new cases —testEnsureAllPartitionsConsumingHonorsPreFetchedSmallestOffset,testEnsureAllPartitionsConsumingDefersRepairWhenSmallestOffsetsNotPreFetched,testPreFetchOffsetsSkipsSmallestOffsetFetchForHealthyTable, andtestPreFetchOffsetsRestoresOffsetCriteriaOnFailure.Concurrency notes (IS updated by another process during an RVM run)
The mutation path is unchanged (serialized per table via
IdealStateGroupCommit, version-checked CAS), so concurrent commits are not lost — a commit landing mid-run causes a CAS retry and RVM re-runs on the newer IS. Only the offset inputs are a snapshot. Residual, all self-healing within one 15-min cycle:Depends on
Complementary to #19116 (batching). Independent at the code level — this PR only touches
pinot-controllerand calls pre-existing stream methods — but both together give the full win (fast fetch + off-lock).