Repository navigation
Pin the part format in 02228_merge_tree_insert_memory_usage - #111929
Conversation
The test asserts that two INSERTs with max_insert_delayed_streams_for_parallel_write=1000000 fail with MEMORY_LIMIT_EXCEEDED under max_memory_usage='30Mi'. Under some randomized MergeTree settings both INSERTs succeed instead, so the negative assertion never fires. CIDB shows 5 hits on 5 unrelated pull requests and 0 on master in 30 days, and the runner's ddmin minimization names the same three settings every time, always including min_bytes_for_wide_part=0. The assertion is a memory-footprint assertion: with no early flush the write buffers of all 100 partitions are held at once and must exceed the budget. Compact parts, the format these ~1.3 KB parts get by default, keep a ~1 MiB compressor per delayed part, so the budget is always exceeded. Setting min_bytes_for_wide_part to 0 flips the parts to Wide, where buffer sizes become setting-dependent: min_columns_to_activate_adaptive_write_buffer at or below the table's 3 columns starts each stream at 16 KiB, and a large min_bytes_for_full_part_storage selects Packed storage whose underlying file buffer allocates nothing. The footprint collapses below 30 MiB and the INSERT succeeds. The lower memory use is correct and intended (b243331); the test simply never pinned the part format its assertion is calibrated for. Pin min_bytes_for_wide_part to the non-cloud default at CREATE TABLE level on both tables. MergeTreeData::choosePartFormat ORs the bytes, rows and level terms, so this single setting guarantees Compact and makes the Wide-only mechanism unreachable. Table-level SETTINGS win over the randomizer, which only injects a setting when it is absent. The assertion, the memory budget and the delayed-stream settings are unchanged. Verified on a debug build: fails without the pin and passes with it on all three fully-minimized culprit sets, 150/150 under full randomization, and across seven adversarial combinations aimed at shrinking Compact buffers. system.parts confirms Compact with the pin and Wide without it under the same injected settings. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus an
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260726-014400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260726-011000 |
|
cc @rschu1ze — could you review this? Test-only: the negative |
|
Workflow [PR], commit [c3877f3] Summary: ✅ AI ReviewSummaryThis PR makes Final VerdictStatus: ✅ Approve |
CI finish ledger — 53c4f14Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Server log, which is what pins the owner:
Not caused by this PR: the diff pins part format and memory-related settings in Session id: cron:our-pr-ci-monitor:20260726-083000 |
CI finish ledger - c3877f3No failures to own on this head. All 174 check-runs are complete, This head is a plain merge of master into the branch, so it carries no source change of mine. The Session id: cron:our-pr-ci-monitor:20260727-073000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
02228_merge_tree_insert_memory_usageasserts that two INSERTs withmax_insert_delayed_streams_for_parallel_write=1000000FAIL withMEMORY_LIMIT_EXCEEDEDunder
max_memory_usage='30Mi'. Under some randomized MergeTree settings both INSERTssucceed instead, so the negative assertion never fires:
Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109408&sha=44dfafb3dcee3c3528e7b5c4f0ca00c04e4aebd8&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29
CIDB, 30 days: 5 hits on 5 unrelated pull requests, 0 on master (~48.7k OK runs), on
arm_binary parallel,amd_debug parallel,amd_tsan parallelandamd_asan_ubsan distributed plan. The runner's--diagnose-random-settingsminimized theculprit to the same three MergeTree settings in every fully-minimized sample, for example
--min_bytes_for_wide_part 0 --min_bytes_for_full_part_storage 509915446 --min_columns_to_activate_adaptive_write_buffer 2.Root cause: the assertion is a memory-footprint assertion. With no early flush, the write
buffers of all 100 partitions are held at once and must exceed the 30 MiB budget. Compact
parts, the format these ~1.3 KB parts get by default, keep a ~1 MiB compressor per delayed
part, so the budget is always exceeded. The runner sets
min_bytes_for_wide_partto 0 withprobability 0.3, which flips the parts to Wide, where the buffer sizes become
setting-dependent:
min_columns_to_activate_adaptive_write_bufferat or below the table's 3columns starts each stream at 16 KiB, and a large
min_bytes_for_full_part_storageselectsPacked storage whose underlying file buffer allocates nothing. The footprint collapses well
under 30 MiB, the INSERT succeeds and the expectation fails. This is not a product bug: the
lower memory use is the intended effect of b243331. The test simply never pinned the
part format its assertion is calibrated for.
Fix: pin
min_bytes_for_wide_part = 10485760, the non-cloud default, at CREATE TABLE levelon both tables.
MergeTreeData::choosePartFormatselects Compact when any one of the bytes,rows or level terms is satisfied, so this single setting guarantees Compact and makes the whole
Wide-only mechanism unreachable. Table-level
SETTINGSwin over the randomizer, which onlyinjects a setting when it is absent. The assertion, the memory budget and the delayed-stream
settings are unchanged.
Coverage note: the test no longer exercises the Wide adaptive-write-buffer path under
randomization. That path has dedicated tests
(
03770_min_columns_to_activate_adaptive_write_buffer.sql.j2,03393_max_merge_delayed_streams_for_parallel_write.sql,03261_delayed_streams_memory.sql),and Compact is the regime this test was written for in 3a5a39a.
Verification, debug build:
the two inverse-assertion lines. With the pin: OK. Both directions, all three sets.
--min_bytes_for_wide_part 0injected,system.partsshows Compact; without the pin, same injection, it shows Wide.
(
max_compress_block_size 1,compact_parts_max_bytes_to_buffer 1024,compact_parts_max_granules_to_buffer 1,min_bytes_for_full_part_storage 536870912,compress_per_column_in_compact_parts 1,ratio_of_defaults_for_sparse_serialization 0.0,min_columns_to_activate_adaptive_write_buffer 0): all OK.