Fix Iceberg write retry loop stuck on explicit metadata file path#101548
Fix Iceberg write retry loop stuck on explicit metadata file path#101548alesapin merged 4 commits intoClickHouse:masterfrom
Conversation
When an Iceberg table is created with iceberg_metadata_file_path (e.g.
for time-travel reads), the metadata write retry loop in INSERT and
mutation operations would always re-read the explicitly specified
metadata version instead of discovering the actual latest version.
This caused the retry loop to regenerate the same target metadata
version on every attempt. If that version already existed (e.g. from
a previous write), all 100 retries would fail with
DATALAKE_DATABASE_ERROR ("Write into iceberg was not successful").
The fix adds an ignore_explicit_metadata_file_path parameter to
getLatestOrExplicitMetadataFileAndVersion(). Write retry paths now
pass this flag to bypass the explicit path and discover the real
latest metadata version, allowing the retry to advance past it.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pre-PR Validation GateSession: a) Deterministic repro? ✅ Yes.
b) Root cause explained? ✅ c) Fix matches root cause? ✅ d) Test intent preserved? ✅ e) Both directions demonstrated? ✅
f) Fix is general? ✅ |
|
cc @scanhex12 @divanik — could you review this? It fixes a bug where the Iceberg write retry loop gets stuck when the table was created with |
|
Workflow [PR], commit [d82943e] Summary: ❌
AI ReviewSummary ClickHouse Rules
Final Verdict
|
Regression test per @alesapin's review request. Reproduces the retry loop bug: creates an IcebergLocal table, adds data to produce multiple metadata versions, then re-creates with iceberg_metadata_file_path pointing to an old version. The INSERT triggers a metadata conflict (target version already exists), and the retry must discover the actual latest version to advance. Without the fix: DATALAKE_DATABASE_ERROR after 100 retries (all targeting the same already-existing version). With the fix: retry ignores the explicit path, discovers the latest version, and creates the next one. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Done — added test It reproduces the retry loop bug with IcebergLocal:
Both directions confirmed locally: fails without fix, 10/10 passes with fix. |
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
Done — merged latest master (includes the SimSIMD SVE MSan fix from #101239) into the branch. CI should re-run with the fix included. |
LLVM Coverage Report
Changed lines: 65.22% (30/46) · Uncovered code |
3424d0e
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix Iceberg INSERT retry loop failing when the table was created with
iceberg_metadata_file_pathand the target metadata version already exists.What this PR does
When an Iceberg table is created with
iceberg_metadata_file_path(e.g. for time-travel reads), the metadata write retry loop in INSERT and mutation operations always re-read the explicitly specified metadata version instead of discovering the actual latest version.This caused the retry loop to regenerate the same target metadata version on every attempt. If that version already existed (e.g. from a previous successful write, or a concurrent writer), all 100 retries would fail with:
Root cause:
getLatestOrExplicitMetadataFileAndVersion()unconditionally returns the explicit metadata file path wheniceberg_metadata_file_pathis set, even during retry loops that need the actual latest version to advance past conflicts.Evidence from server logs (before fix): The retry loop re-reads v2 and tries to write v3 on every attempt:
After fix: The retry reads the actual latest version (v3) and advances to v4:
The fix
Add
ignore_explicit_metadata_file_pathparameter togetLatestOrExplicitMetadataFileAndVersion(). Write retry paths (inIcebergWrites.cppandMutations.cpp) passtrueto bypass the explicit path and discover the real latest metadata version via version hint or directory listing.CI impact
This fixes test
03758_fix_isssue_87414which has been failing across 23 distinct PRs with 89 total hits in the last 30 days. The test writes to an Iceberg table created with an explicit metadata path; when run multiple times (flaky check), subsequent runs fail because v3.metadata.json already exists from the first run.🤖 Generated with Claude Code