1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based replication is used by default if master supports it

This commit makes replicas crash-safe by default by changing the
Using_Gtid value to be Slave_Pos on a fresh slave start and after
RESET SLAVE is issued. If the primary server does not support GTIDs
(i.e., version < 10), the replica will fall back to Using_Gtid=No on
slave start and after RESET SLAVE.

The following additional informational messages/warnings are added:

 1. When Using_Gtid is automatically changed. That is, if RESET
SLAVE reverts Using_Gtid back to Slave_Pos, or Using_Gtid is
inferred to No from a CHANGE MASTER TO given with log coordinates
without MASTER_USE_GTID.
 2. If options are ignored in CHANGE MASTER TO. If CHANGE MASTER TO
is given with log coordinates, yet also specifies
MASTER_USE_GTID=Slave_Pos, a warning message is given that the log
coordinate options are ignored.

Additionally, an MTR macro has been added for RESET SLAVE,
reset_slave.inc, which provides modes/options for resetting a slave
in log coordinate or gtid modes. When in log coordinates mode, the
macro will execute CHANGE MASTER TO MASTER_USE_GTID=No after the
RESET SLAVE command. When in GTID mode, an extra parameter,
reset_slave_keep_gtid_state, can be set to reset or preserve the
value of gtid_slave_pos.

Reviewed By:
===========
Andrei Elkin <andrei.elkin@mariadb.com>
This commit is contained in:
Brandon Nesterenko
2022-05-23 14:14:00 -06:00
parent 8c2faad576
commit 5ab5ff08b0
167 changed files with 1404 additions and 344 deletions

View File

@@ -62,7 +62,7 @@ if ($tmp)
--echo Master_Server_Id #
--echo Master_SSL_Crl #
--echo Master_SSL_Crlpath #
--echo Using_Gtid No
--echo Using_Gtid Slave_Pos
--echo Gtid_IO_Pos #
--echo Replicate_Do_Domain_Ids
--echo Replicate_Ignore_Domain_Ids

View File

@@ -0,0 +1,58 @@
# ==== Purpose ====
#
# Reset the slave on the active connection
#
#
# ==== Usage ====
#
# [--let $master_use_gtid_option= NO]
# --source include/rpl_reset_slave.inc
#
# Parameters:
# $master_use_gtid_option
# Sets the context for the reset slave. When No, execute
# CHANGE MASTER TO MASTER_USE_GTID=No after the RESET SLAVE. When
# Slave_Pos, execute set gtid_slave_pos= "" after RESET SLAVE.
#
# $reset_slave_keep_gtid_state
# When master_use_gtid_option is Slave_Pos, this defines whether or not
# gtid_slave_pos will be reset as well. Accepted values are of boolean
# type. Default value is false.
#
--let $include_filename= reset_slave.inc
--source include/begin_include_file.inc
if (!$rpl_debug)
{
--disable_query_log
}
if (!$master_use_gtid_option)
{
--let $master_use_gtid_option= Slave_Pos
}
if (!$reset_slave_keep_gtid_state)
{
--let $reset_slave_keep_gtid_state=0
}
if (`SELECT strcmp("$master_use_gtid_option","Slave_Pos") != 0 AND strcmp("$master_use_gtid_option","No") != 0`)
{
die Invalid option provided as master_use_gtid_option, Slave_Pos or No are the only allowed options;
}
RESET SLAVE;
if (`SELECT strcmp("$master_use_gtid_option","Slave_Pos") = 0 AND NOT $reset_slave_keep_gtid_state`)
{
SET @@GLOBAL.gtid_slave_pos= "";
}
if (`SELECT strcmp("$master_use_gtid_option","No") = 0`)
{
CHANGE MASTER TO MASTER_USE_GTID=No;
}
--let $include_filename= reset_slave.inc
--source include/end_include_file.inc

View File

@@ -225,7 +225,14 @@ if (!$rpl_skip_change_master)
{
--let $_rpl_master_log_pos=
}
eval CHANGE MASTER TO MASTER_HOST = '127.0.0.1', MASTER_PORT = $_rpl_port, MASTER_USER = 'root', MASTER_LOG_FILE = '$_rpl_master_log_file'$_rpl_master_log_pos, MASTER_CONNECT_RETRY = 1;
if ($rpl_master_log_file)
{
eval CHANGE MASTER TO MASTER_HOST = '127.0.0.1', MASTER_PORT = $_rpl_port, MASTER_USER = 'root', MASTER_LOG_FILE = '$_rpl_master_log_file'$_rpl_master_log_pos, MASTER_CONNECT_RETRY = 1, MASTER_USE_GTID=NO;
}
if (!$rpl_master_log_file)
{
eval CHANGE MASTER TO MASTER_HOST = '127.0.0.1', MASTER_PORT = $_rpl_port, MASTER_USER = 'root', MASTER_CONNECT_RETRY=1;
}
}
if ($_rpl_master == '')
{

View File

@@ -90,7 +90,7 @@ while ($_rpl_server)
--source include/rpl_connection.inc
# Clear Using_Gtid in SHOW SLAVE STATUS to keep check_testcase happy.
CHANGE MASTER TO master_log_file='';
CHANGE MASTER TO master_use_gtid=Slave_Pos;
--dec $_rpl_server
}

View File

@@ -63,13 +63,13 @@ while ($_rpl_server)
--let $rpl_connection_name= server_$_rpl_server
--source include/rpl_connection.inc
RESET MASTER;
# Check if this server is configured to have a master
if (`SELECT SUBSTRING('$rpl_master_list', 1 + ($_rpl_server - 1) * $rpl_server_count_length, $rpl_server_count_length) != ''`)
{
--source include/stop_slave.inc
RESET SLAVE;
--source include/reset_slave.inc
}
RESET MASTER;
--dec $_rpl_server
}

View File

@@ -100,7 +100,7 @@ RESET SLAVE;
--let $_fake_old_master_host= query_get_value(SHOW SLAVE STATUS, Master_Host, 1)
# Setup replication from existing relay log.
eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_filename-fake.000001', RELAY_LOG_POS=4;
eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_filename-fake.000001', RELAY_LOG_POS=4, MASTER_USE_GTID=NO;
--let $include_filename= setup_fake_relay_log.inc
--source include/end_include_file.inc

View File

@@ -11,7 +11,8 @@ DROP TABLE IF EXISTS t1;
sync_slave_with_master;
STOP SLAVE;
RESET SLAVE;
--let $master_use_gtid_option= No
--source include/reset_slave.inc
eval $test_table_slave;
connection master;
@@ -29,7 +30,7 @@ START SLAVE;
# The following should be 0
SELECT COUNT(*) FROM t1;
STOP SLAVE;
RESET SLAVE;
--source include/reset_slave.inc
connection master;
RESET MASTER;