mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
BUG#49978: Replication tests don't clean up replication state at the end
Major replication test framework cleanup. This does the following: - Ensure that all tests clean up the replication state when they finish, by making check-testcase check the output of SHOW SLAVE STATUS. This implies: - Slave must not be running after test finished. This is good because it removes the risk for sporadic errors in subsequent tests when a test forgets to sync correctly. - Slave SQL and IO errors must be cleared when test ends. This is good because we will notice if a test gets an unexpected error in the slave threads near the end. - We no longer have to clean up before a test starts. - Ensure that all tests that wait for an error in one of the slave threads waits for a specific error. It is no longer possible to source wait_for_slave_[sql|io]_to_stop.inc when there is an error in one of the slave threads. This is good because: - If a test expects an error but there is a bug that causes another error to happen, or if it stops the slave thread without an error, then we will notice. - When developing tests, wait_for_*_to_[start|stop].inc will fail immediately if there is an error in the relevant slave thread. Before this patch, we had to wait for the timeout. - Remove duplicated and repeated code for setting up unusual replication topologies. Now, there is a single file that is capable of setting up arbitrary topologies (include/rpl_init.inc, but include/master-slave.inc is still available for the most common topology). Tests can now end with include/rpl_end.inc, which will clean up correctly no matter what topology is used. The topology can be changed with include/rpl_change_topology.inc. - Improved debug information when tests fail. This includes: - debug info is printed on all servers configured by include/rpl_init.inc - User can set $rpl_debug=1, which makes auxiliary replication files print relevant debug info. - Improved documentation for all auxiliary replication files. Now they describe purpose, usage, parameters, and side effects. - Many small code cleanups: - Made have_innodb.inc output a sensible error message. - Moved contents of rpl000017-slave.sh into rpl000017.test - Added mysqltest variables that expose the current state of disable_warnings/enable_warnings and friends. - Too many to list here: see per-file comments for details.
This commit is contained in:
153
mysql-test/include/rpl_sync.inc
Normal file
153
mysql-test/include/rpl_sync.inc
Normal file
@ -0,0 +1,153 @@
|
||||
# ==== Purpose ====
|
||||
#
|
||||
# Sync all servers in an arbitrary replication topology. This works
|
||||
# only if the servers have been configured with rpl_init.inc (and
|
||||
# possibly rpl_change_topology.inc).
|
||||
#
|
||||
#
|
||||
# ==== Usage ====
|
||||
#
|
||||
# [--let $rpl_only_running_threads= 1]
|
||||
# [--let $rpl_debug= 1]
|
||||
# [--let $slave_timeout= NUMBER]
|
||||
# --source include/rpl_sync.inc
|
||||
#
|
||||
# Parameters:
|
||||
# $rpl_only_running_threads
|
||||
# By default, this script assumes that both the IO thread and the
|
||||
# SQL thread are running and fails if one of them is stopped. If
|
||||
# $rpl_only_running_threads is set, this script first checks
|
||||
# which slave threads are running:
|
||||
# - If both threads are running, sync both threads with master.
|
||||
# - If only IO thread is running, sync IO thread with master.
|
||||
# - If only SQL thread is running, sync SQL thread with IO thread.
|
||||
# - If no thread is running, don't sync.
|
||||
#
|
||||
# $slave_timeout
|
||||
# Set the timeout when waiting for threads to sync. See
|
||||
# include/wait_for_slave_param.inc
|
||||
#
|
||||
# $rpl_debug
|
||||
# See include/rpl_init.inc
|
||||
#
|
||||
#
|
||||
# ==== Side effects ====
|
||||
#
|
||||
# Does not change the current connection (note that this is different
|
||||
# from mysqltest's built-in sync_slave_with_master command).
|
||||
|
||||
|
||||
--let $include_filename= rpl_sync.inc
|
||||
--source include/begin_include_file.inc
|
||||
|
||||
|
||||
# Compute $rpl_sync_chain if needed. We could have done this in
|
||||
# rpl_change_topology.inc, but instead we do it here because that
|
||||
# means we only compute $rpl_sync_chain when it is needed.
|
||||
if ($rpl_sync_chain_dirty)
|
||||
{
|
||||
--source include/rpl_generate_sync_chain.inc
|
||||
--let $rpl_sync_chain_dirty= 0
|
||||
}
|
||||
|
||||
|
||||
if ($rpl_debug)
|
||||
{
|
||||
--echo \$rpl_sync_chain = '$rpl_sync_chain' \$rpl_only_running_threads= $rpl_only_running_threads
|
||||
}
|
||||
|
||||
if (!$rpl_server_count_length)
|
||||
{
|
||||
--die \$rpl_server_count_length is not set. Did you call rpl_init.inc?
|
||||
}
|
||||
|
||||
|
||||
--let $_rpl_i= 1
|
||||
--let $_rpl_connect= 0
|
||||
while ($_rpl_i) {
|
||||
# $rpl_sync_chain consists of a sequence of sync chains. Each sync
|
||||
# chain has the form:
|
||||
#
|
||||
# <space><server1_1><server1_2>...<server1_N>
|
||||
#
|
||||
# So the space character indicates that a new sync chain starts.
|
||||
--let $_rpl_server= `SELECT TRIM(SUBSTR('$rpl_sync_chain', 1 + ($_rpl_i - 1) * $rpl_server_count_length, $rpl_server_count_length))`
|
||||
|
||||
if ($_rpl_server)
|
||||
{
|
||||
if ($rpl_debug)
|
||||
{
|
||||
--echo [sync server_$_rpl_prev_server -> server_$_rpl_server]
|
||||
}
|
||||
if ($rpl_only_running_threads)
|
||||
{
|
||||
--connection server_$_rpl_server
|
||||
--let $_rpl_slave_io_running= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1)
|
||||
--let $_rpl_slave_sql_running= query_get_value(SHOW SLAVE STATUS, Slave_SQL_Running, 1)
|
||||
if ($rpl_debug)
|
||||
{
|
||||
--echo Sync IO: $_rpl_slave_io_running; Sync SQL: $_rpl_slave_sql_running
|
||||
}
|
||||
--let $_rpl_slave_io_running= `SELECT IF('$_rpl_slave_io_running' = 'Yes', 1, '')`
|
||||
--let $_rpl_slave_sql_running= `SELECT IF('$_rpl_slave_sql_running' = 'Yes', 1, '')`
|
||||
if ($_rpl_slave_io_running)
|
||||
{
|
||||
--connection server_$_rpl_prev_server
|
||||
if ($_rpl_slave_sql_running)
|
||||
{
|
||||
if ($rpl_debug)
|
||||
{
|
||||
--let $_rpl_master_file= query_get_value("SHOW MASTER STATUS", File, 1)
|
||||
--let $_rpl_master_pos= query_get_value("SHOW MASTER STATUS", Position, 1)
|
||||
--echo syncing master_file='$_rpl_master_file' master_pos='$_rpl_master_pos'
|
||||
}
|
||||
--sync_slave_with_master server_$_rpl_server
|
||||
}
|
||||
if (!$_rpl_slave_sql_running)
|
||||
{
|
||||
--let $sync_slave_connection= server_$_rpl_server
|
||||
--source include/sync_slave_io_with_master.inc
|
||||
}
|
||||
}
|
||||
if (!$_rpl_slave_io_running)
|
||||
{
|
||||
if ($_rpl_slave_sql_running)
|
||||
{
|
||||
--source include/sync_slave_sql_with_io.inc
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$rpl_only_running_threads)
|
||||
{
|
||||
--connection server_$_rpl_prev_server
|
||||
if ($rpl_debug)
|
||||
{
|
||||
--let $_rpl_master_file= query_get_value("SHOW MASTER STATUS", File, 1)
|
||||
--let $_rpl_master_pos= query_get_value("SHOW MASTER STATUS", Position, 1)
|
||||
--echo syncing master_file='$_rpl_master_file' master_pos='$_rpl_master_pos'
|
||||
}
|
||||
--sync_slave_with_master server_$_rpl_server
|
||||
}
|
||||
}
|
||||
|
||||
# This happens at the beginning of a new sync subchain and at the
|
||||
# end of the full sync chain.
|
||||
if (!$_rpl_server)
|
||||
{
|
||||
--inc $_rpl_i
|
||||
--let $_rpl_server= `SELECT TRIM(SUBSTR('$rpl_sync_chain', 1 + ($_rpl_i - 1) * $rpl_server_count_length, $rpl_server_count_length))`
|
||||
|
||||
if (!$_rpl_server)
|
||||
{
|
||||
# terminate loop
|
||||
--let $_rpl_i= -1
|
||||
}
|
||||
}
|
||||
|
||||
--let $_rpl_prev_server= $_rpl_server
|
||||
--inc $_rpl_i
|
||||
}
|
||||
|
||||
|
||||
--let $include_filename= rpl_sync.inc
|
||||
--source include/end_include_file.inc
|
Reference in New Issue
Block a user