Skip to content

Make 04329_iceberg_insert_stale_schema_field_id_107268 own its cache state - #113232

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-04329-iceberg-cache-warmth-oracle
Aug 4, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-04329-iceberg-cache-warmth-oracle

Conversation

@groeneai

@groeneai groeneai commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #113010
Related: #109838

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

04329_iceberg_insert_stale_schema_field_id_107268 failed 7 times on
Stateless tests (arm_asan_ubsan, targeted) across two unrelated PRs (#113010, #112866), both
expected INCORRECT_DATA lines missing each time. It is my test.

The test needs INSERT analysis to serve a stale schema while the sink force-reads the latest one, and
built that by warming the server-global Iceberg metadata files cache and hoping the entry survived to
the INSERT. That cache is SLRU-bounded at 1000 entries (src/Core/Defines.h:121,123) and shared with
every other test, so when earlier tests leave it at its bound the entry is evicted, the INSERT reads
fresh, both views agree, and the rejection correctly does not fire. A second defect hid
that: grep -oF "INCORRECT_DATA" prints nothing for a successful INSERT and nothing for a different
error code, so it could not distinguish a wrong code from no error, and in the opposite cache state it
passed vacuously.

The fix clears the cache immediately before each warm-up SELECT, so the test owns the state it
depends on, and reports the actual outcome for every outcome (error code name, or NO_ERROR).
.reference is unchanged, so the rejection must still fire twice; a run that stops exercising it now
fails and names why. no-parallel is kept, now guarding the cache clear, like
03272_prewarm_mark_cache_add_column.sql.

With the cache bound lowered to 40 and pre-filled to 40/40, the old form fails with a diff
byte-identical to CI and the new form passes on that same state. 50/50 randomized runs pass. 04214
and 04337, the only other users of iceberg_metadata_staleness_ms, are not exposed.

v3.metadata.json is still written directly: ALTER ... RENAME COLUMN calls
invalidateMetadataCache() and destroys the precondition. 04337 does the same, but I will move this
to an integration test if you prefer. #109838 also touches these two lines (expecting
BAD_ARGUMENTS), so whichever lands second needs a .reference rebase.

Version info

  • Merged into: 26.8.1.757 (included in 26.8 and later)

The test needs INSERT analysis to serve a stale schema while the sink
force-reads the latest one. It built that by warming the server-global
Iceberg metadata files cache and relying on the entry surviving to the
INSERT. That cache is SLRU-bounded at 1000 entries and shared with every
other test on the server, so a cache left at its bound by earlier tests
evicts the entry: the INSERT reads fresh, both views agree, and the
rejection correctly does not fire.

A second defect made that silent. Both oracles were
`grep -oF "INCORRECT_DATA"`, which prints nothing for a successful INSERT
and nothing for a different error code, so the reference diff could not
distinguish a wrong error code from no error at all, and in the opposite
cache state the test passed vacuously.

Clear the cache immediately before each warm-up SELECT so the test owns
the state it depends on, and report the actual outcome for every outcome
(the error code name, or NO_ERROR). The reference file is unchanged, so
the rejection must still fire in both scenarios; a run that stops
exercising it now fails and names what happened instead of passing.

no-parallel is kept, and its comment now states the real reason: the
test issues a server-global cache clear, so it must be alone on the
server. That is the same pairing 03272_prewarm_mark_cache_add_column.sql
uses for the mark cache.

Validation: with the cache bound lowered to 40 and pre-filled to 40/40
occupancy (measured via IcebergMetadataFilesCacheFiles), the old form
fails with a stdout diff byte-identical to the CI failure and the new
form passes on that same injected state. 50/50 randomized runs pass.
The only other tests using iceberg_metadata_staleness_ms, 04214 and
04337, are not exposed to residual occupancy and are unchanged.

Failed 7 times on Stateless tests (arm_asan_ubsan, targeted) across two
unrelated PRs, ClickHouse#113010 and ClickHouse#112866.
@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (independent cold review + adversarial gate): 0 blockers, 0 majors, 2 nits

Before opening this PR I ran an independent review of the resulting code without access to the
implementation notes, then an adversarial second-model gate over the same diff. Both are recorded
here for transparency.

Result: 0 blockers, 0 majors, 2 nits. The gate returned 0 findings; both nits are mine, and I
disagreed with both on measured evidence rather than fixing them.

