Skip to content

fix(fulltext2): fence cross-CN cache generations - #27806

Closed
VioletQwQ-0 wants to merge 24 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-27788-fulltext2-cross-cn-fence
Closed

VioletQwQ-0 wants to merge 24 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-27788-fulltext2-cross-cn-fence

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Aug 28, 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:

Fixes #27788

QA required: yes

What this PR does / why we need it:

FULLTEXT2 CDC tail commits previously invalidated only the consumer CN's process-local cache. A different CN could continue serving a warmed pre-commit generation.

This change:

  • gives FULLTEXT2 cache, load-pool, and fence state a tenant/database/hidden-table lifecycle identity;
  • captures the durable generation inside the tail transaction, then installs the local fence and enqueues best-effort fanout only after commit;
  • makes CREATE/REBUILD/MERGE advance a reserved transactional metadata generation, including empty REBUILD, without ordering generations by a CN wall clock;
  • adds an additive MORPC v43 queryservice command whose ACK requires a monotonic required generation and a completed non-blocking eviction claim; earlier protocol versions are explicitly rejected for this method;
  • bounds and coalesces fanout retries, using fixed workers and a bounded pull fallback for sender crash, lost RPC, and mixed-version rollout;
  • retains global cache entries when freshness queries fail or consume the whole deadline, records exact per-index uncertainty, and recovers with versioned single-flight queries plus bounded backoff;
  • rejects lower-generation in-flight loads at global admission, preventing an old transaction snapshot from publishing after a fence or recovery;
  • tracks exact active and in-flight identities, pruning only inactive entries; there is no process-lifetime retired Bloom/filter or irreversible cap;
  • adds default-off deterministic test hooks after tail commit/before local fence and immediately before one target CN's fence RPC;
  • keeps classic FULLTEXT and other vector algorithm behavior unchanged.

Validation

Exact pushed head: 44b0803bdc64e1169fa60a603786bee3a5972abc, against PR base snapshot c46d897e9645b80178568ef0783dd8e99e527222.

  • PASS: focused affected-package tests on the exact head
  • PASS: git diff --check
  • PASS: clean schema-v6 semantic preflight on the exact head: 308 reviewed surfaces, 1661 obligations, diff hash f2e91a01b56ccc7aeef3ac51ce93a478ea73d0a36338272353f037341b66971a
  • PASS: exact-head macOS mo-service build
  • PASS: exact-head Linux/arm64 image pr27806:44b0803-arm64, image ID sha256:68290448b5db2bbad5484e6cdb892bcb7395451f7cb3145f7cffe85cf4c9f586; extracted mo-service SHA256 65ca8b42839dacf812a584de72a633a5d8f2a29902729c8321b324ff4915cea1
  • PASS: exact-head fulltext2_bugfix.sql lifecycle BVT twice, each 58/58 cases with zero failures or abnormal exits
  • PASS: exact-head direct-CN matrix on Linux/arm64 with no Proxy: dual-CN prewarm/no steady-state reload, rollback, INSERT, UPDATE, DELETE, targeted first fence-RPC loss and retry, sender interruption after durable commit with surviving-CN pull recovery, CN restart, CN3 join, and all-serving-CN MORPC v43 admission
  • PASS: matrix resource teardown; direct task ports released
  • PASS: exact pushed-head GitHub CI run 33594034886 attempt 2; SCA passed on Linux/arm64 after attempt 1 ended with self-hosted runner communication loss; all required checks passed
  • PENDING: reviewer acceptance and external QA

Historical results from older heads are not counted as exact-head acceptance.

Direct-CN exact-head evidence

  • Run ID: pr27806-44b0803
  • Image/platform: pr27806:44b0803-arm64, Linux/arm64
  • Topology: direct CN1/CN2/CN3 connections; Proxy was not used
  • Initial durable generation: 0:1; rollback stayed at 0:1
  • Committed generations converged at INSERT 0:2, UPDATE 0:4, DELETE 0:5, lost-RPC 0:6, and sender-interruption 0:7
  • Lost-RPC probe dropped exactly the first targeted fence send and observed two target attempts
  • Sender interruption stopped CN2 after durable commit; CN1 pull-converged and served the committed generation
  • Restarted CN2 and newly joined CN3 both served the current generation with MORPC v43
  • Structured terminal status: MATRIX_PASS; teardown: PASS

