| 1 |
--source include/have_multi_ndb.inc |
| 2 |
--source include/have_binlog_format_mixed_or_row.inc |
| 3 |
--source suite/ndb_rpl/ndb_master-slave.inc |
| 4 |
--source suite/ndb/include/backup_restore_setup.inc |
| 5 |
|
| 6 |
--echo Test to show that combination of Backup + Restore and |
| 7 |
--echo Binlog positioning correctly recovers a slave |
| 8 |
|
| 9 |
# A new MTR testcase (ndb_rpl_backup_epoch) is added, which does a more |
| 10 |
# end-to-end test of Backup, ndb_restore --restore-epoch and replication |
| 11 |
# to check that the --restore-epoch is correct. |
| 12 |
# |
| 13 |
# Basic idea : |
| 14 |
# - Stop replication |
| 15 |
# - Create a table |
| 16 |
# - Start up a stored procedure performing regular inserts to |
| 17 |
# the table on the Master (~10 per second) for some duration |
| 18 |
# - Wait a while |
| 19 |
# - Perform a backup (SNAPSHOTEND) |
| 20 |
# - Wait a while |
| 21 |
# - Perform a backup (SNAPSHOTSTART) |
| 22 |
# - Wait for inserts to finish |
| 23 |
# - Count rows (n) |
| 24 |
# - Replicate to slave |
| 25 |
# - Count rows (n) (basic replication test) |
| 26 |
# - For each of SNAPSHOTEND backup, SNAPSHOTSTART backup : |
| 27 |
# 1 Truncate table on slave |
| 28 |
# 2 Restore backup including --restore-epoch |
| 29 |
# 3 Count rows restored by backup (b < n) |
| 30 |
# 4 Use restored epoch to position slave |
| 31 |
# 5 Start replication |
| 32 |
# 6 Count rows restored by backup + log (bl == n) |
| 33 |
# (Basic check that we can get a consistent final state) |
| 34 |
# 7 Stop replication |
| 35 |
# 8 Truncate table on slave |
| 36 |
# 9 Use epoch position from 4 to position slave |
| 37 |
# 10 Start replication |
| 38 |
# 11 Count rows applied by log (l < n) |
| 39 |
# 12 Check that (b + l == n) |
| 40 |
# (Basic check that we are not applying duplicate entries) |
| 41 |
# |
| 42 |
# Failure modes |
| 43 |
# - If the restore epoch were too high, some entries could be |
| 44 |
# missing and the test would fail @ 6 (and @12) |
| 45 |
# - If the restore epoch were too low, some entries could be |
| 46 |
# applied twice and the test would fail @12. |
| 47 |
|
| 48 |
--connection slave |
| 49 |
stop slave; |
| 50 |
|
| 51 |
--connection master |
| 52 |
use test; |
| 53 |
create table ticker (a int primary key) engine=ndb; |
| 54 |
reset master; |
| 55 |
|
| 56 |
--connection server2 |
| 57 |
|
| 58 |
use test; |
| 59 |
|
| 60 |
delimiter %; |
| 61 |
|
| 62 |
create procedure tick(times int) |
| 63 |
begin |
| 64 |
set @x = 1; |
| 65 |
repeat |
| 66 |
insert into test.ticker values (@x); |
| 67 |
select sleep(0.1); |
| 68 |
set @x = @x + 1; |
| 69 |
until @x > times |
| 70 |
end repeat; |
| 71 |
end % |
| 72 |
|
| 73 |
delimiter ;% |
| 74 |
|
| 75 |
--echo Insert ticks into the table every 100 millis for 20s |
| 76 |
--send call tick(200); |
| 77 |
|
| 78 |
--connection master |
| 79 |
select sleep(2); |
| 80 |
|
| 81 |
--echo Run backup snapshotend |
| 82 |
--source suite/ndb/t/ndb_backup_nowait_start.inc |
| 83 |
--source suite/ndb/t/ndb_backup_nowait_wait.inc |
| 84 |
|
| 85 |
--let $first_backup_id = $the_backup_id |
| 86 |
|
| 87 |
# select sleep(20); # Force second backup to run after all changes |
| 88 |
|
| 89 |
select sleep(2); |
| 90 |
|
| 91 |
--echo Run backup snapshotstart |
| 92 |
let $start_backup_extra = SNAPSHOTSTART; |
| 93 |
--source suite/ndb/t/ndb_backup_nowait_start.inc |
| 94 |
--source suite/ndb/t/ndb_backup_nowait_wait.inc |
| 95 |
|
| 96 |
--let $second_backup_id = $the_backup_id |
| 97 |
|
| 98 |
--echo Wait for ticker to stop |
| 99 |
--connection server2 |
| 100 |
--disable_query_log |
| 101 |
--disable_result_log |
| 102 |
--reap |
| 103 |
--enable_result_log |
| 104 |
--enable_query_log |
| 105 |
|
| 106 |
--echo Expect 200 entries on Master |
| 107 |
select count(1) from test.ticker; |
| 108 |
select max(a) from test.ticker; |
| 109 |
|
| 110 |
--echo Replicate as normal |
| 111 |
--connection slave |
| 112 |
|
| 113 |
use test; |
| 114 |
create table ticker (a int primary key) engine=ndb; |
| 115 |
|
| 116 |
start slave; |
| 117 |
|
| 118 |
--connection master |
| 119 |
--sync_slave_with_master |
| 120 |
--connection slave |
| 121 |
|
| 122 |
--echo Expect 200 entries on Slave |
| 123 |
select count(1) from test.ticker; |
| 124 |
select max(a) from test.ticker; |
| 125 |
|
| 126 |
--echo Verify backup restoration is correct wrt binlog positions |
| 127 |
|
| 128 |
--let $backup_count=2 |
| 129 |
--let $backup_id = $first_backup_id |
| 130 |
|
| 131 |
while($backup_count) |
| 132 |
{ |
| 133 |
--echo Restore backup on the slave |
| 134 |
--connection slave |
| 135 |
stop slave; |
| 136 |
truncate table test.ticker; |
| 137 |
delete from mysql.ndb_apply_status; |
| 138 |
|
| 139 |
--let $outfile = $MYSQLTEST_VARDIR/tmp/ndb_backup_log.txt |
| 140 |
--exec $NDB_RESTORE -c$NDB_CONNECTSTRING_SLAVE -b $backup_id -n 1 -r --restore-epoch $NDB_BACKUPS-$backup_id > $outfile 2>&1 |
| 141 |
--exec $NDB_RESTORE -c$NDB_CONNECTSTRING_SLAVE -b $backup_id -n 2 -r $NDB_BACKUPS-$backup_id >> $outfile 2>&1 |
| 142 |
|
| 143 |
--disable_result_log |
| 144 |
select @backup_rows:=count(1) from test.ticker; |
| 145 |
select @backup_max_val:=max(a) from test.ticker; |
| 146 |
--enable_result_log |
| 147 |
|
| 148 |
# Expect both to be the same here |
| 149 |
select @backup_rows - @backup_max_val; |
| 150 |
|
| 151 |
--let $backup_epoch=query_get_value(select epoch from mysql.ndb_apply_status where server_id=0, epoch, 1) |
| 152 |
|
| 153 |
#--echo Backup epoch of backup $backup_id is $backup_epoch |
| 154 |
|
| 155 |
--let $the_epoch = $backup_epoch |
| 156 |
--source suite/ndb_rpl/t/ndb_rpl_change_master_to_epoch.inc |
| 157 |
|
| 158 |
--connection slave |
| 159 |
|
| 160 |
start slave; |
| 161 |
|
| 162 |
--connection master |
| 163 |
--sync_slave_with_master |
| 164 |
--connection slave |
| 165 |
|
| 166 |
--echo Expect 200 rows when backup and binlog subset combined on slave |
| 167 |
select count(1) from test.ticker; |
| 168 |
select max(a) from test.ticker; |
| 169 |
|
| 170 |
# REMOVE |
| 171 |
#select * from test.ticker order by a; |
| 172 |
|
| 173 |
--echo Now check Binlog apply alone |
| 174 |
stop slave; |
| 175 |
truncate table test.ticker; |
| 176 |
delete from mysql.ndb_apply_status; |
| 177 |
|
| 178 |
--let $the_epoch = $backup_epoch |
| 179 |
--source suite/ndb_rpl/t/ndb_rpl_change_master_to_epoch.inc |
| 180 |
|
| 181 |
--connection slave |
| 182 |
|
| 183 |
start slave; |
| 184 |
|
| 185 |
--connection master |
| 186 |
--sync_slave_with_master |
| 187 |
--connection slave |
| 188 |
|
| 189 |
--disable_result_log |
| 190 |
select @log_rows:=count(1) from test.ticker; |
| 191 |
select @log_max_val:=ifnull(max(a),200) from test.ticker; |
| 192 |
--enable_result_log |
| 193 |
|
| 194 |
--echo Expect 200 when adding backup and log rows |
| 195 |
#select @backup_rows, @log_rows; |
| 196 |
select @backup_rows + @log_rows; |
| 197 |
select @log_max_val; |
| 198 |
|
| 199 |
--let $total_rows = query_get_value(select @backup_rows + @log_rows - 200 as r, r, 1) |
| 200 |
if ($total_rows) |
| 201 |
{ |
| 202 |
--echo Total rows not as expected when restoring backup $backup_id |
| 203 |
--echo $backup_id epoch is $backup_epoch |
| 204 |
select @backup_rows, @log_rows; |
| 205 |
--connection master |
| 206 |
select * from mysql.ndb_binlog_index; |
| 207 |
--die Test fail check logs |
| 208 |
} |
| 209 |
|
| 210 |
--dec $backup_count |
| 211 |
--let $backup_id = $second_backup_id |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
--echo Cleanup |
| 217 |
|
| 218 |
--connection server2 |
| 219 |
drop procedure tick; |
| 220 |
drop table ticker; |
| 221 |
|
| 222 |
--connection master |
| 223 |
reset master; |
| 224 |
|
| 225 |
--connection slave |
| 226 |
#start slave; |
| 227 |
|
| 228 |
--remove_file $outfile |
| 229 |
|
| 230 |
--connection master |
| 231 |
--source suite/ndb/include/backup_restore_cleanup.inc |
| 232 |
--source include/rpl_end.inc |