TiDB Data Migration 查询状态
本文介绍 TiDB Data Migration (DM) query-status 命令的查询结果、任务状态与子任务状态。
查询结果
1. » query-status
1. {
2. "result": true, # 查询是否成功
3. "msg": "", # 查询失败原因描述
4. "tasks": [ # 迁移 task 列表
5. {
6. "taskName": "test", # 任务名称
7. "taskStatus": "Running", # 任务运行状态
8. "sources": [ # 该任务的上游 MySQL 列表
9. "mysql-replica-01",
10. "mysql-replica-02"
11. ]
12. },
13. {
14. "taskName": "test2",
15. "taskStatus": "Paused",
16. "sources": [
17. "mysql-replica-01",
18. "mysql-replica-02"
19. ]
20. }
21. ]
22. }
关于 tasks 下的 taskStatus 状态的详细定义,请参阅任务状态。
推荐的 query-status 使用方法是:
- 首先使用 query-status 查看各个 task 的运行状态是否正常。
- 如果发现其中某一 task 状态有问题,通过
query-status <出错任务的 taskName>来得到更详细的错误信息。
任务状态
DM 的迁移任务状态取决于其分配到 DM-worker 上的子任务状态,定义见下表:
| 任务对应的所有子任务的状态 | 任务状态 |
|---|---|
| 任一子任务处于 “Paused” 状态且返回结果有错误信息 | Error - Some error occurred in subtask |
| 任一处于 Sync 阶段的子任务处于 “Running” 状态但其 Relay 处理单元未运行(处于 Error/Paused/Stopped 状态) | Error - Relay status is Error/Paused/Stopped |
| 任一子任务处于 “Paused” 状态且返回结果没有错误信息 | Paused |
| 所有子任务处于 “New” 状态 | New |
| 所有子任务处于 “Finished” 状态 | Finished |
| 所有子任务处于 “Stopped” 状态 | Stopped |
| 其他情况 | Running |
详情查询结果
1. » query-status test
1. {
2. "result": true, # 查询是否成功
3. "msg": "", # 查询失败原因描述
4. "sources": [ # 上游 MySQL 列表
5. {
6. "result": true,
7. "msg": "",
8. "sourceStatus": { # 上游 MySQL 的信息
9. "source": "mysql-replica-01",
10. "worker": "worker1",
11. "result": null,
12. "relayStatus": null
13. },
14. "subTaskStatus": [ # 上游 MySQL 所有子任务的信息
15. {
16. "name": "test", # 子任务名称
17. "stage": "Running", # 子任务运行状态,包括 “New”,“Running”,“Paused”,“Stopped” 以及 “Finished”
18. "unit": "Sync", # DM 的处理单元,包括 “Check”,“Dump“,“Load” 以及 “Sync”
19. "result": null, # 子任务失败时显示错误信息
20. "unresolvedDDLLockID": "test-`test`.`t_target`", # sharding DDL lock ID,可用于异常情况下手动处理 sharding DDL lock
21. "sync": { # 当前 `Sync` 处理单元的迁移信息
22. "totalEvents": "12", # 该子任务中迁移的 binlog event 总数
23. "totalTps": "1", # 该子任务中每秒迁移的 binlog event 数量
24. "recentTps": "1", # 该子任务中最后一秒迁移的 binlog event 数量
25. "masterBinlog": "(bin.000001, 3234)", # 上游数据库当前的 binlog position
26. "masterBinlogGtid": "c0149e17-dff1-11e8-b6a8-0242ac110004:1-14", # 上游数据库当前的 GTID 信息
27. "syncerBinlog": "(bin.000001, 2525)", # 已被 `Sync` 处理单元迁移的 binlog position
28. "syncerBinlogGtid": "", # 使用 GTID 迁移的 binlog position
29. "blockingDDLs": [ # 当前被阻塞的 DDL 列表。该项仅在当前 DM-worker 所有上游表都处于 “synced“ 状态时才有数值,此时该列表包含的是待执行或待跳过的 sharding DDL 语句
30. "USE `test`; ALTER TABLE `test`.`t_target` DROP COLUMN `age`;"
31. ],
32. "unresolvedGroups": [ # 没有被解决的 sharding group 信息
33. {
34. "target": "`test`.`t_target`", # 待迁移的下游表
35. "DDLs": [
36. "USE `test`; ALTER TABLE `test`.`t_target` DROP COLUMN `age`;"
37. ],
38. "firstPos": "(bin|000001.000001, 3130)", # sharding DDL 语句起始 binlog position
39. "synced": [ # `Sync` 处理单元已经读到该 sharding DDL 的上游分表
40. "`test`.`t2`"
41. "`test`.`t3`"
42. "`test`.`t1`"
43. ],
44. "unsynced": [ # `Sync` 处理单元未读到该 sharding DDL 的上游分表。如有上游分表未完成同步,`blockingDDLs` 为空
45. ]
46. }
47. ],
48. "synced": false # 增量复制是否已追上上游。由于后台 `Sync` 单元并不会实时刷新保存点,当前值为 “false“ 并不一定代表发生了迁移延迟
49. }
50. }
51. ]
52. },
53. {
54. "result": true,
55. "msg": "",
56. "sourceStatus": {
57. "source": "mysql-replica-02",
58. "worker": "worker2",
59. "result": null,
60. "relayStatus": null
61. },
62. "subTaskStatus": [
63. {
64. "name": "test",
65. "stage": "Running",
66. "unit": "Load",
67. "result": null,
68. "unresolvedDDLLockID": "",
69. "load": { # `Load` 处理单元的迁移信息
70. "finishedBytes": "115", # 已全量导入字节数
71. "totalBytes": "452", # 总计需要导入的字节数
72. "progress": "25.44 %" # 全量导入进度
73. }
74. }
75. ]
76. },
77. {
78. "result": true,
79. "sourceStatus": {
80. "source": "mysql-replica-03",
81. "worker": "worker3",
82. "result": null,
83. "relayStatus": null
84. },
85. "subTaskStatus": [
86. {
87. "name": "test",
88. "stage": "Paused",
89. "unit": "Load",
90. "result": { # 错误示例
91. "isCanceled": false,
92. "errors": [
93. {
94. "Type": "ExecSQL",
95. "msg": "Error 1062: Duplicate entry '1155173304420532225' for key 'PRIMARY'\n/home/jenkins/workspace/build_dm/go/src/github.com/pingcap/tidb-enterprise-tools/loader/db.go:160: \n/home/jenkins/workspace/build_dm/go/src/github.com/pingcap/tidb-enterprise-tools/loader/db.go:105: \n/home/jenkins/workspace/build_dm/go/src/github.com/pingcap/tidb-enterprise-tools/loader/loader.go:138: file test.t1.sql"
96. }
97. ],
98. "detail": null
99. },
100. "unresolvedDDLLockID": "",
101. "load": {
102. "finishedBytes": "0",
103. "totalBytes": "156",
104. "progress": "0.00 %"
105. }
106. }
107. ]
108. }
109. ]
110. }
关于 sources 下 subTaskStatus 中 stage 状态和状态转换关系的详细信息,请参阅子任务状态。
关于 sources 下 subTaskStatus 中 unresolvedDDLLockID的操作细节,请参阅手动处理 Sharding DDL Lock。
子任务状态
状态描述
-
New: -
初始状态。
- 如果子任务没有发生错误,状态切换为
Running,其他情况则切换为Paused。 Running:正常运行状态。-
Paused: -
暂停状态。
- 子任务发生错误,状态切换为
Paused。 - 如在子任务为
Running状态下执行pause-task命令,任务状态会切换为Paused。 - 如子任务处于该状态,可以使用
resume-task命令恢复任务。 -
Stopped: -
停止状态。
- 如在子任务为
Running或Paused状态下执行stop-task命令,任务状态会切换为Stopped。 - 如子任务处于该状态,不可使用
resume-task命令恢复任务。 -
Finished: -
任务完成状态。
- 只有
task-mode为full的任务正常完成后,任务才会切换为该状态。
状态转换图
1. error occurs
2. New --------------------------------|
3. | |
4. | resume-task |
5. | |----------------------------| |
6. | | | |
7. | | | |
8. v v error occurs | v
9. Finished <-------------- Running -----------------------> Paused
10. ^ | or pause-task |
11. | | |
12. start task | | stop task |
13. | | |
14. | v stop task |
15. Stopped <-------------------------|
