Skip to content

Fix a crash on an Iceberg manifest list with a huge manifest_length - #116564

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-manifest-length-cache-weight
Aug 28, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-manifest-length-cache-weight

Conversation

@groeneai

@groeneai groeneai commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #116496

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed a server crash when reading an Iceberg table whose manifest list declares a very large manifest_length. The declared value was used as the metadata cache entry weight, overflowing the cache accounting and terminating the server. The size measured while reading the manifest file is now used instead.

Description

An Iceberg manifest-list entry declaring a large manifest_length terminates the server on read.
It is std::terminate, not an exception: a release build dies with an empty response and nothing
in the log.

The cause is magnitude, not signedness: the declared number became the cache cell weight,
3 * manifest_length + 200 (IcebergMetadataFilesCache.h:97), and SLRUCachePolicy::removeOverflow
ends with if (current_size_in_bytes > (1ull << 63)) std::terminate();. Anything above
(2^63 - 200) / 3 trips it. I confirmed that site under gdb; the other std::terminate there,
which the issue cites, is unreachable. Only the default SLRU policy is affected.

The fix weighs the cell by the bytes the Avro parse consumed and deletes getManifestFile's
bytes_size parameter, so no caller can pass a declared length. The constructor already reads the
whole file, so this needs no extra I/O and no size from the storage, which does not always report
one: on an S3 HEAD without Content-Length, size_bytes stays 0 and a manifest of any size is
charged at its 200-byte floor. The writer already takes its buffer's own count first
(IcebergWrites.cpp:1268-1272), so the two sides now agree. memory_bytes is unsigned now to match
the weight function; alone that fixes nothing, verified by building it by itself.

ManifestFileCacheKey::manifest_file_byte_size now has no readers but is kept, since removing it
would conflict with #90740. The std::terminate in SLRUCachePolicy is left alone as its owner's
call.

The regression test is an integration test: the shape needs a hand-written Avro manifest list, and a
functional test may not fabricate metadata files. Its control arm rewrites the manifest list without
changing the value, so on master the control passes and the huge case aborts; with the fix both
pass. It also bounds the cache weight by the manifest's real size on disk, which fails if the weight
stops tracking that size while the results stay correct.


Workflow [PR]
Sync PR [sync-upstream/pr/116564]

Version info

  • Merged into: 26.9.1.289-master (included in 26.9 and later)

An Iceberg manifest-list entry declares manifest_length, and that declared
number became ManifestFileCacheableInfo::file_bytes_size, whose only reader is
the metadata cache cell weight: 3 * file_bytes_size + 200. The cache policy
adds that to current_size_in_bytes, and SLRUCachePolicy::removeOverflow ends
with

    if (current_size_in_bytes > (1ull << 63))
        std::terminate(); // Queue became inconsistent

so any declared value above (2^63 - 200) / 3 = 3074457345618258536 terminates
the server. It is abnormal termination rather than an exception, so a release
build dies with an empty response to the client and nothing in the log.

The mechanism is magnitude, not signedness. memory_bytes was declared Int64 and
the huge size_t expression was narrowed into it, but the weight function
converts it straight back to size_t and recovers the identical bit pattern, and
the guard that fires is a magnitude test. Building the Int64 -> size_t change on
its own still reproduces the abort; that hunk is type correctness, matching the
weight function's own return type, not the fix.

The fix is to stop letting a metadata-declared number reach the weight at all.
getManifestFile now takes the manifest file's size from the object storage,
which createReadBuffer already populates unconditionally and which the function
previously discarded, so there is no extra request. The size_t bytes_size
parameter is deleted, which fixes all three call sites structurally: there is
nowhere left to pass a declared length. This mirrors the Paimon sibling, which
was never vulnerable, and it makes the read side use the same definition of
manifest_length the write side already uses, getObjectMetadata(...).size_bytes.

