1--source include/have_innodb.inc 2--source include/have_debug_sync.inc 3--source include/master-slave.inc 4 5CALL mtr.add_suppression("Failed to start semi-sync ACK receiver thread.*"); 6CALL mtr.add_suppression("Failed to register slave to semi-sync ACK receiver thread.*"); 7CALL mtr.add_suppression("Failed to stop ack receiver thread on pthread_join.*"); 8CALL mtr.add_suppression("Got an error reading communication packets:*"); 9CALL mtr.add_suppression("Timeout waiting for reply of binlog*"); 10CALL mtr.add_suppression("slave_read_sync_header*"); 11CALL mtr.add_suppression("Missing magic number for semi-sync*"); 12CALL mtr.add_suppression("Got timeout reading communication packets*"); 13CALL mtr.add_suppression("Failed to call*"); 14CALL mtr.add_suppression("Execution failed on master*"); 15CALL mtr.add_suppression("Failed on request_dump()*"); 16CALL mtr.add_suppression("Semi-sync master failed on*"); 17CALL mtr.add_suppression("Master command COM_BINLOG_DUMP failed*"); 18CALL mtr.add_suppression("on master failed*"); 19CALL mtr.add_suppression("Master server does not support semi-sync*"); 20CALL mtr.add_suppression("Semi-sync slave net_flush*"); 21CALL mtr.add_suppression("Failed to flush master info*"); 22CALL mtr.add_suppression("Request to stop slave SQL Thread received while apply*"); 23 24connection master; 25echo [ enable semi-sync on master ]; 26set global rpl_semi_sync_master_enabled = 1; 27show variables like 'rpl_semi_sync_master_enabled'; 28 29connection slave; 30echo [ enable semi-sync on slave ]; 31stop slave; 32set global rpl_semi_sync_slave_enabled = 1; 33start slave; 34let $status_var= rpl_semi_sync_slave_status; 35let $status_var_value= ON; 36source include/wait_for_status_var.inc; 37show status like 'rpl_semi_sync_slave%'; 38 39 40connection master; 41CREATE TABLE t1(a INT) ENGINE=InnoDB; 42sync_slave_with_master; 43 44connection master; 45connect(con1,localhost,root,,); 46connect(con2,localhost,root,,); 47connect(con3,localhost,root,,); 48 49show status like 'Rpl_semi_sync_master_clients'; 50show status like "rpl_semi_sync_master_yes_tx"; 51 52--echo ######################################### 53--echo # Test rpl_semi_sync_master_wait_point # 54--echo ######################################### 55--echo # Test after_sync and after_commit first. 56 57--echo #Test after_sync 58connection con1; 59# Let's set a very large timeout value for testing purpose. 60SET GLOBAL rpl_semi_sync_master_timeout = 1000000; 61SET GLOBAL rpl_semi_sync_master_wait_point= 'AFTER_SYNC'; 62SET DEBUG_SYNC= "commit_before_get_LOCK_commit_ordered SIGNAL after_sync_done WAIT_FOR end"; 63--send INSERT into t1 values (1); 64 65connection con2; 66SET DEBUG_SYNC= "now WAIT_FOR after_sync_done"; 67 68sync_slave_with_master; 69--echo #slave can see record (1) after sync slave with master 70select * from t1; 71 72connection con2; 73--echo #con2 shouldn't see record (1) 74select * from t1; 75SET DEBUG_SYNC= "now SIGNAL end"; 76 77connection con1; 78reap; 79 80connection con1; 81select * from t1; 82truncate table t1; 83 84sync_slave_with_master; 85 86# Test more threads in one semisync queue 87connection con1; 88SET DEBUG_SYNC= 'reset'; 89SET DEBUG_SYNC= "commit_before_get_LOCK_log SIGNAL before_fetch_done WAIT_FOR more_queue"; 90#SET DEBUG_SYNC= "before_semisync_fetch SIGNAL before_fetch_done WAIT_FOR more_queue"; 91--send INSERT into t1 VALUES (1); 92 93connection con2; 94SET DEBUG_SYNC= "now WAIT_FOR before_fetch_done"; 95SET DEBUG_SYNC= "after_semisync_queue SIGNAL more_queue"; 96INSERT INTO t1 VALUES (2); 97 98connection con1; 99reap; 100 101# Test more threads in one semisync queue, but disable semisync before 102# waiting. 103connection con1; 104SET DEBUG_SYNC= 'reset'; 105SET DEBUG_SYNC= "commit_before_get_LOCK_log SIGNAL before_fetch_done WAIT_FOR disable_semisync"; 106#SET DEBUG_SYNC= "before_semisync_fetch SIGNAL before_fetch_done WAIT_FOR more_queue"; 107#SET DEBUG_SYNC= "before_semisync_fetch SIGNAL before_fetch_done WAIT_FOR disable_semisync"; 108--send INSERT into t1 VALUES (3); 109 110connection con2; 111SET DEBUG_SYNC= "now WAIT_FOR before_fetch_done"; 112SET GLOBAL rpl_semi_sync_master_enabled= 0; 113SET DEBUG_SYNC= "now SIGNAL disable_semisync"; 114 115connection con1; 116reap; 117SET GLOBAL rpl_semi_sync_master_enabled = 1; 118show status like 'Rpl_semi_sync_master_clients'; 119 120--echo #Test after_commit 121connection con1; 122SET GLOBAL rpl_semi_sync_master_wait_point= 'AFTER_COMMIT'; 123SET DEBUG_SYNC= "after_group_after_commit SIGNAL after_commit_done WAIT_FOR end"; 124--send INSERT into t1 values (4); 125 126connection con2; 127SET DEBUG_SYNC= "now WAIT_FOR after_commit_done"; 128 129sync_slave_with_master; 130select * from t1; 131 132connection con2; 133select * from t1; 134SET DEBUG_SYNC= "now SIGNAL end"; 135 136connection con1; 137reap; 138 139connection con1; 140select * from t1; 141truncate table t1; 142 143--echo ####################################################### 144--echo # Test some other options in order to cover the patch # 145--echo ####################################################### 146connection slave; 147--echo # Test rpl_semi_sync_slave_trace_level 148SET GLOBAL rpl_semi_sync_slave_trace_level= 1; 149SET GLOBAL rpl_semi_sync_slave_trace_level= 16; 150SET GLOBAL rpl_semi_sync_slave_trace_level= 64; 151SET GLOBAL rpl_semi_sync_slave_trace_level= 128; 152SET GLOBAL rpl_semi_sync_slave_trace_level= 32; 153connection master; 154--echo # Test rpl_semi_sync_master_trace_level 155SET GLOBAL rpl_semi_sync_master_trace_level= 1; 156SET GLOBAL rpl_semi_sync_master_trace_level= 16; 157SET GLOBAL rpl_semi_sync_master_trace_level= 64; 158SET GLOBAL rpl_semi_sync_master_trace_level= 128; 159SET GLOBAL rpl_semi_sync_master_trace_level= 32; 160--echo # Test rpl_semi_sync_master_timeout 161SET GLOBAL rpl_semi_sync_master_timeout= 1000; 162SET GLOBAL rpl_semi_sync_master_timeout= 10000; 163SET GLOBAL rpl_semi_sync_master_timeout = 1000000; 164 165--echo # Test rpl_semi_sync_slave_kill_conn_timeout 166SET GLOBAL rpl_semi_sync_slave_kill_conn_timeout= 10; 167SET GLOBAL rpl_semi_sync_slave_kill_conn_timeout= 20; 168SET GLOBAL rpl_semi_sync_slave_kill_conn_timeout= 60; 169SET GLOBAL rpl_semi_sync_slave_kill_conn_timeout= 5; 170 171--echo ############################################ 172--echo # Test rpl_semi_sync_master_wait_no_slave # 173--echo ############################################ 174SET GLOBAL rpl_semi_sync_master_wait_no_slave = 1; 175connection slave; 176STOP SLAVE IO_THREAD; 177--source include/wait_for_slave_io_to_stop.inc 178 179connection con1; 180SET GLOBAL rpl_semi_sync_master_timeout = 1000; 181--send INSERT INTO t1 values (1); 182 183connection con1; 184reap; 185echo # Rpl_semi_sync_master_no_tx should be non-zero 186SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx'; 187 188# test rpl_semi_sync_master_wait_no_slave = 0 189connection slave; 190START SLAVE IO_THREAD; 191--source include/wait_for_slave_io_to_start.inc 192 193connection con1; 194INSERT INTO t1 values (2); 195sync_slave_with_master; 196connection con1; 197let $status_var= Rpl_semi_sync_master_clients; 198let $status_var_value= 1; 199source include/wait_for_status_var.inc; 200let $status_var= Rpl_semi_sync_master_status; 201let $status_var_value= ON; 202source include/wait_for_status_var.inc; 203show status like 'Rpl_semi_sync_master_clients'; 204show status like 'Rpl_semi_sync_master_status'; 205 206connection slave; 207STOP SLAVE IO_THREAD; 208--source include/wait_for_slave_io_to_stop.inc 209 210connection con1; 211SET GLOBAL rpl_semi_sync_master_wait_no_slave= 0; 212SET GLOBAL rpl_semi_sync_master_timeout= 1000000000; 213INSERT INTO t1 values (3); 214show status like 'Rpl_semi_sync_master_clients'; 215show status like 'Rpl_semi_sync_master_status'; 216 217 218connection slave; 219START SLAVE IO_THREAD; 220--source include/wait_for_slave_io_to_start.inc 221 222connection con1; 223--let $status_var= Rpl_semi_sync_master_status 224--let $status_var_value=ON 225--source include/wait_for_status_var.inc 226 227SET GLOBAL rpl_semi_sync_master_timeout= 10000000; 228SET GLOBAL rpl_semi_sync_master_wait_no_slave= 1; 229INSERT INTO t1 values (4); 230sync_slave_with_master; 231 232connection con1; 233show status like 'Rpl_semi_sync_master_status'; 234show status like 'Rpl_semi_sync_master_clients'; 235 236--echo ########################################## 237--echo # Test rpl_semi_sync_slave_delay_master # 238--echo ########################################## 239 240connection slave; 241SET GLOBAL rpl_semi_sync_slave_delay_master= 1; 242START SLAVE IO_THREAD; 243--source include/wait_for_slave_io_to_start.inc 244 245connection con1; 246INSERT INTO t1 values (3); 247--source include/sync_slave_io_with_master.inc 248 249connection con1; 250show status like 'Rpl_semi_sync_master_clients'; 251show status like 'Rpl_semi_sync_master_status'; 252 253sync_slave_with_master; 254 255connection slave; 256select * from t1 order by a; 257connection con1; 258select * from t1 order by a; 259 260connection slave; 261SET GLOBAL rpl_semi_sync_slave_delay_master = 0; 262STOP SLAVE IO_THREAD; 263--source include/wait_for_slave_io_to_stop.inc 264START SLAVE IO_THREAD; 265--source include/wait_for_slave_io_to_start.inc 266 267--echo ########################################################## 268--echo # Test rpl_semi_sync_master_enabled and new ACK thread # 269--echo ######################################################### 270connection con1; 271SET GLOBAL rpl_semi_sync_master_enabled = 0; 272 273let $status_var= Rpl_semi_sync_master_clients; 274let $status_var_value= 1; 275source include/wait_for_status_var.inc; 276show status like 'Rpl_semi_sync_master_clients'; 277 278INSERT INTO t1 VALUES (1); 279SET GLOBAL rpl_semi_sync_master_enabled = 1; 280INSERT INTO t1 VALUES (2); 281show status like 'Rpl_semi_sync_master_clients'; 282 283--echo # Test failure of select error . 284SET GLOBAL debug = 'd,rpl_semisync_simulate_select_error'; 285# It can still receive ACK from semi-sync slave 286INSERT INTO t1 VALUES(3); 287sync_slave_with_master; 288 289connection con1; 290--echo # Test failure of pthread_create 291SET GLOBAL rpl_semi_sync_master_enabled = 0; 292SET GLOBAL debug = 'd,rpl_semisync_simulate_create_thread_failure'; 293SET GLOBAL rpl_semi_sync_master_enabled= ON; 294 295--let $wait_condition= SELECT @@global.rpl_semi_sync_master_enabled = 0 296--source include/wait_condition.inc 297 298# Todo: implement the thread join failure simulation 299--echo # Test failure of pthread_join 300#SET GLOBAL DEBUG = 'd,rpl_semisync_simulate_thread_join_failure'; 301#SET GLOBAL rpl_semi_sync_master_enabled= ON; 302# 303#--let $wait_condition= SELECT @@global.rpl_semi_sync_master_enabled = 0 304#--source include/wait_condition.inc 305SET GLOBAL rpl_semi_sync_master_enabled= OFF; 306 307--echo # 308--echo # Failure on registering semisync slave 309--echo # 310SET GLOBAL debug= 'd,rpl_semisync_simulate_add_slave_failure'; 311SET GLOBAL rpl_semi_sync_master_enabled= ON; 312 313connection slave; 314STOP SLAVE IO_THREAD; 315--source include/wait_for_slave_io_to_stop.inc 316START SLAVE IO_THREAD; 317--source include/wait_for_slave_io_to_start.inc 318 319connection con1; 320#--echo # Should be Zero. 321# Todo: implement the add_slave_failure simulation. Meanwhile 322# the status will be 1. 323# show status like 'Rpl_semi_sync_master_clients'; 324SET GLOBAL debug=''; 325 326--let $status_var= Rpl_semi_sync_master_clients 327--let $status_var_value= 1 328--let $status_type= GLOBAL 329--source include/wait_for_status_var.inc 330 331connection slave; 332--disable_warnings 333START SLAVE IO_THREAD; 334--source include/wait_for_slave_io_to_start.inc 335--enable_warnings 336 337connection con1; 338sync_slave_with_master; 339 340show status like 'Rpl_semi_sync_master_clients'; 341 342--echo ################################################################## 343--echo # Test fixing of BUG#70669 # 344--echo #SLAVE CAN'T CONTINUE REPLICATION AFTER MASTER'S CRASH RECOVERY # 345--echo ################################################################# 346connection con1; 347SET GLOBAL sync_binlog = 1; 348CREATE TABLE t2 (c1 INT); 349sync_slave_with_master; 350 351connection con1; 352# Block the session before its events are synced to disk 353#SET DEBUG_SYNC = 'before_sync_binlog_file SIGNAL before_sync_done WAIT_FOR continue'; 354send INSERT INTO t2 values (1); 355 356connection slave; 357--let $table= t2 358--let $count= 1 359--source include/wait_until_rows_count.inc 360 361connection con2; 362#SET DEBUG_SYNC= "now WAIT_FOR before_sync_done"; 363#SET DEBUG_SYNC = "now SIGNAL continue"; 364 365connection con1; 366reap; 367 368sync_slave_with_master; 369show tables like 't2'; 370select * from t2; 371 372connection con1; 373#SET DEBUG_SYNC= "before_update_pos SIGNAL leader_ready WAIT_FOR follower_ready"; 374send INSERT INTO t2 VALUES (2); 375 376connection con2; 377#SET DEBUG_SYNC= "now WAIT_FOR leader_ready"; 378#SET DEBUG_SYNC= "after_sync_queue SIGNAL follower_ready"; 379send INSERT INTO t2 VALUES (3); 380 381connection con1; 382reap; 383connection con2; 384reap; 385 386connection con1; 387#SET DEBUG_SYNC = 'before_sync_binlog_file SIGNAL before_sync_done WAIT_FOR continue'; 388SET GLOBAL sync_binlog = 0; 389 390# Todo: fix this simulation and implement the intended sync protocol. 391# As a workaround the DROP sender explicitly okays 392# which naturally increments the binlog position. 393#send DROP TABLE t2; 394DROP TABLE t2; 395 396connection con2; 397#SET DEBUG_SYNC= "now WAIT_FOR before_sync_done"; 398 399sync_slave_with_master; 400 401# t2 should be dropped 402show tables like 't2'; 403 404connection con2; 405#SET DEBUG_SYNC = "now SIGNAL continue"; 406 407# This block is commented out on purpose. See the todo/workaround above. 408#connection con1; 409#reap; 410 411 412--echo #cleanup 413connection master; 414SET DEBUG_SYNC= 'reset'; 415disconnect con1; 416disconnect con2; 417disconnect con3; 418SET GLOBAL rpl_semi_sync_master_timeout= 10000; 419SET GLOBAL rpl_semi_sync_master_enabled = 0; 420DROP TABLE t1; 421connection slave; 422SET GLOBAL rpl_semi_sync_slave_enabled = 0; 423stop slave;start slave; 424 425--source include/rpl_end.inc 426