Skip to content

[Performance]: avoid full base materialization on FULLTEXT2 cache miss and CDC invalidation #27445

Closed as not planned

Description

@VioletQwQ-0

Background

FULLTEXT2 cache misses currently materialize the complete base index before serving a query. The reproduction was run on mo-55 with the exact binary from commit 94528dcb63d55921b936cda611ea61eb1862ea79, reusing the existing 2,303,643-row runtime. The result is directional only and is marked PERF_INCONCLUSIVE_HOST_BUSY.

The relevant load path is:

Fulltext2Search.Load
  -> LoadAllBases
  -> LoadFromStorage
  -> streamChunksToFile
  -> mmap/search

LoadFromStorage reads the tag=0 base chunks through internal SQL, writes a local anonymous file, and maps the materialized segment. A cache miss therefore performs multi-GiB local writes even when the query term has DF=1.

Reproduction evidence

Run artifacts:

/home/sunyuze/fulltext2-product-baseline-94528-20260820/results/coldload-repro-20260821/20260821-025000-coldload-repro-v4/
Scenario First query Immediate repeat
Restart, high-DF term 210 s, 2.61 GiB written 13 ms stable warm control
Restart, DF=1 term 234 s, 2.61 GiB written 12 ms
480 s TTL idle, unchanged generation 213 s, 2.60 GiB written 12 ms
CDC tail 3 -> 4 209 s, 2.60 GiB written 0.5 s
MERGE FORCE_SYNC 32.5 s, 2.89 GiB written 12 ms
REBUILD FORCE_SYNC 31.3 s, 2.81 GiB written 12 ms

The R3 generation stayed unchanged during the 480-second idle and reloaded on the next query. In R4 the tail advanced strictly from chunk 3 to chunk 4 before the query, and the next query reloaded the base. MERGE folded the tail and changed the metadata generation; REBUILD changed it again. All marker probes returned exactly one expected row and there were no query errors. A full exhaustive PK-set oracle was not part of this diagnostic run.

One R1 warm sample in v4 raced with a background CDC transition (tail 2 -> 3), so it is excluded from the warm comparison. The archived v3 run provides the stable 13 ms warm control.

Problem

The current invalidation granularity is the whole loaded search object. A tail flush or generation change removes the object, and the next query reloads all immutable base chunks instead of reusing the unchanged base and loading only the new tail/delete state. This creates multi-minute first-query latency and multi-GiB local temporary writes on a 2.3M-row index.

Proposed fix

Implement a conservative in-process immutable-base reuse path:

  1. Key the reusable base materialization by index identity and base generation, independently from the CDC tail generation.
  2. On tail-only invalidation, retain the immutable base segment and load only new tail/delete frames plus liveness state.
  3. Keep MERGE/REBUILD generation changes as explicit base replacement points; do not reuse a base whose storage generation changed.
  4. Add single-flight protection so concurrent cache misses do not materialize the same base more than once.
  5. Add bounded lifecycle accounting for retained mmap/temp files and deterministic cleanup on TTL expiry, MERGE, REBUILD, shutdown, and error paths.
  6. Add low-overhead counters or trace fields for base reuse, full materialization, tail-load bytes, local write bytes, generation, and load latency. Keep diagnostic tracing disabled by default.

The first implementation must preserve the current SQL and index formats. It should not require a new runtime-filter protocol or persistent cache format.

Non-goals

  • No changes to SQL, DDL, FST, FULLTEXT2 index format, CDC wire protocol, or public APIs.
  • Do not mix this work into P0 pure-MUST, P0.1 live-DF, P1 phrase positions, F1A membership, P2A term metadata, or safe candidate LIMIT.
  • No claim about absolute QPS/P99 from the busy mo-55 host.
  • No global unbounded cache or background cleanup goroutine without an explicit lifecycle design.