QA Decision

  • required: yes
  • reason: this changes distributed CDC/cache coherence, persisted generation, mixed-version protocol, retry, restart, and join behavior
  • production_entrypoint: FULLTEXT2 MATCH after CDC tail commit across independently serving CN processes
  • automated_terminal_coverage: deterministic unit tests, exact-head lifecycle BVT, and the direct-CN fault matrix above
  • remaining_validation: reviewer acceptance and tester QA

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Follow-up on the current-head review:

Pushed 5180cf178d3035d0b4c7a0ac55d77e18b1f219b8 after merging main@3a52dd0ecf7ad7ee04fcf14700682caaf5b3466a.

  • Fixed the base reproduction's aggregate type boundary: checkTailLoadBudgetAfter now uses CAST(COALESCE(SUM(LENGTH(data)), 0) AS SIGNED) before the production int64 accessor.
  • Added TestTailLoadBudgetCastsSumLengthToSigned; the pre-fix query-shape assertion failed and the final focused test passed.
  • PASS: complete pkg/fulltext2 normal and race tests, pkg/cnservice FULLTEXT2 fence tests normal and race, and the related -race -count=100 regressions.
  • PASS: clean-worktree semantic preflight (fe1df426eb83620769af3b8a6985136746e091e17e4edc7938bb91e0dc847a17).
  • Fresh required CI run 33321352564 is still pending; no CI success is claimed yet.

The required exact-head direct-CN matrix remains pending. I have not treated proxy sessions, unit tests, or BVT as per-CN evidence, and the blocking review request remains in place until two independent prewarmed CNs cover INSERT/UPDATE/DELETE, rollback, lost RPC, post-commit sender interruption, restart, and join convergence.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Exact merged-head direct-CN QA status for ae44d3f5148af34406d865b11f2ba0e655585626 (base main@5b9261e4f7c5b9f66442879f2e18cd9e8fcc8a12): BLOCKED before the dual-prewarm gate.

The run used two independent CN processes and direct SQL endpoints. Proxy sessions were not used as per-CN evidence.

endpoint connection ID mo_sessions.node_id config UUID
127.0.0.1:16001 9 dd1dccb4-4d3c-41f8-b482-5251dc7a41bf dd1dccb4-4d3c-41f8-b482-5251dc7a41bf
127.0.0.1:16002 106 dd2dccb4-4d3c-41f8-b482-5251dc7a41be dd2dccb4-4d3c-41f8-b482-5251dc7a41be

Before the initial durable FULLTEXT2 tail appeared, CN2 exited with panic: runtime error: index out of range [1] with length 1 in pkg/lockservice.(*fixedSlice).append. The observed durable generation was still (0,-1), and no MATCH was issued. The stack does not include either newly added FULLTEXT2 fault hook, but it blocks the exact-head acceptance path.

Consequently:

  • direct-CN identity mapping: PASS;
  • durable-tail prerequisite: BLOCKED;
  • dual independent prewarm: BLOCKED_NOT_RUN;
  • rollback, INSERT/UPDATE/DELETE, one lost RPC, post-commit sender interruption, restart, and CN3 join: BLOCKED_NOT_RUN;
  • review re-request: not performed.

Historical pre-fix supporting evidence, not acceptance evidence: on the older exact-main baseline the first MATCH hit the DECIMAL128 aggregate/int64 decoder mismatch. Applying only the recorded one-line signed CAST let both independent CN processes run, and an UPDATE then produced the expected pre-fix split: consumer CN red=[2], green=[1]; the other warmed CN red=[1,2], green=[] while durable tail advanced once from chunk 1 to 3.

Exact-head local code gates are PASS: owning ordinary/race tests, both deterministic hook groups with -race -count=100, make generate-pb, Linux go build -mod=readonly ./cmd/mo-service, git diff --check, and schema-v6 semantic preflight (PASS semantic=PASS, diff hash 3ba822a2397d89d590d8aa596bd82696368fbafa7ae0075920e0ae20919d8c48). This is a code-diff result, not direct-CN QA acceptance.

