Repository navigation
fix(group): an allocation failure in a group on the radix route answers oom, not a crash or an answer short of a column or groups - #1809
Conversation
…rs oom, not a crash or an answer short of a column or groups The radix emit of exec_group_run skipped a key column it could not allocate, or whose source column was missing, and phase 3 then wrote that key through its NULL data: SIGSEGV in radix_phase3_fn. It skipped an aggregate column it could not allocate the same way, and the answer lacked that column; the failed allocation's error was dropped (error objects are not reference counted). The classic radix route's phase 2 skipped a partition whose table it could not initialise, and nothing after it checked a partition's oom (also set when a table cannot grow while folding rows in), so the answer lacked that partition's groups. The emit now records a missing key or aggregate column, and once both loops have set every slot it discards the columns and the result and answers the allocation's own error (`oom`). Phase 2 marks a partition whose init failed as oom, as a failed grow does; after the dispatch any such partition frees every partition table (one whose init failed has its slots but no rows) and answers `oom`. Two DEBUG seams test it. ray_group_alloc_fail_for_test fails the nth allocation of the calling thread's own code while the outermost group runs; the allocator skips those the thread makes inside pool tasks it steals (pool.c marks them), whose share varies from run to run, so the sweep is deterministic. The partition-init seam of #1806 now also counts the classic route's phase 2. aware/group_alloc_fail sweeps both over a v2-radix, a two-key and a classic-radix query. Fixes #1808
05f38ad to
d2143ff
Compare
singaraiona
left a comment
There was a problem hiding this comment.
Review of d2143ff: NEEDS CHANGES
The radix route itself now holds under every single allocation failure I injected, on any thread. One instance of the same column skip is left on a path the radix route falls back to (item 1). The sweep was time-boxed; what it did and did not cover is stated below.
Finding
-
The sequential emit that the radix route falls back to still skips a column it cannot allocate. When
radix_bufscannot be allocated,exec_group_runtakesgoto sequential_fallback. That emit (group.c~22605-22612) then has both skips:- a key column
if (!src_col) continue;/if (!new_col || RAY_IS_ERR(new_col)) continue;; - an aggregate column
if (!new_col || RAY_IS_ERR(new_col)) continue;(~22883).
These are the skips this PR removes from the radix emit, and they drop the failed
ray_vec_new's 128-byte error the same way. A query on the radix route that meets a second failure in that emit (the first beingradix_bufs) would answer short a column. The same emit serves the hash-table path for groups that never go radix.I found this by reading. I did not reproduce it: a single injected failure is consumed by
radix_bufsitself, so the fallback's emit allocations then succeed, and my time-boxed small-table run did not complete. The fix is the same as the radix emit's: flag, discard, answer the allocation's own error. - a key column
What the sweep covered (on this head)
I added a probe seam to my local tree only, never pushed. It fails the nth allocation process-wide, on whichever thread makes it, while exec_group runs (a counter exec_group raises). It is optionally restricted to allocations inside pool tasks, which covers the worker threads and the tasks the calling thread steals that the PR's seam skips. Every position n from 1 to the run's count was swept once. Because which thread allocates where varies between runs, this is a randomised cover of the worker allocations, not a deterministic one.
Each run had to give the unfailed answer byte for byte (ser), or oom with net_bytes <= 0 by ray_mem_trace over every heap, after the error's release and a GC.
| Query, 262,144 rows, 4 threads | Any thread | Pool tasks only |
|---|---|---|
by: k (F64, v2) |
5,130 positions: same 5,124, oom 9 | 5,120: same 5,123, oom 0 (v2 falls back and answers) |
sum/avg by k |
5,131: same 5,124, oom 10 | 5,120: all same |
count/sum by [k j] |
8,364: same 8,357, oom 10 | 8,352: all same |
max by k (classic) |
3,594: same 2,556, oom 1,041 | 3,586: same 2,541, oom 1,048 |
sum by k under where: |
5,129: same 5,124, oom 8 | all same |
min/max by [k s] |
4,374: same 2,646, oom 1,731 | 4,484: same 2,711, oom 1,776 |
by: j (I64), i (I32), d (DATE), s (SYM) |
14-43 each: all same or oom | the same |
Across about 57,000 injected failures: no crash, no short or different answer, no error class other than oom, and 0 bytes kept.
- The base a6779b7 crashes on the first query of the same sweep (the SIGSEGV in
radix_phase3_fn). - A random multiple-failure mode (about 0.1% of allocations failing) ran only one cell before the time-box:
by: k, 150 runs, same 136, oom 14, nothing kept.
Not covered: two or more failures per run beyond that one cell, which is the route into item 1. The whole-query scope, beyond the group, was not swept to completion.
Outside the group, for the record: a whole-query run, stopped partway, shows faults before the group starts, so not this PR:
- 576-640 bytes kept at an early allocation;
- one injected failure answers
nyiinstead ofoom; - a SIGSEGV in
ray_select_body(query.c:28688,root->idwithrootNULL after a graph allocation failed) for thewhere:+by:query.
These deserve their own issue.
The PR's own seam: what it cannot reach
ray_group_alloc_fail_for_test skips allocations inside pool tasks, so it never fails a worker's allocation or a stolen task's. That leaves the phase-1 buffers, the worker HT grows, the v2 worker HTs and phase-3 work. ray_group_test_ht_rows_fail covers one site inside tasks, the phase-2 partition init. The rest is covered only by an any-thread injection like the one above. I would add one to the test, scoped to the group as the PR's seam is, for example a process-wide atomic countdown, and accept that positions vary between runs.
The author's two "not fixed" claims: both real
I confirmed both by reading.
- Dense-array route.
- Its emit (
group.c~9692) has the same aggregate-columncontinue, and the key loop too. - Its
dense_*scratch buffers (~20147-20162) arescratch_alloc'd without a check. The per-aggregate copies are guarded byif (dense_sum)and the like, so a failed one silently drops that aggregate's values.dense_counts[gi] = …is written unconditionally. - My
by: w(I64 over 50 values) single-failure runs answered right oroom, so I did not reproduce a fault there.
- Its emit (
- Keys-only result build. It sits in
ray_select_body, outsideexec_group. The whole-query run above did show bytes kept there.
Uninjected behaviour and cost
- Release output: seven queries over the 262,144-row table (
by: k,sum/avg,[k j],max,[k s],by: w,by: s). Theserof all the results is byte-identical between this head and a6779b7. - Callgrind (
-c 1, the whole script): 1,756,806,079 instructions against 1,756,806,010, which is +69 for the seven queries. Nothing per row.
Runs (gcc)
- Release build clean.
make -j4 test TEST_ARGS="-j 4": 5890 of 5894 passed, 4 skipped, 0 failed. - ASan+UBSan test binary:
aware/group_alloc_fail1/1,-f cancel87/88 (1 skip),-f group/98/98, no sanitizer report. - TSan:
aware/group_alloc_fail1/1 and-f cancel87/88 (1 skip), 0 reports.
…ers oom, not a table short of a column or a write through NULL The dense-array route of exec_group_run skipped a key column it could not allocate, and emit_agg_columns, which builds the aggregate columns of this and several other routes, skipped an aggregate column the same way: the answer lacked that column, and the failed allocation's error was dropped. The route used its dense_* scratch buffers unchecked and wrote through NULL when one failed to allocate. The route now answers the allocation's failure through one exit that frees its scratch, its shared buffers and the result: a failed key column, a failed ray_table_add_col, or a missing scratch buffer. emit_agg_columns makes *result the failed column's own error; its callers return the result as before, and the whole-table route, which recomputes columns after it, takes it as its recompute error. The sequential fallback the radix route takes when its buffer table fails to allocate had the same two skips in its own emit, a key column and an aggregate column; both now answer the failed column's error. Its group_ht_init failing part-way kept the slots it had allocated; single_ht is zeroed first and freed on that exit. A failed group_ht_rehash kept the old slot table, which was resized only after the insert that took it past half full: the fallback table starts at two slots, so that insert filled it, and the next probe for a new key found no empty slot and looped forever. The two probes that insert (group_probe_entry and group_merge_row) now rehash before that insert and probe again, and a failed rehash marks the table oom, as a failed grow of its rows does, so it takes no more groups and the group answers oom. A DEBUG seam, ray_select_keys_alloc_fail_for_test, fails each allocation of the keys-only select-by result build in ray_select_body; aware/group_alloc_fail sweeps it, and the group seam of #1809 now also sweeps the dense-array route, and, with a second DEBUG seam (ray_group_test_radix_bufs_fail) failing the radix buffer table, the sequential fallback. Fixes #1811
|
On the review's point (the sequential fallback the radix route takes when I added the fix and a two-failure test to #1812, now at 7bbcfb1. This pull request is unchanged. The test:
The sweep found two more defects on that fallback, both also fixed in #1812:
The timing is the same before and after (within run-to-run noise): 20M rows with 5M groups, at |
|
The lead accepts this pull request as it is. The latest review's one point (the radix route's sequential fallback emit could still skip a column on a second allocation failure) was found by reading, not reproduced, and everything the review ran passed. The author has fixed that fallback, with a two-failure test, in the stacked #1812 (issuecomment-7211176320), which is reviewed next. No other finding against this change is open, so it goes to the merge queue. |
…ers oom, not a table short of a column or a write through NULL The dense-array route of exec_group_run skipped a key column it could not allocate, and emit_agg_columns, which builds the aggregate columns of this and several other routes, skipped an aggregate column the same way: the answer lacked that column, and the failed allocation's error was dropped. The route used its dense_* scratch buffers unchecked and wrote through NULL when one failed to allocate. The route now answers the allocation's failure through one exit that frees its scratch, its shared buffers and the result: a failed key column, a failed ray_table_add_col, or a missing scratch buffer. emit_agg_columns makes *result the failed column's own error; its callers return the result as before, and the whole-table route, which recomputes columns after it, takes it as its recompute error. The sequential fallback the radix route takes when its buffer table fails to allocate had the same two skips in its own emit, a key column and an aggregate column; both now answer the failed column's error. Its group_ht_init failing part-way kept the slots it had allocated; single_ht is zeroed first and freed on that exit. A failed group_ht_rehash kept the old slot table, which was resized only after the insert that took it past half full: the fallback table starts at two slots, so that insert filled it, and the next probe for a new key found no empty slot and looped forever. The two probes that insert (group_probe_entry and group_merge_row) now rehash before that insert and probe again, and a failed rehash marks the table oom, as a failed grow of its rows does, so it takes no more groups and the group answers oom. A DEBUG seam, ray_select_keys_alloc_fail_for_test, fails each allocation of the keys-only select-by result build in ray_select_body; aware/group_alloc_fail sweeps it, and the group seam of #1809 now also sweeps the dense-array route, and, with a second DEBUG seam (ray_group_test_radix_bufs_fail) failing the radix buffer table, the sequential fallback. Fixes #1811
The defect
An allocation that failed while a group ran on the radix route could crash the process or answer a wrong result (#1808, found by the reviewer of #1806):
exec_group_runskipped a key column it could not allocate, or whose source column was missing. Phase 3 then wrote that key through its NULL data: SIGSEGV inradix_phase3_fn(write_col_i64,data=0x0).oom(also set when a table cannot grow while folding rows in), so the answer lacked that partition's groups.ray_vec_new's error object: 128 bytes each (error objects are not reference-counted).The fix
oom; any further error is freed).oom, as a failed grow does. After the dispatch, any such partition makes the route free every partition table and answeroom. A partition whose init failed has its slots but no rows, whichcleanup's rows-only free would keep.Test
Two DEBUG seams:
ray_group_alloc_fail_for_test(n)fails the nth allocation of the calling thread's own code while the outermost group (exec_group) runs, and reports how many it made. The allocator skips allocations the thread makes inside pool tasks it steals (pool_execmarks them,ray_alloc_fail_skip_tasks_for_test). Which tasks the calling thread steals varies from run to run, its own code does not, so the sweep covers every position deterministically.ray_group_test_ht_rows_fail(n, cancel), from fix(group): a cancelled group on the v2 radix route frees its worker and partition hash tables #1806, now also counts the classic route's phase-2 partition inits, on any thread. It is the coverage for allocations inside the pool tasks.aware/group_alloc_fail(test/test_aware.c) runs a v2-radix query (by: k, k an F64 column), a two-key query withcountandsum, and a classic-radix query (max). It fails:Each run must answer byte for byte the unfailed answer, or
oomkeeping nothing by the process's allocation trace (every heap) over the run, the error's release and a GC.Reverting each fix on its own, with the seams kept:
aware/group_alloc_failtakes a SIGSEGV;(select {c: (count v) s: (sum v) from: F by: [k j]}), allocation 11 of 12 fails: an answer, not the reference;(select {from: F by: k}), allocation 9 of 10 fails: 128 bytes kept;(select {m: (max v) from: F by: k}), partition init 1 fails: an answer, not the reference.Not changed (listed in #1808)
dense_*scratch buffers unchecked.ray_select_body's keys-only result build keeps 128 bytes on a fewoomexits.Both are outside the radix route; the test's queries do not take them.
Cost
Release behaviour is unchanged when nothing fails. The seams are DEBUG only, including the allocator's check. The emit adds one flag per column. The route adds one check per partition after phase 2: a few hundred instructions per query, nothing per row. Callgrind, release (gcc),
-c 1, 1,048,576 rows, against its base, #1806's head (now on dev): every shape is +22 instructions, exactly the setup's own difference.Checks
make -j4 test TEST_ARGS="-j 4": 5,890 of 5,894 passed, 4 skipped.aware/group_alloc_failpasses; filtercancel: 87 of 88 passed (1 skipped); no sanitizer report.cancel): 87 of 88 passed (1 skipped), no report.clang-23 -fsyntax-onlyongroup.c,heap.candpool.c(with and without-DDEBUG) andtest_aware.c: clean.Fixes #1808