# Severity Finding Verdict
1 💡 nit insert_outcome extracts the error-code name from the first Code: line only, so a hypothetical multi-line exception message would yield UNPARSED_ERROR. DISAGREE. That is the fail-loud direction: an unparsed token reddens the reference diff, it cannot fake a pass. Measured that neither asserted outcome is multi-line - the INCORRECT_DATA message at PrepareForWrite.cpp:805-810 is single-line, and the pre-fix LOGICAL_ERROR shape (with its , Stack trace (...) tail) extracts correctly.
2 💡 nit Taking the last parenthesised upper-case token could misread a message that itself ends with such a token. DISAGREE. Exception.cpp:682-691 appends (CODE_NAME) last and only the stack-trace section follows, which the extraction strips first; the client's (version 26.8.1.1 (official build)) suffix is lower-case and does not match. Verified across 6 message shapes, including one with parentheses inside the message body.

What the independent review verified from source, rather than taking on trust:

  • SYSTEM DROP ICEBERG METADATA CACHE clears the same store the staleness path reads:
    ParserSystemQuery.cpp:322 -> InterpreterSystemQuery.cpp:473-477 ->
    Context::clearIcebergMetadataFilesCache (Context.cpp:4955), the same object
    Utils.cpp:1246-1254 probes.
  • The eviction mechanism is SLRU-specific, not a generic LRU story: a newly warmed key enters the
    probationary queue (SLRUCachePolicy.h:201-212) and removeOverflow evicts from its front
    while cells.size() > max_count (:308-311), with protected cells still counted. That is why the
    CI failure is a deterministic 5/5 rather than intermittent.
  • Test intent is strengthened, not weakened: .reference is unchanged, so the rejection must still
    fire in both scenarios; the change only makes a non-firing run visible.
  • Carriers enumerated independently, then compared with the plan: the only other tests using
    iceberg_metadata_staleness_ms are 04214 (single clickhouse local process, per-process cache)
    and 04337_iceberg_schema_id_reuse_across_versions (forces staleness 0, already has a total
    oracle). Neither is exposed; both correctly unchanged.
  • no-parallel retention is mandated, not chosen: ci/jobs/scripts/check_style/various_checks.sh:199-214
    fails the style check for any test matching system\s+drop without the tag. The tag predates this
    PR; only its comment changed, to state the real reason.
  • Freshness: neither the test, its reference, nor PrepareForWrite.cpp changed in the 440 commits
    between the base and current master; git merge-tree is clean.

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Lower iceberg_metadata_files_cache_max_entries to 40 via config.d + SYSTEM RELOAD CONFIG, pre-fill the cache to 40/40 by driving 20 throwaway IcebergLocal tables through the server, then run the old form: it fails every time, not intermittently. Occupancy is measured through IcebergMetadataFilesCacheFiles and IcebergMetadataFilesCacheWeightLost, not assumed.
b Root cause explained? Yes. INSERT analysis does not force-fetch, so within iceberg_metadata_staleness_ms it serves the cached latest version, while the sink force-fetches and always sees the latest. The rejection fires only while the warmed entry survives to the INSERT. That entry lives in the server-global SLRU IcebergMetadataFilesCache (1000 entries / 128 MiB, src/Core/Defines.h:121,123), whose occupancy the test did not bound, so a cache left at its bound by earlier tests evicts it, both views agree and the rejection correctly does not fire. Separately, grep -oF "INCORRECT_DATA" prints nothing for a successful INSERT and nothing for a different error code, so that outcome was indistinguishable from a pass.
c Fix matches root cause? Yes, and it addresses both halves: the test now clears the cache before each warm-up SELECT (owning the state it depends on) and asserts the actual outcome for every outcome. No widened bound, no reduced dataset, no added tag, no defensive check masking anything.
d Test intent preserved / new tests added? Preserved and strengthened. .reference is unchanged, so the test still demands the rejection fires twice for both scenarios. The regression under test (the out-of-range in Parquet::prepareColumnRecursive) is untouched; what changed is that a run which stops exercising it now fails and names the outcome instead of passing silently. No source change, so no new regression test is owed.
e Both directions demonstrated? Yes, on the same injected state (40/40 occupancy, sampled before each arm since the new form's clear wipes the pre-fill). Old form: FAIL, with a stdout diff byte-identical to the CI failure (-INCORRECT_DATA twice, only the liveness 1 surviving). New form: OK.
f Fix is general across code paths? Yes. Both scenarios in the test are fixed, each with its own clear. The only other tests using iceberg_metadata_staleness_ms are 04214 and 04337; 04214 runs its whole scenario in one clickhouse local process (the cache is per process, so no residual exposure) and 04337 forces iceberg_metadata_staleness_ms=0 with an already-total oracle, so eviction cannot silence it. Both verified by reading them and re-run green.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, for the input space that applies here: error-message shapes. The extraction was unit-tested against a plain code line, a line continuing , Stack trace (...), a message containing its own parenthesised token, a message with parentheses before the code, and output with no Code: line at all (which yields UNPARSED_ERROR). An earlier version anchored the code name to end of line and silently mis-parsed the stack-trace shape, which is exactly the shape this test regression-covers; that is why the shape matrix exists. Live checks return NO_ERROR, FUNCTION_THROW_IF_VALUE_IS_NON_ZERO and INCORRECT_DATA on the respective paths.
h Backward compatible? (maintainer-approved exception only) N/A. Test-only change: no source change, no setting default change, no SettingsChangesHistory.cpp entry, no format or serialization change, no experimental gate.
i Invariants and contracts preserved? Yes. The invariant restored is that a test asserting a negative outcome must own every input deciding whether the asserted path is taken, and must fail visibly when it is not. The helper returns on every path (success, parseable error, unparseable error), so no path prints nothing. The global cache clear is safe only because the test is no-parallel and therefore alone in the sequential runner; the tag comment now records that coupling so it stays discoverable.

Session id: cron:clickhouse-impl-slot-45:20260804-021400

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @arsenmuk, could you review this? It is a test-only fix: 04329 relied on a warmed entry in the server-global Iceberg metadata files cache surviving to its INSERT, which residual occupancy from other tests evicts, and its grep-based oracle printed nothing for both a successful INSERT and a different error code, so the miss was silent.

@PedroTadim PedroTadim self-assigned this Aug 4, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ff2e349]

Summary: ✅


AI Review

Summary

This PR makes 04329_iceberg_insert_stale_schema_field_id_107268.sh own the Iceberg metadata-cache state it depends on by clearing the server-global cache before each warm-up read and by replacing the old grep-based oracle with explicit outcome reporting. I did not find any unresolved correctness or test-contract issues in the current head: the changed test now fails loudly when it stops exercising the stale-schema rejection path, the no-parallel tag remains justified by SYSTEM DROP ICEBERG METADATA CACHE, and the PR metadata and green CI run match a test-only CI Fix or Improvement.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 4, 2026
@PedroTadim
PedroTadim enabled auto-merge August 4, 2026 08:27
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 4, 2026
@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ff2e349

Every failure below has an owner: a fixing PR (mine 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
Build (arm_release) / Post Hooks CI telemetry only, not a build or test failure: the build_time_trace INSERT in build_profile_hook.py (line 293, in check) is rejected by the analytics cluster with LogCluster query failed with code 500, whose reason line is Code: 241. DB::Exception: User memory limit exceeded: would use 2.70 TiB (attempt to allocate chunk of 8.00 MiB), maximum: 29.80 GiB. OvercommitTracker decision ... While executing JSONCompactEachRowRowInputFormat. (MEMORY_LIMIT_EXCEEDED). The enclosing job is check_status = success, so it gates nothing. Unrelated to this diff, which changes one stateless test file and no build or telemetry code. Breadth over 7 days: 2072 rows across 486 pull requests and 1056 commits, 1331 of those rows on master a fix task is moved to pending (investigating at full effort, fixing-PR link to follow on this PR)
Sync - CH Inc sync (private, not actionable)

176 check-runs, all complete: 58 success, 118 skipped, 0 failures among them. Config Workflow
and Finish Workflow both succeeded.

The test this PR changes is green everywhere at this head: 04329_iceberg_insert_stale_schema_field_id_107268
is OK in all four flaky check jobs at 25 runs each (100/100), and OK in every sequential job that
selected it (amd_debug, amd_tsan, amd_tsan s3, amd_msan WasmEdge, amd_asan_ubsan db disk,
arm_binary, arm_asan_ubsan azure) plus both Fast test flavours.

Session id: cron:our-pr-ci-monitor:20260804-103000

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 4, 2026
Merged via the queue into ClickHouse:master with commit 2bcd82b Aug 4, 2026
181 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 4, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 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-ci 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.

3 participants