Repository navigation
fix(fulltext2): rebuild + refresh cache so COPY ALTER leaves the index queryable (#28837) - #28879
Conversation
…x queryable (matrixorigin#28837) An unrelated COPY ALTER (e.g. ADD COLUMN) left an unaffected FULLTEXT2 index returning empty for minutes until a reindex/restart. Two causes, both fixed: 1. Base-less rebuild. cloneUnaffectedIndexes marks fulltext2 SkipWholeIndex, so the ALTER clones the table to a new id with empty index tables rebuilt from the CDC log -- but RunFulltext2 appends only a tag=1 cdc_tail and a fulltext2 base is written ONLY by buildFromSource, so the replacement had no base. New plugin hook AlterCopyInitSQL: fulltext2 returns an ALTER REINDEX ... FULLTEXT2 FORCE_SYNC seed (run post-commit by the CDC's first iteration); every other algo returns (false, "") because its consumer rebuilds from the ts=0 replay. Wired into alter.go's unaffected-index ISCP block, mirroring RestoreInitSQL, including its initSQL=="" => startFromNow=false guard. 2. Stale warm cache. The querying CN kept its doc-less warm cache across the CDC flush (the matrixorigin#28005 keep-warm optimization), serving false negatives until the ~10-min IsStale sweep. New cache.RemoveIdle evicts a cached index only when no search is in flight (wraps evictIdleEntry/tryClaimIdle); a busy entry stays warm and refreshes later -- no reader thrash. RunFulltext2 calls it (via fulltext2.EvictIdleCache) after a non-empty tail commit. Scope: fulltext2 only. cagra/ivfpq (also base-less) REINDEX and converting hnsw/cagra/ivfpq forcible Remove to RemoveIdle are deferred follow-ups. Regression: a two-CN-safe BVT (pessimistic_transaction/fulltext2/ fulltext2_copy_alter.sql) force-builds FULLTEXT2, performs an unrelated COPY ALTER, and @wait_expect's on the REPLACEMENT index's durable tag=0 base (never polls MATCH, which can pin a stale per-CN cache) before comparing MATCH to a LIKE base-table oracle. Pre-fix the tag=0 base never appears, so the case times out and fails; post-fix it converges in ~1s. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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? |
…ixorigin#28837) The coverage gate scores newly-added lines; the copy-alter CDC-seed logic read low because it only executes on the copy-alter path (BVT, which truncates for fulltext2 in CI). Move the testable core out and add CPU unit tests: - Extract alterCopyCdcSeed (idxDefs build + AlterCopyInitSQL call + the initSQL=="" ts=0-replay guard) from alterTableCopy into a package helper and cover it with TestAlterCopyCdcSeed (rebuild passthrough, empty-InitSQL guard, (false,"") algo, error propagation, index-name filter) via a fake Hooks. - Add TestAlterCopyInitSQL for cagra/ivfpq/ivfflat/classic-fulltext plugin compile (0% -> 100%); hnsw and fulltext2 already had one. - Revert incidental churn (idxcronCctx var rename, expanded logutil line) back to origin/main so those non-new lines leave the diff. No behavior change: alterCopyCdcSeed is the same dispatch previously inlined, and the guard mirrors RestoreInitSQL (ddl.go). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
GPT-6 medium deep re-review APPROVE at exact head d79dc6f\n\nAll prior findings are fixed: identifier escaping, CDC watermark/replay snapshot handling, stale empty-generation eviction, the empty-generation destruction race (both search paths capture under the entry read lock), and the initialization-window regression. Exact-head affected-package race/UT coverage passed, and the multi-CN regression passed 33/33 with no ignored statements. No concrete blockers remain.
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed d79dc6f against c61ed37. No confirmed blocker.
The fulltext2 COPY ALTER seed builds a real base via escaped REINDEX FORCE_SYNC SQL; other plugins retain their established replay path and empty InitSQL forces startFromNow=false. Cache refresh happens after commit, idle removal preserves busy readers/snapshot generations, and a base-less/tail-less load is served but not retained. Both Search and SearchInto capture empty-generation state under the entry read lock, closing the destruction race.
Read the 25-file production/test change, hook dispatch and deterministic cache/commit-boundary controls, plus MATCH-versus-base-table BVT oracles. Reused green exact-head CI and existing exact-head race/33-of-33 multi-CN evidence; no fresh native/GPU/cluster run. Cross-CN nonempty-cache freshness remains eventual, not an instantaneous global invalidation guarantee.
aptend
left a comment
There was a problem hiding this comment.
Deep re-review at exact head d79dc6f87b6d1b501ef5147e3fd684737544e70c, covering the full 25-file diff, all prior reviews/replies/resolved threads, and the increment since my previous reviewed head 8c89a3711e1ecfac23d76db09a5879d2ca30211c. The previous synchronization blocker is closed: both Search paths now capture the fulltext2 empty-generation state while the cache entry read lock is held, and the deterministic reload test proves an empty prewarm is not retained. I also revalidated the init transaction: FORCE_SYNC rebuild drops/recreates the CDC generation in the same transaction, so the new job starts at the rebuild snapshot rather than replaying copied rows. Focused exact-head cache, race, compile-hook, plugin, and ISCP tests passed with the required CGO/thirdparties setup; exact-head CI remains green. No blocking issue found.
Merge Queue Status
This pull request spent 42 minutes 36 seconds in the queue, with no time running CI. ReasonPull request #28879 has been merged manually at d5c4e8b HintYou were too fast! 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:
issue #28837
What this PR does / why we need it:
Fixes #28837 — an unrelated COPY ALTER (e.g.
ADD COLUMN) left an unaffectedFULLTEXT2index returning empty fromMATCHfor minutes, until a manual reindex or a CN restart.Root cause
Why the index is rebuilt from source, not copied
A fulltext2 index — like every async index — is populated from CDC, not
synchronously with the base-table DML: the index table always trails the base
table by however far the CDC consumer has progressed. At the instant
ALTER TABLEruns, that CDC may not have caught up, so the index table is leftbehind — it does not reflect the base table's committed state. Cloning such an
index into the replacement table would therefore copy a stale, partial snapshot
(and the copy point has no clean watermark to resume CDC from consistently),
producing an index that silently omits whatever the CDC had not yet applied.
That is exactly why
cloneUnaffectedIndexesmarks these indexesSkipWholeIndexand the replacement is rebuilt from source (
REINDEX FORCE_SYNC) rather thancopied. It also means the issue's stated Expected behavior — that the COPY
ALTER carries the existing index over intact — is not valid for an async index:
there is no consistent index snapshot to carry over, so a rebuild from source is
the only correct outcome. The bug this PR fixes is not "the index wasn't copied"
(it correctly isn't) but that after skipping the copy, the replacement was never
rebuilt (no tag=0 base) and the stale warm cache kept serving empty.
Two independent causes, both required for the bug:
Base-less rebuild.
cloneUnaffectedIndexesmarks fulltext2SkipWholeIndex, so a COPY ALTER clones the table to a newid with empty index tables that are rebuilt from the CDC log. But
RunFulltext2appends only a tag=1cdc_tail, and afulltext2 tag=0 base is written only by
buildFromSource— so the replacement index had no base and nothing to serve.Stale warm cache. The querying CN kept its doc-less warm cache across the CDC flush (the [Performance]: keep FULLTEXT2 cache read-only across CDC updates #28005 keep-warm
optimization), serving false negatives until the ~10-minute
IsStalesweep.Fix (scoped to fulltext2)
New plugin hook
AlterCopyInitSQL(pkg/indexplugin/compile/hooks.go): fulltext2 returnsALTER TABLE … ALTER REINDEX … FULLTEXT2 FORCE_SYNC, run post-commit by the CDC's first iteration to rebuild a real tag=0 base. Every other algorithmreturns
(false, "")because its consumer already rebuilds from the ts=0 replay (hnsw/cagra/ivfpq viaRunHnsw/RunCuvs,ivfflat entries, classic row-based fulltext). Wired into
alter.go's unaffected-index ISCP block, mirroringRestoreInitSQL—including its
initSQL=="" ⇒ startFromNow=falseguard so a no-rebuild path can never arm the tail from now and droppre-existing rows.
New
cache.RemoveIdle(key, reason)(pkg/vectorindex/cache/cache.go): evicts a cached index only when no search is inflight (wraps the existing
evictIdleEntry/tryClaimIdle); a busy entry stays warm and refreshes at the next idle moment —no reader thrash, and [Performance]: keep FULLTEXT2 cache read-only across CDC updates #28005's keep-warm is left intact.
RunFulltext2calls it (viafulltext2.EvictIdleCache) after anon-empty tail commit, so the idle doc-less cache is refreshed promptly instead of after the ~10-min sweep.
Scope
fulltext2 only. cagra/ivfpq are also base-less on COPY ALTER (same shape) but work today via idxcron; converting them to
REINDEX, and changing hnsw/cagra/ivfpq's forcible
RemovetoRemoveIdle, are deferred follow-ups.Testing
test/distributed/cases/pessimistic_transaction/fulltext2/fulltext2_copy_alter.sql: force-builds aFULLTEXT2index, performs an unrelated COPY ALTER, then@wait_expects on the replacement index's durable tag=0 base(never polls
MATCH, which can pin a stale per-CN cache) before comparingMATCHagainst aLIKEbase-table oracle. Pre-fixthe tag=0 base never appears → the case times out and fails; post-fix it converges in ~1s. Validated in mo-tester run mode:
25/25 (100%).
RemoveIdlebusy-vs-idle + snapshot-preservation (-race -count=40, full cache package-race); rewritten[Performance]: keep FULLTEXT2 cache read-only across CDC updates #28005 consumer contract test (
-race -count=20);AlterCopyInitSQLREINDEX + fail-closed-on-empty-defs; plugin(false,"")stubs.
MATCH== oracle converge in ~2.5s.