Skip to content

Commit b2b20a6

Browse files
committed
sync changes from the zh PR
1 parent cd201ed commit b2b20a6

File tree

5 files changed

+93
-62
lines changed

5 files changed

+93
-62
lines changed

TOC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@
772772
- [`BATCH`](/sql-statements/sql-statement-batch.md)
773773
- [`BEGIN`](/sql-statements/sql-statement-begin.md)
774774
- [`CALIBRATE RESOURCE`](/sql-statements/sql-statement-calibrate-resource.md)
775+
- [`CANCEL DISTRIBUTION JOB`](/sql-statements/sql-statement-cancel-distribution-job.md)
775776
- [`CANCEL IMPORT JOB`](/sql-statements/sql-statement-cancel-import-job.md)
776777
- [`COMMIT`](/sql-statements/sql-statement-commit.md)
777778
- [`CREATE BINDING`](/sql-statements/sql-statement-create-binding.md)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: CANCEL DISTRIBUTION JOB
3+
summary: An overview of the usage of CANCEL DISTRIBUTION JOB in TiDB.
4+
---
5+
6+
# CANCEL DISTRIBUTION JOB
7+
8+
The `CANCEL DISTRIBUTION JOB` statement is used to cancel a Region scheduling task created using the [`DISTRIBUTE TABLE`](/sql-statements/sql-statement-distribute-table.md) statement in TiDB.
9+
10+
## Syntax diagram
11+
12+
```ebnf+diagram
13+
CancelDistributionJobsStmt ::=
14+
'CANCEL' 'DISTRIBUTION' 'JOB' JobID
15+
```
16+
17+
## Examples
18+
19+
The following example cancels the distribution job with ID `1`:
20+
21+
```sql
22+
CANCEL DISTRIBUTION JOB 1;
23+
```
24+
25+
The output is as follows:
26+
27+
```
28+
Query OK, 0 rows affected (0.01 sec)
29+
```
30+
31+
## MySQL compatibility
32+
33+
This statement is a TiDB extension to MySQL syntax.
34+
35+
## See also
36+
37+
* [`DISTRIBUTE TABLE`](/sql-statements/sql-statement-distribute-table.md)
38+
* [`SHOW DISTRIBUTION JOBS`](/sql-statements/sql-statement-show-distribution-jobs.md)

sql-statements/sql-statement-distribute-table.md

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,38 @@ The `DISTRIBUTE TABLE` statement redistributes and reschedules Regions of a spec
1111

1212
```ebnf+diagram
1313
DistributeTableStmt ::=
14-
"DISTRIBUTE" "TABLE" TableName PartitionNameList? EngineOption? RoleOption?
14+
"DISTRIBUTE" "TABLE" TableName PartitionNameListOpt "RULE" EqOrAssignmentEq Identifier "ENGINE" EqOrAssignmentEq Identifier "TIMEOUT" EqOrAssignmentEq Identifier
1515
1616
TableName ::=
1717
(SchemaName ".")? Identifier
1818
1919
PartitionNameList ::=
2020
"PARTITION" "(" PartitionName ("," PartitionName)* ")"
21+
```
2122

22-
EngineOption ::=
23-
"ENGINE" Expression
23+
## Parameter description
2424

