Skip to content

perf(fulltext2): add cold-load observability - #27461

Merged
XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/fulltext2-load-observability-pr
Aug 24, 2026
Merged

XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/fulltext2-load-observability-pr

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #27445

What this PR does / why we need it:

Adds low-overhead FULLTEXT2 cold-load observability without changing query semantics, SQL/DDL, index format, CDC protocol, or public configuration.

Changes:

  • Records bounded load miss reasons for process start, TTL, CDC flush, MERGE, REBUILD, and generation change.
  • Records base/tail bytes, internal SQL, temporary-file, mmap, checksum, total-load time, waiter count, and success/error/cancel terminal state.
  • Keeps the observer disabled by default; diagnostics use the internal MO_FULLTEXT2_LOAD_TRACE=1 switch or a package-private observer.
  • Wires invalidation reasons through the existing vector-index cache lifecycle.
  • Ensures local CDC/MERGE/REBUILD mutation sites register the reason once and use reasonless cache eviction, so a delayed old-entry destroy cannot append a phantom duplicate reason.
  • Claims the exact old cache entry before eviction, publishes TTL/stale reason while it still occupies the key, atomically removes that exact value, and destroys it exactly once after the old reader releases.

Validation:

  • Cache package: GOWORK=off go test -mod=readonly -count=1 ./pkg/vectorindex/cache — PASS.
  • Cache lifecycle race: GOWORK=off go test -race -mod=readonly -count=1 ./pkg/vectorindex/cache — PASS.
  • Exact HouseKeeping/active-reader and replacement regressions: normal and -race -count=100 — PASS; the replacement test fails on old exact head 8b5cef57f9c37ef00d24831f21f90625c59efbaa before exact-entry snapshotting.
  • Fulltext2 replacement regression: GOWORK=off .agents/skills/mo-dev/scripts/mo-cgo-test -mod=readonly -count=1 ./pkg/fulltext2 and -race -count=20 — PASS.
  • Full pkg/fulltext2 normal/race suites — PASS.
  • Touched-package go list -mod=readonly, go build, and go vet — PASS.
  • BVT: N/A for the observer/cache identity contract; event timing and process-cache lifecycle are not deterministic in distributed BVT. Existing test/distributed/cases/fulltext2/fulltext2_merge_forcesync.sql covers the production MERGE/REBUILD terminal path; mo-55 production SQL black-box evidence covers CDC/restart/TTL.
  • git diff --check: PASS.
  • Semantic preflight and self-review: PASS (PASS semantic=PASS) at exact head 380b32fbd888570ab4005d8df4cbc156088f6223.

QA required: yes — this changes cache invalidation diagnostics around CDC, restart, mmap and temporary-file lifecycle. Production terminal: FULLTEXT2 MATCH after restart, TTL, CDC, MERGE and REBUILD. Remaining deployed validation is recorded in #27445.

Current status: Ready for review; CI and reviewer re-review are pending on pushed exact head 380b32fbd888570ab4005d8df4cbc156088f6223.

Non-goals:

  • No immutable-base reuse in this PR; that is the stacked P1 PR.
  • No new SQL/session/public API, persistent cache format, or cross-CN SLA.

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Aug 21, 2026
@VioletQwQ-0
VioletQwQ-0 marked this pull request as ready for review August 23, 2026 16:47
@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 →

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the current-head invalidation race.

  • Local CDC, MERGE, and REBUILD mutation sites still record the reason explicitly, but now use reasonless Cache.Remove so the evicted entry cannot record the same event again through DestroyWithReason.
  • Reason-aware destroy callbacks remain for TTL/stale cache lifecycle paths.
  • Added a production-shaped replacement-load/reason-consume regression and a cache-level Remove contract test.
  • Cache package tests pass normally and under -race; touched-package go list and git diff --check pass.
  • The fulltext2 CGo regression is blocked before compilation by the missing worktree cgo/libmo.dylib, so no local fulltext2 test pass is claimed.

The pushed head is e88ade07b3d502a568d8705fb3597e846a336513. Please re-review this exact head.

@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 re-reviewed exact head e88ade07b3d502a568d8705fb3597e846a336513 against the prior requested-change lifecycle race and the complete invalidation call graph. The new commit fixes the CDC consumer and compile hooks, but the same blocker remains in two production mutation paths:

