The terms master and slave have historically been used in replication, but the terms terms primary and replica are now preferred. The old terms are used still used in parts of the documentation, and in MariaDB commands, although MariaDB 10.5 has begun the process of renaming. The documentation process is ongoing. See MDEV-18777 to follow progress on this effort.
Multi-source replication means that one server has many primaries from which it replicates.
You specify which primary connection you want to work with by either specifying the connection name in the command or setting default_master_connection to the connection you want to work with.
The connection name may include any characters and should be less than 64 characters. Connection names are compared without regard to case (case insensitive). You should preferably keep the connection name short as it will be used as a suffix for relay logs and primary info index files.
The new syntax introduced to handle many connections:
CHANGE MASTER ['connection_name'] TO .... This creates or modifies a connection to a primary. FLUSH RELAY LOGS ['connection_name'] MASTER_POS_WAIT(....,['connection_name']) RESET SLAVE ['connection_name'] [ALL]. This is used to reset a replica's replication position or to remove a replica permanently. SHOW RELAYLOG ['connection_name'] EVENTS SHOW SLAVE ['connection_name'] STATUS SHOW ALL SLAVES STATUS START SLAVE ['connection_name'...]] START ALL SLAVES ... STOP SLAVE ['connection_name'] ... STOP ALL SLAVES ... The original old-style connection is an empty string ''. You don't have to use this connection if you don't want to.
You create new primary connections with CHANGE MASTER.
You delete the connection permanently with RESET SLAVE 'connection_name' ALL.
The new replication variable default_master_connection specifies which connection will be used for commands and variables if you don't specify a connection. By default this is '' (the default connection name).
The following replication variables are local for the connection. (In other words, they show the value for the @@default_master_connection connection). We are working on making all the important ones local for the connection.
| Type | Name | Description |
|---|---|---|
| Variable | max_relay_log_size | Max size of relay log. Is set at startup to max_binlog_size if 0 |
| Variable | replicate_do_db | Tell the replica to restrict replication to updates of tables whose names appear in the comma-separated list. For statement-based replication, only the default database (that is, the one selected by USE) is considered, not any explicitly mentioned tables in the query. For row-based replication, the actual names of table(s) being updated are checked. |
| Variable | replicate_do_table | Tells the replica to restrict replication to tables in the comma-separated list |
| Variable | replicate_ignore_db | Tell the replica to restrict replication to updates of tables whose names do not appear in the comma-separated list. For statement-based replication, only the default database (that is, the one selected by USE) is considered, not any explicitly mentioned tables in the query. For row-based replication, the actual names of table(s) being updated are checked. |
| Variable | replicate_ignore_table | Tells the replica thread to not replicate any statement that updates the specified table, even if any other tables might be updated by the same statement. |
| Variable | replicate_rewrite_db | From MariaDB 10.11. Allows one to configure a replica to rewrite database names. It uses the format primary_database->replica_database. If a replica encounters a binary log event in which the default database (i.e. the one selected by the USE statement) is primary_database, then the replica will apply the event in replica_database instead. |
| Variable | replicate_wild_do_table | Tells the replica thread to restrict replication to statements where any of the updated tables match the specified database and table name patterns. |
| Variable | replicate_wild_ignore_table | Tells the replica thread to not replicate to the tables that match the given wildcard pattern. |
| Status | Slave_heartbeat_period | How often to request a heartbeat packet from the primary (in seconds). |
| Status | Slave_received_heartbeats | How many heartbeats we have got from the primary. |
| Status | Slave_running | Shows if the replica is running. YES means that the sql thread and the IO thread are active. No means either one is not running. '' means that @@default_master_connection doesn't exist. |
| Variable | Sql_slave_skip_counter | How many entries in the replication log that should be skipped (mainly used in case of errors in the log). |
You can access all of the above variables with either SESSION or GLOBAL.
Note that in contrast to MySQL, all variables always show the correct active value!
Example:
set @@default_master_connection=''; show status like 'Slave_running'; set @@default_master_connection='other_connection'; show status like 'Slave_running';
If @@default_master_connection contains a non existing name, you will get a warning.
All other primary-related variables are global and affect either only the '' connections or all connections. For example, Slave_retried_transactions now shows the total number of retried transactions over all replicas.
If you need to set gtid_slave_pos you need to set this for all primaries at the same time.
New status variables:
| Name | Description |
|---|---|
Com_start_all_slaves |
Number of executed START ALL SLAVES commands. |
Com_start_slave |
Number of executed START SLAVE commands. This replaces Com_slave_start. |
Com_stop_slave |
Number of executed STOP SLAVE commands. This replaces Com_slave_stop. |
Com_stop_all_slaves |
Number of executed STOP ALL SLAVES commands. |
SHOW ALL SLAVES STATUS has the following new columns:
| Name | Description |
|---|---|
Connection_name |
Name of the primary connection. This is the first variable. |
Slave_SQL_State |
State of SQL thread. |
Retried_transactions |
Number of retried transactions for this connection. |
Max_relay_log_size |
Max relay log size for this connection. |
Executed_log_entries |
How many log entries the replica has executed. |
Slave_received_heartbeats |
How many heartbeats we have got from the primary. |
Slave_heartbeat_period |
How often to request a heartbeat packet from the primary (in seconds). |
The basic principle of the new files used by multi source replication is that they have the same name as the original relay log files suffixed with connection_name before the extension. The main exception is the file that holds all connection is named as the normal master-info-file with a multi- prefix.
When you are using multi source, the following new files are created:
| Name | Description |
|---|---|
multi-master-info-file |
The master-info-file (normally master.info) with a multi- prefix. This contains all primary connections in use. |
master-info-file-connection_name.extension
|
Contains the current primary position for what's applied to in the replica. Extension is normally .info
|
relay-log-connection_name.xxxxx
|
The relay-log name with a connection_name suffix. The xxxxx is the relay log number. This contains the replication data read from the primary. |
relay-log-index-connection_name.extension |
Contains the name of the active relay-log-connection_name.xxxxx files. Extension is normally .index
|
relay-log-info-file-connection_name.extension
|
Contains the current primary position for the relay log. Extension is normally .info
|
When creating the file, the connection name is converted to lower case and all special characters in the connection name are converted, the same way as MySQL table names are converted. This is done to make the file name portable across different systems.
Hint:
Instead of specifying names for mysqld with --relay-log, --relay-log-index, --general-log-file, --slow-query-log-file, --log-bin and --log-bin-index, you can just specify --log-basename and all the other variables are set with this as a prefix.
Master 'connection_name':. This makes it easy to see from where an error originated. ER_MASTER_INFO and WARN_NO_MASTER_INFO now includes connection_name. log_warnings > 1 then you will get some information in the log about how the multi-master-info file is updated (mainly for debugging). SHOW SLAVE STATUS, since it includes the connection_name column. RESET SLAVE now deletes all relay-log files. replicate-... variables from the command line or in my.cnf for a given connection by prefixing the variable with the connection name. replicate.. variable, then the value will be used as the default value for all connections that don't have a value set for this variable. Example:
mysqld --main_connection.replicate_do_db=main_database --replicate_do_db=other_database
The have sets the replicate_do_db variable to main_database for the connection named main_connection. All other connections will use the value other_database.
One can also use this syntax to set replicate-rewrite-db for a given connection.
replicate-do-db do not apply to replication connections, but also to Galera write set applier threads. By using a named multi-primary replication connection instead, even when replicating from just one primary into the cluster, the primary-replica replication rules can be kept separate from the Galera intra-node replication traffic. server-id's. If you don't do this, you will get into trouble if you try to replicate from the multi-source replica back to your primaries. max_relay_log_size, which can't be changed at runtime. max_binlog_size at startup if its value is 0. GLOBAL or SESSION. Com_slave_start is replaced with Com_start_slave. Com_slave_stop is replaced with Com_stop_slave. FLUSH RELAY LOGS are not replicated anymore. This is not safe as connection names may be different on the replica.
© 2023 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/multi-source-replication/