Repository navigation
fix(vector): stabilize IVF object ownership across coordinators - #29319
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Design review for head 5cd1a35 — PASS (design decision only; implementation review follows separately).
Change scope: issue #29226, cross-coordinator IVF scan object ownership and MORPC admission. This crosses CN ownership, execution routing, and a wire/mixed-version contract, so the design gate applies.
Reviewed revision: docs/design/CLAUDE_ISSUE_29226_VECTOR_SCAN_OWNERSHIP.md at 5cd1a35. The fixed-selected-CN-set invariant is explicit: sort by (ServiceID, PipelineServiceAddress), assign CNCNT/CNIDX, and retain the existing full-ObjectID partition function. The execution route separately owns in-memory/workspace rows. The design covers compile-time fallback, same-stream admission for remote partition zero, receive-time downgrade rejection, cancellation bounds, rollout/rollback, alternatives, and proportional UT plus two-CN SQL validation. It makes no unsupported production-scale speedup claim.
Accepted tradeoffs: membership changes may remap objects; each-query capability probes and one extra remote-zero stream round trip cost latency; unknown capability keeps legacy layout; a compiled stable layout fails explicitly if capability disappears. The planned scale measurements remain the acceptance evidence for any performance claim, not a blocker to this correctness design decision.
No design blocker remains at this revision. This records design approval only, not approval of the implementation or current PR merge. Please update the document's pending-review status in a follow-up revision if desired; this review is the traceable decision for the linked revision.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Implementation review at 5cd1a35 — REQUEST_CHANGES. The design was approved separately in review #5314085804; this is the implementation finding.
P2 — Avoid fully decoding every remote pipeline a second time (pkg/sql/compile/remoterunClient.go:97-101). remoteRun is the common path for every remote scope. prepareRemoteRunSendingData has already built and marshaled the complete pipeline.Pipeline through encodeRemoteScope; the new unconditional Pipeline.Unmarshal(scopeEncodeData) immediately parses the entire plan, data source, and child tree into another allocated object just to compute one boolean. This adds O(encoded scope size) CPU and heap work for all distributed queries, including those without a vector scan, and repeats for each remote fragment. It can be especially costly for large plans and is outside the vector scan capability path. Please derive/return hasRemoteVectorPartitionZero while the post-folded pipeline is still available in the encode path, so the check remains accurate without materializing the full tree again.
I traced the stable ObjectID owner mapping, route-based in-memory ownership, mixed-version fallback, same-stream admission, receiver downgrade check, and cleanup on handshake failure. I found no other verified implementation blocker in those paths. Exact-head CI Required, Ubuntu/x86 UT, arm64 SCA, multi-CN compose BVT, and coverage are green; those correctness checks do not measure this newly added hot-path cost. Production-scale cache-affinity benefit remains an explicit measurement item in the approved design, not a claimed result of this review.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Implementation deep review at exact head 4979ff8e20ee16d1082125fd267eb2c978bdd20b, against verified main / merge-base 426cf10b000b6a828e8c69f1af26082f26036ed3: APPROVE — no verified blocking finding in this revision.
本轮重新检查完整 17 文件变更、历史 review 的修复闭环、异常/取消路径、跨 CN 所有权、协议兼容性和热路径成本。
上轮 P2 已修复:remoteRun 不再把刚编码的 scope 完整反序列化一次。能力标记从已经构造、变量折叠后的 pipeline 传出,普通查询、remote nonzero 和嵌套 remote zero 的判定均有验证。先前 design decision 仍适用;本次调整实现了当时要求的优化,没有扩大协议或所有权契约。
确认的闭环:
- 固定参与 CN 集合按身份排序,保留查询原始
cnList,完整 ObjectID 仍只归一个 partition;切换协调 CN 不再交换持久化对象的 owner。 ScanIdentity.IsRemote从真实执行路由传递,本地非零分片收集内存数据,远端零分片只读持久化对象。可写 workspace、强制本地和必需 membership 的本地执行边界保持原样。- 95/未知/探测失败回退 legacy layout;父 context 取消向上传递;已编译布局在发送或接收阶段能力下降时显式拒绝。实际 execution stream 的握手补齐独立 QueryService 探测与旧实例接管之间的窗口。
- 握手失败时没有 pipeline 执行所有权需要停止:本地 root 清理后关闭 stream,不等待不存在的执行终态。查询能力响应正常释放,握手和探测都有 context 上限,不新增长期缓存、队列或后台 worker。
本地验证(Linux amd64,Go 1.26.4,仓库 CGo wrapper):
- 9 个关键 placement / routing / capability / nested transport 测试各自
-race -count=100全通过;次数由每测试 30 秒预算、实测时长及 100 次上限确定。 - 完整
pkg/sql/compile、pkg/vectorindex/ivfflat、pkg/pb/pipeline、pkg/defines:-race -vet=all -count=1通过;pkg/indexplugin/search同命令构建/vet 通过,无独立测试文件。 TestIssue29226VectorScanAcrossCoordinators在两个嵌入式 CN 的真实 MySQL/远端 pipeline 路径下通过,开启 race;涵盖两入口、持久化与内存行,以及事务更新/删除/提交/回滚。单次测试 18.8 秒,按 30 秒预算取 N=1。- 额外审查探针覆盖 send error、错误响应状态、remote error、等待中取消/超时:
-race -count=100通过;确认失败后不发送 pipeline / StopSending,stream 只关闭一次。探针未写入 PR。 - 针对上轮 P2 的合成微基准:33 个 pipeline 节点、共 512 KiB 载荷,原重复解码检查为 54.6–70.4 µs、535,128 B、104 allocs/op;复用已构造树的检查为 50.7–56.4 ns、0 B、0 allocs/op。此结果只隔离被移除的解析开销,不是整条 SQL 或生产 QPS 的加速倍数。
git diff --check通过,审查工作树无源代码变更。
工程判断:稳定排序、执行路由标记和局部协议 admission 与问题规模相称;没有必要扩展为全局对象映射或缓存框架。每查询能力探测和 remote-zero 的额外往返是设计已接受的成本。
验收边界:Wiki 10M 的缓存/IO/decode/QPS/每 CN 内存对照仍待执行,不能由上述小测试推断生产收益;95/96 混合二进制集群未在本轮实际部署,降级路径由协议测试验证。当前 head 的 CI run 36113651799 shared build 已成功,UT/SCA/coverage/Compose BVT 仍在运行,compatibility jobs skipped。本次 approval 是实现审查结论;合入仍须等待 required CI 通过。
Merge Queue Status
This pull request spent 6 minutes 30 seconds in the queue, with no time running CI. ReasonPull request #29319 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Waiting for any of
All conditions
Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29226.
What this PR does / why we need it:
With the same selected CNs
{A, B}, switching the SQL coordinator previously reversed their IVF object partitions, moving reads away from reusable local cache entries. This change assigns vector-scan partitions by stable CN identity so a fixed selected CN set retains the same persisted-object owners across ingress changes.In-memory ownership follows the execution route through
ScanIdentity.IsRemote, allowing a nonzero local partition to read coordinator-visible rows while a remote partition zero reads only its persisted objects. Writable-workspace and required-membership scans retain their existing local execution paths.The stable layout requires MORPC 96 on the coordinator and every selected worker. Upstream assigned MORPC 95 to prepared scalar precision and 94 to lossless NoFull CDC; this branch preserves both meanings. Old, unknown, or unavailable capabilities retain the legacy distributed layout. Sender and receiver guards reject incompatible remote partition-zero execution after a capability downgrade, including nested pipelines. Before sending a remote partition-zero pipeline, the sender also confirms the receiver version on the actual Pipeline stream, preventing a replacement older CN from running it after a separate capability probe. The need for this handshake is carried from the already constructed, post-folded pipeline during encoding, without decoding the serialized scope a second time. Capability probes use a timeout cause that does not report a false timeout on successful requests.
Design review
XuPeng-SH approved the design at revision
5cd1a359d7, covering the ownership invariant, nested transport, MORPC 96 mixed-version and rollback behavior, resource bounds, alternatives, and acceptance plan. The design record now records that decision. Design approval is separate from implementation approval.Validation
Validated locally on macOS arm64 with Go 1.26.4 and the repository CGo test wrapper:
-vet=all, including post-folded handshake-flag propagation for remote zero and nonzero partitions and nested scans. The changed executable statements in this review fix had 19/21 (90.5%) coverage across focused and two-CN tests.TestIssue29226VectorScanAcrossCoordinatorspassed against two embedded CNs through MySQL, including persisted and in-memory rows and transaction visibility.make err-check, scopedgo vet, and scoped golangci-lint v2.6.2 passed after merging main. The previous fullmake static-checkpassed before this merge.