DM-worker Introduction
DM-worker is a component of TiDB Data Migration (DM) that executes tasks and subtasks assigned by DM-master. For a full and incremental migration, it dumps data from one MySQL-compatible source instance and loads the dumped data into the target TiDB cluster. It then reads the source binlog as a replication client, transforms and filters events, and applies them to the target. DM-master queries DM-worker for the status of sources and subtasks.
Key concepts
- If a worker instance goes offline, DM-master can automatically reschedule its tasks to another available worker to resume the data replication. Note that this does not apply during a full export/import phase.
- A single DM-worker process connects to one upstream source database instance at a time. To migrate from multiple sources, such as when merging sharded tables, you must run multiple DM-worker processes.
DM-worker processing units
Depending on its task mode, a DM-worker subtask runs the dump, load, and binlog replication processing units. DM-worker can also run an optional relay log processing unit for its bound source.
Relay log
Relay log is optional and disabled by default. When enabled, DM-worker stores upstream binlog events on the local disk before the binlog replication processing unit reads them. Enable relay log if a long-running full migration or a blocked task might outlast upstream binlog retention period, or if multiple tasks for the same source need to share a single binlog stream. Relay logging consumes disk, I/O, and CPU resources, and can increase replication latency. For configuration and operational details, see DM relay log.
Dump processing unit
The dump processing unit dumps the full data from the upstream MySQL/MariaDB to the local disk.
Load processing unit
The load processing unit reads the dumped files of the dump processing unit and then loads these files to the downstream TiDB.
Binlog replication/sync processing unit
Binlog replication/sync processing unit reads the binlog events of the upstream MySQL/MariaDB or the binlog events of the relay log, transforms these events to SQL statements, and then applies these statements to the downstream TiDB.
Privileges required by DM-worker
This section describes the upstream and downstream database users' privileges required by DM-worker, and the user privileges required by the respective processing unit.
Upstream database user privileges
The required privileges for the upstream database user depend on the database flavor (MySQL/MariaDB) and version.
MySQL and MariaDB (before MariaDB 10.5.2)
For MySQL, and for MariaDB versions earlier than 10.5.2, the user must have the following privileges:
To grant these privileges, execute the following statement:
GRANT RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'your_user'@'your_wildcard_of_host';
GRANT SELECT ON `db1`.* TO 'your_user'@'your_wildcard_of_host';
For a full data export from MariaDB earlier than 10.5.2, also grant PROCESS so that the dump unit can query InnoDB metadata:
GRANT PROCESS ON *.* TO 'your_user'@'your_wildcard_of_host';
MariaDB 10.5.2 to 10.5.8
Starting from MariaDB 10.5.2, the REPLICATION CLIENT privilege is renamed to BINLOG MONITOR, and several replication statements use new privileges created by splitting SUPER. For MariaDB 10.5.2 to 10.5.8, the user must have the following privileges:
To grant these privileges, execute the following statement:
GRANT PROCESS, RELOAD, BINLOG MONITOR, REPLICATION SLAVE, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN ON *.* TO 'your_user'@'your_wildcard_of_host';
GRANT SELECT ON `db1`.* TO 'your_user'@'your_wildcard_of_host';
MariaDB 10.5.9 or later
Starting from MariaDB 10.5.9, SHOW SLAVE STATUS and SHOW REPLICA STATUS require the REPLICA MONITOR privilege. MariaDB displays this privilege as SLAVE MONITOR in SHOW GRANTS. Grant the privileges listed for MariaDB 10.5.2 to 10.5.8 plus REPLICA MONITOR:
GRANT PROCESS, RELOAD, BINLOG MONITOR, REPLICATION SLAVE, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, REPLICA MONITOR ON *.* TO 'your_user'@'your_wildcard_of_host';
GRANT SELECT ON `db1`.* TO 'your_user'@'your_wildcard_of_host';
Downstream database user privileges
The downstream database (TiDB) user must have the following privileges:
Execute the following GRANT statement for the databases or tables that you need to migrate:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER,INDEX ON db.table TO 'your_user'@'your_wildcard_of_host';
GRANT ALL ON dm_meta.* TO 'your_user'@'your_wildcard_of_host';
Minimal privilege required by each processing unit
The following table lists the minimal privileges required by each processing unit for MySQL and for MariaDB versions earlier than 10.5.2. For MariaDB 10.5.2 and later, refer to the privilege tables in the preceding section.