| 1 |
--source include/have_innodb.inc |
| 2 |
--source include/have_debug.inc |
| 3 |
--source include/master-slave.inc |
| 4 |
|
| 5 |
--connection slave |
| 6 |
--source include/stop_slave.inc |
| 7 |
# Since we inject an error updating mysql.gtid_slave_pos, we will get different |
| 8 |
# output depending on whether it is InnoDB or MyISAM (roll back or no roll |
| 9 |
# back). So fix it to make sure we are consistent, in case an earlier test case |
| 10 |
# left it as InnoDB. |
| 11 |
SET sql_log_bin=0; |
| 12 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; |
| 13 |
SET sql_log_bin=1; |
| 14 |
--source include/start_slave.inc |
| 15 |
|
| 16 |
--connection master |
| 17 |
CREATE TABLE t1 (i int) ENGINE=InnoDB; |
| 18 |
|
| 19 |
--sync_slave_with_master |
| 20 |
|
| 21 |
--echo *** MDEV-4484, incorrect error handling when entries in gtid_slave_pos not found. *** |
| 22 |
TRUNCATE TABLE mysql.gtid_slave_pos; |
| 23 |
|
| 24 |
--connection master |
| 25 |
INSERT INTO t1 VALUES (1); |
| 26 |
--sync_slave_with_master |
| 27 |
|
| 28 |
# Inject an artificial error deleting entries, and check that the error handling code works. |
| 29 |
--connection slave |
| 30 |
--source include/stop_slave.inc |
| 31 |
SET @old_gtid_cleanup_batch_size= @@GLOBAL.gtid_cleanup_batch_size; |
| 32 |
SET GLOBAL gtid_cleanup_batch_size= 2; |
| 33 |
SET @old_dbug= @@GLOBAL.debug_dbug; |
| 34 |
SET GLOBAL debug_dbug="+d,gtid_slave_pos_simulate_failed_delete"; |
| 35 |
SET sql_log_bin= 0; |
| 36 |
CALL mtr.add_suppression("<DEBUG> Error deleting old GTID row"); |
| 37 |
SET sql_log_bin= 1; |
| 38 |
--source include/start_slave.inc |
| 39 |
|
| 40 |
--connection master |
| 41 |
--disable_query_log |
| 42 |
let $i = 20; |
| 43 |
while ($i) { |
| 44 |
eval INSERT INTO t1 VALUES ($i+10); |
| 45 |
dec $i; |
| 46 |
} |
| 47 |
--enable_query_log |
| 48 |
--save_master_pos |
| 49 |
|
| 50 |
--connection slave |
| 51 |
--sync_with_master |
| 52 |
|
| 53 |
# Now wait for the slave background thread to try to delete old rows and |
| 54 |
# hit the error injection. |
| 55 |
--let _TEST_MYSQLD_ERROR_LOG=$MYSQLTEST_VARDIR/log/mysqld.2.err |
| 56 |
--perl |
| 57 |
open F, '<', $ENV{'_TEST_MYSQLD_ERROR_LOG'} or die; |
| 58 |
outer: while (1) { |
| 59 |
inner: while (<F>) { |
| 60 |
last outer if /<DEBUG> Error deleting old GTID row/; |
| 61 |
} |
| 62 |
# Easy way to do sub-second sleep without extra modules. |
| 63 |
select(undef, undef, undef, 0.1); |
| 64 |
} |
| 65 |
EOF |
| 66 |
|
| 67 |
# Since we injected error in the cleanup code, the rows should remain in |
| 68 |
# mysql.gtid_slave_pos. Check that we have at least 20 (more robust against |
| 69 |
# non-deterministic cleanup and future changes than checking for exact number). |
| 70 |
--disable_cursor_protocol |
| 71 |
SELECT COUNT(*), MAX(seq_no) INTO @pre_count, @pre_max_seq_no |
| 72 |
FROM mysql.gtid_slave_pos; |
| 73 |
--disable_cursor_protocol |
| 74 |
SELECT IF(@pre_count >= 20, "OK", CONCAT("Error: too few rows seen while errors injected: ", @pre_count)); |
| 75 |
SET GLOBAL debug_dbug= @old_dbug; |
| 76 |
|
| 77 |
--connection master |
| 78 |
--disable_query_log |
| 79 |
let $i = 20; |
| 80 |
while ($i) { |
| 81 |
eval INSERT INTO t1 VALUES ($i+40); |
| 82 |
dec $i; |
| 83 |
} |
| 84 |
--enable_query_log |
| 85 |
--sync_slave_with_master |
| 86 |
|
| 87 |
--connection slave |
| 88 |
# Now check that 1) rows are being deleted again after removing error |
| 89 |
# injection, and 2) old rows are left that failed their delete while errors |
| 90 |
# where injected (again compensating for non-deterministic deletion). |
| 91 |
# Deletion is async and slightly non-deterministic, so we wait for at |
| 92 |
# least 10 of the 20 new rows to be deleted. |
| 93 |
let $wait_condition= |
| 94 |
SELECT COUNT(*) <= 20-10 |
| 95 |
FROM mysql.gtid_slave_pos |
| 96 |
WHERE seq_no > @pre_max_seq_no; |
| 97 |
--source include/wait_condition.inc |
| 98 |
SELECT IF(COUNT(*) >= 1, "OK", CONCAT("Error: too few rows seen after errors no longer injected: ", COUNT(*))) |
| 99 |
FROM mysql.gtid_slave_pos |
| 100 |
WHERE seq_no <= @pre_max_seq_no; |
| 101 |
|
| 102 |
# Clean up |
| 103 |
--connection master |
| 104 |
DROP TABLE t1; |
| 105 |
--connection slave |
| 106 |
SET GLOBAL gtid_cleanup_batch_size= @old_gtid_cleanup_batch_size; |
| 107 |
|
| 108 |
--source include/rpl_end.inc |