All pages
Powered by GitBook
1 of 1

Loading...

Replication Threads

Gain insight into the background threads that drive replication. Understand the roles of the I/O thread, SQL thread, and binlog dump thread in moving data between servers.

The terms master and slave have historically been used in replication, and MariaDB has begun the process of adding primary and replica synonyms. The old terms will continue to be used to maintain backward compatibility - see MDEV-18777 to follow progress on this effort.

MariaDB's replication implementation requires several types of threads.

Threads on the Primary

The primary usually only has one type of replication-related thread: the binary log dump thread.

If is enabled, then the primary also has an ACK receiver thread.

Binary Log Dump Thread

The binary log dump thread runs on the primary and dumps the to the replica. This thread can be identified by running the statement and finding the thread where the is "Binlog Dump".

The primary creates a separate binary log dump thread for each replica connected to the primary. You can identify which replicas are connected to the primary by executing the statement.

Binary Log Dump Threads and the Shutdown Process

When a primary server is shut down and it goes through the normal shutdown process, the primary kills client threads in random order. By default, the primary also considers its binary log dump threads to be regular client threads. As a consequence, the binary log dump threads can be killed while client threads still exist, and this means that data can be written on the primary during a normal shutdown that won't be replicated. This is true even if is being used. Data is not lost; it is stored in the primary server's binary log. The replicas on reconnection, after the primary server restarts, will resume at the exact position they were killed off during the primary shutdown. No data is lost.

In and later, this problem can be solved by shutting down the server using either the utility or the command and providing a special option.

For example, this problem can be solved by shutting down the server with the utility and by providing the --wait-for-all-slaves option to the utility and by executing the shutdown command with the utility:

Or this problem can be solved by shutting down the server with the command and by providing the WAIT FOR ALL SLAVES option to the command:

When one of these special options is provided, the server only kills its binary log dump threads after all client threads have been killed, and it only completes the shutdown after the last has been sent to all connected replicas.

In and later, it is still not possible to enable this behavior by default. This means that this behavior is currently inaccessible when shutting down the server using tools like or .

In and before, it is recommended to manually switchover replicas to a new primary before shutting down the old primary.

ACK Receiver Thread

When is enabled, semisynchronous replicas send acknowledgements (ACKs) to their primary to confirm that they have received some transaction. The primary creates an ACK receiver thread to receive these ACKs.

Threads on the Replica

The replica has three types of replication-related threads: the replica I/O thread, the replica SQL thread, and worker threads, which are only applicable when is in use.

When is in use, each independent replication connection has its own replica threads of each type.

Replica I/O Thread

The replica's I/O thread receives the events from the primary and writes them to its .

Binary Log Position

The position of the replica's I/O thread can be checked by executing the statement. It will be shown as the Master_Log_File and Read_Master_Log_Pos columns.

The position of the replica's I/O thread can be set by setting the and options with the statement.

The position of the replica's I/O thread and the values of most other options are written to either the default master.info file or the file that is configured by the option. The replica's I/O thread keeps this position updated as it downloads events only when the option is set to NO. Otherwise the file is not updated on a per event basis. See for more information.

Replica SQL Thread

The replica's SQL thread reads events from the . What it does with them depends on whether is in use. If is not in use, then the SQL thread applies the events to its local copy of the data. If is in use, then the SQL thread hands off the events to its worker threads to apply in parallel.

Relay Log Position

The position of the replica's SQL thread can be checked by executing the statement. It will be shown as the Relay_Log_File and Relay_Log_Pos columns.

The position of the replica's SQL thread can be set by setting the and options with the statement.

The position of the replica's SQL thread is written to either the default relay-log.info file or the file that is configured by the system variable. The replica's SQL thread keeps this position updated as it applies events. See for more information.

Binary Log Position

The corresponding position of the current position of the replica's SQL thread can be checked by executing the statement. It will be shown as the Relay_Master_Log_File and Exec_Master_Log_Pos columns.

GTID Position

If the replica is replicating events that contain , then the will write every GTID that it applies to the table. This GTID can be inspected and modified through the system variable.

If the replica has the system variable enabled and if the replica has the enabled, then every write by the will also go into the replica's . This means that of replicated transactions would be reflected in the value of the system variable.

See for more information.

Worker Threads

When is in use, then the SQL thread hands off the events to its worker threads to apply in parallel.

This page is licensed: CC BY-SA / Gnu FDL

semisynchronous replication
binary log
SHOW PROCESSLIST
thread command
SHOW SLAVE HOSTS
semi-synchronous replication
mariadb-admin
SHUTDOWN
mariadb-admin
SHUTDOWN
binary log
systemd
sysVinit
semisynchronous replication
parallel replication
multi-source replication
binary log
relay log
binary log
SHOW SLAVE STATUS
binary log
MASTER_LOG_FILE
MASTER_LOG_POS
CHANGE MASTER
binary log
CHANGE MASTER
master_info_file
binary log
MASTER_USE_GTID
CHANGE MASTER TO: Option Persistence
relay log
parallel replication
parallel replication
parallel replication
relay log
SHOW SLAVE STATUS
relay log
RELAY_LOG_FILE
RELAY_LOG_POS
CHANGE MASTER
relay log
relay_log_info_file
relay log
CHANGE MASTER TO: Option Persistence
binary log
relay log
SHOW SLAVE STATUS
binary log
GTIDs
replica's's SQL thread
mysql.gtid_slave_pos
gtid_slave_pos
log_slave_updates
binary log
replica's SQL thread
binary log
GTIDs
gtid_binlog_pos
CHANGE MASTER TO: GTID Persistence
parallel replication
mariadb-admin --wait-for-all-slaves shutdown
SHUTDOWN WAIT FOR ALL SLAVES;
MariaDB 10.4
MariaDB 10.4
MariaDB 10.3