25-
RoleOption ::=
26-
"Role" Expression
27-
```
25+
When redistributing Regions in a table using the `DISTRIBUTE TABLE` statement, you can specify the storage engine (such as TiFlash or TiKV) and different Raft roles (such as Leader, Learner, or Voter) for balanced distribution.
2826

29-
## Examples
27+
- `RULE`: specifies which Raft role's Region to balance and schedule. Optional values are `"leader-scatter"`, `"peer-scatter"`, and `"learner-scatter"`.
28+
- `ENGINE`: specifies the storage engine. Optional values are `"tikv"` and `"tiflash"`.
29+
- `TIMEOUT`: specifies the timeout limit for the scatter operation. If PD does not complete the scatter within this time, the scatter task will automatically exit. When this parameter is not specified, the default value is `"30m"`.
3030

31-
When redistributing Regions using the `DISTRIBUTE TABLE` statement, you can specify the storage engine (such as TiFlash or TiKV) and different Raft roles (such as Leader, Learner, or Voter) for balanced distribution.
31+
## Examples
3232

3333
Redistribute the Regions of the Leaders in the table `t1` on TiKV:
3434

3535
```sql
3636
CREATE TABLE t1 (a INT);
3737
...
38-
DISTRIBUTE TABLE t1 engine tikv role leader
38+
DISTRIBUTE TABLE t1 RULE="leader-scatter" ENGINE="tikv" TIMEOUT="1h";
3939
```
4040

4141
```
4242
+---------+
4343
| JOB_ID |
44-
100
44+
+---------+
45+
| 100 |
4546
+---------+
4647
```
4748

@@ -50,63 +51,53 @@ Redistribute the Regions of the Learners in the table `t2` on TiFlash:
5051
```sql
5152
CREATE TABLE t2 (a INT);
5253
...
53-
DISTRIBUTE TABLE t2 ENGINE tiflash role learner;
54+
DISTRIBUTE TABLE t2 RULE="learner-scatter" ENGINE="tiflash";
5455
```
5556

5657
```
5758
+---------+
5859
| JOB_ID |
59-
101
60+
+---------+
61+
| 101 |
6062
+---------+
6163
```
6264

63-
Redistribute the Regions of the Leaders in the table `t3`'s `p1` and `p2` partitions on TiKV:
65+
Redistribute the Regions of the Peers in the table `t3`'s `p1` and `p2` partitions on TiKV:
6466

6567
```sql
66-
CREATE TABLE t3 (a INT);
68+
CREATE TABLE t3 ( a INT, b INT, INDEX idx(b)) PARTITION BY RANGE( a ) (
69+
PARTITION p1 VALUES LESS THAN (10000),
70+
PARTITION p2 VALUES LESS THAN (20000),
71+
PARTITION p3 VALUES LESS THAN (MAXVALUE) );
6772
...
68-
DISTRIBUTE TABLE t3 PARTITION (p1, p2) ENGINE tikv role leader;
73+
DISTRIBUTE TABLE t3 PARTITION (p1, p2) RULE="peer-scatter" ENGINE="tikv";
6974
```
7075

7176
```
7277
+---------+
7378
| JOB_ID |
74-
102
79+
+---------+
80+
| 102 |
7581
+---------+
7682
```
7783

78-
Execute the [`SHOW DISTRIBUTION JOBS`](/sql-statements/sql-statement-show-distribution-jobs.md) statement to view all distribution jobs:
79-
80-
```sql
81-
SHOW DISTRIBUTION JOBS;
82-
```
83-
84-
```
85-
+---------+------------+------------+-----------------+------------+-----------+----------+-------------+---------------+
86-
| JOB_ID | DB_NAME | TABLE_NAME | PARTITION_NAMES | ENGINE_TYPE | ROLE_TYPE | STATUS | CREATE_USER | CREATE_TIME |
87-
+---------+------------+------------+-----------------+------------+-----------+--------+---------------+---------------+
88-
| 1 | db_1 | t1 | | TIKV | LEADER | RUNNING | ADMIN | 20240712 |
89-
| 2 | db_1 | t2 | | TIFLASH | LEARNER | FINISHED | ADMIN | 20240715 |
90-
| 3 | db_1 | t3 | | TiKV | VOTER | STOPPED | ADMIN | 20240713 |
91-
| 4 | db_1 | t4 | | TIFLASH | LEARNER | FINISHED | ADMIN | 20240713 |
92-
+---------+------------+------------+-----------------+------------+-----------+----------+-------------+---------------+
93-
```
94-
95-
Execute the [`SHOW TABLE DISTRIBUTION`](/sql-statements/sql-statement-show-table-distribution.md) statement to view the Region distribution of the table `t1`:
84+
Redistribute the Regions of the Leaders in the table `t4`'s `p1` and `p2` partitions on TiFlash:
9685

9786
```sql
98-
SHOW TABLE DISTRIBUTION t1;
87+
CREATE TABLE t4 ( a INT, b INT, INDEX idx(b)) PARTITION BY RANGE( a ) (
88+
PARTITION p1 VALUES LESS THAN (10000),
89+
PARTITION p2 VALUES LESS THAN (20000),
90+
PARTITION p3 VALUES LESS THAN (MAXVALUE) );
91+
...
92+
DISTRIBUTE TABLE t4 PARTITION (p1, p2) RULE="leader-scatter" ENGINE="tiflash";
9993
```
10094

10195
```
102-
+---------+------------+----------------+----------+------------+-------------------+--------------------+-----------------+------------------+
103-
| DB_NAME | TABLE_NAME | PARTITION_NAME | STORE_ID | STORE_TYPE | REGION_LEADER_NUM | REGION_LEADER_BYTE | REGION_PEER_NUM | REGION_PEER_BYTE |
104-
+---------+------------+----------------+----------+------------+-------------------+--------------------+-----------------+------------------+
105-
| db_1 | t1 | | 1 | TiKV | 315 | 24057934521 | 1087 | 86938746542 |
106-
| db_1 | t1 | | 2 | TiKV | 324 | 28204839240 | 1104 | 91039476832 |
107-
| db_1 | t1 | | 3 | TiKV | 319 | 25986274812 | 1091 | 89405367423 |
108-
| db_1 | t1 | | 4 | TiKV | 503 | 41039587625 | 1101 | 90482317797 |
109-
+---------+------------+----------------+----------+------------+-------------------+--------------------+-----------------+------------------+
96+
+---------+
97+
| JOB_ID |
98+
+---------+
99+
| 103 |
100+
+---------+
110101
```
111102

112103
## Notes
@@ -121,4 +112,5 @@ This statement is a TiDB extension to MySQL syntax.
121112

122113
- [`SHOW DISTRIBUTION JOBS`](/sql-statements/sql-statement-show-distribution-jobs.md)
123114
- [`SHOW TABLE DISTRIBUTION`](/sql-statements/sql-statement-show-table-distribution.md)
124-
- [`SHOW TABLE REGIONS`](/sql-statements/sql-statement-show-table-regions.md)
115+
- [`SHOW TABLE REGIONS`](/sql-statements/sql-statement-show-table-regions.md)
116+
- [`CANCEL DISTRIBUTION JOB`](/sql-statements/sql-statement-cancel-distribution-job.md)

sql-statements/sql-statement-show-distribution-jobs.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ SHOW DISTRIBUTION JOBS;
2323
```
2424