Confirmed the abort site under gdb with a breakpoint conditioned on the Iceberg
cell, since the two identical std::terminate() blocks in that function are tail
merged and a plain backtrace attributes the frame elsewhere: it is the magnitude
check, reached from the protected-queue pass of set, with current_size_in_bytes
= 13835058055282168350 for a declared 2^62. The other std::terminate() in the
same function is not reachable on this path, because the eviction loop guarding
it does not run. Exposure is limited to the default SLRU policy; LRU evicts the
oversized cell before reaching its own equivalent check.

ManifestFileCacheKey::manifest_file_byte_size keeps the declared value and now
has no readers. It is left in place deliberately: the struct is a faithful
record of a manifest-list entry, and removing it would conflict with ClickHouse#90740,
which edits that construction line.

Regression coverage is an integration test rather than a functional one, because
the shape needs a hand-written Avro manifest list and a functional test may not
fabricate metadata files. It reuses the existing Avro harness in
test_storage_iceberg_no_spark and carries a control arm that performs the same
manifest-list round trip without changing the value, so "any rewrite breaks it"
cannot masquerade as the finding. The control is ordered first: the defect
aborts the server and the package fixture is stay_alive, so running the huge
case first makes the control fail with a connection error instead of reporting
its own result.

Closes: ClickHouse#116496

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Independent cold review of the resulting code plus a second-model gate pass, adjudicated against
the recorded validation. 2 gate findings, 3 of my own. No blockers; nothing bounced.

# Finding Verdict
⚠️ The regression test's oracle is results-only, so it does not itself assert that the manifest entered the metadata cache with a weight derived from the real object size. Remedy asked for: a cache hit/miss or cache-byte oracle. Fact agreed, remedy declined. See below.
💡 Use Critical Bug Fix rather than Bug Fix, since the failure is a release-build server termination. Declined: I do not self-select that category. Facts for the call are below.
💡 manifest_object_info.metadata ? ... : 0 guards a state createReadBuffer cannot leave behind, and its comment says HEAD request where the local backend uses stat. Both withdrawn by me: PaimonClient.cpp:305-306 and :331-332 carry the byte-identical ternary and the same comment, and Paimon is the design being mirrored.
💡 The test docstring says an entry may declare any manifest_length, but a negative one is still rejected with Code: 743. Noted, not changed.

On the test oracle. The concern is that the test could pass with the cache bypassed, or with the
size replaced by zero. The first is settled by measurement rather than argument: base-reddening was
observed through this exact test, and the aborted server's build id was asserted byte-identical to
the pre-fix binary, so the run that failed necessarily went through getOrSetManifestFile. The
setup-with-cache-off / read-back-with-cache-on split exists for precisely this reason. The remedies
do not survive: IcebergMetadataFilesCacheMisses and Hits are incremented by all four cell kinds,
so a counter cannot tell the manifest cell from the metadata.json or manifest-list cells; and a
lower bound on cache bytes would pin something the code deliberately does not promise, since
createReadBuffer itself distrusts size_bytes when is_size_known is false, which is reachable on
S3 without Content-Length and on web storage and legitimately leaves the weight at 200. Any tight
numeric bound would also hardcode a manifest size the harness perturbs by dropping avro.codec when
it rewrites the file. So the property is verified positively in validation instead: with 2**62
still on disk the fixed build reports IcebergMetadataFilesCacheBytes of 31833, which is
3 * 9065 + 200 for the manifest cell plus 4438 for the others, and that same 4438 appears inside
the pre-fix total of 3 * 2**62 + 200 + 4438. What remains true is the narrow version: the
committed test does not assert the cache path, so it is the measurement above, not the test, that
pins where the weight comes from.

On the changelog category. I do not self-select Critical Bug Fix; it is yours to apply if you
want it, and the body and changelog entry already call the failure a crash in those words. The facts
for that call: the vulnerable weight line is live on 26.5, 26.6 and 26.7 (checked per branch), and
not on 25.8. The chosen category does not create a CI problem either way, since the new-tests gate
accepts a new tests/integration/test_* file.

