Repository navigation
fix: bound HashBuild memory and spill under query budgets - #25837
Conversation
4780080 to
174b8cc
Compare
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? |
# Conflicts: # pkg/container/hashtable/int64_hash_map.go # pkg/container/hashtable/string_hash_map.go # pkg/pb/pipeline/pipeline.pb.go
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
发现至少 1 个明确的 correctness blocker,另外还有 1 个完整性风险:
-
LOAD TABLE现在会直接把 manifest 里的ObjectStats当成权威元数据写进 catalog,而不再回读目标对象做物理元数据校验。handleLoadTable在pkg/frontend/table_dump.go:1199-1253这里只检查了len(item.Stats)、GetAppendable()和ObjectName(),随后submitTableDumpObjects在table_dump.go:990-1045里直接把这些 stats 展开并提交给 relation。相比 main 分支原先会通过loadPhysicalTableDumpStats/validatePhysicalTableDumpObjects重新读取 extent/blocks/rows/size/sort-key zone map 并覆盖 manifest stats,这里少了最后一道 fail-closed 校验。结果是:只要 manifest 里的对象名对得上,一个 stale/forged manifest 就能把错误的 extent、block count、row count、origin size、sort-key zone map 写进 catalog;后续 block location 展开和 zone-map pruning 都会基于这些错误 stats 工作,直接变成错误结果风险,而不仅仅是装载失败。 -
provider-side
CopyObject路径现在也把 manifest 的 SHA-256 检查降成了 size-only。copyTableDumpFile在pkg/frontend/table_dump.go:348-382对providerCopied返回空 hash,installTableDumpObject在table_dump.go:921-929里对providerCopied只看 size 相等就放行;verifyTableDumpObject对空 hash 也是 size-only(table_dump.go:886-896)。现有测试甚至显式锁定了这个行为:pkg/frontend/table_dump_test.go:838-843允许 same-size 的"corrupt object byte"成功安装,pkg/frontend/table_dump_test.go:964-972也断言 provider-copy 返回空 hash 并只做 size 校验。
如果你坚持当前 PR 描述里的“trusted manifest / trusted provider”边界,第 2 点可以算风险接受;但第 1 点我认为仍然是 blocker,因为它把未经物理校验的 stats 直接写成了后续读路径的权威 catalog 元数据。
|
关于 physical
在这个契约下,manifest stats 就是备份元数据的权威来源。stale/forged manifest 与 trusted provider 产生 same-size corruption 属于同一个被明确排除的威胁模型。若认为 manifest 可被不可信方修改,那么仅恢复 extent/blocks/rows/zone-map 回读也不是完整的安全方案:对象 payload 仍可能发生同尺寸篡改,应该另行设计 authenticated manifest 和 provider checksum,而不是只在 catalog stats 这一侧增加昂贵的部分防御。 这里也需要区分两类成本:SHA-256 回读会扫描完整 100 GB / 1 TB;物理 stats 校验虽只读取 header/meta range,但仍会为每个 object 增加远端 GET、metadata 解析和 CN 路径,成本按 object 数增长,直接破坏 server-side copy 后的快速 catalog install。我们之前正是因为实际大规模验证显示这些逐对象防御让 LOAD 接近重新导入的慢路径,才删除它们。 当前真实结果是:
这些数据验证的是我们真正支持的闭环:由 因此本 PR 保持当前 fast trusted-restore 路径,不恢复默认 physical metadata reread。若产品后续需要接收不可信备份,可以单独设计显式 strict validation/authenticated manifest 模式,并单独承担和验收其性能成本。 |
|
补充精确的逐提交 A/B 数据。刚才重新核对了当时三个 TKE job 的原始日志;使用的是同一个 COS fixture
对应原始 run/job:
三个日志分别明确打印:
两个 MatrixOne 变更也是连续且隔离的: 因此这不是笼统的性能担忧:
同一 final run 的 1T fixture load 为 49s;另一次独立 load 记录为约 44s。所以恢复默认 physical metadata 校验会直接否定该功能的规模化价值。 |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes.
I withdraw my previous physical ObjectStats blocker after re-checking the enforced tenant-admin boundary, DUMP publication order, and the supplied A/B data. Same-size corruption is outside the explicitly trusted fixture/provider contract and is not a blocker for this PR.
There is, however, a blocking ownership gap in the new HashBuild budget implementation: SpillEngine can destroy retained build batches without releasing the reservations that own those bytes.
-
In RebuildHashmap with NeedBatches=false, builder.Batches.Clean releases the physical mpool allocations, but GetJoinMap immediately transfers builder.batchReservations into the JoinMap. Semi/anti/mark-style joins therefore carry phantom batch charges throughout probing. A focused 8,192-row int32 reproduction left generation.Used unchanged at 1,769,472 bytes before and after the physical clean.
-
reSpillBucket detaches builder.Batches.Buf and cleans each batch, but the corresponding reservations remain charged until reSpillBucket returns and the caller later frees the builder. This is specifically the recovery path entered after an admission rejection; retaining already-freed batch charges while reserving expression/scatter/read scratch can turn a recoverable spill into another false admission failure.
Please fix this at the ownership boundary: provide a HashmapBuilder API that drains physical batches and their reservations together (respecting CopyIntoBatches coalescing, so releasing all ingress tokens after the last physical batch is fine), and use it in both paths instead of manipulating Batches directly. Add budgeted tests proving that NeedBatches=false drops the batch charge before probe admission and that re-spill drops drained-batch charges before subsequent scratch/read admission.
The current Ubuntu UT failure is TestDelete3 in untouched TAE code; it does not appear related to this diff, but the check is still red.
| e.buckets = e.buckets[1:] | ||
| if bucket.ProbeFd != nil { | ||
| e.probeReader.ResetForFd(bucket.ProbeFd) | ||
| if err := e.probeReader.EnsureBuffer(e.cfg.Budget); err != nil { |
There was a problem hiding this comment.
This probe-buffer admission still sees stale build-batch reservations when NeedBatches=false: the physical batches were cleaned just above, but GetJoinMap transferred their tokens. A focused 8,192-row int32 reproduction left generation.Used() unchanged at 1,769,472 bytes across that clean. Please release batch ownership before this admission through a HashmapBuilder lifecycle API.
| if b != nil { | ||
| buildRows += int64(b.RowCount()) | ||
| } | ||
| if err := evalAndScatter(b, buildWriters, nil, e.keyExecs); err != nil { |
There was a problem hiding this comment.
The re-spill loop cleans these detached physical batches, but their reservations remain in the builder until the caller frees it after reSpillBucket returns. Since this is the admission-recovery path, those phantom charges can reject the expression/scatter/read scratch needed to progress. Please drain Batches and reservation ownership together rather than detaching Batches.Buf directly.
|
Addressed the HashBuild budget ownership blocker in The fix introduces one ownership boundary,
Both affected SpillEngine paths now use this boundary:
Added budgeted regressions covering:
Fresh local validation:
The unrelated |
XuPeng-SH
left a comment
There was a problem hiding this comment.
我重新做了一轮 deep review,并且把作者在评论里对 trusted-manifest / trusted-provider 边界的说明也纳入考虑了。当前结论是:在这个明确声明的管理员级 fixture/restore 契约下,LOAD TABLE 不回读物理 metadata、provider-side copy 只做 size 校验,是有意识的性能/信任边界选择,不再构成我这边的 correctness blocker。
除此之外,我又把 HashBuild budget / spill / remote pipeline 终态发布主链过了一遍,没有再确认出新的高置信 correctness、robustness 或 unhappy-path 问题。LGTM.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25782
What this PR does / why we need it:
HashBuild could grow past spill and process-memory safeguards, allowing large joins to exhaust a CN and trigger a system OOM. This PR makes memory admission finite and hierarchical, and gives shuffle joins a bounded spill/re-spill path when hard admission rejects growth.
The commits are separated so the correctness, performance, diagnostics, and validation infrastructure can be reviewed independently. Together they:
Eval, returning a bounded budget error before allocation when that peak cannot be admitted;DUMP TABLE/LOAD TABLEfixture support and reusable image-build caches for repeatable TPCH-scale validation;LOAD TABLEtrust and integrity boundaryDUMP TABLE/LOAD TABLEis an administrator-level fixture transport, not an untrusted file-ingestion API. The manifest and the configuredObjectCopierare trusted inputs. The streaming fallback computes and verifies SHA-256, while a provider-native server-side copy deliberately verifies object existence and size without reading the copied object back through CN to recompute its hash or physical metadata.This is an intentional performance contract: re-reading and hashing every copied object would turn a metadata/server-side-copy operation back into a full 100 GB / 1 TB data scan, consume CN bandwidth and CPU, and erase the measured fixture-load benefit (about 9 seconds for 100 GB and 44 seconds for 1 TB). Same-size corruption introduced by a trusted storage provider is therefore outside this SQL command contract and belongs to the provider checksum/integrity layer.
Validation
After rebasing onto current
main:go buildandgo vetpass forprocess,group,hashbuild,hashjoin, andspillutil;-race -count=3tests pass for retained emergency scratch growth, bounded group reload preallocation, and expression-key spill admission;go test ./pkg/vm/process ./pkg/sql/colexec/spillutil ./pkg/sql/colexec/hashbuild;132096, with spill on both CNs and no OOM, OOM kill, or swap;Performance run: https://github.com/matrixorigin/mo-auto-test/actions/runs/30081071473
maindaily run (11.2% faster). All queries succeeded and no spill occurred.maindaily run (12.7% faster). The two turns differ by only 0.37%.mainrun also spilled in Q18 through the existing group-aggregation spill path, but it did not enter HashBuild spill for Q9. With this PR, Q9 reached the 40 GiB query-wide HashBuild budget and spilled 10.96 GB and 28.39 GB in the two measured turns. Q9 still completed in 92.33 s and 92.78 s, effectively flat against themainaverage of 92.39 s, demonstrating added OOM protection without a material Q9 regression.