2525
```
26-
+---------+------------+------------+-----------------+------------+-----------+----------+-------------+---------------+
27-
| JOB_ID | DB_NAME | TABLE_NAME | PARTITION_NAMES | ENGINE_TYPE | ROLE_TYPE | STATUS | CREATE_USER | CREATE_TIME |
28-
+---------+------------+------------+-----------------+------------+-----------+--------+---------------+---------------+
29-
| 1 | db_1 | t1 | | TIKV | LEADER | RUNNING | ADMIN | 20240712 |
30-
| 2 | db_1 | t2 | | TIFLASH | LEARNER | FINISHED | ADMIN | 20240715 |
31-
| 3 | db_1 | t3 | | TiKV | VOTER | STOPPED | ADMIN | 20240713 |
32-
| 4 | db_1 | t4 | | TIFLASH | LEARNER | FINISHED | ADMIN | 20240713 |
33-
+---------+------------+------------+-----------------+------------+-----------+----------+-------------+---------------+
26+
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+
27+
| Job_ID | Database | Table | Partition_List | Engine | Rule | Status | Create_Time | Start_Time | Finish_Time |
28+
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+
29+
| 100 | test | t1 | NULL | tikv | leader-scatter | finished | 2025-04-24 16:09:55 | 2025-04-24 16:09:55 | 2025-04-24 17:09:59 |
30+
| 101 | test | t2 | NULL | tikv | learner-scatter| cancelled | 2025-05-08 15:33:29 | 2025-05-08 15:33:29 | 2025-05-08 15:33:37 |
31+
| 102 | test | t5 | p1,p2 | tikv | peer-scatter | cancelled | 2025-05-21 15:32:44 | 2025-05-21 15:32:47 | 2025-05-21 15:32:47 |
32+
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+
3433
```
3534

