pingcap / pingcap/tidb

[import] NextGen IMPORT INTO can report success after writing the full input into a truncated table generation

Open
#70,088 1 comment 0 reactions 0 assignees View on GitHub
component/import found-by-ai may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)

**Environment**

TiDB master 231dad5225f0; NextGen user and SYSTEM keyspaces; CSE TiKV server/worker ce46fc5067; PD 8.5.4; MDL enabled

**Steps**

Run NextGen with a user keyspace and a CSE TiKV worker. Stop the worker; create empty t; submit file IMPORT INTO t WITH DETACHED; after the job and DXF task are queued, TRUNCATE TABLE t and insert a marker into the new generation; restart the worker; wait for finished; compare the current table and a raw record-prefix scan of the pre-TRUNCATE table ID.

### 2. What did you expect to see? (Required)

TRUNCATE is blocked while the import owns the table, or the scheduler/worker rejects the task because the persisted target generation is no longer live.

### 3. What did you see instead? (Required)

The job reports finished with row-count 2. Current t, whose ID changed from 44 to 46, contains only the post-TRUNCATE marker. Both imported records exist under retired table ID 44, and ADMIN CHECK TABLE t succeeds.

### 4. What is your TiDB version? (Required)

TiDB master 231dad5225f0; NextGen user and SYSTEM keyspaces; CSE TiKV server/worker ce46fc5067; PD 8.5.4; MDL enabled

Likely root cause and fix direction

**Likely root cause**

NewImportPlan snapshots TableInfo and table ID. Classic IMPORT INTO sets TableModeImport, but NextGen user-keyspace submission skips it and commits a user job before creating a SYSTEM-keyspace DXF task. Scheduler preparation and the CSE task executor never bind the cached ID to a live table generation; the executor reconstructs a table from cached TableInfo and completion records statistics against the same retired ID.

**Fix direction**

Persist the target generation identity and revalidate it before preparation and before the first irreversible write. Add a NextGen-compatible table-operation fence or generation lease so TRUNCATE/DROP cannot retire an active import target. Fail closed and cancel the job when the generation differs.

Contributor guide

Open the contributing guide

Research direction

Start with the NextGen IMPORT INTO submission path, then trace scheduler preparation and the CSE task executor described in the report. Reproduce the detached import with TRUNCATE TABLE between queuing and worker restart, and inspect how the cached table ID is used. Done means a retired generation is rejected or fenced before writes, and the job cannot report success for that generation.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.