Repository navigation
fix: reserve hashbuild spill recovery budget - #26585
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Accepted the latest P1 and fixed it on The review counterexample was reproduced before changing production code: All four cases failed the same The fix now derives the expression peak from the physical ownership oracle used by the executor (
The new regression coverage includes:
Final validation on the rebased head:
Please re-review the new head. |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
The separate spill-expression lease and serial_full false-rejection blockers are fixed and withdrawn; the descriptor-scan performance concern remains fixed/non-blocking. The latest commit also fixes the exact cap(data)+cap(area) under-reservation previously reported. One distinct blocking owner remains: serial/serial_full's retained Packer is outside the recovery budget.
P1 - Charge the serial Packer to the expression recovery lease (pkg/sql/colexec/hashbuild/hashmap.go:526)
Author response: 271724a32b derives the peak from physical vector capacities and correctly fixes the prior cap(data)+cap(area) finding. Why this remains blocking: this line still converts the encoded serial width into only a result-vector peak. opSerial also retains a types.Packer, whose power-of-two class allocation is excluded by ExpressionExecutorRetainedBytes. This is a distinct owner. For one row of serial_full over four supported, zero-filled VARBINARY(65535) arguments, the encoded result is 524,292 bytes. The recovery formula reserves 1,458,288 bytes, but evaluation retains a 1,048,576-byte Packer plus 532,480 bytes of result area and a 24-byte descriptor: 1,581,080 bytes. Thus a cap between those values admits recovery while physical expression memory exceeds the hard cap; shared workers can amplify this into the OOM the budget is intended to prevent. Account the Packer's size-class capacity and growth overlap in the same lease, or preallocate it under an equivalent accounted contract, and cover the admission boundary with a real serial executor test.
aptend
left a comment
There was a problem hiding this comment.
Deep review at 271724a32b. The earlier spill-expression ownership, serial_full false-rejection, descriptor-scan, and Vector physical-capacity findings are fixed. One distinct P1 blocker remains.
P1 — Charge the retained serial Packer to the expression recovery lease
expressionResultPeak (pkg/sql/colexec/hashbuild/hashmap.go:526) converts the serial encoding bound only into a result-Vector peak. However, opSerial also retains a types.Packer; Reset preserves its backing allocation, and ExpressionExecutorRetainedBytes does not include it. Packer growth additionally allocates the replacement before releasing the old class allocation.
I reproduced this with a real one-row serial_full executor over four zero-filled VARBINARY(65535) arguments:
- encoded result: 524,292 bytes
- recovery lease: 1,458,288 bytes
- retained Packer size class: 1,048,576 bytes
- retained result Vector: 532,504 bytes
- retained expression memory: at least 1,581,080 bytes
The preflight therefore admits 122,792 bytes less than the post-run retained owners, even before accounting for the Packer replacement overlap. With a cap in that interval—or sibling workers consuming the remaining shared generation—evaluation bypasses the hard recovery budget and can recreate the OOM condition this PR is intended to prevent.
Please account the Packer initial/retained capacity and growth overlap in the expression recovery ownership, or preallocate it under an equivalent accounted contract, and add a real serial-executor N-1/N/N+1 admission regression. Existing lease.Retained() assertions do not cover this owner because they count only mpool-backed Vector capacity.
Fresh local ordinary and full race suites passed for vector/function/hashbuild, as did focused adaptive race repetitions and dependent join/spill/compile packages; this finding is independent of CI.
|
Accepted both latest P1 reviews from @gouhongshen and @aptend and fixed the shared root cause on The reflection is that the prior audit stopped at the existing ownership oracle: The fix closes that lifecycle without changing the serial format, Packer growth policy, or per-row Eval path:
The exact reported counterexample is now a real executor boundary test for both Validation on the final tree:
No encoding-format change, result-preallocation framework, query-specific branch, row scan, or non-serial per-row work was added. Please re-review the new head. |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
The previously blocking uncharged serial Packer ownership is fixed and withdrawn. Earlier spill-expression, serial bound, vector-capacity, and descriptor-scan topics are also fixed or accepted as non-blocking; none remain blocking. The new allocator-bound and lifecycle logic is consistent with construction, growth overlap, reset, and cleanup contracts. Focused Packer tests passed normally and under race; formatting, vet, and diff checks passed. CGo-transitive tests were unavailable locally because libmo.dylib is absent.
|
Deep review completed at exact head The previously blocking uncharged Fresh local validation on this exact head passed:
Code verdict: clean. Merge readiness remains separate: the PR is currently behind |
ck89119
left a comment
There was a problem hiding this comment.
Approved after exhaustive review of exact head 2c3fa408d37d4b2d5cd5bc8e62b605b0ce5aa8e3. The previously blocking Packer ownership gap is fixed, no new actionable code issue was found, and the owning-package normal/race tests, vet/build, SQL recovery regression, and diff checks passed locally.
aptend
left a comment
There was a problem hiding this comment.
Re-reviewed head 2c3fa408d3. The prior P1 is fixed: serial/serial_full Packer ownership, constructor admission, growth overlap, reuse, and cleanup are now covered by the expression recovery lease. Focused adaptive race tests, full changed-package normal/race tests, dependent-package tests, build, vet, and diff checks passed. No remaining code-review blocker found; CI was not used for this conclusion.
|
复审结论(head bcb48b0):未发现新的 blocking issue。 这次更新仅为 merge main;相对上一版 2c3fa40,新增改动只涉及 5 个 disttae 文件,与本 PR 的 HashBuild / Vector / serial 改动零重叠,因此没有引入冲突解决或改变本 PR 语义。 我重新核对了:
本地以 -p=1 定向运行 HashBuild、Packer、Vector、serial 契约测试,均通过。远端 CI 仍有任务运行中,因此这里只记录代码复审结论,不宣称整套 CI 已完成。 PR 在本次复审完成前已经合并,GitHub 已不能再提交有意义的 APPROVE;此评论用于记录最新 head 的 no-blocker 结论。 |
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #26586.
Related architecture issue: #26459.
What this PR does / why we need it:
Root cause
Shuffle HashBuild workers share one finite query/CN budget. A worker could retain build batches until the shared budget was nearly exhausted, then discover that it did not own every resource needed to drain them:
A sibling worker could consume the missing headroom after retention. Recovery then failed before the first retained batch was released. This is a recovery-ownership defect, not a TPCH-Q9-specific threshold problem.
Recovery invariant and fix
Before shuffle HashBuild retains a spillable destination, the same execution generation now owns a complete recovery proof:
ExpressionMemoryLeasethat pre-admits the complete sequential expression recovery high-water. Spill reuses that executor/lease; the former second spill executor/lease owner is removed.Retained batches are drained oldest-first and released immediately after each successful spill. Reset, Free, cancellation, expression failure, spill I/O failure, and publication handoff each preserve exactly one cleanup owner.
Scope and performance
VARCHAR_AREA_128A/B benchmark: 5.436 ms/op to 5.359 ms/op, p=0.684; no significant regression. Allocation delta is bounded at about 40 B and 2 allocations per execution.Validation on latest main
Rebased onto
4a747e4458.mo-cgo-test -count=1 ./pkg/sql/colexec/hashbuildmo-cgo-test -race -count=1 ./pkg/sql/colexec/hashbuild-count=100, including the deterministic expression-key/shared-pressure reproducer.hashjoin,dedupjoin,rightdedupjoin,spillutil, andpkg/sql/compile.go buildfor HashBuild andgo vetfor HashBuild plus the issue regression passed.Review-comment closure
The P1 expression-key counterexample at old head
9b5a8125is accepted.TestShuffleHashBuildExpressionRecoverySurvivesSharedBudgetPressureuses a real computed%shuffle key, retains the first batch, fills the same generation exactly with sibling pressure, then proves retained drain plus direct spill succeeds and all budget ownership returns to zero.Non-goals