Skip to content

[Bug]: TestIssue28931 queries a new index before the cross-CN commit fence #32975

Done

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

#28931 and #32244 track the production CREATE INDEX/concurrent DML correctness problem. This issue is specifically about the regression test's missing cross-CN commit fence before index-dependent assertions; it is not a claim that the production data-loss race has returned.

Branch Name

main and 4.2-dev

Commit ID

  • main: c33ce3ff8e7555c8053c85693e55e93e73d898b7
  • Failing 4.2-dev PR revision: efe8fb12e41da43bbc81689f58a96c3ae917b2e2

Other Environment Information

Actual Behavior

The regular-index subtest can fail immediately after CREATE INDEX returns success:

Error 1176 (42000): Key 'ix_payload' doesn't exist in table 'regular_update'

The failing statement is executed on writer CN:

SELECT COUNT(*), COALESCE(SUM(id), 0)
FROM regular_update IGNORE INDEX(ix_payload)
WHERE payload = 'changed';

On main, the subtest waits for ddlDone and immediately runs IGNORE/FORCE INDEX queries without a cross-CN commit fence:

waitForPlan, release := issue289InstallPlanBarrier(t, ctx, issue289CreateIndexPlanCompiled, 1)
ddlDone := make(chan error, 1)
go func() {
_, err := ddlDB.ExecContext(ctx, "create index ix_payload on "+table+" (payload)")
ddlDone <- err
}()
waitForPlan()
execSQLRequire(t, ctx, writerDB, "update "+table+" set payload = 'changed' where id = 1")
release()
require.NoError(t, <-ddlDone)
var scannedCount, scannedSum, indexedCount, indexedSum int
require.NoError(t, writerDB.QueryRowContext(ctx,
"select count(*), coalesce(sum(id), 0) from "+table+" ignore index(ix_payload) where payload = 'changed'").
Scan(&scannedCount, &scannedSum))
require.NoError(t, writerDB.QueryRowContext(ctx,
"select count(*), coalesce(sum(id), 0) from "+table+" force index(ix_payload) where payload = 'changed'").
Scan(&indexedCount, &indexedSum))
require.Equal(t, 1, scannedCount)
require.Equal(t, 1, scannedSum)
require.Equal(t, scannedCount, indexedCount)
require.Equal(t, scannedSum, indexedSum)

On the failing 4.2-dev revision, syncAuthenticatedClusterCommit is present but placed after those queries:

waitForPlan, finishDDL := issue289StartPlanBlockedDDL(t, ctx, ddlDB, "create index ix_payload on "+table+" (payload)")
waitForPlan()
execSQLRequire(t, ctx, writerDB, "update "+table+" set payload = 'changed' where id = 1")
require.NoError(t, finishDDL())
var scannedCount, scannedSum, indexedCount, indexedSum int
require.NoError(t, writerDB.QueryRowContext(ctx,
"select count(*), coalesce(sum(id), 0) from "+table+" ignore index(ix_payload) where payload = 'changed'").
Scan(&scannedCount, &scannedSum))
require.NoError(t, writerDB.QueryRowContext(ctx,
"select count(*), coalesce(sum(id), 0) from "+table+" force index(ix_payload) where payload = 'changed'").
Scan(&indexedCount, &indexedSum))
require.Equal(t, 1, scannedCount)
require.Equal(t, 1, scannedSum)
require.Equal(t, scannedCount, indexedCount)
require.Equal(t, scannedSum, indexedSum)
syncAuthenticatedClusterCommit(t, ctx, cluster)

Thus finishDDL()/<-ddlDone only establishes DDL completion on ddl CN. It does not establish that writer CN has applied and synchronized the corresponding commit timestamp.

Expected Behavior

After CREATE INDEX succeeds and before any index-dependent assertion, the test should establish the suite's existing cross-CN fence:

