MySQL 的复制功能通过以下类型的线程实现:MySQL replication capabilities are implemented using the following types of threads:
二进制日志传输线程。 当副本连接时,源会创建一个线程将二进制日志内容发送给副本。这个线程可以在源的
SHOW PROCESSLIST输出中被识别为Binlog Dump线程。Binary log dump thread. The source creates a thread to send the binary log contents to a replica when the replica connects. This thread can be identified in the output ofSHOW PROCESSLISTon the source as theBinlog Dumpthread.复制 I/O 接收线程。 当在从服务器上发出
START REPLICA语句时,从服务器会创建一个 I/O(接收)线程,该线程连接到源服务器,并请求其发送在二进制日志中记录的更新。Replication I/O receiver thread. When aSTART REPLICAstatement is issued on a replica server, the replica creates an I/O (receiver) thread, which connects to the source and asks it to send the updates recorded in its binary logs.复制接收线程读取源服务器的
Binlog Dump线程发送的更新(见前一项),并将它们复制到组成从服务器中继日志的本地文件中。The replication receiver thread reads the updates that the source'sBinlog Dumpthread sends (see previous item) and copies them to local files that comprise the replica's relay log.该线程的状态在
SHOW REPLICA STATUS的输出中显示为Slave_IO_running。The state of this thread is shown asSlave_IO_runningin the output ofSHOW REPLICA STATUS.复制 SQL 应用线程。 当
replica_parallel_workers等于 0 时,副本会创建一个 SQL(应用)线程来读取由复制接收线程写入的中继日志,并执行其中包含的事务。当replica_parallel_workers为时,将有N>= 1N个应用线程和一个协调线程,协调线程按顺序从中继日志中读取事务,并将其调度给工作线程应用。每个工作线程会应用协调线程分配给它的事务。Replication SQL applier thread. Whenreplica_parallel_workersis equal to 0, the replica creates an SQL (applier) thread to read the relay log that is written by the replication receiver thread and execute the transactions contained in it. Whenreplica_parallel_workersis, there areN>= 1Napplier threads and one coordinator thread, which reads transactions sequentially from the relay log, and schedules them to be applied by worker threads. Each worker applies the transactions that the coordinator has assigned to it.
您可以通过将系统变量replica_parallel_workers设置为大于 0 的值,为副本上的任务启用进一步的并行处理。完成此操作后,副本会创建指定数量的工作线程来应用事务,以及一个协调线程,该线程从中继日志中读取事务并分配给工作线程。将replica_parallel_workers(slave_parallel_workers)设置为大于 0 的副本称为多线程副本。如果您使用多个复制通道,每个通道都有使用此变量指定的线程数。You can enable further parallelization for tasks on a replica by
setting the system variable
replica_parallel_workers to a value greater
than 0. When this is done, the replica creates the specified
number of worker threads to apply transactions, plus a coordinator
thread which reads transactions from the relay log and assigns
them to workers. A replica with
replica_parallel_workers
(slave_parallel_workers) set to a value greater
than 0 is called a multithreaded replica. If you are using
multiple replication channels, each channel has the number of
threads specified using this variable.
NDB 集群也支持多线程副本。有关更多信息,请参见 第 25.7.11 节,“使用多线程应用器的 NDB 集群复制”。Multithreaded replicas are also supported by NDB Cluster. See Section 25.7.11, “NDB Cluster Replication Using the Multithreaded Applier”, for more information.