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.
MariaDB's replication implementation requires several types of threads.
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.
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.
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.
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.
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.
The replica's I/O thread receives the events from the primary and writes them to its .
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.
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.
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.
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.
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.
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
mariadb-admin --wait-for-all-slaves shutdownSHUTDOWN WAIT FOR ALL SLAVES;