One thing I noticed and am not raising: IcebergDataObjectInfo::getFileSizeHint and
IcebergIterator.cpp:541 cast the declared file_size_in_bytes to size_t with no range check, so
a negative declared value becomes a nonsense total_bytes_to_read. It reaches progress accounting
only, never a cache weight or an allocation, so there is no user-visible consequence to fix here.

@clickhouse-gh clickhouse-gh Bot closed this Aug 26, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ea66278]

Summary: ✅


AI Review

Summary

This PR fixes Iceberg manifest-cache accounting so it no longer trusts a manifest list entry's declared manifest_length when sizing cached manifest files, and instead uses the bytes actually consumed while reading the manifest. I read the current diff and surrounding Iceberg code, checked all prior discussion and inline threads, and did not find any unresolved correctness, safety, or test-coverage issues in the current version.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit ea66278.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.80% 80.70% -0.10%

Changed lines: Changed C/C++ lines covered: 31/31 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate
# Check Result
a Deterministic repro Yes. 100% on demand, fresh process per run, both the count() (IcebergMetadata::totalRows) and sum(c0) (ordinary scan) paths. Build a table with ClickHouse's own writer, set manifest_length = 2**62 in the manifest list, read it back: Aborted, exit 134, zero bytes on stdout and stderr.
b Root cause explained Yes. The declared manifest_length became ManifestFileCacheableInfo::file_bytes_size, whose only reader is the cache cell weight 3 * file_bytes_size + 200 (IcebergMetadataFilesCache.h:97). SLRUCachePolicy::removeOverflow then trips if (current_size_in_bytes > (1ull << 63)) std::terminate();. Threshold (2^63 - 200) / 3 = 3074457345618258536. Confirmed under gdb with a breakpoint conditioned on the Iceberg cell: current_size_in_bytes = 13835058055282168350, reached from the protected pass of set.
c Fix matches root cause Yes. The declared number is no longer read: the size comes from the object storage and the bytes_size parameter is deleted, so no caller can supply one. No clamp, no widened bound, no guard at the crash site. Rejected alternatives: clamp the weight; harden the shared cache policy; validate declared-vs-real and throw; widen the field only (refuted by measurement, row e).
d Test intent preserved / new tests Yes. Nothing existing weakened or removed. New integration test with a control arm; integration rather than functional because a functional test may not fabricate metadata files.
e Demonstrated in both directions Yes. 4-cell matrix, each cell for both queries: base + original value passes (3, 6); base + 2**62 aborts; fix + 2**62 passes; fix + original passes. Separately, Int64 -> size_t alone still aborts, so that hunk is type-correctness and the size change is the fix. Positive confirmation of the mechanism: with 2**62 still on disk, IcebergMetadataFilesCacheBytes reads 31833 = 3*9065 + 200 + 4438, i.e. the real 9065-byte object size, where the base build's total was 3*2^62 + 200 + 4438.
f General across code paths Yes. All three getManifestFile call sites passed the declared value; deleting the parameter fixes all three structurally. manifest_file_byte_size goes from 4 identifier occurrences repo-wide to 1: the declaration plus those 3 reads, all 3 removed here. Its write is positional aggregate initialization (StatelessMetadataFileGetter.cpp:244-246), so it carries no identifier and a name grep does not see it; the field is left written-but-unread, as the description says. The other three IcebergMetadataFilesCacheCell constructors derive weight from String::capacity(), sizeof(...) + path.size() and a sum over cache keys, so nothing symmetric to fix. Paimon, the only other DataLake metadata cache, already uses the real object size and an unsigned field; DeltaLake and Hudi have no weight function.
g Generalizes across inputs Yes. The field is a non-nullable Avro long, so no Nullable / LowCardinality / Array / Map / Const wrapper can reach it. Negative values are already rejected upstream with Code: 743 (unchanged). 2**62 and the original value both measured; after the fix the declared value is not read at all, so the remaining range is equivalent by construction rather than by sampling. An unknown object size leaves the weight at 200, matching Paimon.
h Backward compatible Yes, nothing to migrate. No setting, no serialization format, no persisted or wire value; the changed quantity is an in-memory cache-eviction weight. No SettingsChangesHistory.cpp entry needed. getManifestFile is internal to DB::Iceberg with three in-tree callers.
i Invariants and contracts preserved Yes. The weight remains a non-negative byte count and is now bounded by a real object size, which strengthens the cache policy's accounting invariant instead of relying on it. The metadata is read after createReadBuffer returns, null-guarded, and before std::move(buffer), so there is no use-after-move and no early return in between. No lock, ordering or lifetime is touched. Not a durability fix: the value is RAM-only.