3635
## MySQL compatibility
@@ -40,4 +39,5 @@ This statement is a TiDB extension to MySQL syntax.
4039
## See also
4140

4241
- [`DISTRIBUTE TABLE`](/sql-statements/sql-statement-distribute-table.md)
43-
- [`SHOW TABLE DISTRIBUTION`](/sql-statements/sql-statement-show-table-distribution.md)
42+
- [`SHOW TABLE DISTRIBUTION`](/sql-statements/sql-statement-show-table-distribution.md)
43+
- [`CANCEL DISTRIBUTION JOB`](/sql-statements/sql-statement-cancel-distribution-job.md)

sql-statements/sql-statement-show-table-distribution.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ SHOW TABLE DISTRIBUTION t1;
2626
```
2727

2828
```
29-
+---------+------------+----------------+----------+------------+-------------------+--------------------+-----------------+------------------+
30-
| DB_NAME | TABLE_NAME | PARTITION_NAME | STORE_ID | STORE_TYPE | REGION_LEADER_NUM | REGION_LEADER_BYTE | REGION_PEER_NUM | REGION_PEER_BYTE |
31-
+---------+------------+----------------+----------+------------+-------------------+--------------------+-----------------+------------------+
32-
| db_1 | t1 | | 1 | TiKV | 315 | 24057934521 | 1087 | 86938746542 |
33-
| db_1 | t1 | | 2 | TiKV | 324 | 28204839240 | 1104 | 91039476832 |
34-
| db_1 | t1 | | 3 | TiKV | 319 | 25986274812 | 1091 | 89405367423 |
35-
| db_1 | t1 | | 4 | TiKV | 503 | 41039587625 | 1101 | 90482317797 |
36-
+---------+------------+----------------+----------+------------+-------------------+--------------------+-----------------+------------------+
29+
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+
30+
| Job_ID | Database | Table | Partition_List | Engine | Rule | Status | Create_Time | Start_Time | Finish_Time |
31+
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+
32+
| 100 | test | t1 | NULL | tikv | leader-scatter | finished | 2025-04-24 16:09:55 | 2025-04-24 16:09:55 | 2025-04-24 17:09:59 |
33+
| 101 | test | t2 | NULL | tikv | learner-scatter| cancelled | 2025-05-08 15:33:29 | 2025-05-08 15:33:29 | 2025-05-08 15:33:37 |
34+
| 102 | test | t5 | p1,p2 | tikv | peer-scatter | cancelled | 2025-05-21 15:32:44 | 2025-05-21 15:32:47 | 2025-05-21 15:32:47 |
35+
+--------+----------+-------+----------------+--------+----------------+-----------+---------------------+---------------------+---------------------+
3736
```
3837

3938
## MySQL compatibility
@@ -43,4 +42,5 @@ This statement is a TiDB extension to MySQL syntax.
4342
## See also
4443

4544
- [`DISTRIBUTE TABLE`](/sql-statements/sql-statement-distribute-table.md)
46-
- [`SHOW DISTRIBUTION JOBS`](/sql-statements/sql-statement-show-distribution-jobs.md)
45+
- [`SHOW DISTRIBUTION JOBS`](/sql-statements/sql-statement-show-distribution-jobs.md)
46+
- [`CANCEL DISTRIBUTION JOB`](/sql-statements/sql-statement-cancel-distribution-job.md)

0 commit comments

Comments
 (0)