Skip to content

[Bug]: index rebuild: remote FULLTEXT2/HNSW writes can be lost after successful FORCE_SYNC #29566

Closed

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

  • Incident: 32f54981401fd3888702f2dab8702d2e62c6997a.
  • Revalidated on current main: b75086c6fab613b147bff4e474dddac7e237c637.
  • Also reproduced the distributed-path defect on the older 52eecb55bee9b55e776d09c64dfbaa55d5db8f1f.

Other Environment Information

  • Incident: Run 36881937434 / MOTR Job 110585528706, weekly-shadow-1x2, 1 TP CN + 2 AP CNs, 55 GiB per CN, 16 GiB FileService memory cache.
  • The MOTR connection was directly to the TP CN, not through the proxy. The affected case was issue_29079_29276_fulltext_query_contracts.
  • Previous run: 36734661643, MO c2abd6a54b7cd3e13c1b1494388cd7a81b8369d4. Both runs used MOTR 957dd0c and the same test SQL/golden.
  • Controlled validation: isolated local macOS embedded cluster, 3 CNs, real MySQL frontend, real source-table persistence, real remote pipelines and internal index INSERTs. No production cluster was modified.

Actual Behavior

There is a placement-dependent correctness defect in the distributed synchronous index rebuild path. A remote fulltext2_create / hnsw_create operator can execute its index-table INSERTs successfully against a remote transaction workspace, but those writes do not become part of the coordinator's committed rebuild. ALTER ... FORCE_SYNC returns success while indexed queries silently miss rows.

Confirmed in controlled execution:

  1. A local FULLTEXT2 build over three committed source rows returns the expected matches. The metadata and chunk tables each contain one row.
  2. Route only the subsequent synchronous rebuild through the normal remote-pipeline machinery.
  3. The remote FULLTEXT2 builder receives all three non-null source rows, tokenizes them, finishes a three-document segment, and emits the metadata/chunk INSERTs. Both INSERTs report AffectedRows=1, no error.
  4. After the successful ALTER commits, both hidden tables contain zero rows and all six tested MATCH variants return empty results. The source rows remain intact.
  5. An ordinary HNSW control using [1,0], [2,0], [3,0] likewise changes from correct Top-K results and nonempty hidden tables to empty indexed results and zero hidden-table rows after a remote rebuild. This does not depend on extreme numeric values.

This is different from temporarily serving an old cached generation: the controlled failure has no committed replacement metadata/chunks, including on the initiating connection.

Observed in the incident, but not yet completely attributed to that mechanism:

Query group Expected Incident result
FULLTEXT2 26-byte token: NL, BM25, quoted boolean, mandatory boolean IDs 1,3 Empty
FULLTEXT2 hello + 26-byte token ID 3 Empty
FULLTEXT2 23-byte control token ID 2 Empty
FULLTEXT2 scalar / anti / correlated subquery forms, five queries Matching source rows Empty
Equivalent classic FULLTEXT controls Matching source rows Correct

All 34 SQL statements in the fulltext contract case executed; the case failed on 11 result mismatches, not on SQL errors. The six long-token queries passed in the previous run, while the five FULLTEXT2 subquery forms were already failing there.

The HNSW extreme-score case also unexpectedly succeeded. Importantly, its server log at 2026-10-01 21:59:50.258962 UTC / 2026-10-02 05:59:50.258962 CST reported:

hnsw/search.go:439
loaded 0 generation(s), rows=0, build_ts=unknown

Its source table had three rows. Consequently, this observation alone is not evidence that the numeric overflow guard stopped working: an empty model can make the query succeed without reaching score validation.

Expected Behavior

  • A successful synchronous rebuild must persist all index writes in the rebuilding transaction, regardless of the selected scan worker.
  • A nonempty source must not become a queryable empty index because the builder ran remotely.
  • If a side-effecting build TVF cannot safely execute in a remote mirror transaction, the compiler must not schedule it there, or must fail explicitly before replacing the existing generation.
  • This contract concerns the committed index state; it does not require an immediate cluster-wide cache invalidation barrier.

Steps to Reproduce