Verification: new integration test base-reddened through the test itself (control passes, huge case aborts, harness reports Crash in instance 'node1', server log build id matching the base binary), then 2 passed twice on the fixed build. Whole test_storage_iceberg_no_spark module: 51 passed.

The cell weight was taken from `manifest_object_info.metadata->size_bytes`, which
`createReadBuffer` leaves at `0` whenever the storage does not report a size:
`getObjectInfo.cpp:75-76` sets `is_size_known = ContentLengthHasBeenSet()`, so an S3
HEAD without `Content-Length` yields `0`, and `WebObjectStorage.cpp:399-402` is a second
carrier. A manifest cached on that path weighed only the 200-byte floor, so the
128 MiB `iceberg_metadata_files_cache_size` stopped bounding it and only the 1000-entry
limit remained. Before this PR the weight came from the manifest list's declared
`manifest_length`, which is always present, so this was a regression introduced here.

`AvroForIcebergDeserializer`'s constructor already drains the whole file, so the bytes it
read are the file's size on storage and need no cooperation from the storage layer.
`AvroInputStreamReadBufferAdapter::byteCount()` is already `in.count()`, so this is the
existing idiom rather than a new one.

Measured weight-preserving, not merely plausible: on the same table
`system.metrics.IcebergMetadataFilesCacheBytes` is bit-identical before and after
(31815, and 123882 on a second fixture). That equality is not vacuous, because the
declared length works as a knob that proves the cell's weight lands in that metric with
coefficient 3: with `manifest_length` set to 1000000 on a 9064-byte manifest, the pre-fix
build reports 3004626 against 31818, a delta of exactly 3 * (1000000 - 9064), while both
fixed builds ignore the declared number.

The regression test now asserts that weight against the manifest's real size on disk,
read from the file rather than hardcoded so that it stays stable as the fixture moves.
Charging the cell from a declared `1` instead makes it fail (`weight 4695 < 3 * 9085`)
while the result assertions still pass, so the bound is what catches a weight that does
not come from the real size.