require.NoError(t, finishDDL()) // or require.NoError(t, <-ddlDone) on main
syncAuthenticatedClusterCommit(t, ctx, cluster)

// Run IGNORE INDEX, FORCE INDEX, and physical-index assertions only here.

syncAuthenticatedClusterCommit waits for every CN's timestamp waiter to reach the maximum observed commitTS and calls SyncLatestCommitTS, which is the synchronization this cross-CN assertion requires.

The test should not use sleep or retry to hide the ordering problem.

Steps to Reproduce

  1. Run TestIssue28931StaleUpdatePlanCannotBypassNewIndex/regular_index_includes_the_update with its existing plan barrier and two CN endpoints.
  2. Pause CREATE INDEX planning on ddl CN and execute the writer UPDATE.
  3. Release CREATE INDEX and wait only for the DDL call to return.
  4. Immediately run IGNORE INDEX(ix_payload) on writer CN, before syncAuthenticatedClusterCommit.
  5. Depending on cross-CN apply timing, the query can fail with error 1176 instead of testing index/table result consistency.

Additional information

The CI log shows that the SELECT snapshot did not include the index commit:

CREATE INDEX snapshot/start = 1795150050975226628-1
CREATE INDEX commit         = 1795150050977581583-0
SELECT snapshot             = 1795150050975226628-1

This is consistent with the missing test fence. Move/add the fence immediately after DDL success on both branches. If the index is still absent after the fence, investigate production snapshot/catalog invalidation separately.

Related:

#32244 also records an earlier error-1176 observation whose root cause was left unresolved; this report does not assume that observation had the same cause without its own fence evidence.

Activity

  1. added
    kind/bug
    on Nov 20, 2026
  2. slyunnn commented on Nov 23, 2026

    @slyunnn

    Partially fixed — #32975 4.2-dev fence verified; main fix pending (2026-11-23)

    Merged 4.2-dev fix: #32977, 53b3bc7c95c500de89a60001d947001c5d77d958 — [4.2-dev] fix(test): establish the cross-CN commit fence before TestIssue28931 index queries.

    Verified latest fetched 4.2-dev@f811a8673b44f592e5f60db10843de119d662e89 — fix(tae): bound catalog replay input memory (#33078), Go 1.26.5 on macOS/arm64. The corrected TestIssue28931StaleUpdatePlanCannotBypassNewIndex ran twice, using its actual embedded two-CN MySQL clients and deterministic plan barrier. All six subtests passed in both runs (14 parent/subtest pass events total), including regular-index visibility, stale unique conflict, admitted writers, rollback and canceled index creation. No 1176 occurred. Source inspection confirms syncAuthenticatedClusterCommit runs immediately after successful finishDDL(), before IGNORE INDEX, FORCE INDEX and physical-index assertions. No sleep or retry substitutes for the fence.

    A separate full 2 CN / 1 TN / 1 Log service / Proxy deployment at the same service commit passed actual SQL and recovery checks on Proxy 6001, CN1 16001, CN2 16002. Those endpoint checks are not presented as the internal plan-barrier test.

    The latest main source e17d5541537d30252009a9a2d4c70ab5480d3bc3 still lacks this fence immediately before the hinted queries. Its change from the initially fetched f86cc46cfc5d5e4a0e2e52af6e4cbd58f9f9c449 is the unrelated TN recovery port #33090. No merged main fence was found, so main regression was skipped, as requested. Suggested remaining action: merge the main counterpart with the same ordering; if visibility still fails after that fence, investigate catalog/snapshot invalidation separately.

    No additional large data is needed: the defect is deterministic cross-CN assertion ordering. The existing owning test already supplies the necessary barrier and timestamp waiter; a SQL-only MOTR duplicate would not assert either and was not added. This is not a claim that the historical production CREATE INDEX/DML issue has recurred or is fully revalidated.

    Conclusion: 4.2-dev test-fence repair verified; main remains pending. Keep the issue open without a close label.

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions