[core] improve insert overwrite conflict detection#7595
Open
hbgstc123 wants to merge 1 commit intoapache:masterfrom
Open
[core] improve insert overwrite conflict detection#7595hbgstc123 wants to merge 1 commit intoapache:masterfrom
hbgstc123 wants to merge 1 commit intoapache:masterfrom
Conversation
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.
Purpose
Problem
Sort Compact reads data from snapshot S_read, sorts it, then commits as OVERWRITE. However,
tryOverwritePartitionbuilds the DELETE list fromlatestSnapshot(which may beS_read+N). If concurrent writes add new files between S_read and latestSnapshot, those files are deleted without their data being included in the sorted output, causing silent
data loss.
Root Cause
Timeline:
Solution
Part 1: Pin DELETE list to base snapshot
Build the DELETE list from the snapshot the sort compact actually read from (base snapshot) instead of latestSnapshot. This ensures we only delete files that were included in the
sorted output.
Part 2: Concurrent write detection
When the base snapshot differs from the latest snapshot, use
readIncrementalChanges(baseSnapshot, latestSnapshot)to detect new files added to the overwritten partitions. If newfiles exist, fail the commit with a clear conflict error instead of silently losing data.
Changes
Core
FileStoreCommit.java: Add@Nullable Long baseSnapshotIdparameter tooverwritePartition()FileStoreCommitImpl.java:tryOverwritePartition()to build DELETE list frombaseSnapshotInnerTableCommit.java: AddwithOverwriteBaseSnapshot(@Nullable Long snapshotId)methodTableCommitImpl.java: ImplementwithOverwriteBaseSnapshot()and passbaseSnapshotIdto commitFlink
SortCompactAction.java: Capture read snapshot ID before building source, pass to sink builderFlinkSinkBuilder.java: AddoverwriteBaseSnapshotIdfield and setterFlinkWriteSink.java: AddoverwriteBaseSnapshotIdfield and setter, pass to committerSpark
CompactProcedure.java: Capture read snapshot ID for sort compact operationsPaimonSparkWriter.scala: AddwithOverwriteBaseSnapshot()methodBackward Compatibility
When
baseSnapshotId == null,tryOverwritePartitionfalls back to current behavior (latestSnapshot), so existing code paths (SQL INSERT OVERWRITE, DROP PARTITION, TRUNCATE,etc.) are unaffected.
The concurrent write detection only activates when:
baseSnapshotId != null(explicitly set by sort compact)Data Flow After Fix
Tests