The three-row SQL below requires a controlled remote-placement harness to reproduce. Ordinary default scheduling is a passing control, not a standalone deterministic reproducer.

CREATE DATABASE ft_remote_rebuild;
USE ft_remote_rebuild;
SET experimental_fulltext2_index=1;
CREATE TABLE docs(id INT PRIMARY KEY, body VARCHAR(200));
INSERT INTO docs VALUES
  (1,'bbbbbbbbbbbbbbbbbbbbbbbbbb'),
  (2,'aaaaaaaaaaaaaaaaaaaaaaa'),
  (3,'hello bbbbbbbbbbbbbbbbbbbbbbbbbb');
CREATE FULLTEXT2 INDEX ft ON docs(body) WITH PARSER ngram;

-- Before the rebuild: 1,3.
SELECT id FROM docs
WHERE MATCH(body) AGAINST('bbbbbbbbbbbbbbbbbbbbbbbbbb') ORDER BY id;

-- Enable the remote-placement probe only around this statement.
ALTER TABLE docs ALTER REINDEX ft FULLTEXT2 FORCE_SYNC;

-- In a failing remote placement: empty, although the source still has 3 rows.
SELECT id FROM docs
WHERE MATCH(body) AGAINST('bbbbbbbbbbbbbbbbbbbbbbbbbb') ORDER BY id;
SELECT id FROM docs
WHERE MATCH(body) AGAINST('aaaaaaaaaaaaaaaaaaaaaaa') ORDER BY id;
SELECT id,body FROM docs ORDER BY id;

Harness details, so the test's limits are explicit:

  1. Use embed.StartTestCluster(embed.WithCNCount(3)) and connect through CN0's public MySQL frontend.
  2. Persist the tiny source before rebuilding. The existing test fault objectio.FJ_CNWorkspaceForceFlush was used to make source object placement available without loading millions of rows.
  3. Save plan.GetForceScanOnMultiCN(), set plan.SetForceScanOnMultiCN(true) only for ALTER ... FORCE_SYNC, and restore it immediately afterward. This bypasses the tiny query's execution-classification threshold; it does not replace the builder, SQL executor, transaction implementation, or remote transport with mocks.
  4. Verify from the builder trace that the source-bearing worker differs from the coordinator and uses Txn.Mirror=true. Object placement can leave a particular table's source on the coordinator; such a placement passes and must not be mislabeled as a failed reproduction.
  5. Query mo_catalog.mo_indexes for the hidden metadata/storage names, and count their rows before/after ALTER. Record actual query rows, not just the Go test exit code.
  6. Add the ordinary HNSW three-vector control above; compare indexed Top-K before/after its FORCE_SYNC and confirm the base table still contains three rows.

The same side-effecting APPLY can attach to distributed scan scopes under normal scheduling; IsSingle only constrains each scope's parallelism. The small-row harness forces placement to expose that path cheaply. We have not yet reproduced the incident's exact natural placement selection without the probe.

Additional information

Code facts and failure chain

All links below are pinned to the incident commit.

  1. Compile.compileApply attaches CROSS APPLY to each input scope. For these build TVFs, IsSingle sets Mcpu=1; it does not gather inputs onto the transaction-owning coordinator. The mo_view_columns origin-session exception does not cover them.
  2. generateProcessHelper restores a transaction from its snapshot. newTxnOperatorWithSnapshot marks it as a mirror. The remote server binds a separate local disttae.Transaction workspace.
  3. sqlexec.RunSql borrows that process transaction via WithTxn(...). txnExecutor.commit does not commit executor-borrowed transactions. The remote builder's ordinary workspace writes are not returned as coordinator workspace entries by the SELECT pipeline result path.
  4. FULLTEXT2 buildAndRegisterCDC clears the old base/tail in the coordinator rebuild transaction; fulltext2CreateState.sealSegment writes replacement metadata/chunks through the borrowed process transaction. A remote replacement is therefore missing from the committed state.
  5. hnswCreateState.end also performs clear/rebuild SQL through its process transaction. A zero-input local scope can clear while the source-bearing remote scope writes an uncommitted replacement.

