mariadb/mysql-test/suite/rpl/t/rpl_reset_slave_fail.test
Brandon Nesterenko 5ab5ff08b0 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>
2022-07-26 13:31:27 -06:00

91 lines
3 KiB
Text

###############################################################################
# Bug#24901077: RESET SLAVE ALL DOES NOT ALWAYS RESET SLAVE
#
# Problem:
# =======
# If you have a relay log index file that has ended up with
# some relay log files that do not exists, then RESET SLAVE
# ALL is not enough to get back to a clean state.
###############################################################################
# Remove all slave-relay-bin.0* files (do not remove slave-relay-bin.index)
# During server restart rli initialization will fail as there are no
# relay logs. In case of bug RESET SLAVE will not do the required clean up
# as rli is not inited and subsequent START SLAVE will fail.
# Disable "Warning 1612 Being purged log ./slave-relay-bin.0* was not found"
# because it is different on Unix and Windows systems.
--source include/have_binlog_format_mixed.inc
--source include/master-slave.inc
--connection master
CREATE TABLE t1 (c1 INT);
INSERT INTO t1 (c1) VALUES (1);
--sync_slave_with_master
--connection slave
--source include/stop_slave_sql.inc
--let $MYSQLD_SLAVE_DATADIR= `select @@datadir`
--connection master
# Generate more relay logs on slave.
FLUSH LOGS;
FLUSH LOGS;
INSERT INTO t1 (c1) VALUES (2);
--source include/sync_slave_io_with_master.inc
call mtr.add_suppression("File '.*slave-relay-bin.");
call mtr.add_suppression("Could not open log file");
call mtr.add_suppression("Failed to open the relay log");
call mtr.add_suppression("Failed to initialize the master info structure");
# Stop slave
--let $rpl_server_number= 2
--source include/rpl_stop_server.inc
# Delete file(s)
--echo # Removing $remove_pattern file(s)
--let $remove_pattern= slave-relay-bin.0*
--remove_files_wildcard $MYSQLD_SLAVE_DATADIR $remove_pattern
# Start slave
--let $rpl_server_number= 2
--source include/rpl_start_server.inc
# Start slave must fail because of the removed file(s).
--error ER_MASTER_INFO
START SLAVE;
# Try a second time, it must fail again.
--error ER_MASTER_INFO
START SLAVE;
# Retrieve master executed position before reset slave.
--let $master_exec_file= query_get_value("SHOW SLAVE STATUS", Relay_Master_Log_File, 1)
--let $master_exec_pos= query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1)
# Reset slave.
# Disable "Warning 1612 Being purged log ./slave-relay-bin.0* was not found"
# because it is different on Unix and Windows systems.
--disable_warnings
--source include/reset_slave.inc
--enable_warnings
DROP TABLE t1;
--replace_result $master_exec_file MASTER_LOG_FILE $master_exec_pos MASTER_LOG_POS
--eval START SLAVE UNTIL MASTER_LOG_FILE= '$master_exec_file', MASTER_LOG_POS= $master_exec_pos;
--source include/wait_for_slave_sql_to_stop.inc
--source include/stop_slave_io.inc
# Start slave.
--source include/start_slave.inc
--connection master
--sync_slave_with_master
# Check consistency.
--let $diff_tables= master:t1, slave:t1
--source include/diff_tables.inc
# Cleanup
--connection master
DROP TABLE t1;
--sync_slave_with_master
--source include/rpl_end.inc