Skip to content

La Casa Del Dolor: do not generate a split SLRU cache with an empty queue - #133366

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/casa-del-dolor-slru-element-queue
Nov 22, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/casa-del-dolor-slru-element-queue

Conversation

@groeneai

@groeneai groeneai commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131994

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

La Casa Del Dolor can draw a filesystem cache that the server refuses at startup, so the run ends before any fuzzing. La Casa Del Dolor (arm_asan_ubsan) failed with Instance 'node0' failed to start: the server exited with code 36, and the server log has Incorrect max elements cache configuration. Max size: 10, size ratio: 0.01. Cannot have zero max elements after ratio is applied. (BAD_ARGUMENTS).

The drawn cache was SLRU with use_split_cache=1, split_cache_ratio=0.99, slru_size_ratio=0.01 and max_elements=1000. Its data part gets 1000 * 0.01 = 10 elements and the protected SLRU queue of that part lround(10 * 0.01) = 0, which SLRUFileCachePriority rejects. 174d412 (in #131994) lowered the max_elements floor from 10000 to 1000; with 10000 the worst case still rounded to 1.

normalize_cache_properties already shrinks the file segment to fit the smallest SLRU queue of each split part, using the server's rounding. This PR applies the same computation to max_elements: when the smallest queue of an SLRU cache would get 0 elements, max_elements is raised to the smallest value that gives every queue at least one element (at most 4950 for the generated ratios, within MAX_CACHE_ELEMENTS). Other generated configs do not change.

The alternative is to restore the floor to 10000 (or revert #131994). That also drops the 1000-9999 range for every cache, although only split SLRU caches with extreme ratios are invalid.

Validation (local): over 200000 seeded draws, master's generator produces 1022 caches the server would reject and this PR produces 0; on 100000 seeds of both generators, the only differences are max_elements of caches master leaves unstartable. A master debug server exits with code 36 on the CI cache block and starts with the normalized one (max_elements 4950).

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.12.1.202-master (included in 26.12 and later)

…ueue

La Casa Del Dolor (arm_asan_ubsan) on PR 133339 (sha 6e867ce) drew
`fcache0` as SLRU with `use_split_cache=1`, `split_cache_ratio=0.99`,
`slru_size_ratio=0.01` and `max_elements=1000`. `SplitFileCachePriority`
gives the data part lround(1000 * 0.01) = 10 elements, its protected SLRU
queue gets lround(10 * 0.01) = lround(0.1) = 0, and the
`SLRUFileCachePriority` constructor rejects a queue without elements:
"Cannot have zero max elements after ratio is applied" (BAD_ARGUMENTS),
so the server exits with code 36 and the run ends before any fuzzing.

174d412 ("Cap `max_elements` of the Dolor filesystem caches", in
ClickHouse#131994) lowered the generator floor of `max_elements` from 10000 to 1000.
With 10000 the worst case, both ratios at an extreme, was
10000 * 0.01 * 0.01 = 1; with 1000 it rounds to 0.

`normalize_cache_properties` already computes the smallest SLRU queue of
each split part with the server's rounding, to fit the file segment into
it. Factor that into `get_smallest_queue` and apply it to `max_elements`
too: raise it until every SLRU queue gets at least one element, staying
within `MAX_CACHE_ELEMENTS`. For the generated ratios (0.01 to 0.99) the
worst case needs 4950, by the server's `std::lround` and by the harness
rounding alike. The size logic is unchanged.

Measured with an oracle that re-implements the server's check with libm
`lround`: master's generator yields 1022 unstartable caches in 200000
seeded draws, this one 0; on 100000 seeds of both `filesystem_caches`
entries and cache disks, 1042 configs differ and every difference is only
`max_elements` of a cache master left unstartable. A master debug server
exits with code 36 on the CI cache block (protected queue 0 elements) and
starts with the normalized block (`max_elements` 4950; smallest queue
1 element).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 use_split_cache is rebound from the XML element to a bool in the SLRU branch (properties.py) AGREE Harmless: the element is not read after the overcommit check; left as is.
2 💡 The harness mirrors the server's std::lround split/SLRU rounding, so a server rounding change must update it DISAGREE The mirror matches master (SplitFileCachePriority.cpp, SLRUFileCachePriority.cpp); my open #133195 changes that rounding, and whichever of the two PRs lands second updates the mirror.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-10:20261121-043000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim, could you review this? The harness can draw a split SLRU filesystem cache whose smallest queue rounds to 0 elements since the max_elements floor went to 1000, so the server refuses to start; normalize_cache_properties now raises max_elements to the smallest value that gives every SLRU queue at least one element.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The CI fcache0 block (SLRU, split 0.99, slru 0.01, max_elements 1000) makes a master debug server exit with code 36 on every start, with the CI message. The seeded generator sweep emits 1022 such caches in 200000 draws on master.
b Root cause explained? The data part of the split cache gets 10 elements, its protected SLRU queue lround(0.1) = 0, and SLRUFileCachePriority rejects a 0-element queue. 174d412 lowered the max_elements floor from 10000 (worst case 1) to 1000 (worst case 0), and normalize_cache_properties fitted only the size of each queue.
c Fix matches root cause? Yes. The generator fits the element count of every SLRU queue the same way it already fits the size. No ratio range or floor is narrowed; only configs the server would reject change.
d Test intent preserved / new tests added? Test-infrastructure change: no test of the harness itself. Validated locally (sweep + server start A/B); the PR's own La Casa Del Dolor jobs run the harness end to end.
e Both directions demonstrated? Yes. Sweep: master 1022 unstartable, this PR 0 (oracle: the server rule with libm lround). Server: exit 36 with max_elements 1000, starts with the normalized 4950 (smallest queue 1 element).
f Fix is general across code paths? filesystem_caches entries and cache disks both go through normalize_cache_properties (both checked on the same seeds: the only differences are max_elements of rejected caches). The distributed cache server cache is forced to an overcommit policy without split (at least 10 elements). LRU has no such rejection.
g Fix generalizes across inputs (params/datatypes/wrappers)? All four extreme ratio corners (0.01/0.99) need at most 4950, within MAX_CACHE_ELEMENTS (10000); non-split SLRU caches always have at least 10 elements; max_elements stays in (0, 10000] on every draw.
h Backward compatible? (maintainer-approved exception only) Yes. Harness only, no server setting or format change.
i Invariants and contracts preserved? Every SLRU queue of a generated cache now has at least 1 element and at least 1 byte (the size half was already there), and max_elements <= MAX_CACHE_ELEMENTS still bounds the debug-build startup check.

Session id: cron:clickhouse-impl-slot-5:20261121-041700

@clickhouse-gh

clickhouse-gh Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [45d707c]

Summary: ✅


AI Review

Summary

The PR prevents generated split SLRU caches from failing server startup by raising max_elements until every queue has at least one element, preserving the existing 10,000-element cap. No actionable findings. Validation against the server's std::lround calculation covered the reported regression, 3,200 boundary/default/policy cases, and 100,000 seeded generator draws: all 188 invalid base configurations were repaired, with no other generated values changed. Validation used extracted generator functions and a rounding oracle; no live server was started locally.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI comp-fuzzing Fuzzers: BuzzHouse (the query generator in the client), the AST fuzzer (QueryFuzzer), and the lib... labels Nov 21, 2026
@alexey-milovidov alexey-milovidov self-assigned this Nov 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 22, 2026
Merged via the queue into ClickHouse:master with commit da0a5e3 Nov 22, 2026
390 of 391 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 Nov 22, 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 comp-fuzzing Fuzzers: BuzzHouse (the query generator in the client), the AST fuzzer (QueryFuzzer), and the lib... manual approve Manual approve required to run CI 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