Counterfactual and negative controls

A temporary diagnostic change gathered inputs onto c.newMergeScope(rs) only for fulltext2_create / hnsw_create, leaving the forced distributed source scan unchanged. On the incident code this restored:

  • all six long-token query results;
  • direct/scalar/correlated short-word matches;
  • nonempty metadata/chunk tables;
  • normal HNSW Top-K;
  • the extreme HNSW query's expected 20101 overflow error.

This is a causal diagnostic, not a published or fully reviewed production fix. The temporary change was removed.

The default three-row SQL also passes without forced placement, including a local 1 TP + 2 AP role configuration. Merely having multiple CNs is not sufficient to reproduce.

Regression status and remaining uncertainty

  • The distributed-path defect was reproduced on older 52eecb55..., incident 32f54981..., and latest checked main b75086c6...; it is not fixed in latest main.
  • No introducing commit is established. The previous-night pass does not prove the latest 15 commits introduced this defect. Different physical object/worker placements produce different outcomes even on the same code.
  • The incident logs show empty HNSW model state and successful synchronous rebuild statements, but do not retain the decisive per-builder CN/mirror/workspace trace. Therefore the local defect is confirmed, while attributing every incident mismatch to it remains a leading explanation, not a completed production RCA.
  • Internal index SQL disables normal executor SQL logging. Absence of INSERT lines in the incident log is not evidence that INSERTs did not execute. Similarly, a build SELECT's zero result batch size does not prove that its source scan was empty.
  • No base-table data loss, OOM, or restart is demonstrated by this finding. The demonstrated impact is silent incorrect indexed query results and loss of the replacement index state.

Existing issue comparison

Duplicate searches covered FULLTEXT2/HNSW + remote, empty, rebuild, FORCE_SYNC, mirror transaction, and workspace across recent open/closed issues, followed by reading the plausible matches above. No issue accurately tracking this remote builder write/commit ownership defect was found.

