[txn] 1PC can commit with an obsolete schema after concurrent DDL and corrupt a newly added index when MDL is off
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
> Evidence status: confirmed.
### 1. Minimal reproduce step (Required)
On exact TiDB commit 5c9198e9484d with tidb_enable_metadata_lock=OFF, enable 1PC and pause tikvclient/beforePrewrite once. Start INSERT INTO t VALUES (1,10), wait until it is paused after calculateMaxCommitTS, execute ALTER TABLE t ADD INDEX idx_v(v), then release the pause. Capture @@tidb_last_txn_info, the DDL history FinishedTS, table and forced-index rowsets, and ADMIN CHECK TABLE. The reusable script is scaffolds/top-level/ai_native_onepc_schema_horizon_probe.sh. The same matrix was executed on testbed 8220955 against three real TiKV nodes.
### 2. What did you expect to see? (Required)
If the DML commitTS is later than the DDL FinishedTS, the write must be validated against and applied with the new schema, or return a retryable schema-change error. A successful commit must preserve table/index consistency and must not write an obsolete table identity.
### 3. What did you see instead? (Required)
The ADD INDEX run returned txn_commit_mode=1pc and commit_ts greater than the DDL FinishedTS. The table scan returned 1:10, FORCE INDEX(idx_v) returned no row, and ADMIN CHECK TABLE failed. The paired 2PC run retried and returned 1:10 through both paths with ADMIN CHECK passing. The TRUNCATE sibling returned success with commitTS greater than FinishedTS while the current table was empty.
### 4. What is your TiDB version? (Required)
TiDB 5c9198e9484d and client-go 661db4f5f4e8; exact-commit testbed 8220955 with real TiKV confirmed
Likely root cause and fix direction
When MDL is disabled, TiDB installs a delta SchemaChecker. client-go calls it from calculateMaxCommitTS before beforePrewrite, then 1PC asks TiKV to atomically prewrite and commit. Unlike 2PC, the successful 1PC branch returns immediately and never validates the schema at its actual commitTS. A DDL completed in that interval can therefore be older than the 1PC commitTS while the mutation still uses the obsolete table/index key set.
Contributor guide
Research direction
Start with scaffolds/top-level/ai_native_onepc_schema_horizon_probe.sh and reproduce the ADD INDEX case on the stated TiDB commit with metadata locking off. Trace calculateMaxCommitTS, tikvclient/beforePrewrite, and the successful 1PC branch, comparing them with the 2PC retry path. Done means a commit after DDL validation either uses the new schema or returns a retryable schema-change error, with both table and forced-index scans passing ADMIN CHECK TABLE.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100