1
0
mirror of https://github.com/MariaDB/server.git synced 2025-05-27 01:57:48 +03:00
mariadb/mysql-test/suite/sys_vars/t/rpl_init_slave_func.test
Sujatha 43ec9370b3 MDEV-10149: sys_vars.rpl_init_slave_func fails sporadically in buildbot
problem:
========
mysqltest: In included file "./include/assert.inc":
included from mysql-test/suite/sys_vars/t/rpl_init_slave_func.test at line 69:
Assertion text: '@@global.max_connections = @start_max_connections'
Assertion result: '0'


mysqltest: In included file "./include/assert.inc":
included from mysql-test/suite/sys_vars/t/rpl_init_slave_func.test at line 86:
Assertion text: '@@global.max_connections = @start_max_connections + 1'
Assertion result: '0'

Analysis:
=========
A slave SQL thread sets its Running state to Yes very early in its
initialisation, before the majority of initialisation actions, including
executing the init_slave command, are done. Thus the testcase has a race
condition where the initial replication setup might finish executing later
than the testcase SET GLOBAL init_slave, making the testcase see its effect
where it checks for its absence.

Fix:
===
Include 'sync_slave_sql_with_master.inc' at the beginning of the test to
ensure that slave applier has completed the execution of 'init_slave' command
and proceeded to event application. Replace the apparently needless RESET
MASTER / RESET SLAVE etc.

Patch is based on:
b91e2e6f90
Author: laurynas-biveinis
2020-10-22 07:16:29 +05:30

112 lines
5.3 KiB
Plaintext

###############################################################################
# #
# Variable Name: init_slave #
# Scope: GLOBAL #
# Access Type: Dynamic #
# Data Type: string #
# Default Value: #
# Range: #
# #
# #
# Creation Date: 2008-03-08 #
# Author: Rizwan #
# Modified: HHunger 2008-09-29 Fixed the bug by inserting the usual wait and #
# SQL-Satements to control master and slave, #
# deleted the sleep and made improvements like: #
# - Replaced the opt file by dynamic variables, #
# - Made the tests independant of the initial #
# values of the global variables, #
# - Reduced the test to the needed test case to #
# save run time, #
# - Beautification. #
# #
# Description: Test Cases of Dynamic System Variable init_slave #
# that checks the behavior of this variable #
# #
# Reference: #
# http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html #
# #
###############################################################################
source include/master-slave.inc;
# Since a part of slave SQL thread initialisation happens after Slave_SQL_Running
# has been set to Yes, there is a race condition between initialisation above and
# init_slave setting given below. Synchronise slave applier with master to ensure
# init_slave is complete and applier had processed few events like FD.
--source include/sync_slave_sql_with_master.inc
--disable_query_log
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
--enable_query_log
#
# save the current values
SET @start_max_connections= @@global.max_connections;
SET @start_init_slave= @@global.init_slave;
# setting of a global value with an effect on the next start of the slave server
# check that @@global.init_slave could be set
SET NAMES utf8;
let $my_init_slave=
'SET @@global.max_connections = @@global.max_connections + 1 -- комментарий';
eval SET @@global.init_slave = $my_init_slave;
# show the data type of the variable
--disable_warnings
DROP TABLE IF EXISTS t1;
CREATE TEMPORARY TABLE t1 AS SELECT @@global.init_slave AS my_column;
--enable_warnings
DESCRIBE t1;
select length(my_column) from t1;
DROP TABLE t1;
#
# check that the new setting of @@global.init_slave becomes immediately visible
eval SELECT @@global.init_slave = $my_init_slave;
--echo Expect 1
# wait for the slave threads have set the global variable.
let $wait_timeout= 90;
let $wait_condition= SELECT @@global.max_connections = @start_max_connections;
--source include/wait_condition_sp.inc
# check that the action in init_slave does not happen immediately
--let $assert_text= @@global.max_connections = @start_max_connections
--let $assert_cond= @@global.max_connections = @start_max_connections
--source include/assert.inc
--source include/restart_slave_sql.inc
# Upon slave start, sync the applier with master, to ensure slave has
# completed init_slave command execution and processed FD event from the
# master.
--connection master
--source include/sync_slave_sql_with_master.inc
#
# wait for the slave threads have set the global variable.
let $wait_timeout= 90;
let $wait_condition= SELECT @@global.max_connections = @start_max_connections + 1;
--source include/wait_condition_sp.inc
# check that the action in init_slave was executed and had the intended effect
--let $assert_text= @@global.max_connections = @start_max_connections + 1
--let $assert_cond= @@global.max_connections = @start_max_connections + 1
--source include/assert.inc
#
# Setting a variable(which is local to a session) and must not be visible
SET @@global.init_slave = "SET @a=5";
#
--source include/restart_slave_sql.inc
#
SHOW VARIABLES LIKE 'init_slave';
# expect NULL
SELECT @a;
--echo Expect NULL
#
# Clean up
SET @@global.max_connections= @start_max_connections;
SET @@global.init_slave= @start_init_slave;
##################################################
# End of functionality Testing for init_slave #
##################################################
--source include/rpl_end.inc