pingcap / pingcap/tidb

ddl: scatter may fail before TiFlash placement rules are satisfied when tidb_scatter_region is enabled

Open
#68,401 4 comments 0 reactions 0 assignees View on GitHub
component/ddl severity/minor type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

Prepare a TiDB cluster with TiFlash available and enable region scatter for DDL-created ranges:

```sql
SET GLOBAL tidb_scatter_region = 'TABLE';
```

Create a table that has TiFlash replica configured. The table should use DDL paths that create new physical table ranges and trigger split/scatter, for example `TRUNCATE TABLE`:

```sql
CREATE TABLE t (
id BIGINT PRIMARY KEY
) SHARD_ROW_ID_BITS = 4 PRE_SPLIT_REGIONS = 2;

ALTER TABLE t SET TIFLASH REPLICA 1;

-- Wait until the original TiFlash replica is available if needed.
SELECT * FROM information_schema.tiflash_replica WHERE TABLE_NAME = 't';

TRUNCATE TABLE t;
```

The same issue can happen for DDL paths that create new physical table/partition ranges and then scatter them while the table also has TiFlash replica placement rules.

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

For a table with TiFlash replica and `tidb_scatter_region` enabled, DDL should wait until the corresponding TiFlash placement rules are satisfied for the newly created physical table ranges before triggering scatter.

The DDL should complete without PD rejecting or failing the scatter request due to placement rules not being satisfied yet.

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

The DDL creates new physical table ranges and triggers scatter before the TiFlash replica placement rules become satisfied.

PD requires the region replicas to satisfy the placement rules before scatter can proceed. Because the TiFlash placement is still pending, the scatter operation can fail. The DDL currently logs the scatter failure and continues, so the newly created ranges may not be scattered as expected.

This affects scenarios such as `TRUNCATE TABLE` when the table has TiFlash replica and `tidb_scatter_region` is set to `TABLE` or `GLOBAL`.

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

v8.5.5

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.