Its read-back queries also pin `use_iceberg_metadata_files_cache`. Without the pin the
test depends on the setting's default: with it flipped off, the poisoned case passes
against a pre-fix binary, i.e. the test goes blind while still looking green.
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ea66278af with master d2237d7d0 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of fd57f120f; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 712.38 MiB 707.00 MiB -5.39 MiB (-0.76%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

23 object files changed (-3.89 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Transforms/TTLDeleteFilterTransform.cpp.o 133.34 KiB 116.63 KiB -16.71 KiB (-12.53%)

835 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

46 translation units recompiled, 479 s compile time in total, 46 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6d2cb70

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Docs examples / Documentation examples stale tests/docs_examples/known_failures.txt:50 entry Function/catboostEvaluate#0; the runner reports 1 known failure(s) no longer exist and must be removed because #109710 removed the integration #116566 (external, merged) - the revert restores catboostEvaluate, making the entry valid again; merged 20:09:12Z but this branch is 191 commits behind it, so the tree under test lacks it

That is the only failure: praktika's report for this head is OK 151 / SKIPPED 23 / FAIL 1, all 175
check-runs are complete, Finish Workflow is green and no job was dropped. Mergeable Check and
PR are aggregate roll-ups of that one row, not separate failures. Nothing is caused by this PR:
Style check, Fast test, Fast test (arm_darwin), Build (arm_tidy), every Build (*) and every
Bugfix validation lane are green, and the Iceberg lanes that exercise this change pass.

Session id: cron:our-pr-ci-monitor:20260827-013000

@PedroTadim PedroTadim self-assigned this Aug 27, 2026
@PedroTadim
PedroTadim enabled auto-merge August 28, 2026 14:31
@PedroTadim

Copy link
Copy Markdown
Member

This LGTM, it's mostly changing an Int64 with size_t, the correct type

@grantholly-clickhouse grantholly-clickhouse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 28, 2026
Merged via the queue into ClickHouse:master with commit d6d200b Aug 28, 2026
175 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 28, 2026
alexey-milovidov pushed a commit that referenced this pull request Sep 19, 2026
Merge backport/26.8/116723 into cherrypick/26.8/116723 to finish the robot
cherry-pick of #116723 "Parallelize Iceberg data manifest decoding", which
GitHub reports as CONFLICTING.

Five of the nineteen paths needed a decision; the other fourteen land as the
merge produced them.

src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp: the rewrite
consolidated both manifest-iterator call sites into createManifestIterator, so
the resolved file is master's file plus two argument-level edits. 26.8's
Iceberg::getManifestFile still takes the bytes_size parameter that master
dropped in #116564, so manifest_list_entry.manifest_file_byte_size is passed;
26.8's ManifestFileIterator::create has no row-lineage parameter, so
manifest_list_entry.first_row_id is not passed.

src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp: the
incoming constructor body materializes per-entry first_row_id values for
format-version 3 manifests. Iceberg row lineage does not exist on 26.8, so the
26.8 (empty) side is taken. The cancellation check the PR adds between rows in
next() sits outside the conflict and is kept, so the new stop flag still
reaches the decode loop rather than being dropped with the walk.

src/Interpreters/PreparedSets.h: include union only. 26.8 keeps its own include
block plus <mutex> for the mutex member the PR adds.

src/Core/SettingsChangesHistory.cpp: a plain merge resolves this file by
importing master's whole "26.9" section, which names settings that do not exist
on 26.8, so applyCompatibilitySetting() throws UNKNOWN_SETTING for every SET
compatibility and a server with compatibility in a profile exits with code 115
at startup. That was fixed once already on this branch, by 0debf7d. The
imported section is therefore dropped and the two new entries are appended to
the branch's own "26.8" block, without master's "pre-26.9" and "compatibility
at or below 26.8" clauses, which are false here. The branch's existing
iceberg_delete_manifest_decode_concurrency entry is unchanged, so compatibility
at or below 26.7 yields 2 for both the data and the delete path, and an
unpinned server yields 4 for both. Leaving the entries out entirely is not an
option: 03999_stateless_settings_history requires every setting absent from the
frozen baseline to be recorded, and neither new setting is in the baseline.

tests/integration/test_storage_iceberg_with_spark/test_data_manifest_decode_concurrency.py:
test_data_manifest_decode_concurrency_row_lineage writes a format-version 3
table and selects _row_id, a virtual column 26.8 does not have. It is excised
and the other five tests are unchanged. Nothing on 26.8 loses coverage, because
the behavior it pins, per-entry first_row_id materialization under concurrency,
has no implementation on this branch.

Related: #116723
Related: #120406
@PedroTadim PedroTadim added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 2, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 2, 2026
robot-clickhouse added a commit that referenced this pull request Nov 2, 2026
robot-clickhouse added a commit that referenced this pull request Nov 2, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 2, 2026
PedroTadim added a commit that referenced this pull request Nov 2, 2026
Backport #116564 to 26.3: Fix a crash on an Iceberg manifest list with a huge manifest_length
clickhouse-gh Bot added a commit that referenced this pull request Nov 2, 2026
Backport #116564 to 26.8: Fix a crash on an Iceberg manifest list with a huge manifest_length
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg: a large manifest_length in the manifest list aborts the server via std::terminate — on release builds, with no diagnostic

6 participants