Skip to content

Commit 5ab5ff0

Browse files
committed
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>
1 parent 8c2faad commit 5ab5ff0

File tree

167 files changed

+1404
-344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+1404
-344
lines changed

mysql-test/include/check-testcase.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if ($tmp)
6262
--echo Master_Server_Id #
6363
--echo Master_SSL_Crl #
6464
--echo Master_SSL_Crlpath #
65-
--echo Using_Gtid No
65+
--echo Using_Gtid Slave_Pos
6666
--echo Gtid_IO_Pos #
6767
--echo Replicate_Do_Domain_Ids
6868
--echo Replicate_Ignore_Domain_Ids

mysql-test/include/reset_slave.inc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# ==== Purpose ====
2+
#
3+
# Reset the slave on the active connection
4+
#
5+
#
6+
# ==== Usage ====
7+
#
8+
# [--let $master_use_gtid_option= NO]
9+
# --source include/rpl_reset_slave.inc
10+
#
11+
# Parameters:
12+
# $master_use_gtid_option
13+
# Sets the context for the reset slave. When No, execute
14+
# CHANGE MASTER TO MASTER_USE_GTID=No after the RESET SLAVE. When
15+
# Slave_Pos, execute set gtid_slave_pos= "" after RESET SLAVE.
16+
#
17+
# $reset_slave_keep_gtid_state
18+
# When master_use_gtid_option is Slave_Pos, this defines whether or not
19+
# gtid_slave_pos will be reset as well. Accepted values are of boolean
20+
# type. Default value is false.
21+
#
22+
23+
--let $include_filename= reset_slave.inc
24+
--source include/begin_include_file.inc
25+
26+
27+
if (!$rpl_debug)
28+
{
29+
--disable_query_log
30+
}
31+
32+
if (!$master_use_gtid_option)
33+
{
34+
--let $master_use_gtid_option= Slave_Pos
35+
}
36+
37+
if (!$reset_slave_keep_gtid_state)
38+
{
39+
--let $reset_slave_keep_gtid_state=0
40+
}
41+
42+
if (`SELECT strcmp("$master_use_gtid_option","Slave_Pos") != 0 AND strcmp("$master_use_gtid_option","No") != 0`)
43+
{
44+
die Invalid option provided as master_use_gtid_option, Slave_Pos or No are the only allowed options;
45+
}
46+
47+
RESET SLAVE;
48+
if (`SELECT strcmp("$master_use_gtid_option","Slave_Pos") = 0 AND NOT $reset_slave_keep_gtid_state`)
49+
{
50+
SET @@GLOBAL.gtid_slave_pos= "";
51+
}
52+
if (`SELECT strcmp("$master_use_gtid_option","No") = 0`)
53+
{
54+
CHANGE MASTER TO MASTER_USE_GTID=No;
55+
}
56+
57+
--let $include_filename= reset_slave.inc
58+
--source include/end_include_file.inc

mysql-test/include/rpl_change_topology.inc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ if (!$rpl_skip_change_master)
225225
{
226226
--let $_rpl_master_log_pos=
227227
}
228-
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;
228+
if ($rpl_master_log_file)
229+
{
230+
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;
231+
}
232+
if (!$rpl_master_log_file)
233+
{
234+
eval CHANGE MASTER TO MASTER_HOST = '127.0.0.1', MASTER_PORT = $_rpl_port, MASTER_USER = 'root', MASTER_CONNECT_RETRY=1;
235+
}
229236
}
230237
if ($_rpl_master == '')
231238
{

mysql-test/include/rpl_end.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ while ($_rpl_server)
9090
--source include/rpl_connection.inc
9191

9292
# Clear Using_Gtid in SHOW SLAVE STATUS to keep check_testcase happy.
93-
CHANGE MASTER TO master_log_file='';
93+
CHANGE MASTER TO master_use_gtid=Slave_Pos;
9494

9595
--dec $_rpl_server
9696
}

mysql-test/include/rpl_reset.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ while ($_rpl_server)
6363
--let $rpl_connection_name= server_$_rpl_server
6464
--source include/rpl_connection.inc
6565

66+
RESET MASTER;
6667
# Check if this server is configured to have a master
6768
if (`SELECT SUBSTRING('$rpl_master_list', 1 + ($_rpl_server - 1) * $rpl_server_count_length, $rpl_server_count_length) != ''`)
6869
{
6970
--source include/stop_slave.inc
70-
RESET SLAVE;
71+
--source include/reset_slave.inc
7172
}
72-
RESET MASTER;
7373
--dec $_rpl_server
7474
}
7575

mysql-test/include/setup_fake_relay_log.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ RESET SLAVE;
100100
--let $_fake_old_master_host= query_get_value(SHOW SLAVE STATUS, Master_Host, 1)
101101

102102
# Setup replication from existing relay log.
103-
eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_filename-fake.000001', RELAY_LOG_POS=4;
103+
eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_filename-fake.000001', RELAY_LOG_POS=4, MASTER_USE_GTID=NO;
104104

105105
--let $include_filename= setup_fake_relay_log.inc
106106
--source include/end_include_file.inc

mysql-test/include/test_fieldsize.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ DROP TABLE IF EXISTS t1;
1111

1212
sync_slave_with_master;
1313
STOP SLAVE;
14-
RESET SLAVE;
14+
--let $master_use_gtid_option= No
15+
--source include/reset_slave.inc
1516
eval $test_table_slave;
1617

1718
connection master;
@@ -29,7 +30,7 @@ START SLAVE;
2930
# The following should be 0
3031
SELECT COUNT(*) FROM t1;
3132
STOP SLAVE;
32-
RESET SLAVE;
33+
--source include/reset_slave.inc
3334

3435
connection master;
3536
RESET MASTER;

mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include/rpl_start_server.inc [server_number=1]
1212
connection slave;
1313
RESET SLAVE;
1414
RESET MASTER;
15-
CHANGE MASTER TO master_host='127.0.0.1', master_port=SERVER_MYPORT_1, master_user='root', master_log_file='master-bin.000001', master_log_pos=4;
15+
CHANGE MASTER TO master_host='127.0.0.1', master_port=SERVER_MYPORT_1, master_user='root', master_log_file='master-bin.000001', master_log_pos=4, master_use_gtid=no;
1616
include/start_slave.inc
1717
DESC t1;
1818
Field Type Null Key Default Extra

mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
RESET SLAVE;
3737
RESET MASTER;
3838
--replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1
39-
eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SERVER_MYPORT_1, master_user='root', master_log_file='master-bin.000001', master_log_pos=4;
39+
eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SERVER_MYPORT_1, master_user='root', master_log_file='master-bin.000001', master_log_pos=4, master_use_gtid=no;
4040
--source include/start_slave.inc
4141
--sync_with_master
4242
DESC t1;

mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted.result

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
include/rpl_init.inc [topology=1->2]
55
connection server_2;
66
include/stop_slave.inc
7+
CHANGE MASTER TO MASTER_USE_GTID=NO;
8+
include/start_slave.inc
9+
connection server_1;
10+
connection server_2;
11+
include/stop_slave.inc
712
#####################################################
813
# Part 1: unencrypted master
914
#####################################################
@@ -63,7 +68,9 @@ SHOW TABLES;
6368
Tables_in_test
6469
table1_no_encryption
6570
include/stop_slave.inc
66-
reset slave;
71+
include/reset_slave.inc
72+
Warnings:
73+
Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos'
6774
##########
6875
# Cleanup
6976
##########

0 commit comments

Comments
 (0)