Evidence identifiers:

  • exact runtime binary SHA-256: e1ba6ea04fff647cd45285fa9c155cbadaab4c45269d527cfdc7c2345fac94f1
  • Compose SHA-256: 6b546ef4d2a1daaa55fbd7225fe2ad30b17e8dc309cd97570cb42315f841fa98
  • structured manifest SHA-256: b555a9c25f8540b81c563d9eb796359226a9350d5d5926614a8a8a2ae835df45
  • evidence checksum-list SHA-256: 13397d17f41bb1b5801963a9fd2cbc575eb39c5b3e6638cf6e9559da7efb7164

The exact-head containers were removed; the named data volume is retained for reproducing the blocker. The PR remains Ready with direct-CN QA and formal review still pending.

…ulltext2-cross-cn-fence

# Conflicts:
#	pkg/fulltext2/storage.go

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

Blocking review

This R3 distributed cache-coherence change cannot be approved yet.

  1. Exact-head direct-CN acceptance remains missing. The issue requires stale-read exclusion after a durable CDC tail commit across independently serving CNs. The PR body records the required two-CN prewarm matrix as BLOCKED_NOT_RUN; proxy BVT and unit/race tests do not identify or prewarm each serving CN. Please first rebase onto the latest main, then attach final-head direct-CN evidence for INSERT/UPDATE/DELETE, rollback, one lost-RPC case, post-commit sender interruption, restart, and new-CN join. The current head is also behind main, so older evidence is not reusable as final acceptance.

  2. Bound the failure-path operational amplification in the 30-second freshness sweep. checkStale(..., fast=true) now runs every 30 seconds for every loaded FULLTEXT2 cache entry. A QueryGeneration failure is treated as stale, logs one Warn plus one Info per entry, evicts it, and active MATCH traffic reloads it for the next sweep. Therefore a persistent internal SQL/metadata outage with N active identities yields repeated O(N) logs and reload work every 30 seconds. Please aggregate/rate-limit this per-entry logging (and expose a counter/summary) before enabling the fast sweep globally.

@XuPeng-SH

Copy link
Copy Markdown
Contributor

@Mergifyio refresh

@mergify

mergify Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

refresh

✅ Pull request refreshed

@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 review completed on exact head 3ccd4fb. I reviewed the full diff, design, issue, all reviews/comments/threads, and the lifecycle/concurrency paths. Three blockers remain:

  1. Fence-registry overflow is not fail-closed for the omitted identity. In pkg/fulltext2/coherence.go:172-176, capacity overflow returns without recording the new identity. InstallGenerationFence then only bumps coherenceEpoch and claims currently visible fulltext2: entries at :234-242; it neither installs the omitted lower bound nor retires that identity. A transaction whose snapshot predates the tail commit can start its first MATCH after this epoch bump: UseTransientLoad is false, requiredGeneration is absent, and Load captures the already-bumped epoch, so the old generation passes both checks and is published globally before the sender retry. Later transactions can then acquire the stale object, violating the stated admission invariant. A minimal exact-head test with registry capacity 1, identity A left claiming, and identity B overflowing fails the required assertion requiredGeneration(B) exists || UseTransientLoad(B): both are false. Keep the omitted identity transient/fail-closed until its exact fence is installed.

  2. The pull fallback is not bounded to 30 seconds and can exceed the issue SLA. In pkg/vectorindex/cache/cache.go:684-717, the 16-slot semaphore is acquired before the goroutine is launched, while each five-second timeout is created only inside that goroutine at :697. With 1,024 loaded FULLTEXT2 identities and slow/hung generation reads, the last group does not even start until about 315 seconds; startStaleCheck is single-flight, so intervening 30-second ticks are discarded. Even two-second metadata reads place the last identities beyond the 120-second issue gate. Please make the whole population coverage/SLA explicit and bounded rather than only bounding each individual check.

  3. Exact-head multi-CN acceptance is still absent. The PR body records the required direct two-CN prewarm matrix as BLOCKED_NOT_RUN after the CN2 panic, including INSERT/UPDATE/DELETE, rollback, lost RPC, post-commit sender interruption, restart, and join. Unit/race/proxy coverage cannot establish per-CN stale-read exclusion for this distributed protocol. Please provide the final-head direct-CN evidence after resolving the environment blocker.