Acceptance criteria

  • Restart cold-load behavior remains correct, but a warm repeat does not rematerialize the base.
  • After a tail-only CDC flush, the next query reuses the unchanged base and does not write base-sized temporary data; only tail/delete work is proportional to the delta.
  • TTL eviction, MERGE, REBUILD, shutdown, cancellation, and load errors release retained mmap/temp resources exactly once.
  • INSERT/UPDATE/DELETE, tombstones, superseded PK copies, MERGE, REBUILD, and restart preserve PK membership and score semantics.
  • Concurrent first queries perform at most one base materialization per (index, base generation).
  • The cold-load reproduction is rerun with R1 through R5; correctness has zero lost, duplicate, phantom, or stale markers, and no service crash.
  • Add production-entry BVT coverage for CDC invalidation/reload and the relevant restart or MERGE terminal behavior. Package tests alone are insufficient.
  • Report cold/warm wall time, local read/write bytes, mmap bytes, RSS, generation, and tail bytes. Performance results remain host-validity qualified until repeated on a quiet host.

Related work

QA decision

  • QA required: yes
  • Reason: this changes CDC invalidation, restart, cache lifecycle, mmap/temp-file ownership, and user-visible first-query latency.
  • Production entrypoint: FULLTEXT2 MATCH ... AGAINST after restart, CDC tail flush, TTL expiry, MERGE, and REBUILD.
  • Automated terminal coverage: package/race tests, production SQL BVT, exact membership/score differential tests, and the cold-load reproduction harness.
  • Remaining manual/deployed validation: repeated 2.3M-row runs on a quiet host and failure/cancellation/restart lifecycle checks.

