Flink: Validate concurrent commits in IcebergSink to prevent commit duplication - #17901
Open
fmorillo7694 wants to merge 1 commit into
Open
Flink: Validate concurrent commits in IcebergSink to prevent commit duplication#17901fmorillo7694 wants to merge 1 commit into
fmorillo7694 wants to merge 1 commit into
Conversation
…uplication The non-dynamic IcebergSink committer reads the max-committed-checkpoint-id once before committing, then commits without re-validation. If a previous commit attempt for the same checkpoint reached the catalog after the committer gave up (e.g. client timeout on a slow catalog commit) and the commit request is redelivered on recovery, the redelivered commit lands cleanly on the refreshed base snapshot, duplicating the checkpoint's data. Port the MaxCommittedCheckpointIdValidator introduced for the DynamicIcebergSink in apache#14517 to IcebergCommitter: validate the base snapshot ancestry inside the commit transaction and skip the commit when the branch already contains changes for the staged checkpoint. Fixes the non-dynamic sink exposure described in apache#14425.
fmorillo7694
force-pushed
the
fix-iceberg-committer-duplicate-commits
branch
from
August 31, 2026 10:10
cffbd48 to
ee7577a
Compare
fmorillo7694
marked this pull request as ready for review
August 31, 2026 16:24
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
The non-dynamic
IcebergSinkcommitter (IcebergCommitter) is exposed to the duplicate-commit race described in #14425, which was fixed for theDynamicIcebergSinkin #14517 (+ Flink 2.0/2.1 port in #14637) but never ported to the non-dynamic path.IcebergCommitter.commit()readsgetMaxCommittedCheckpointId()once, up front, and then commits without re-validation:getMaxCommittedCheckpointId()— the original commit has not landed yet, so it decides checkpoint N is uncommitted.SnapshotProducer.apply(), the refresh picks up the just-landed snapshot as the new parent, so the second commit applies cleanly — no conflict, no retry exhaustion — and the same checkpoint's data files are committed twice.We reproduced this deterministically (test included) and verified the resulting table has 2 snapshots carrying the same
flink.max-committed-checkpoint-idfor the same job/operator id, with doubled record counts. The behavior is identical on HadoopTables, AWS Glue, and Amazon S3 Tables catalogs — once the interleaving occurs, the second commit is structurally valid from the catalog's perspective, so only the committer can prevent it.Solution
Port the
MaxCommittedCheckpointIdValidatorintroduced in #14517 toIcebergCommitter: register aSnapshotAncestryValidatoron the commit operation that re-checksmax-committed-checkpoint-idagainst the base snapshot ancestry inside the commit transaction, and skip the commit (log + return) when the branch already contains changes for the staged checkpoint — mirroringDynamicCommitter's behavior.SinkUtil.INITIAL_CHECKPOINT_IDis widened fromprivateto package-private so the validator can reuse it.The validator is currently duplicated as a private inner class (same shape as in
DynamicCommitter). Happy to extract a shared class for both committers if preferred — kept the diff minimal for review.Testing
TestIcebergCommitterDuplicateCommitreproduces the race deterministically (a delegatingTableLoader/TableinterceptsAppendFiles.commit()to land a concurrent commit of the same committable between the committer's dedup read and its commit). Fails on the unpatched committer withsnapshots=2 / doubled records; passes with this change (snapshots=1, duplicate skipped).TestIcebergCommitter: 288 tests, 0 failures (no regressions).TestDynamicCommitter: 12/12 (unchanged).spotlessApplyclean.If the approach is accepted I'll follow up with the ports to the other Flink versions (v1.20, v2.0, v2.2, v2.3), mirroring how #14517 → #14637 was staged.
Relates to #14425 (fixes the non-dynamic
IcebergSinkexposure it describes).