[AMORO-4163][ams] Fix Version-N-already-exists race in newTableOperations for legacy mixed-iceberg#4185
Merged
czy006 merged 1 commit intoapache:masterfrom Apr 23, 2026
Conversation
…ions for legacy mixed-iceberg When AMS saves a new legacy mixed-iceberg table to the database, a background table-explorer thread can concurrently pick up the same table and call newTableOperations(), which now commits the mixed-format properties to the Iceberg metadata (introduced by the AMORO-4163 fix). If the background thread wins the race and writes v2.metadata.json before the onTableCreated() path attempts the same commit, HadoopTableOperations throws CommitFailedException: "Version 2 already exists", aborting the createTableMeta RPC. Fix: catch CommitFailedException in the commit block, refresh to obtain the latest on-disk metadata, and proceed if a concurrent writer already committed the correct properties. Re-throw only when the properties still differ after refresh, indicating a genuine commit conflict. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
czy006
approved these changes
Apr 21, 2026
Contributor
Author
|
Gentle nudge — this fix also unblocks CI on #4180. The recent CI run on #4180 fails with the exact pattern described in this PR's body: And the cascading symptoms match too — once the commit race fails once, Same pattern showed up on a recent master hadoop3 run (#24488461765, 2026-04-16), confirming it's pre-existing flakiness rather than regressions introduced by the feature PRs that hit it. Would be great to get this merged so downstream CI stabilizes. |
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 changes were proposed in this pull request?
Follow-up fix for AMORO-4163. The original fix changed
ops.current()toops.refresh()insideInternalMixedIcebergHandler.newTableOperations()so that the returnedTableMetadatareference satisfies Iceberg 1.7.x's reference-equality check incommit(). However, this introduced a new race condition:DefaultTableManager.createTable()consists of two sequential steps:catalog.createTable()— saves the table to the database (the table is now visible to all threads)onTableCreated()→triggerTableAdded()→newTableOperations()→ops.commit()— tries to writev2.metadata.jsonThe background
tableExplorerSchedulerrunsexploreInternalCatalog()concurrently. If it scans the database between steps 1 and 2, it finds the new table (not yet intableRuntimeMap) and also callstriggerTableAdded()→newTableOperations()→ops.commit(). Whichever thread wins writesv2.metadata.jsonfirst; the other then fails with:Fix: catch
CommitFailedExceptionin the commit block, refresh to obtain the latest on-disk metadata, and proceed normally if a concurrent writer already committed the correct mixed-format properties. Re-throw only when the properties still differ after refresh, indicating a genuine conflict.How was this patch tested?
The existing
CompatibilityCatalogTests.testNewCatalogLoadHistoricalinTestInternalMixedCatalogServicecovers this scenario — it was consistently failing in CI before this fix.