Local exact-head evidence: the overflow counterexample failed as described; the temporary test was removed. All owning-package tests passed for pkg/fulltext2/..., pkg/vectorindex/cache, pkg/cnservice, pkg/iscp, and pkg/queryservice/client; race tests passed for pkg/fulltext2, pkg/fulltext2/fencepublisher, and pkg/vectorindex/cache; go vet and git diff --check passed. GitHub exact-head CI is green.

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

Request changes: the mandatory distributed acceptance proof is still objectively missing. The design requires direct connections to at least two independently identified CN processes with both caches prewarmed, followed by mutation and rollback checks plus lost-RPC, sender interruption, restart, and join recovery. The PR body states that the current exact-head run hit an unrelated lockservice panic before the dual-prewarm gate and that all subsequent scenarios are BLOCKED_NOT_RUN. Standard green CI and proxy BVT do not establish per-CN cache attribution or this push/pull recovery contract. The design also has no recorded independent PASS. Resolve the acceptance blocker, run the design-required scenarios on the exact implementation head with every serving CN at the allocated protocol version, and record an independent design decision before requesting implementation approval.

@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 at exact head 963ec48594aa6d2cf679f5db094c40f5c9fba116. The latest commit fixes the previously reported omitted-fence overflow and serial 16-slot sweep scheduling, and it removes per-entry warning amplification. Two new blockers remain in the replacement design: timeout/error eviction is not a generation fence and can both republish an old transaction snapshot and trigger an O(N) reload storm; registry reclamation permanently disables caching for retired identities and cumulatively collapses cache effectiveness above the process-wide 1024-identity cap. In addition, the design-required exact-head direct-CN acceptance matrix is still explicitly BLOCKED_NOT_RUN in the PR body, so the distributed issue is not yet proven solved.

Comment thread pkg/vectorindex/cache/cache.go Resolved
Comment thread pkg/fulltext2/coherence.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.

Deep re-review of exact head 44b0803. The earlier registry-cap, sweep-scheduling, and exact-head direct-CN evidence gaps are materially addressed, and the focused affected-package suite passes locally. Three remaining races still break the stated fence/availability contract: housekeeping can forget an acknowledged fence while a transient load is in flight; concurrent transient loads supersede each other through the global attempt counter; and fanout omits Draining CNs that can still serve existing/direct sessions.

