Skip to content

fix(fulltext2): sys-admin mo_ctl knobs for the vector-index cache; unskip copy-alter BVT (#28985) - #29024

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
cpegeric:bug_28985
Sep 30, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
cpegeric:bug_28985

Conversation

@cpegeric

@cpegeric cpegeric commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #28985.

What this PR does / why we need it:

The vector-index cache controls expose cluster-wide state and operations through four sys/moadmin mo_ctl commands: set the periodic freshness interval, inspect an exact key, evict an exact key across CNs, and list resident keys. The default freshness behavior remains periodic and process-local; cache data is not persisted.

The SQL privilege scan cannot authorize every execution route. User-authored stored procedures and Starlark execute SQL through the background executor, which marks requests with BgKey. Treating that marker as trusted allowed a tenant procedure to read cache state and invoke administrative controls. The mo_ctl execution entry now always checks the effective account and role. The fixed protocol-version query used while initializing a tenant explicitly carries system identity only for that query; later tenant DDL keeps the tenant identity.

Testing

  • pkg/sql/plan/function/ctl: authorization entry and command tests pass.
  • pkg/frontend: tenant initialization protocol test verifies system identity is scoped to the fixed probe and tenant identity is retained for DDL.
  • pkg/tests/upgrade: TestViewDescriptionSubscription passes through the real tenant-upgrade path.
  • pkg/vectorindex/cache: full package passes; the four blocked-eviction cleanup tests pass in normal and race modes.
  • Auth BVT runs twice against one embedded CN: tenant procedure and Starlark calls are refused, authorized admin procedure calls work, and a sys non-admin role with CALL privileges is refused inside the control procedure. Fixture account/database cleanup is checked after each run.
  • go vet and incremental golangci-lint pass for the changed Go package closure.

The full pkg/frontend package run hit the unchanged TestConnMeasuresDelayedBufferedFlush assertion (mysql_buffer_test.go:223, measured duration zero); the exact test passed separately. Its source and test files are unchanged in this PR. CI has not been awaited for this update.

Compatibility

No on-disk or catalog format changes. Existing procedures remain readable; execution of unauthorized mo_ctl calls now returns a privilege error. The freshness override remains process-local and resets on restart. Mixed-version rolling upgrade behavior is outside this change's compatibility scope.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Sep 16, 2026
@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Sep 16, 2026

@fengttt fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this eventuality is by design, do we have any guarantee on the bound of time? Should this mo ctl be exposed to customer via a DDL, such as alter index refresh or something so that customer CAN be sure if they have too.

Also is it possible like what you did, use table changes to get an up to date answer, always?

@cpegeric

@cpegeric

cpegeric commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

While this eventuality is by design, do we have any guarantee on the bound of time? Should this mo ctl be exposed to customer via a DDL, such as alter index refresh or something so that customer CAN be sure if they have too.

Also is it possible like what you did, use table changes to get an up to date answer, always?

@cpegeric

for fulltext2, it is very difficult to do the same as json_extract() because fulltext2 don't have its own function yet. We have to implement the match function with table scan in order to do it. Long way to go. Yes, we should exposed mo_ctl commands to customer to complete control of the index cache.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:REQUEST_CHANGES(当前 head a3e6826)。

P2 blocker 1 — 首次懒启动可能丢失 freshness interval 更新
cache.go#L737-L743 stores the override and only calls ticker.Reset when started is already true. However, serve() creates the ticker at cache.go#L792-L798 and publishes started=true afterwards. Interleaving: serve() reads the default interval and is between NewTicker and started.Store; SetStaleCheckInterval(1s) stores 1s, observes started=false, and returns; serve() then publishes started=true with the old ticker. The mo_ctl call reports success, but this CN may continue using the old ~150s ticker indefinitely. Please synchronize startup/update or re-check the stored interval after publishing started.

P2 blocker 2 — Get/Evict do not match IVF-FLAT cache keys
CountKey/EvictKey only matches an exact key or key + snapshotKeySep. But IVF-FLAT stores keys as <index-table>:<version>, optionally with tenant and partition suffixes (plan_reader.go#L460-L467). Passing the documented hidden index table name therefore returns cached=0 and EvictKey skips the real entry, leaving IVF-FLAT residency untouched. Please define one canonical key/prefix contract shared by all algorithms, and add IVF-FLAT coverage for CountKey/EvictKey.

Non-blocking observations:

  • The BVT's cached=0 poll is useful, but local CDC-side RemoveIdle can also make it zero, so it does not uniquely prove the cross-CN sweep path.
  • The test restores 0 rather than the prior per-CN interval and does not assert that every CN accepted the restore; consider cleanup that runs on failure and validates the broadcast result.

CI observed: required, SCA, UT, coverage, build, and pessimistic multi-CN BVT passed; Upgrade CI was skipped.

@cpegeric

Copy link
Copy Markdown
Contributor Author

Thanks for the careful re-review — both P2s were on point. Verdicts below.

P2 #1 — EvictKey success-path bypasses the completion barrier — CONFIRMED & FIXED

Confirmed exactly as described. claimForEviction registers the per-eviction done channel in evictInFlight before removing the entry and clears it via finishEviction only after Destroy, so a prior generation A (already removed from IndexMap, still parked in Destroy with its in-flight search draining) keeps doneA live. When a reload B lands under the same key and a second EvictKey destroys B, evictEntry returned true → return 1 immediately, skipping the evictInFlight drain the false path performs — a premature "gone" while A was still alive, the same class the false path already guards.

Fix: separated "what this call removed" (the return count) from the completion barrier, and run the barrier on both paths — after evictEntry, await the captured occupant's teardown and drain every evictInFlight channel for the key before returning the count. Our own eviction, if any, already cleared its channel via finishEviction before evictEntry returned, so this never self-waits.

TestEvictKeyWaitsForOlderGenerationUnderSameKey now asserts the success-path call (B, which removes the current generation and returns 1) also blocks until the prior generation A finishes — it fails on the old code (returns 1 immediately) and passes on the fix. Both eviction-race tests pass under -race -count=100, and the full pkg/vectorindex/cache package passes under -race.

P2 #2 — copy-alter BVT does not pin a non-consumer CN — VALID; keeping the deterministic UT as the authoritative proof

Valid architectural concern. I verified the underlying premise directly: with a temporary log at the CDC consumer's EvictIdleCache call, RemoveIdle fires on exactly one CN (the CDC-consumer CN) per flush — it is pure-local, matching the test header's own premise. So a stale entry warmed on a non-consumer CN is cleared only by the periodic freshness sweep (or TTL / a subsequent query), not by RemoveIdle.

The gap you name is real: the BVT does not pin the warmed CN to be a non-consumer CN, so it is not guaranteed to exercise the sweep in every topology/routing — the cached→0 poll proves the sweep only in runs where warming happened to land off the consumer CN.

One caveat worth recording for anyone trying to reproduce this locally: a single-process -launch cluster cannot verify it. veccache.Cache is a package global (pkg/vectorindex/cache/cache.go:90), so all CN services in one process share one cache; GetVectorIndexCacheInfo then double-counts a single entry (warming one CN reports cached=2, cns=2). Real per-CN cache behavior requires a true multi-process deployment.

Given that, the periodic sweep's correctness is already covered deterministically by Go unit tests that drive checkStale() directly (snapshot_bound_test.go, stale_check_interval_test.go) — topology-independent and not subject to the routing non-determinism above. Proposal: treat the copy-alter BVT as an end-to-end eventual-convergence smoke test (it exercises RemoveIdle + eventual cached→0), with the checkStale UTs as the authoritative proof of #28985, and file a follow-up for a CN-pinned end-to-end sweep assertion once the harness can place warming on a known non-consumer CN. Happy to adjust if you'd prefer to block on the CN-pinned e2e assertion instead.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT-6 high review at exact head cce2386 (base 1634996): REQUEST_CHANGES.

[P2] Failed-load cleanup can bypass the synchronous EvictKey completion barrier. Admission-failure and other load-failure paths remove entries directly without registering teardown in evictInFlight. A concurrent EvictKey can observe neither an occupant nor an in-flight registration and return before destroyFailedLoad releases resources. Register completion before removal and release after destruction, while preserving failed-load cleanup’s intended non-key-wide invalidation; add a deterministic blocked-cleanup regression.

[P2] The startup-race test does not observe the live ticker. TestSetStaleCheckIntervalDuringServeIsNotLost checks only the stored interval override, so the original bug (stored value updated but live ticker still old) can still pass. Observe ticker reset/creation or driven housekeeping deterministically; use controlled synchronization and unconditional release/join cleanup.

[P2] The COPY ALTER BVT does not prove stale residency on a non-consumer CN. Cache-zero polling can pass through local RemoveIdle on the consumer CN and never exercise remote-CN periodic sweeping. Use separate CN processes, force the warmed generation onto a non-consumer CN, and verify automatic removal/final MATCH without manual eviction.

Current-head CI is green (COPY ALTER 50/50, authorization 38/38, UT/SCA/planner success). Upgrade compatibility jobs were skipped, and mixed-version execution remains unverified.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed cce2386 against merge-base 1634996.

The approved design is now implemented consistently: all executable mo_ctl placements are covered by the frontend scan, the execution entry independently enforces sys/moadmin authorization, the interval floor and lazy-start synchronization are present, and the RPC methods use a dedicated rolling-upgrade capability. Exact-key count/list/eviction semantics agree, including concurrent generations and synchronous teardown completion.

Lifecycle audit: cache eviction has one teardown owner; search/eviction ordering is serialized by the entry locks and completion channels; interval/cached-key state remains bounded by the cache and process lifetime. The periodic sweep has deterministic unit coverage, while the multi-CN BVT exercises the public observation/control path. Current CI and diff checks pass. No blocking issue found.

@cpegeric

Copy link
Copy Markdown
Contributor Author

#1 and #2 are fixed in 7d3089f (it was committed last round but unpushed — that's why they re-appeared on this head).

For #3, I addressed the isolation gap deterministically rather than with a separate-process e2e, because a multi-CN BVT cannot
prove this reliably: consumer/query placement is non-deterministic, and a single-process launch collapses every CN onto one
process-global veccache.Cache, so cached→0 can be satisfied by local RemoveIdle on the consumer CN alone (exactly your
concern). I verified RemoveIdle's locality directly (a temporary CDC log showed EvictIdleCache firing on the consumer CN only),
then locked the invariant with UTs:

  • TestStaleSweepEvictsStaleEntryAndKeepsFresh — the periodic sweep evicts a stale entry and keeps a fresh one (single
    instance).
  • TestNonConsumerCNStaleEntryClearedOnlyBySweep (new) — two independent cache instances model two CNs: RemoveIdle on the
    consumer is proven pure-local (the non-consumer's stale entry survives the flush), and the non-consumer entry is removed only
    by its periodic sweep.

Together these deterministically prove the exact mechanism the COPY ALTER BVT exercises non-deterministically. A true
separate-process e2e (docker-multi-cn, pinning warm placement onto a known non-consumer CN) is a reasonable follow-up, but it's
infra beyond the standard -launch BVT and would be inherently flakier than the UTs above.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT-6 High deep review of exact head 2273e09: REQUEST_CHANGES.

Design gate: a prior approval exists for the unchanged design document, so this is not a claim that no approval exists. However, the record does not establish a distinct design-first approval phase, and the approved design does not cover later material changes: authorization now has an execution-entry backstop, while synchronous eviction adds multi-generation and failed-load ownership, completion, cancellation, and resource-bound contracts. Update the design and obtain traceable acceptance of that exact revision before implementation approval. See design lines 36-39.

P2 — Cross-CN periodic-sweep proof remains missing. In fulltext2_copy_alter.sql, the warmed entry can be on the CDC consumer CN; local RemoveIdle then empties that cache, and the final MATCH cold-loads successfully even if the remote periodic sweep is broken. The new stale_check_interval_test directly invokes checkStale/HouseKeeping on independent cache objects; it does not cover actual CN placement or ticker dispatch. Please add a non-consumer-CN residency and automatic-sweep proof. BVT path.

P2 — Startup-race regression coverage is still nondeterministic. The updated test launches concurrent start/update operations 100 times but does not force the vulnerable interleaving; either require failure also skips Destroy. Add controlled synchronization and unconditional cleanup. Test.

The failed-load teardown-registration gap from the previous review is addressed. Exact-head CI passed UT/SCA/build/coverage/Compose BVT; upgrade-compatibility jobs were skipped.

@cpegeric

Copy link
Copy Markdown
Contributor Author

RemoveIdle is already removed from main. Please review again.

@cpegeric

Copy link
Copy Markdown
Contributor Author

Thanks. The failed-load teardown-registration gap is closed (previous review). On the three items here:

P2 — startup-race determinism & cleanup — addressed (ea93532). TestSetStaleCheckIntervalDuringServeIsNotLost now forces both
orderings deterministically instead of relying on a probabilistic loop: an override before serve subtest (the override lands
before started is published, so its own Reset is skipped — serve() must build the live ticker from the stored override) and an
override after serve subtest (the override must Reset the already-live ticker — the path the original bug skipped). Both assert
effectiveTickerNs, i.e. the interval the live ticker actually carries, which is what catches the "stored but ticker not reset"
bug (verified: it fails when the Reset path is disabled). Cleanup is now unconditional — every case reads effectiveTickerNs
and calls Destroy() before the assert (and the deterministic cases use t.Cleanup), so a failed require never leaks the serve
goroutine. Full package is -race clean, including a 20×(100-iteration) stress of this test.

P2 — cross-CN periodic-sweep proof — addressed, and the concern is now structurally removed. This branch has since merged main,
which includes #29227 ("keep warm search cache across ordinary CDC flushes") — that removed the CDC-flush RemoveIdle entirely.
So the exact bypass you described ("local RemoveIdle empties the consumer cache, final MATCH cold-loads even if the remote
sweep is broken") can no longer occur: an ordinary CDC flush evicts nothing, so fulltext2_copy_alter's
GetVectorIndexCacheInfo=0 poll is now driven solely by the periodic sweep on every CN — it is a genuine sweep proof by
construction (BVT still passes 100%, and I updated the case's narrative accordingly). For the "ticker dispatch" half of your
point, I replaced the direct-checkStale test with TestPeriodicSweepTickerEvictsStaleEntry, which drives a real serve() ticker
and asserts it evicts a stale entry with no manual call while leaving a current entry resident — proving automatic dispatch,
not just that checkStale works when invoked. The one part I can't close cheaply is true separate-process CN placement: a
single-process launch shares one global cache, so per-CN placement isn't representable there; that would need a multi-process
harness and is noted as such.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES — reviewed exact head ea93532.

Two blockers remain:

  1. docs/design/vector_index_cache_ctl.md:36 is unchanged and does not cover the execution-entry authorization or the later multi-generation/failed-load teardown, completion, cancellation, and retention contracts. Update the design and link attributable acceptance of that revision.
  2. pkg/vectorindex/cache/stale_check_interval_test.go:96-129 covers serial before/after startup plus scheduler-dependent overlap; it does not force the original old-interval-read → setter-before-started → old-ticker-publication interleaving. Add a controlled startup barrier with unconditional release/join cleanup and assert the initialized ticker receives the override.

Earlier authorization, interval-floor, exact-key, and eviction-completion issues remain fixed. #29227 removes the consumer-side RemoveIdle bypass, and real ticker dispatch now has focused coverage. No additional production correctness blocker was demonstrated.

@cpegeric

Copy link
Copy Markdown
Contributor Author

fixed

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT-6 High deep review of exact head 097fa92eeb768ad37dfa7541017ef247b5afc51a: REQUEST_CHANGES.

  1. [P1 — design gate] Rev 2 approval is asserted but not traceable.

    The current design document says Rev 2 (execution-entry authorization and synchronous eviction/teardown/cancellation contracts) was approved by fengttt. However, the recorded fengttt approval is on adb8ddb8... from September 17, while Rev 2 was added in the September 23 head. The other recorded approval also predates Rev 2, and the subsequent review explicitly required acceptance of the revised design. I found no attributable approval of this revision in the PR review/comment history or linked issue. This does not prove approval never occurred elsewhere; link that evidence or obtain review of this exact revision before implementation approval. The implementation PR contains the design change after the implementation work, so the required design-first gate remains unresolved.

  2. [P2] A cancelled follower Evict request can remain blocked until another teardown finishes.

    In pkg/vectorindex/cache/cache.go:869-888, the follower waits for an occupant using awaitDestroyed(context.Background()) and waits on every pending teardown with unconditional <-ch. The RPC handler at pkg/queryservice/rpc_version.go:81-85 ignores its ctx and calls eviction without propagating cancellation.

    Reachable sequence: eviction A removes an entry but is waiting for an active search to drain; retry B finds the same generation's teardown and waits; B's RPC deadline expires. Its server handler still retains request resources until A's teardown completes, so the caller's timeout does not bound server-side waiting. This contradicts the Rev 2 cancellation contract. Propagate the request context and make follower waits cancellable without interrupting the cleanup owner; add a deterministic held-teardown test that cancels the follower, verifies prompt return, and then confirms cleanup completes.

Exact-head CI run 35883911812 passed, including race-enabled owning-package jobs, proxy BVT (fulltext2_copy_alter 50/50 and authorization 38/38), and diff checks. Mixed-version compatibility jobs were skipped; the cancellation counterexample is source-traced, not locally reproduced.

@cpegeric

Copy link
Copy Markdown
Contributor Author

fixed

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of exact head 57ff16b2855c7864dcfb800c01e0960e391ad72a, against main / merge-base 426cf10b000b6a828e8c69f1af26082f26036ed3: REQUEST_CHANGES.

本轮检查完整源代码变更及新增 wire fields、历史 review 的修复闭环、权限边界、失败加载/多代清理、取消与 RPC 调度、热路径成本及测试稳定性。

一个新确认的 P2:同步 Evict 阻塞共享 QueryService 连接。 见行内评论。真实 QueryService + 默认 QueryClient 的复现中,用可控阻塞的 eviction hook 模拟清理 owner 等待 Search/Destroy;Evict 调用方超时后,同一连接上的 GetProtocolVersion 仍然超时。仅在对照测试中改为异步派发就通过。初次和随后 -race -count=3 均得到相同结果;这是请求调度问题,缓存层 follower 的 context 修复本身有效。请将长时间清理移出连接的读/派发循环,保留同步完成的响应语义和清理任务的生命周期管理,并加入 RPC 层回归。

之前的代码问题已闭环: 启动间隙现在有受控交错和 live-ticker 检查;follower context 已从 RPC 贯通到等待处;多代、失败加载、重复计数的完成路径通过验证;execution-entry 授权及 prepared/window 覆盖保留。当前基线已移除普通 CDC flush 的 RemoveIdle,不再把这个已消除的绕过路径作为 BVT blocker。

已有设计验收事项仍未闭环: docs/design/vector_index_cache_ctl.md:131 声称 Rev 2 获 fengttt 批准,但公开记录中的 fengttt approval 位于 9 月 17 日 adb8ddb8...;该版本尚无后续 execution-entry backstop 和 multi-generation teardown registry。未在最新 PR/issue 历史找到对这些新增契约、当前 Rev 2 的可追溯 owner 接受记录。这里不是断言线下没有批准;请链接该接受记录,或取得当前 revision 的明确接受。此项与上述运行时缺陷分开。

验证:

  • 本地完整 pkg/vectorindex/cache:-race -count=1 通过。
  • 7 个明确命名的关键并发测试,各自 -race -count=100 全通过(按每测试 30 秒预算和实测时长计算、上限 100):in-flight / older-generation / failed-load 等待、follower cancel、startup interleaving、真实 ticker sweep、single eviction owner。
  • RPC 对照复现:当前注册方式失败、异步派发对照通过;使用阻塞 hook 隔离调度问题,没有声称跑过真实大索引故障注入。
  • 核验当前 head 的 CI run 36105358740 及下载产物:owning-package race/plan/upgrade UT 通过,Compose fulltext2_copy_alter 50/50、authorization 38/38,SCA/coverage/required green;混合版本 compatibility jobs skipped,未宣称完成混合版本运行验证。
  • git diff --check 通过。

工程判断:init hook 用于避开 import cycle、每代完成记录用于明确清理归属,均有实际必要;默认扫描周期不变,没有新增查询命中路径 RPC,未发现需要额外框架或重构的证据。修复应集中在 RPC 调度闭环。非阻塞文档整理:PR body 的协议版本仍为 85(代码为 96),授权用例数仍为 11(现为 38),并残留已移除的 CDC RemoveIdle 描述。

Comment thread pkg/queryservice/query_service.go Resolved

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 94e766a against current base 71c4157, including the delta since the last review, prior reviews/replies, and resolved threads. REQUEST_CHANGES.

[P1 — design approval gate] docs/design/vector_index_cache_ctl.md:14-16, 126-131 asserts that Rev 2 was approved by fengttt, but the attributable fengttt approval in this PR is on adb8ddb (Sep 17), whereas Rev 2 was added at 097fa92 (Sep 23). I found no later acceptance of that revision in the PR reviews/comments or linked issue #28985. Rev 2 materially changes the security and synchronous multi-generation teardown/cancellation contract; without owner acceptance of those exact decisions, the required design-first approval is not established. Reproducible record check: compare the two commits and review timestamps above. Please link the attributable Rev 2 acceptance, or obtain an explicit owner review of this revision before implementation approval. An author's approval annotation is not independent approval.

The prior shared-connection eviction blocker appears addressed by async QueryService registration at pkg/queryservice/query_service.go:115 and the new RPC regression. I am not re-raising that code issue. Diff check passes. Current-head CI has failing required/coverage/pessimistic BVT jobs, so it does not provide a green validation claim; I did not attribute those failures to this PR without log analysis.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of exact head 0bc13ac3a6a2006229c8e032168f714165c32aaf, base/merge-base afa347996b878336ff294f5cd070492194352b30: REQUEST_CHANGES — existing design approval gate remains open.

Blocking: attributable acceptance of Rev 2 is still missing

docs/design/vector_index_cache_ctl.md:14-16,126-131 asserts that fengttt approved Rev 2, covering execution-entry authorization and synchronous multi-generation teardown/cancellation. The attributable fengttt approval is dated September 17 on adb8ddb8f7bf9d17e43daffb90b06ba810bff5bb; Rev 2 was introduced September 23 in 097fa92eeb. The other recorded approval also predates Rev 2. I found no subsequent attributable acceptance of this revision in the PR reviews/comments or linked issue #28985.

This is the existing mandatory design-gate blocker, not a newly discovered runtime defect or a claim that offline approval never happened. Please link the owner's acceptance of the current design (document blob b33b68329eac5647bf752564e0920afd0515ed77), or obtain that acceptance and correct the approval record. Resolving inline threads does not close this review-level requirement.

Previous runtime blocker: addressed

pkg/queryservice/query_service.go:115 now dispatches EvictVectorIndexCache asynchronously through the existing RPC mechanism. The connection read loop no longer executes the blocking teardown inline; the response still follows handler completion. This addresses the previously reproduced shared-connection head-of-line blocking issue. I am not re-raising it.

The cache implementation, runtime eviction hook, and design document have no delta against the previously reviewed 57ff16b2855c7864dcfb800c01e0960e391ad72a. The earlier startup, follower-cancellation, multi-generation/failed-load teardown and duplicate-count findings remain closed on the reviewed source changes; this is not a claim that all historical tests were rerun locally at today's head.

QA challenge: tighten the new RPC regression (non-blocking suggestion)

pkg/queryservice/evict_async_28985_test.go:65-87 does not establish its stated post-timeout scenario. After <-started, it immediately sends GetProtocolVersion, then releases the eviction owner. With async dispatch this can finish before the 300 ms Evict deadline, and the Evict error is discarded. Thus the comment “The Evict caller deadline already fired” is not guaranteed.

The test does distinguish inline versus async dispatch, so its existing value is real. To additionally prove the cancellation boundary: capture the Evict result, wait for and assert the caller timeout while keeping the owner blocked, then verify the unrelated request succeeds before releasing that owner. Bound the startup wait and ensure release/join occurs on failure as well. This is a test-evidence gap, not evidence that the fixed production path still fails.

Design / engineering / performance judgment

The direction is defensible: sys-admin-only control-plane operations, exact cache-key discovery, explicit partial-failure/version behavior, and per-generation cleanup ownership address actual boundaries. The execution-entry authorization backstop and teardown completion records have concrete reasons; the RPC fix reuses existing dispatch rather than adding another framework.

However, the knobs and administrative eviction are not a promise of immediate query freshness or read-your-writes after DDL. The default refresh cadence is unchanged, and no performance speedup of normal query traffic has been demonstrated here. Keep the operational control contract distinct from a stronger consistency guarantee. PR-body references to protocol version 85, 11 authorization cases and the removed CDC RemoveIdle path are stale; current code uses protocol version 101 and the BVT has 38 cases.

Evidence and scope

  • Current-head CI run 36440009497 is green for required, UT, SCA, coverage and executed BVT jobs; the prior review's failing-CI statement no longer describes this head.
  • Downloaded pessimistic BVT artifacts confirm actual execution: fulltext2_copy_alter.sql 50/50, and vector_index_cache_ctl_authz.sql 38/38, with zero failures/ignored cases.
  • Mixed-version compatibility jobs were skipped; they are not upgrade-validation evidence.
  • git diff --check passes. No local tests or production edits were made in this pass; no subagents were used.

This pass covers the change inventory, design/history gate, the changed RPC closure and its test, prior finding closure, and exact-head CI artifacts. Under the repository mo-self-review design-first rule, the unresolved mandatory design approval stops full implementation approval; this is deliberately not a fresh all-30-file implementation sign-off. Not all review comments are closed: the design acceptance item remains outstanding.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of exact head 0bc13ac against base afa3479. I read the historical reviews, issue/PR replies and both resolved inline threads, and checked the current design, control-plane/security, RPC, cache-lifecycle, test and BVT changes. The earlier authorization, ticker-startup, eviction-generation/cancellation and shared-connection dispatch defects have corresponding fixes; I found no new verified runtime blocker. Exact-head required/UT/SCA/coverage and executed multi-CN BVT checks are green; mixed-version compatibility jobs were skipped.

REQUEST_CHANGES — the mandatory design acceptance for Rev 2 is still not traceable. At docs/design/vector_index_cache_ctl.md:14-16 and 126-131, Rev 2 claims fengttt approval for the execution-entry authorization and synchronous multi-generation teardown/cancellation contracts. The attributable fengttt APPROVED review (id 5239979141) was submitted on 2026-09-17 at adb8ddb, but Rev 2 was first added in commit 097fa92 on 2026-09-23. There is no later fengttt review or comment in this PR or linked issue #28985 accepting the current design blob b33b68329eac5647bf752564e0920afd0515ed77. Reproducible check: compare those commit/review timestamps and inspect the design blob at this head. Please link the owner's acceptance of this exact revision (or an explicit owner exception), or obtain one and update the design record. An author's “Approved by” annotation alone cannot establish the decision for this material security/lifecycle revision.

Non-blocking: the PR body still describes MORPCVersion85, 11 authorization cases and CDC RemoveIdle, while this head uses MORPCVersion101, 38-case authorization BVT and a base without that flush eviction.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head 0bc13ac against base afa3479: APPROVE.

I reviewed the full 30-file change map, historical reviews and author replies, both resolved inline threads, and the unchanged implementation since the last aptend review. The previous authorization bypasses, ticker-start race, exact-key and multi-generation eviction/failed-load completion defects, follower cancellation, and shared QueryService connection blocking are addressed in the current code. The Rev 2 design acceptance previously requested is now attributable: fengttt approved this exact head after the last review (review 5348039829, 2026-09-29 05:23 UTC). I found no remaining verified blocker.

Local validation on this exact worktree: make thirdparties and make -C cgo; go test -count=1 for vectorindex/cache, common/runtime, queryservice and ctl; focused -race cache/queryservice tests; focused frontend/planner authorization tests; git diff --check. All passed. Exact-head GitHub checks currently show 13 passes and 16 skips; skipped mixed-version jobs are not claimed as compatibility evidence.

Non-blocking integration note: this PR currently allocates MORPCVersion101; other open PRs also claim 101, so later merges must rebase and allocate a distinct version. The PR body and proto comment about empty-key eviction should be refreshed to match current code, but neither is an implementation blocker.

@cpegeric

Copy link
Copy Markdown
Contributor Author

fix merge conflict.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of exact head fa0120a82af5610daf5fad78cdcb32b5ad49e1db, base/merge-base c628836143ff3f2d2265124ffd84ae5acebf0d6c: REQUEST_CHANGES — one verified P1 authorization blocker.

Blocking: a background execution path is not a trusted principal

The new execution-entry check treats every BgKey=true invocation as trusted. User-authored stored procedures also execute through that background executor. An ordinary tenant can therefore bypass the sys-account/moadmin policy and use the new cluster-wide cache controls. The inline comment contains the public SQL reproducer and the traced ownership of this context flag.

I verified this through the actual MySQL frontend on an isolated, exact-head embedded CN/TN/logservice cluster, not merely a synthetic context:

  • Direct tenant SELECT mo_ctl('cn','GetVectorIndexCacheKeys','') was denied.
  • The identical call inside a tenant-created SQL procedure succeeded, returning {"keys":[],"cns":1}; this direct/procedure contrast reproduced twice on the same connection and cluster.
  • A procedure calling SetVectorIndexFreshnessInterval('2s') succeeded with applied=[127.0.0.1:10102:2000000000]: this reached and changed the CN-global setting.
  • A procedure calling EvictVectorIndexCache('reviewer_missing_key') also reached the administrative handler and returned {"evicted":0,"cns":1}. I deliberately used a nonexistent key; no claim that another tenant's real index was evicted in this probe.
  • The setting was restored by the sys administrator, the test tenant removed, and the cluster shut down. The regression probe fails on its authorization oracle as expected.

This is a demonstrated failure of the newly exposed commands' security contract, not a preference about the accepted interface. Keep the execution-entry owner, but enforce user authorization independently of whether SQL runs in the foreground or background. Do not infer trust from a scheduling/execution flag. Preserve genuinely system-authored initialization/upgrade calls with a narrowly established trusted origin or explicit system identity; do not add per-command copies of the same gate.

Historical findings and design

The previous Rev 2 approval blocker is closed: fengttt approved 0bc13ac3... on September 29, after Rev 2 existed; the current design blob is still b33b68329eac5647bf752564e0920afd0515ed77. I am not re-raising that gate.

Startup/reset synchronization, exact-key discovery, single-owner removal counts, older-generation and failed-load completion tracking, cancellable follower waits, and async eviction dispatch have corresponding current code and passing validation. The two previously resolved inline findings remain closed in their original scenarios. However, the authorization closure is not complete: the stored-procedure path contradicts the earlier claim that only system-authored SQL can carry BgKey.

Design, integration, unhappy paths and performance

The direction remains reasonable as an administrative control plane, not immediate read-your-writes: cache owns residency and teardown; runtime init hooks avoid an import cycle; QueryService supplies existing dispatch/transport; SQL owns privilege enforcement. Per-generation completion records solve a real lifecycle requirement rather than introducing a second cache or persistence path. New commands do not change on-disk/index/catalog formats, so this PR adds no data migration. Mixed-version rolling-upgrade compatibility is excluded from this review as requested.

Closure Ownership / wait / growth check Result
Cache eviction and failed load Completion published before removal; CAS selects cleanup owner; each unfinished generation has its own record; records removed after teardown; failed-load cleanup retains its non-key-wide rollback behavior No additional verified blocker
Eviction followers and RPC Follower waits observe request context; owned native cleanup may outlive caller timeout by contract; async dispatch keeps the shared connection readable; reviewer probe releases and drains the owner Passed post-deadline counterexample
Interval and periodic work Startup/update serialized; lower bound enforced; stale/cap scans reuse existing single-flight work; reset restores the default Focused normal/race tests passed
SQL trust and tenant boundary Stored-procedure text is user-controlled, but background flag exempts its execution from the policy P1 blocker

There is no new per-query RPC or generation validation on a cache hit, and the default cadence is unchanged. This is not evidence of a query-throughput improvement. Shortening the interval increases map sweeps, lifecycle work and metadata queries on all CNs; the floor/single-flight guards prevent a busy loop/overlapping sweeps, not arbitrary fleet-scale cost. The September 27 issue reproduction of a warm generation missing a new CDC term is relevant, but this PR's accepted promise remains periodic convergence rather than immediate freshness.

The implementation/schema increment is +1053/-100, test/BVT increment +1465/-104, design documentation +133/-0, generated binding increment +2473/-736. These were assessed separately: generated growth is reproducible plumbing, not new hand-written architecture; the test volume does not establish complete security coverage. The current authorization UT even explicitly permits a tenant context marked BgKey; the missing orthogonal oracle is the real user-authored background path.

Non-blocking test improvement: strengthen TestEvictVectorIndexCacheAsyncFreesConnection by capturing/asserting the Evict timeout and waiting for that terminal result before sending the unrelated request, with bounded startup and unconditional owner release/drain. Its current immediate second request proves async dispatch but need not exercise the stated post-timeout boundary. My independent probe closes that runtime uncertainty; it does not replace a maintained regression.

Non-blocking documentation cleanup: the PR body still references protocol version 85, 11 authorization cases and the removed ordinary CDC RemoveIdle path. Current code uses version 102 and 38 authorization cases. The proto comment claiming empty-key eviction means “all entries” also disagrees with the rejected-empty-key API. Keep the final documented contract consistent.

Validation

  • Local exact-head normal and owning-package -race -count=1: vectorindex/cache, common/runtime, queryservice, sql/plan/function/ctl all passed using the repository CGo wrapper and platform-matched native build.
  • Focused frontend/planner tests passed: Test_hasMoCtrl, TestNodeHasMoCtrl, TestMakeWindowFrameConstValueRejectsMoCtrl.
  • Eleven exact cache concurrency tests individually repeated -race -count=100 in one process per test: in-flight, older-generation, failed-load, follower cancellation, interval/reset/startup, stale/fresh controls, live periodic ticker and single-owner counts; all passed. Counts follow the 30-second measured-test protocol, capped at 100.
  • Author RPC dispatch test and independent TestReviewer29024EvictAfterCallerDeadline each repeated -race -count=30; all passed. The latter establishes that the Evict caller actually timed out while the cleanup owner remained blocked, then proves an ordinary request still progresses on the same connection.
  • Current-head CI run 36695736365 is green for executed required/UT/SCA/build/coverage/BVT checks. Downloaded pessimistic BVT artifacts confirm fulltext2_copy_alter.sql 50/50 (23.362s), authorization 38/38 (1.494s), zero failed/ignored cases. These cases do not select the procedure bypass.
  • Query protobuf regenerated separately with the repository's gogofaster/goimports pipeline: byte-identical to the committed binding. git diff --check passed.
  • Reviewer probes/evidence retained in /tmp/mo-pr29024-review.0Z2nhI; no production code edits, no subagents.

Approval is withheld until the user-authored background SQL boundary is closed and negative procedure coverage plus the legitimate system/admin controls pass.

Comment thread pkg/sql/plan/function/ctl/ctl.go Resolved

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stored-procedure and Starlark authorization bypass is closed at the mo_ctl execution boundary. The tenant initialization protocol probe now uses scoped system identity, while tenant DDL retains its caller identity. The failure-path cleanup issue in the eviction tests is also fixed. GPT-6.1 Sol xhigh final review approved head 1f19507. Local targeted tests, BVT, upgrade, vet and lint passed; CI was not awaited.

@mergify

mergify Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-30 18:04 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-09-30 19:09 UTC · at 6d4957b395df919d201cc84ae60e40bb7b637657 · squash

This pull request spent 1 hour 4 minutes 58 seconds in the queue, including 1 hour 4 minutes 36 seconds running CI.

Required conditions to merge

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] CI BVT fulltext2_copy_alter misses expected rows

6 participants