[bug] Emit REMOVE in HudiDataFileExtractor when CLEAN deletes previous file version before incremental sync#824
Open
vinishjail97 wants to merge 1 commit into
Conversation
…e incremental sync When Hudi CLEAN physically removes an old base file from storage before XTable processes the corresponding UPSERT commit incrementally, getAllBaseFiles() only returns the new file. The else-if branch in getUpdatesToPartition that emits a REMOVE for the previous version never fires, leaving a stale ADD in the downstream Delta log that causes FILE_NOT_FOUND errors on read. Fix: after the base-file loop, if an ADD was emitted but no REMOVE was emitted and HoodieWriteStat.prevCommit indicates a prior version exists, recover the old file path by reading the previous commit's metadata from the visible Hudi timeline and emit a REMOVE. Gracefully degrades (logs warning, skips) if the previous commit has been archived. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
What is the purpose of the pull request
Fixes a bug in
HudiDataFileExtractor(source side) where XTable's incremental Hudi sync can leave a staleADD/ data-file reference in the target table's metadata, causingFILE_NOT_FOUNDon read. Affects any target format — Delta and Iceberg — since the missingREMOVEis in the format-agnosticInternalFilesDiffproduced by the source.RCA (one line)
Hudi
CLEANdeletes an old Parquet file before XTable's next incremental sync runs, soHudiDataFileExtractor.getUpdatesToPartitioncan't see the deleted file viagetAllBaseFiles()and skips emitting aREMOVEfor it — leaving a stale reference in the target's metadata (ADDin the Delta log, data-file entry in the Iceberg manifest) that points to a non-existent file; this PR recovers the deleted file path from the previous commit's metadata in the Hudi timeline (HoodieWriteStat.prevCommit) so theREMOVEis emitted correctly.Brief change log
HudiDataFileExtractor.getUpdatesToPartitionnow also takesHoodieTimelineandList<HoodieWriteStat>so it can build afileId → prevCommitmap.ADDwas emitted but noREMOVEwas, look up the previous commit's metadata viaHoodieCommitMetadata.fromBytes(timeline.getInstantDetails(prevInstant).get(), ...)and emit theREMOVEfromHoodieWriteStat.getPath().Verify this pull request
This change added tests and can be verified as follows:
TestHudiDataFileExtractorwith three unit tests forrecoverRemovedFile: previous commit present, previous commit archived, fileId not in previous commit metadata.ITConversionController.testIncrementalSyncEmitsRemoveWhenHudiCleanRunsBeforeSync, an end-to-end regression test that reproduces the race (insert → sync → upsert → insert → clean → incremental sync) and asserts Delta equivalence at 120 records.