Activity

  1. added
    severity/s0
    on Aug 21, 2026
  2. VioletQwQ-0 commented on Aug 21, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    2026-08-21 validation and PR update

    The requested mo-55 black-box validation is complete on the exact 94528dcb63d55921b936cda611ea61eb1862ea79 runtime. The candidate binary used for the fixed rerun is SHA256 5be2d37bf34f2c49c9d6a3e408d3c603fd762c97baa5e2eaac214c883b6e1352.

    300K correctness

    The fixed candidate passed INSERT, UPDATE, DELETE, rollback invisibility, repeated UPDATE latest-version selection, graceful restart, forced cancellation with the service alive, MERGE and REBUILD. The first candidate run exposed a real tail_pool.go nil-map panic on an insert-only CDC delta; it is fixed by initializing/merging the delete state and covered by TestMergeTailDeletesInitializesInsertOnlyDelta. The initial cancellation attempt completed before the timeout; the corrected forced-timeout retry is the valid cancellation evidence.

    Artifact:

    /home/sunyuze/fulltext2-product-baseline-94528-20260820/results/coldload-fix-300k-blackbox-r4/
    

    2.3M cold/warm evidence

    Candidate artifacts:

    /home/sunyuze/fulltext2-product-baseline-94528-20260820/results/coldload-repro-candidate/20260821-candidate-r1r3r4r5/
    /home/sunyuze/fulltext2-product-baseline-94528-20260820/results/coldload-repro-candidate/focused-ttl/
    

    Key structural comparison against the retained exact-base v4 run:

    Scenario Previous full-reload baseline Candidate after reuse
    Restart cold ~2.80 GiB temporary write ~2.80 GiB temporary write (expected process-start cold load)
    Same-process TTL ~2.79 GiB write / ~213 s reload 20 KiB write / 1.13 s reload; immediate repeat 13 ms
    CDC tail-only ~2.79 GiB write / ~209 s reload 57 KiB write / 1.20 s reload; immediate repeat 12 ms
    MERGE ~3.10 GiB base replacement ~3.10 GiB base replacement (expected)
    REBUILD ~3.01 GiB base replacement ~3.01 GiB base replacement (expected)

    The candidate R1/R3/R4/R5 membership checks passed, and generation/tail transitions were recorded. All results are directional and marked PERF_INCONCLUSIVE_HOST_BUSY; no absolute QPS/P99 claim is made. The diagnostic run did not include an exhaustive 2.3M PK-set oracle, so the issue remains open for QA and broader exactness validation.

    Draft PRs

    Both are Draft and based on the current upstream/main (dd040ad6913e9b86f592b574e5fffb610003f72a). #27462 is stacked conceptually on #27461; its second semantic commit is perf(fulltext2): reuse immutable bases across cache generations.

    Code validation

    On mo-55 exact candidate build:

    go test -mod=readonly -count=1 ./pkg/fulltext2                 PASS
    go test -mod=readonly -count=1 ./pkg/vectorindex/cache         PASS
    go test -race -mod=readonly -count=1 ./pkg/fulltext2 -run ...  PASS
    go vet -mod=readonly ./pkg/fulltext2 ./pkg/vectorindex/cache   PASS
    make build-with-prebuilt-native                              PASS
    

    Existing test/distributed/cases/fulltext2/fulltext2_merge_forcesync.sql covers the production MERGE/REBUILD terminal path. Restart/TTL byte-level assertions remain harness-only because distributed BVT cannot deterministically control process cache state and host I/O; this is called out as BVT N/A in the PR bodies. QA required remains yes for CDC, restart, cancellation, mmap and temp-file lifecycle.

  3. VioletQwQ-0 commented on Aug 25, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    Post-merge evaluation for #27461:

    No issue state, label, or assignment mutation was made.

  4. VioletQwQ-0 commented on Aug 25, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    QA handoff after merge

    Issue #27445 remains open for production QA after the stacked implementation merged:

    Automated evidence already recorded:

    • The merged PRs passed the focused/full FULLTEXT2 and cache normal/race regressions, including exact publication-before-remove retry, generation-supersession, active-reader, cancellation, stale-publication, and cleanup checks; the perf(fulltext2): reuse immutable bases across cache generations #27462 local semantic preflight and git diff --check passed on its reviewed content.
    • The production-shaped mo-55 black-box run covered 300K INSERT/UPDATE/DELETE, rollback invisibility, repeated-update latest-version selection, restart, forced cancellation with the service alive, MERGE, and REBUILD. The 2.3M-row R1/R3/R4/R5 membership checks passed; tail-only and TTL reuse reduced the observed reload to about 1.13–1.20 seconds with delta-sized writes. Results remain host-validity qualified.
    • BVT is recorded as N/A for the internal cache/load lifecycle contract; the existing MERGE/REBUILD SQL case and production-shaped regressions are the automated terminal coverage. Remaining remote post-merge workflow checks are not a tester PASS.

    QA scenarios and expected results:

    • Repeat the 2.3M-row cold/warm, TTL, CDC tail-only, MERGE, and REBUILD scenarios on a quiet deployment and verify no lost, duplicate, phantom, or stale PK membership/score results.
    • Verify restart, cancellation, load-error, TTL eviction, MERGE, REBUILD, and shutdown release mmap/temp-file/pool resources exactly once, with no panic, hang, or service restart.
    • Confirm tail-only invalidation reuses the unchanged immutable base and writes only delta-sized tail/delete state; base replacement remains correct for MERGE/REBUILD.

    Tester selection basis: the issue author is VioletQwQ-0, not heni02; per the automation rule the tester is Ariznawlll.

  5. VioletQwQ-0 commented on Sep 3, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    Closing this issue as not planned.

    The immutable-base reuse and incremental-refresh direction proposed here was intentionally reverted by #28017 (merged as 1092ab739c120052fff0b8d1ff27854663cd098f) after owner review. FULLTEXT2 cached indexes now follow a read-only lifetime contract: CDC persists updates without evicting or incrementally refreshing the warm search index, and the accepted visibility delay is handled by the ordinary stale/TTL lifecycle so CDC updates do not block concurrent searches on cache replacement.

    The replacement contract and its remaining QA follow-up are tracked in #28005. There is no remaining implementation work under the design proposed by this issue.

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

Metadata

Metadata

Assignees

Labels

area/performancekind/performancephase/testingseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions