Skip local build on CRC mismatch during ONLINE transition for upsert tables#18895
Open
deepthi912 wants to merge 1 commit into
Open
Skip local build on CRC mismatch during ONLINE transition for upsert tables#18895deepthi912 wants to merge 1 commit into
deepthi912 wants to merge 1 commit into
Conversation
…nsition When a CONSUMING segment transitions to ONLINE and its offset matches the committed offset in ZK, the server builds the segment locally and swaps it in. For upsert tables this is unsafe: a locally-built segment can diverge from the segment committed by the winning replica (e.g. different docId ordering), so its CRC differs from the committed CRC. Swapping in a CRC-divergent local build can leave the upsert metadata (validDocIds / primary-key -> record-location) inconsistent across replicas. This change adds a buildSegmentAndReplace(SegmentZKMetadata) overload that, for upsert-enabled tables, compares the locally-built segment's CRC against the committed CRC in ZK (via BaseTableDataManager.hasSameCRC). On a mismatch it skips the local build and the caller downloads the committed segment instead. The guard is applied on both the matched-offset and post-catch-up reconciliation paths in goOnlineFromConsuming. Non-upsert tables and callers that do not pass the committed metadata are unaffected. If the locally-built segment metadata cannot be read, the check reports a mismatch so the transition downloads the committed segment rather than throwing. Rolling upgrade: behavior change is scoped to upsert tables; no wire/ZK format change. Mixed-version replicas converge to the committed segment either way.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18895 +/- ##
============================================
- Coverage 64.80% 64.79% -0.02%
- Complexity 1322 1347 +25
============================================
Files 3393 3393
Lines 211332 211677 +345
Branches 33234 33308 +74
============================================
+ Hits 136952 137152 +200
- Misses 63329 63442 +113
- Partials 11051 11083 +32
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.
Summary
When a CONSUMING segment transitions to ONLINE and its offset matches the committed offset in ZK, the server builds the segment locally and swaps it in. For upsert tables this is unsafe: a locally-built segment can diverge from the segment committed by the winning replica (e.g. different docId ordering), so its CRC differs from the committed CRC. Swapping in a CRC-divergent local build can leave the upsert metadata (
validDocIds/ primary-key → record-location) inconsistent across replicas.For example consider a case where the time column/comparison columns are transformed on tables, or maybe commit time compaction differers crc between replicas
Changes
buildSegmentAndReplace(SegmentZKMetadata)overload that, for upsert-enabled tables, compares the locally-built segment's CRC against the committed CRC in ZK (viaBaseTableDataManager.hasSameCRC). On a mismatch it skips the local build so the caller downloads the committed segment instead.goOnlineFromConsuming.Non-upsert tables and callers that do not pass the committed metadata are unaffected.
Rolling upgrade
Behavior change is scoped to upsert tables; no wire/ZK format change. Mixed-version replicas converge to the committed segment either way.
Testing
Added coverage in
RealtimeSegmentDataManagerTestfor the CRC-match, CRC-mismatch, unreadable-metadata, and non-upsert paths.