r.mu.Lock()
defer r.mu.Unlock()
for key, entry := range r.entries {
if !entry.claiming && !entry.recovering && !cachePresent(key) {

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.

Blocking: pruneInactive only asks whether the generic IndexMap contains this key, but transient loads deliberately bypass that map. Repro: install/claim required H=(2,-1), mark the identity uncertain, start a transient MATCH whose caller transaction reads G=(1,-1), and pause its GenerationSQL read. If housekeeping runs now, it sees no IndexMap entry and deletes both the fence and uncertainty; after resuming, both required-generation checks in Fulltext2Search.Load see no bound, global admission is skipped for the transient object, and the stale G search succeeds after H was already ACKed. I reproduced this with a deterministic package test on this exact head. This contradicts the invariant at design lines 12-17 and the PR-body claim that in-flight identities are tracked. Keep the entry while transient loads are in flight, or give transient completion a durable validation/bound that cleanup cannot erase.

return errLoadGenerationSuperseded
}
index := s.identity.Key()
generation := beginLoadGeneration(index)

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.

Blocking: every transient Fulltext2Search.Load still enters the single per-identity loadGeneration attempt sequence. A later one-shot load increments state.attempt and makes every older overlapping one fail loadGenerationCurrent. Deterministic counterexample: pause transient request A after its generation read, let transient request B complete, then release A; repeat before each retry. Four ordinary overlapping B requests force A through all four attempts and it returns FULLTEXT2 cache coherence retry exhausted. I reproduced this on the exact head. Thus the timeout/error fallback that is supposed to preserve caller-snapshot availability can livelock/thrash a hot identity and return service unavailable under concurrent MATCH traffic. Transient one-shot loads need isolated or safely serialized reusable-pool bookkeeping rather than superseding unrelated transient requests.

}
nodes := make([]metadata.CNService, 0, 4)
err = clusterservice.GetCNServiceWithoutWorkingStateWithContext(ctx, cluster, clusterservice.NewSelector(), func(cn metadata.CNService) bool {
if cn.WorkState != metadata.WorkState_Working && cn.WorkState != metadata.WorkState_Unknown {

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.

Blocking: this excludes Draining CNs from every retry even though the work-state transition only starts asynchronous proxy tunnel migration; the CN frontend/query service and existing or direct sessions are still live. Counterexample: prewarm G on CN2, mark CN2 Draining, commit H on CN1, then issue MATCH on CN2 through an existing/direct connection before its pull sweep. Fanout never targets CN2 and can finish allAcked for the reduced inventory, so CN2 can serve stale G. This violates the every-live-v43-CN push invariant. Include Draining until the node is actually drained or its query address is withdrawn, or establish a fence that prevents it from serving before filtering it out.

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

We already have mechanism to clean up the stale cache every 5 mins. ( in pkg/vectorindex/cache). We can never clean the cache instantly in multiple CNs case. I don't think we need this mechanism.

@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 44b0803bdc64e1169fa60a603786bee3a5972abc against base c46d897e9645b80178568ef0783dd8e99e527222, including issue #27788, the full 42-file protocol/cache/CDC/queryservice change map, design invariants, all historical blockers, the latest convergence rewrite, direct-CN evidence, concurrency ownership, and Q1-Q3 unhappy paths.

The latest head materially closes the old fixed-cap retirement, serialized sweep, log-storm, and missing direct-CN evidence blockers. Three exact-head races remain:

  1. [P1 stale read] Housekeeping can forget an acknowledged fence while a transient load is in flight. pruneInactive retains an entry only for claiming, recovering, or a generic VectorIndexCache.IndexMap entry. Transient loads deliberately bypass that map. Therefore an identity can have required=H, uncertainty set, and a transient load from caller snapshot G < H in progress, while the lifecycle sweep observes no map entry and deletes the entire fence entry. When that load resumes, the post-load required-generation check finds no bound, and transient mode skips validateGlobalAdmission; the stale search can succeed after H was already ACKed. The separate load-generation active count is not consulted by registry pruning. Keep fence and uncertainty state while any transient load is active, or bind each transient completion to a durable requirement token that cleanup cannot erase.

  2. [P1 availability] Concurrent transient loads supersede one another through the global per-identity attempt counter. Every Fulltext2Search.Load, including one-shot transient loads, calls beginLoadGeneration, which increments one shared state.attempt. loadGenerationCurrent accepts only the latest attempt. A later independent MATCH therefore invalidates an older transient request even though neither is being globally published. Repeating ordinary overlapping requests before each retry can force one caller through all four coherence attempts and return retry exhaustion. Isolate transient bookkeeping, or safely serialize/share one transient load without letting unrelated callers invalidate each other.

  3. [P1 stale read] Fence fanout omits Draining CNs before they stop serving. fencepublisher.nodes includes only Working and Unknown work states. Draining begins asynchronous migration; the CN query service and existing or direct sessions can still be live. A CN with warmed generation G can enter Draining, be omitted from every broadcast retry for committed H, and serve G before its pull sweep. Include Draining nodes until their query address is withdrawn or establish a serving fence before excluding them.

These are current-code findings, not missing-CI gates. The exact-head direct-CN matrix is useful but does not schedule these three interleavings. Add deterministic regressions for prune versus paused transient load, overlapping transient attempts, and direct traffic on a Draining CN.

Q1 cleanup and Q3 bounded worker/registry behavior are improved on this head; I found no separate leak or unbounded-growth blocker. The unresolved stale-read and retry-livelock races violate the design terminal invariant and block approval.

@cpegeric

cpegeric commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

( in pkg/vectorindex/cache). We can never clean the cache instantly in multiple CNs case. I don't think we need this mechanism.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Closing this PR following the component owner's decision on #27788.

Multi-CN FULLTEXT2 cache convergence is asynchronous by design, and the current product contract accepts a delay of several minutes. The 120-second threshold was a validation threshold, not a product SLA. Therefore the MORPC generation-fence mechanism introduced by this PR is not required and should not be merged.

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 kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: FULLTEXT2 cross-CN cache invalidation can serve stale MATCH results after CDC tail append

7 participants