Activity

  1. added
    kind/bug
    on Oct 2, 2026
  2. LeftHandCold commented on Oct 2, 2026

    @LeftHandCold
    CollaboratorAuthor

    Confirmed defect and main fix

    Submitted PR #29568,
    targeting main, head 41238efc092c1f013a61d047a119982b242ccae8, based on
    d50a2d475a406829f67127fef7b2ad4abc1c1d3d.

    The controlled root cause is a transaction-workspace ownership defect,
    not long-token normalization or ordinary cache freshness:

    distributed source scan
      -> fulltext2_create / hnsw_create attached to a remote input scope
      -> remote process uses a mirror transaction and separate workspace
      -> builder's internal index INSERTs succeed in that workspace
      -> SELECT results do not return its workspace write entries
      -> initiating transaction commits without the replacement index writes
      -> FORCE_SYNC returns success, but indexed queries silently miss rows
    

    IsSingle establishes one worker per scope, not one transaction-owning
    coordinator for the statement. Executor-borrowed transactions are not
    independently committed. For HNSW, a local zero-input builder can additionally
    clear the old generation while the source-bearing remote builder's
    replacement is lost. The base-table rows remain intact in this reproduction.

    Fix boundary

    The patch opts only fulltext2_create and hnsw_create into coordinator
    placement through the existing plugin registry. The compiler gathers their
    inputs through its existing merge scope before invoking the writer, for both
    APPLY and child-bearing table-function execution. Standalone TVFs already run
    locally. This makes the original transaction own clear and replacement writes
    together, without adding a remote-write protocol or changing commit behavior.

    Source scans remain distributed and retain their parallelism. Searches and
    ordinary TVFs retain their placement. No tokenizer/search algorithm, on-disk
    format, WAL/Raft, retry, background worker, or generation-cache changes.

    Pre-fix / post-fix evidence

    The retained regression uses a real public MySQL frontend, two CNs, three
    rows per algorithm, and public DN flush to persist the source. It uses the
    existing scoped multi-CN classification hook only for the scan probe and
    rebuild, and rebuilds from both coordinators. This does not mock the
    builder, executor, transaction, storage, or remote transport. Default tiny
    query scheduling remains a passing control rather than a standalone trigger.

    Check Pre-fix Fixed head
    FULLTEXT2 indexed MATCH after successful rebuild On clean 52eecb55: empty instead of IDs 1,3 IDs 1,3 from rebuilds initiated on both CNs
    Ordinary HNSW Top-K after successful rebuild On clean 52eecb55: empty instead of IDs 1,2,3 IDs 1,2,3 from both coordinators
    Typed builder placement On b75086c6: all four CROSS/OUTER builder cases fail; view/search controls pass One origin-owned writer, distributed inputs unchanged
    Replacement metadata and source rows Earlier traced reproduction loses committed index rows while base rows survive New non-null generation, base count remains 3
    Empty-source rebuild inside a transaction Not claimed as pre-fix passing evidence Old index cleared; rollback restores source, indexed results, and prior metadata generation

    Final local validation completed with exit 0:

    • Four changed owning packages: full normal tests with -vet=all, and full
      -race tests.
    • Entire pkg/tests/sqlintegration/multicn: all three tests executed and
      passed, 61.806s, including existing join/view placement controls.
    • Exact two-CN rebuild regression under -race: 20.48s, both algorithms and
      rollback/empty-input checks passed.
    • Registry placement test: 100 focused race repetitions passed; unchanged
      source evidence reused across the final rebase.
    • Existing dependent APPLY and FULLTEXT2/HNSW builder tests passed, including
      invalid-input and empty/end controls.

    These tests ran locally on macOS, not server 50 or the original TKE
    environment. The new public regression costs about 19 seconds in normal mode.
    The seven-file patch has approximately 40 added production lines; the rest
    is focused test coverage. Final self-review found no unresolved blockers.

    Remaining boundaries

    • This fixes the confirmed remote-writer defect. The original nightly lacks
      the decisive builder-CN/mirror trace, so every historical mismatch is not
      independently attributed by this fix.
    • No introducing commit is established; this is not proof of a regression
      introduced by the incident day's commits.
    • Gathered build input can add network traffic and concentrate build work.
      Full-scale build throughput/memory was not benchmarked. Ordinary search
      runtime is unchanged; this is not a claim of zero risk for all workloads.
    • No 4.2 backport is included. PR CI is currently pending/running, not passed.
  3. LeftHandCold commented on Oct 4, 2026

    @LeftHandCold
    CollaboratorAuthor

    Verified the fix against the latest completed scheduled Main nightly and the mechanism-specific regression. Closing the confirmed remote-builder transaction/workspace ownership defect as fixed by #29568.

    • Fix actually included: fix(index): keep synchronous FULLTEXT2 and HNSW builders on coordinator #29568 merged as d59cc02ef6ca68f340c9570e56f7eb71d90e42e7. Run 37135891536 deployed MO c1c8ea97477dd12a79cb1991d283905ca9ebf3a5; the fix is its ancestor, verified by commit comparison.
    • Original nightly assertions recovered: MOTR job records issue_29079_29276_fulltext_query_contracts 34/34 and issue_29050_hnsw_score_consistency 17/17 passing. Both SQL and expected-result files are byte-identical to incident MOTR 957dd0c; current MOTR is 569655bad03d26de8022ee8944912c3c1da877d1. The HNSW overflow assertion is still enforced.
    • Placement-specific protection: TestIssue29566IndexRebuildCoordinator uses a real two-CN cluster, forced distributed source scans with peer-plan verification, and rebuilds through both coordinators. It checks FULLTEXT2/HNSW indexed results, replacement metadata generation, intact source rows, empty-input handling and rollback. The PR Ubuntu UT job explicitly shows this test running and the UT stage succeeding. Its source is unchanged in the nightly-tested MO. This supplements the existing controlled before/after validation; ordinary nightly placement alone would not establish the remote-path fix.

    Scope: Main's confirmed synchronous rebuild ownership defect. The overall nightly/MOTR job still has unrelated failures. This does not certify a 4.2 backport, all cache-invalidation behavior, or prove every historical mismatch had the same cause.

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s-1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions