Skip to content

fix(fulltext2): evict idle search cache after CDC flush so incremental DML is visible (#30401) - #30606

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
cpegeric:bug_30401
Oct 19, 2026
Merged

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

Conversation

@cpegeric

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:

issue #30401

What this PR does / why we need it:

A FULLTEXT2 index indexed its initial (pre-create) rows correctly, but an
INSERT/UPDATE/DELETE issued after CREATE FULLTEXT2 INDEX stayed
invisible to MATCH ... AGAINST for ~10 minutes.

Root cause

The deltas are not lost. The ISCP consumer materializes them into
cdc_tail frames correctly (confirmed: the frames are on disk, and a process
restart — fresh cache — shows every incremental row). The defect is that the
warm in-memory fulltext2 search cache never refreshes to include new
cdc_tail frames in a live session, so MATCH keeps serving the create-time
snapshot until the ~10-minute async stale sweep (VectorIndexCacheTTL/2 × 4)
finally evicts the entry. DROP+recreate "fixes" it only because it builds a
fresh cache object.

#29227 removed the post-flush idle-evict from RunFulltext2 (and the
EvictIdleCache helper), leaving the stale sweep as the only refresh path.

Fix

Restore the idle-evict: after a CDC tail flush that wrote frames, drop the
cache entry if idle so the next query reloads the appended tail.

  • RemoveIdle evicts only when no search is in flight, so it never thrashes
    concurrent readers — a busy entry stays warm and refreshes later via the
    sweep. This was fix(fulltext2): keep warm search cache across ordinary CDC flushes #29227's stated concern, and idle-only addresses it.
  • The reloaded object is a fresh read-only generation, so the
    read-only-cache contract is unchanged.
  • The evict is local to the CN that hosts the CDC consumer, giving
    read-your-writes on the single-CN standalone case (the reported setup); a
    different querying CN still converges via the sweep (unchanged cross-CN
    eventual behavior).

Validation

  • Unit tests (deterministic, cover the change): TestEvictIdleCache
    (idle→evict+destroy, absent→no-op) and
    TestRunFulltext2RefreshesIdleCacheAfterNonEmptyCDCFlush (a committed
    non-empty CDC flush evicts the idle warm entry; the next reader reloads the
    committed row; a mid-flush reader is never yanked). Full pkg/fulltext2 and
    pkg/iscp packages pass.
  • End-to-end on a single-node standalone instance at default freshness
    (no ctl override): a post-create INSERT is searchable in ~3s and an
    UPDATE's new/removed terms in ~10s, versus ~10 minutes before.

No BVT timing assertion is added for the evict path: at default freshness the
idle-evict is single-shot per flush, so a polling MATCH would create busy
windows that can make the single RemoveIdle miss (flaky). The existing
fulltext2_async warm_refresh case already covers the sweep refresh path
robustly (via a 1s freshness override) and still passes with this change.

🤖 Generated with Claude Code

…emental DML is visible (matrixorigin#30401)

A FULLTEXT2 index built the initial (pre-create) rows correctly, but an
INSERT/UPDATE/DELETE after CREATE stayed invisible to MATCH for ~10 minutes.
The deltas were in fact materialized into cdc_tail frames by the ISCP
consumer -- the warm in-memory search cache simply never refreshed to include
them, so MATCH kept serving the create-time snapshot until the ~10-minute
async stale sweep (VectorIndexCacheTTL/2 x 4) finally evicted it.

matrixorigin#29227 removed the post-flush idle-evict from RunFulltext2 (and the
EvictIdleCache helper), leaving the stale sweep as the only refresh path.
Restore it: after a CDC tail flush that wrote frames, drop the cache entry
IF idle so the next query reloads the appended tail.

RemoveIdle evicts only when no search is in flight, so it never thrashes
concurrent readers (a busy entry stays warm and refreshes later via the
sweep). The reloaded object is a fresh read-only generation, so the
read-only-cache contract is unchanged. The evict is local to the CN that
hosts the CDC consumer, giving read-your-writes on the single-CN standalone
case; a different querying CN still converges via the sweep.

Verified end-to-end (default freshness, no ctl override): a post-create
INSERT is searchable in ~3s and an UPDATE's new/removed terms in ~10s,
versus ~10 minutes before.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@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 →

@XuPeng-SH

XuPeng-SH commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: ac830dd97915b5cff23bbfce485c59ff9d1e49e5

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: ac830dd97915b5cff23bbfce485c59ff9d1e49e5

"interrupted"

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

mo-bot review · mo-bot-local · review

Commit: ac830dd97915b5cff23bbfce485c59ff9d1e49e5

Assessment: approve

Reviewed the complete four-file delta and affected callers. The scoped fix reasonably reuses existing cache ownership to evict idle live entries after successful, nonempty CDC commits. Commit ordering, active-reader protection, snapshot isolation and cleanup are preserved. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Isolation preflight passed. Initial testing stopped on missing native prerequisites; rebuilding through the repository owner in an exact-candidate diagnostic snapshot resolved setup, and native provenance verified.

  • TestEvictIdleCache, TestRunFulltext2RefreshesIdleCacheAfterNonEmptyCDCFlush and TestRemoveIdleEvictsIdleButKeepsBusyAndSnapshots each passed measurement and 100 separate exact-test repetitions under -race.

  • Full pkg/fulltext2, pkg/iscp and pkg/vectorindex/cache suites passed once under -race, with no failed or skipped tests.

  • Reconciled commands, source fingerprints, exit receipts and retained logs; confirmed source remained unchanged. Detailed evidence: /home/xupeng/.local/state/mo-bot/jobs/457020f446865fb9a06adde1/attempt-1/review-audit.json.

  • Reviewed frozen exact-head CI successes and traced delete-only frames, empty flushes, transaction failures, cancellation and plugin wiring.

Limitations:

  • Invalidation is single-shot and local: busy entries and other CNs retain eventual refresh behavior. This does not provide strict read-your-writes consistency.

  • Successful eviction requires a full index reload on the next query. That freshness tradeoff can increase fulltext workload I/O and latency; no quantitative performance comparison was performed.

  • The consumer test mocks SQL execution and the search backend. Author-reported default-freshness SQL timings lack retained logs; the standalone linked issue body and raw CI logs were not supplied.

@mergify mergify Bot added the queued label Oct 19, 2026
@mergify

mergify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-19 12:49 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-19 20:05 UTC · at fed3bf59700158212a9135d0b619c3849034bb65 · squash

This pull request spent 7 hours 15 minutes 59 seconds in the queue, including 55 minutes 42 seconds running CI.

Required conditions to merge

@XuPeng-SH

Copy link
Copy Markdown
Contributor

QA verification on main@3ad9adbb4c (post-merge)

Fresh isolated instance, local build, create fulltext index then incremental DML (10 repetitions across separate tables, all consistent):

Step Query Result
baseline match(body) against('hello') 1
after insert (3,'hello again') same 1, 3 — new row visible without manual flush
after update ftx set body='changed words' where id=2 against('goodbye') empty (old term no longer matches)
against('changed') 2 (new term matches)
against('world') 1 (unaffected row still matches)
after delete where id=1 against('hello') 3

So the stale-cache symptom this commit targets (incremental DML invisible until a manual flush) did not reproduce: insert/update/delete are all reflected on the next query.

One caveat for the record: during an earlier exploratory run I observed a single against('goodbye') → id=1 result after the same update. I could not reproduce it in 10 subsequent iterations (4 aggregate-shaped + 3 plain-select + 3 mixed), so I am not filing it as a defect; if it resurfaces under concurrent DML, the search-cache eviction path is the first place to look.

mergify Bot pushed a commit that referenced this pull request Dec 1, 2026
## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [x] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #28005

## What this PR does / why we need it:

Document the idle-cache refresh implemented by #30606 and the effect of the MATCH transaction read point on reload. Issue #28005 still requires strict cache retention across CDC commits. Its QA result remains a failure against that requirement, and the product decision must account for the visibility requested in #30401. The matrix records evidence needed for either decision and keeps historical strict-retention results tied to their original build.

QA required: yes

The deployment matrix covers exact MATCH IDs across read points and CNs, durable tail and watermark outcomes for empty batches and rollback/retry, and resource release during ordinary eviction, MERGE, REBUILD, graceful shutdown, cancellation, and partial load failure. It distinguishes per-generation mappings and file holds from shared index-file cache entries retained under their own policy. The Linux failed-load mmap test and deployment QA remain pending for this revision.

### Validation

- Documentation whitespace check and `mo-pipe preflight` passed locally for `cfa32b10a2ce66a055c3e3cbb80f790f08b967b8` against `275030e3c51a83962786f5a4317934a9ec2c3212` after synchronizing with `main`. The complete PR patch is byte-for-byte identical to the patch reviewed at `bfc477a0618f764f568bfba0ca4a778b88ea245b`.
- BVT: N/A for the Markdown-only change. Component tests and deployment QA were not run for this revision.


Approved-by: XuPeng-SH <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — 4622e059 Deployed Oct 19, 2026 by mergify[bot]
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants