Repository navigation
Pin the JBOD least_used placement test to single-threaded inserts - #112500
Conversation
tests/integration/test_jbod_load_balancing/test.py::test_jbod_load_balancing_least_used_next_disk asserts an exact part-to-disk placement. That assertion is only well posed when the parts of one INSERT are written sequentially. least_used picks the disk with the most unreserved space at reserve time. DiskLocal::getUnreservedSpace is statvfs f_bavail minus the full reservation size (DiskLocal.cpp:308-313), and a reservation lives only while its own part is being written, because MergeTreeTemporaryPart holds no ReservationPtr. So while a part is in flight its bytes are charged twice, and with several insert threads the chosen disk depends on whether a concurrently writing part's reservation is still live. With jbod3 mid-write it reports (300 - w) - 108 MiB, so the idle 100 MiB jbod1 wins once about 92 MiB of jbod3's part has reached the filesystem, giving the observed jbod1 placement. The test passed for years because max_insert_threads defaulted to 1. Changing that default to auto (number of CPU cores) made the reserves interleave and exposed the latent ill-posedness. That default change is correct and is not at fault here. Reproduced locally on a pristine master binary with the same log line CI shows (Reserved 92.99 MiB on local disk `jbod1`, having unreserved 100.00 MiB). With the two arms alternated run by run, 30 runs each: at the auto default two threads issue the three reserves and placement diverged 1/30; at max_insert_threads = 1 a single thread issues them and it diverged 0/30. The assertion is unchanged and is not weakened. Mutating the LEAST_USED branch to always take disks[0] still reddens the pinned test, while round_robin, which ignores free space, stays green. The accounting error direction is conservative, so it can never over-commit; it can separately refuse a concurrent insert with NOT_ENOUGH_SPACE on tight disks. Both the parallel-insert placement quality and that false rejection are tracked separately, as is a dead DiskWithSize::reserve plus stale free_size on the least_used_ttl_ms > 0 path. 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 a cold
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260730-001100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260729-231900 |
|
cc @azat, could you review this? The least_used volume rebuilds its free-space queue on every reserve, and getUnreservedSpace subtracts the full live reservation while statvfs already counts the flushed bytes, so once inserts run in parallel a reserve can see a mid-write part and the exact-placement assertion this test makes stops being well defined; this pins max_insert_threads = 1 on that one INSERT without touching the assertion. |
|
Workflow [PR], commit [969e444] Summary: ✅ AI ReviewSummaryThis PR pins Final VerdictStatus: ✅ Approve |
|
@groeneai I think the test test_jbod_load_balancing_least_used_next_disk got a fix merged into master yesterday. Do we still need this PR? |
CI finish ledger - 969e444Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task No failures on this commit. All 174 check-runs completed with zero non-success conclusions Session id: cron:our-pr-ci-monitor:20260730-163853 |
|
@PedroTadim where? |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
test_jbod_load_balancing_least_used_next_diskstarted failing on master and on unrelated PRs on2026-07-29 (6 runs so far, 1 of them on master, against ~1500 passes that day). It asserts an exact
part-to-disk placement and got
jbod1where it expectsjbod2. Master run:https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=e0e5e04a027ed740ab3756d4853fb6d21126c077&name_0=MasterCI&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%203%2F6%29
That assertion is only well posed for single-threaded inserts.
least_usedpicks the disk with themost unreserved space at reserve time;
getUnreservedSpaceisstatvfs f_bavailminus thefull reservation size (
DiskLocal.cpp:308-313), and a reservation lives only while its own partis written (
MergeTreeTemporaryPartholds noReservationPtr). So an in-flight part has its bytescharged twice, and with several insert threads the choice depends on whether a concurrently writing
part's reservation is still live. Reproduced locally, byte-identical to CI:
jbod3 reports
(300 - w) - 108, so idle jbod1 wins once ~92 MiB of jbod3's part has reached thefilesystem. The test passed for years because
max_insert_threadsdefaulted to 1; #109006 changedthat default to auto, which exposed it. That change is correct and is not at fault.
This pins
max_insert_threads = 1on that one INSERT so the assertion runs in the mode where it isdeterministic. The assertion is unchanged and not weakened: with
least_useddeliberately broken toalways pick the first disk, the pinned test still fails.
The accounting error is conservative, so it cannot over-commit; separately it can refuse a
concurrent insert with
NOT_ENOUGH_SPACEon tight disks. Neither is addressed here, both are filedas follow-ups.
Validation
Pre-fix binary, arms alternated run by run so host load cannot bias either:
max_insert_threads = 1VolumeJBOD.cpp:172to always takedisks[0]reddens the pinned test witha real placement assertion failure;
round_robin, which ignores free space, stays green. Becausethe natural divergence rate is well under 1%, this mutation, not a revert of this diff, is what
shows the pinned test still catches a real regression.
0 assertion failures (5 runs lost to a container kill on a loaded host). Restoring the unfixed
test file on the same host failed more often, also with 0 assertion failures, so those deaths are
environmental.
GROUP BY disk_nameappears in exactly one integration test file, this suite, out of the 31 thatreference
disk_name;test_jbod_balancerandtest_ttl_moveassert sets, not exact placement.No sibling test needs the same pin.