[P1 observability correctness] Convert the MERGE and REBUILD TVF paths to single-owner invalidation too. These sites still explicitly publish a reason and then evict with the same reason:

pkg/sql/colexec/table_function/fulltext2_compact.go:127-128
pkg/sql/colexec/table_function/fulltext2_create.go:362-363

In both cases the sequence is still OnCacheInvalidated(reason) followed by Cache.RemoveWithReason(key, reason). If an entry exists, RemoveWithReason performs LoadAndDelete and then DestroyWithReason; a replacement load can install and peek the first reason while the removed old entry is waiting for its write lock, after which the delayed destroy callback writes the same physical invalidation again. Timestamp-aware consumption deliberately preserves that later write, leaving a phantom merge/rebuild reason for the following unrelated load.

The new regression only exercises the corrected manual OnCacheInvalidated + Remove sequence, so it cannot catch these unchanged real call sites. Please use reasonless Remove at both remaining explicit-notification sites and add production-path or exhaustive call-graph coverage proving no local CDC/MERGE/REBUILD path combines an explicit notification with reason-aware eviction. Reason-aware destroy must remain only for cache-owned TTL/generation-stale events.

The previous cancellation classification and failed-retry retention fixes remain correct. Full affected package suites (fulltext2, vector cache, compile plugin, ISCP, table functions) pass; focused observer/reason lifecycle tests pass under -race -count=20. Default-path overhead, bounded reason storage, phase/resource cleanup, and wait/lock ownership show no additional blocker.

@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.

P1 — Publish TTL/stale invalidation before a replacement can load

The latest commit closes the remaining MERGE/REBUILD duplicate producers, but the cache-owned TTL and generation-stale path still loses the reason under the same real eviction/replacement interleaving.

HouseKeeping calls LoadAndDelete first, then DestroyWithReason. The latter waits for the old entry write lock before invoking OnCacheInvalidated. With an active reader:

  1. housekeeping removes the old entry and blocks on its lock;
  2. a replacement is installed and peeks no pending reason, so this actual TTL/stale reload is recorded as process_start;
  3. the old reader releases;
  4. delayed destruction publishes ttl_expired or generation_changed;
  5. the next unrelated load consumes that phantom reason.

This leaves both adjacent events wrong, even though local CDC/MERGE/REBUILD now have a single producer. I reproduced the production HouseKeeping ordering on exact head 3d64abdde8637c9f5db7e600bce789336fcb4761 by holding the old entry lock: after the map entry disappeared, the replacement saw an empty reason; after destruction completed, the registry contained ttl_expired. The counterexample failed deterministically in the normal run and 20/20 under -race.

Please claim the exact old entry and publish its reason while it still occupies the key, then atomically remove it and perform reasonless destruction, with an exactly-once guard for competing eviction paths. Add a regression that blocks old-entry destruction and proves a replacement cannot start before the reason is visible and that no reason remains after a successful replacement load.

Validation after removing the temporary test: full ./pkg/fulltext2 ./pkg/vectorindex/cache passes; existing reason/cache regressions pass with -race -count=20; git diff --check passes.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the current-head P1 about TTL/stale invalidation being published after LoadAndDelete.

On exact head 8b5cef57f9c37ef00d24831f21f90625c59efbaa:

  • HouseKeeping and reason-aware removal now claim the exact VectorIndexSearch once with an atomic guard.
  • The claim fences new searches, publishes ttl_expired or generation_changed while the old value still occupies the key, and then uses CompareAndDelete before waiting for the old reader lock and destroying the entry.
  • Competing eviction paths cannot double-destroy or append a second reason.
  • Added TestVectorIndexCacheHouseKeepingPublishesReasonBeforeRemovingEntry and TestFulltext2HouseKeepingPublishesTTLReasonBeforeReplacementLoad.
  • The cache regression fails on the previous exact head 3d64abdde8637c9f5db7e600bce789336fcb4761 because the callback waits behind the held entry lock; it passes on this head. The FULLTEXT2 replacement Load consumes the published reason and leaves no pending reason.

Focused normal/race, -race -count=20, and full pkg/fulltext2 plus pkg/vectorindex/cache suites pass. go build/go vet remain blocked by the same baseline pkg/common/docfilter C declaration issue. BVT remains N/A for nondeterministic observer timing; QA is required. CI and re-review are pending.

