Repository navigation
Fix LOGICAL_ERROR crash in IcebergMetadata::iterate when datalake_table_state is missing - #102033
Conversation
Pre-PR Validation Gate (Session: cron:clickhouse-ci-task-worker:20260408-084500)a) Deterministic repro? b) Root cause explained? c) Fix matches root cause? d) New tests added? e) Demonstrated in both directions? f) Fix is general, not a narrow patch? |
|
cc @scanhex12 @divanik — could you review this? It adds defense-in-depth fallback to |
c745e76 to
c16eefb
Compare
|
@alesapin Reworked per your feedback. The approach is now: What changed: Instead of adding fallback hacks inside
What's preserved: The No changes to IcebergMetadata.cpp — the fix is entirely at the caller level. The root cause is a TOCTOU race: |
|
Workflow [PR], commit [45cb6bd] Summary: ✅
AI ReviewSummaryThis PR moves the data-lake snapshot pin into Tests
Final Verdict
|
|
@alesapin @Michicosun @scanhex12 @alexey-milovidov — re-review request Following @alexey-milovidov's directive 4 hours ago on #100277:
This PR is that fix. It has been awaiting re-review for 18 days (since 2026-04-08). PR status
Reviewer feedback already addressed@alesapin's inline comment was: "Let's fix all the places to create table_state_snapshot instead of this adhoc hacks". We complied: removed the in-callee fallbacks and moved the fix to the call sites so
The Active trunk impact — CIDB last 30 days
13 affected check variants: amd_msan, arm_tsan, arm_msan, amd_tsan, arm_ubsan, arm_asan_ubsan (+s3), amd_asan_ubsan, arm_release, amd_debug, arm_debug, experimental serverfuzz (azure amd_tsan, arm_tsan). The bug is still triggering today. Fix has been ready and CI-green for 18 days. Asks
If anything in the rework needs further changes, please flag it explicitly so I can address it today. |
|
24h follow-up ping — @alesapin @Michicosun @scanhex12 @alexey-milovidov 24h have elapsed since the previous ping and there is still no response from any reviewer. Per @alexey-milovidov's directive on #100277 ("we should be ruthless about pinging him on Iceberg defects"), I am being ruthless. Fresh hit since the previous ping (last 24h):
30-day chronic pattern (refreshed now):
PR state, unchanged since 2026-04-08:
Asks:
This is a chronic P0 LOGICAL_ERROR landing on master twice this week alone. Each day it sits is another set of stress runs hitting the same crash. |
|
@groeneai, "Bug Fix" category requires new tests that reproduce the issue. |
|
@alexey-milovidov thanks for the direct feedback. You're right that "Bug Fix" requires a regression test. I just pushed What the test does It exercises both call sites the fix protects ( Why concurrent rather than fully deterministic The bug is a TOCTOU race between two clients ( The 30-day CIDB stress evidence in the PR description (11 master + 44 PR hits across 13 sanitizer/build variants) is exactly that kind of concurrent reproducer — the test mirrors that shape in a single stateless test file. Other shapes I considered and rejected
If you'd prefer a different test shape (e.g. extending cc @alesapin @Michicosun @scanhex12 — |
… isDataSortedBySortingKey() Instead of adding fallback hacks inside IcebergMetadata::iterate() and IcebergMetadata::isDataSortedBySortingKey(), fix the callers to ensure datalake_table_state is present in the storage metadata before calling these functions. The state is normally set by updateExternalDynamicMetadataIfExists() during query analysis, but can be missing due to race conditions between concurrent queries (TOCTOU between setInMemoryMetadata and getInMemoryMetadataPtr), or when called from code paths that bypass the analyzer/interpreter (schema inference, cluster functions). Two call sites fixed: - createFileIterator(): the funnel for all iterate() calls — when the metadata lacks datalake_table_state, obtain it from the configuration and create a patched metadata copy before calling iterate(). - requestReadingInOrder(): entry point for isDataSortedBySortingKey() — same approach. This preserves the LOGICAL_ERROR assertions inside iterate() and isDataSortedBySortingKey() as safety nets for any unknown future code paths, while fixing the actual root cause at the call sites. Fixes STID 2606-4a47 (43 hits in 30 days, 3 on master).
Issue ClickHouse#93278 (reopened): `IcebergMetadata::iterate` and `IcebergMetadata::isDataSortedBySortingKey` throw `LOGICAL_ERROR` "Can't extract iceberg table state from storage snapshot" when `datalake_table_state` is missing from the storage metadata snapshot (STID 2606-4a47, 11 master + 45 PR hits over 30 days). The PR's fix in `StorageObjectStorageSource::createFileIterator` and `ReadFromObjectStorageStep::requestReadingInOrder` re-fetches the snapshot from the configuration when it is missing. PR ClickHouse#101577 already covered the materialized-view-target path (`04077_iceberg_mv_select_crash`); this new test exercises the concurrent-normal-SELECT path that the same fix has to keep stable. The test runs many parallel `SELECT`s (both plain and `ORDER BY c0`) against an `IcebergLocal` table while a writer thread produces new snapshots, then asserts that the "Can't extract iceberg table state" `LOGICAL_ERROR` never appears in captured stderr and that the table remains readable.
a972e9b to
e0fc016
Compare
|
Rebased onto current master (was 8714 commits behind, last activity 2026-04-28). Two-commit fix is unchanged:
Why this matters now: STID 2606-44c0 just hit @alexey-milovidov's unrelated PR #105087 (Stress test arm_release). That STID is the same chronic family as 2606-4a47 — identical error message ("Can't extract iceberg table state from storage snapshot for table location A"), same call into cc @alesapin @Michicosun @scanhex12 @kssenii — could one of you take another look? @alesapin dismissed the original review on the day this opened (2026-04-08), but no comments were left, so the action item never came back to me. The fix is at the call sites (4 files / 143 lines / 1 deletion), preserves the LOGICAL_ERROR assertions inside — @groeneai (session |
|
Re-engagement ping from @PedroTadim on the parent issue today: #102037 (comment-4519163992). @alesapin @Michicosun @scanhex12 @alexey-milovidov could one of you take a review pass? Status snapshot on HEAD
CIDB still shows STID 2606-4a47 firing sporadically in PR stress runs (last hit PR #105172 arm_asan_ubsan 2026-05-21 18:42). The defense-in-depth call-site fix prevents the LOGICAL_ERROR on both reaching paths. Question on the issue thread is whether to keep |
|
@groeneai merge with master |
|
@PedroTadim merged master into the branch and pushed. New HEAD Fix scope unchanged (4 files): call-site fix for the TOCTOU race in Ready for re-review. |
|
Please apply This fix is on master and present on 26.7, but 26.6, 26.5 and 26.3 still take the pre-fix path while the throw site exists on all three. It surfaced on 26.6 on 2026-08-02 as a logical error reaching
I simulated the cherry-pick the way The same port also carries the DeltaLake half of this class (issue #107334). This PR is labelled Measurements (branch tips of 2026-08-03, re-measured through 12:40 UTC)Per-branch presence, read from the
The message occurs twice per affected branch ( Cherry-pick simulation, reducing On 26.6, 26.5 and 26.3 this resolves cleanly and the resolved tree differs from the branch tip by exactly the 11 files of this PR (+278/-3), with no collateral. I re-ran it as those three tips advanced during the day (three generations each) and the result was identical every time, so it is not a property of one tip. The naive CIDB, 45 days, keyed on the message: 8 rows. Seven are on master and all predate the merge (latest 2026-06-30); the only later row is the 26.6 sighting above. |
Pre-PR validation gate (click to expand)This request carries no code change: the fix is already merged on master as this PR, and the ask is a backport label. The gate is answered against that deliverable.
Session id: cron:clickhouse-review-slot-49:20260803-115800 |
Resolve conflict in `src/Common/FailPoint.cpp`: both branches added a failpoint at the same place; keep both `datalake_get_tables_throw` (from 26.5) and `datalake_simulate_missing_table_state` (from #102033).
Cherry pick #102033 to 26.5: Fix LOGICAL_ERROR crash in IcebergMetadata::iterate when datalake_table_state is missing
…:iterate when datalake_table_state is missing
Cherry pick #102033 to 26.6: Fix LOGICAL_ERROR crash in IcebergMetadata::iterate when datalake_table_state is missing
…:iterate when datalake_table_state is missing
Backport #102033 to 26.5: Fix LOGICAL_ERROR crash in IcebergMetadata::iterate when datalake_table_state is missing
…on 26.3 `04306_delta_lake_merge_missing_table_state` failed in CI with `Unknown table expression identifier`: the branch has no `tests/queries/0_stateless/data_delta_lake/struct_column_mapping` dataset (it was added to `master` by a later pull request), so the `cp -r` copied nothing and `CREATE TABLE ... ENGINE = DeltaLakeLocal` failed before the read. The files are copied verbatim from `master`; they are identical to the state at the merge commit of the original pull request #102033. Verified with the 26.3 build of this pull request: the failpoint-guarded read returns the expected `1` / `2`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114383&sha=0925d7c93148d0914652ed32e40cf3b18bdf669b&name_0=BackportPR Pull request: #114383
Backport #102033 to 26.6: Fix LOGICAL_ERROR crash in IcebergMetadata::iterate when datalake_table_state is missing
Backport #102033 to 26.3: Fix LOGICAL_ERROR crash in IcebergMetadata::iterate when datalake_table_state is missing
…gMetadata::iterate when datalake_table_state is missing
The fallback added in 7612950 calls `getTableStateSnapshot` early in `StorageObjectStorage::read`, but on cluster table function workers and other paths that bypass the analyzer the underlying datalake configuration has never had `update`/`updateExternalDynamicMetadataIfExists` run on it yet. `getTableStateSnapshot` then hits `assertInitialized` and throws `Metadata is not initialized` instead of the expected `PATH_ACCESS_DENIED` (or normal read result), regressing `test_local_table_safety`, `test_cluster_table_function*`, and stateless flaky-check / bugfix-validation runs on PR ClickHouse#102033 head 2d39c85 (STID 2377-2862). Initialize the configuration the same way the surrounding analyzer paths do (`lazyInitializeIfNeeded` for table functions, `update` for ENGINE tables) before invoking `getTableStateSnapshot`, so the fallback works for all callers and any underlying error such as `PATH_ACCESS_DENIED` keeps propagating with its original code.
The flaky-check (50x) on amd_debug/amd_msan/amd_tsan caught `Code: 117 INCORRECT_DATA: JSON object/array should start with corresponding opening bracket` from a `SELECT c0 FROM ... ORDER BY c0 LIMIT 5` race against a concurrent INSERT-side iceberg manifest write. That is a separate (manifest-read mid-write) race, not the `LOGICAL_ERROR: Can't extract iceberg table state` class this test exists to gate. The previous `grep -iE "error|exception"` final guard plus the `status=0` exit-on-any-non-zero check folded both classes together and turned this test into a generic flake detector. This test only exists to catch the specific LOGICAL_ERROR thrown by `IcebergMetadata::iterate()` and `isDataSortedBySortingKey()` when `datalake_table_state` is missing under concurrent commits. The deterministic counterpart `04305_iceberg_missing_table_state.sh` already covers the LOGICAL_ERROR path via `datalake_simulate_missing_table_state` failpoint; 04141 is the noisy concurrent-workload counterpart that should only fail when the LOGICAL_ERROR resurfaces. Tighten the LOG_FILE check to a literal `Can't extract iceberg table state` match. Stop exiting on any non-zero background-PID status; transient non-LOGICAL_ERROR failures (e.g. INCORRECT_DATA on manifest reads, randomized-setting validation errors) are not in scope. PedroTadim directive on PR ClickHouse#102033 2026-06-09: ClickHouse#102033 (comment)
The test exceeded the 180s test-runtime limit in the sync branch on a debug build with randomized settings and --max_threads 1 (reported by PedroTadim on PR ClickHouse#102033). Root cause: the test spawned a fresh clickhouse-client process per query (12 readers x 10 iterations x 2 queries + 24 writer inserts = ~264 spawns). On a contended debug runner each spawn re-parses ~200 randomized settings, which dominated the runtime. Fix: each reader/writer now runs its whole loop inside a single client connection (7 spawns total instead of ~264). Every statement still re-resolves the Iceberg table-state snapshot independently, so the concurrent-commit TOCTOU race the test exists to detect is fully preserved (verified: a later SELECT in the same connection sees rows the writer committed after an earlier SELECT, and a live run shows reader ORDER BY queries overlapping with writer commits). Reader/writer counts were also right-sized (6 readers x 15 read-pairs, 20 writer commits) so the workload keeps the readers active across the writer's commit window without the hundreds of expensive read-in-order queries that each trigger a full Iceberg manifest re-parse via totalRows(). Also redirect stdin from /dev/null on the client invocations: a backgrounded clickhouse-client running INSERT ... VALUES reads stdin for trailing insert data, so an inherited non-EOF stdin would block the insert. The LOGICAL_ERROR guard string is unchanged, so the test still fails on the specific "Can't extract iceberg table state" error and ignores unrelated transient errors. Deterministic coverage stays in 04305_iceberg_missing_table_state. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…e-missing-datalake-state Fix LOGICAL_ERROR crash in IcebergMetadata::iterate when datalake_table_state is missing
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix
LOGICAL_ERRORexceptions when readingIcebergorDeltaLakedata lake tables through paths that can reach the read pipeline without a pinneddatalake_table_state, such as concurrentIcebergmetadata updates ormergereads overDeltaLaketables.What this PR does
Problem:
IcebergMetadata::iterateandisDataSortedBySortingKeythrow aLOGICAL_ERROR(Can't extract iceberg table state from storage snapshot) whendatalake_table_stateis not set in the storage metadata snapshot. The same family of failures hitsDeltaLake(No version found in table state snapshot). This raises an exception (and, in stress tests, a server abort underabort_on_logical_error) — tracked as STID2606-4a47, a chronic failure with master and PR hits across many sanitizer/build variants over the last 30 days.PR #101577fixed one such path (materialized views accessingIcebergtarget tables), but the failure continued on master because other code paths can reach the read pipeline withoutdatalake_table_state:updateExternalDynamicMetadataIfExistssetting the state (viasetInMemoryMetadata) and the nextgetInMemoryMetadataPtrreading it.read/iteratewithout having had the state pinned.mergereads overDeltaLaketables reach the read step with a snapshot that lacks the pinned state.Fix: Pin a single, internally consistent data lake snapshot at the source instead of papering over the missing state deep inside the callees. This follows the reviewer's guidance to fix all the places to create the table state snapshot instead of ad-hoc fallbacks in the callees:
StorageObjectStorage::readpins one coherentdatalake_table_statebeforeprepareReadingFromFormat, so the requested columns, the field-id mapping used to list/read files, and the read-in-order sorting key all come from the same data lake snapshot. For cluster table functions it first callslazyInitializeIfNeeded, otherwiseupdate, sogetTableStateSnapshotdoes not hit an uninitialized-metadata assertion. WhenshouldReloadSchemaForConsistencyis set, columns and sorting key are rebuilt from the same state viabuildStorageMetadataFromStateso they cannot diverge.StorageObjectStorageSource::createFileIteratorrepopulatesdatalake_table_statefromgetTableStateSnapshotbeforeiterate, as a safety net for the remaining callers.ReadFromObjectStorageStep::getDataOrderreads the sorting key from the pinnedstorage_snapshot->metadatarather than re-deriving it.The
LOGICAL_ERRORassertions insideiterateandisDataSortedBySortingKeyare preserved untouched as safety nets — they should now be unreachable on the fixed paths.A test-only failpoint
datalake_simulate_missing_table_statestrips the pinned state from the snapshot right before the read step, so the regression test reproduces the missing-state condition deterministically.Tests
04305_iceberg_missing_table_state.sh— deterministic reproducer using thedatalake_simulate_missing_table_statefailpoint; a non-trivial read (sum) and anORDER BYquery exercise both theiterateandisDataSortedBySortingKeysites.04306_delta_lake_merge_missing_table_state.sh—mergeread over aDeltaLaketable, theDeltaLakevariant of the same bug.04141_iceberg_concurrent_no_logical_error.sh— concurrent readers and a writer producing fresh snapshots, exercising the TOCTOU race in the regular planner path.Closes: #102037
Closes: #107334
Related: #93278
Version info
26.7.1.448(included in26.7and later)26.6.3.41,26.5.7.46,26.3.18.32