@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 8b5cef5.

The prior TTL/stale publication race is directionally fixed, but one P1 exact-entry lifecycle race remains:

HouseKeeping snapshots only expired key strings during IndexMap.Range. In the later loop it calls IndexMap.Load(k) and claims whatever value currently occupies that key, without checking that it is the expired entry observed by Range or even rechecking Expired/stale. A normal concurrent sequence can therefore evict a fresh replacement:

  1. Range observes expired entry A and records key K.
  2. Before the eviction loop reaches K, another invalidation removes A and a query installs fresh, unexpired entry B at K.
  3. HouseKeeping loads B, publishes ttl_expired/generation_changed for B, CompareAndDelete removes B, and destroys it.

This causes an unnecessary second cold load, can force an in-progress query to retry, and leaves a phantom miss reason. It also contradicts the new exact-old-entry claim contract.

I reproduced the real HouseKeeping path deterministically: one expired entry blocks the first invalidation callback after Range has completed; while blocked, the other captured keys are normally removed and replaced with fresh unexpired entries; after release, HouseKeeping removes those fresh entries. The assertion failed in the normal run and in 20/20 race runs.

Please snapshot {key, expected *VectorIndexSearch}, verify the current map value is still that exact entry before claiming/publishing, and use CompareAndDelete against that expected value. If identity changed, skip it and let the replacement manage its own TTL. Add the replacement-between-Range-and-eviction regression.

Validation after removing the temporary counterexample: the two new TTL/replacement regressions pass under race for 100 repetitions; full pkg/fulltext2 and pkg/vectorindex/cache tests pass normally and under race; go list/build/vet, gofmt, and git diff --check pass.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed XuPeng-SH's current-head exact-entry eviction finding in commit 380b32fbd888570ab4005d8df4cbc156088f6223.

  • HouseKeeping now snapshots {key, expected *VectorIndexSearch} rather than only the key.
  • Before claiming an entry, it verifies that the current map value is the exact snapshot pointer and rechecks the current TTL/stale state.
  • Eviction uses CompareAndDelete(key, expected), so a fresh replacement at the same key is skipped and keeps its own lifecycle.
  • Added a production-path regression that blocks the first invalidation after Range, replaces another captured entry with a fresh value, and verifies the replacement survives.

Validation on the exact clean head:

  • Pre-fix counterexample: FAIL as expected; it evicted the fresh replacement.
  • Focused regression: PASS, including -race -count=100.
  • Full pkg/vectorindex/cache normal/race suites: PASS.
  • go list, go build, go vet, gofmt, git diff --check, self-review, and semantic preflight: PASS.
  • Existing remote FULLTEXT2 CI/BVT evidence is green; this cache identity repair adds no SQL-visible behavior.

Please re-review exact head 380b32fbd888570ab4005d8df4cbc156088f6223.

@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 re-review of exact head 380b32fbd888570ab4005d8df4cbc156088f6223 against the prior exact-entry housekeeping blocker and the complete PR diff.

The latest commit closes the blocker: HouseKeeping now snapshots {key, expected entry}, verifies the current map value is still that exact pointer, rechecks expiry/staleness, claims destruction exactly once, and uses CompareAndDelete against the expected value. A fresh replacement installed between Range and eviction is skipped, so it is neither destroyed nor assigned a phantom TTL/generation reason.

Lifecycle audit: Q1 ownership is single-winner through destroying.CompareAndSwap; Q2 invalidation is published while the old entry still occupies the key, map removal opens replacement, and destruction waits only for active readers; Q3 the temporary housekeeping snapshot is bounded by current cache cardinality and released after the sweep, while reason bookkeeping remains disabled by default and bounded when enabled. No blocking correctness, unhappy-path, leak, or default warm-path performance issue found.

Validation on the exact head: the replacement regression, publication-order regression, and FULLTEXT2 reason-consumption regression each passed under -race -count=100; full pkg/fulltext2, pkg/fulltext2/plugin/compile, and pkg/vectorindex/cache suites passed normally and under race; all five touched owning packages passed go list, go build, and go vet; gofmt and git diff --check passed.

This branch was previously deployed

1 inactive deployment
ci — 167a3128 Deployed Aug 25, 2026 by XuPeng-SH via Matrixone Utils CI / Coverage #48033
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants