| 1 |
# Change master coordinates to those for the given epoch ($the_epoch) |
| 2 |
# |
| 3 |
# Uses the Position and File of the *next* entry after |
| 4 |
# the entry for the given epoch. |
| 5 |
# When restarting from a real epoch we can start using |
| 6 |
# the next_file and next_position of the actual epoch |
| 7 |
# row, but when starting from a 'backup' epoch |
| 8 |
# (GCI << 32 | 0xffffffff), we must find either the |
| 9 |
# preceding or following epoch |
| 10 |
# |
| 11 |
# |
| 12 |
|
| 13 |
--disable_query_log |
| 14 |
--disable_result_log |
| 15 |
--connection master |
| 16 |
#--eval select * from mysql.ndb_binlog_index where epoch > $first_backup_epoch LIMIT 1; |
| 17 |
|
| 18 |
let $exact_count=0; |
| 19 |
let $after_count=0; |
| 20 |
let $before_count=0; |
| 21 |
|
| 22 |
set @exact_count = 0; |
| 23 |
eval select @exact_count:=count(1) |
| 24 |
from mysql.ndb_binlog_index where epoch = $the_epoch LIMIT 1; |
| 25 |
let $exact_count = query_get_value(select @exact_count as ec, ec, 1); |
| 26 |
|
| 27 |
set @after_count = 0; |
| 28 |
eval select @after_count:=count(1) |
| 29 |
from mysql.ndb_binlog_index where epoch > $the_epoch |
| 30 |
order by epoch asc LIMIT 1; |
| 31 |
let $after_count = query_get_value(select @after_count as ac, ac, 1); |
| 32 |
|
| 33 |
set @before_count = 0; |
| 34 |
eval select @before_count:=count(1) |
| 35 |
from mysql.ndb_binlog_index where epoch < $the_epoch |
| 36 |
order by epoch desc LIMIT 1; |
| 37 |
let $before_count = query_get_value(select @before_count as bc, bc, 1); |
| 38 |
|
| 39 |
|
| 40 |
if ($exact_count) |
| 41 |
{ |
| 42 |
# Have an entry corresponding exactly to the restore-point epoch |
| 43 |
# So start from *next* location in the Binlog described in that entry |
| 44 |
eval select @the_pos:=next_position, |
| 45 |
@the_file:=SUBSTRING_INDEX(REPLACE(next_file,'\\\\','/'), '/', -1) |
| 46 |
from mysql.ndb_binlog_index where epoch = $the_epoch LIMIT 1; |
| 47 |
|
| 48 |
#--echo Choosing exact position for $the_epoch |
| 49 |
} |
| 50 |
if (!$exact_count) |
| 51 |
{ |
| 52 |
if ($after_count) |
| 53 |
{ |
| 54 |
# Have an entry after the restore point epoch |
| 55 |
# Assume that nothing is missing between restore point and this first |
| 56 |
# following epoch |
| 57 |
# Start from beginning of this following epoch |
| 58 |
eval select @the_pos:=position, |
| 59 |
@the_file:=SUBSTRING_INDEX(REPLACE(file,'\\\\','/'), '/', -1) |
| 60 |
from mysql.ndb_binlog_index where epoch > $the_epoch |
| 61 |
order by epoch asc LIMIT 1; |
| 62 |
#--echo Choosing first position after restore point for $the_epoch |
| 63 |
} |
| 64 |
if (!$after_count) |
| 65 |
{ |
| 66 |
if ($before_count) |
| 67 |
{ |
| 68 |
# Have no entry with the exact epoch, or following it |
| 69 |
# However we can get a binlog start point by starting from just after |
| 70 |
# the preceding epoch in the binlog, assuming nothing is missing. |
| 71 |
# |
| 72 |
eval select @the_pos:=next_position, |
| 73 |
@the_file:=SUBSTRING_INDEX(REPLACE(next_file,'\\\\','/'), '/', -1) |
| 74 |
from mysql.ndb_binlog_index where epoch < $the_epoch |
| 75 |
order by epoch desc LIMIT 1; |
| 76 |
#--echo Choosing last position before restore point for $the_epoch |
| 77 |
} |
| 78 |
if (!$before_count) |
| 79 |
{ |
| 80 |
# Have no position at all binlog index table is empty |
| 81 |
# Could be optional to allow this and just start from first binlog etc |
| 82 |
# But let's leave this |
| 83 |
# |
| 84 |
--echo No position info available in masters ndb_binlog_index table |
| 85 |
--echo Epoch : $the_epoch |
| 86 |
select * from mysql.ndb_binlog_index; |
| 87 |
--die Cannot continue |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
let $the_pos=0; |
| 93 |
let $the_file="BADFILE"; |
| 94 |
let $the_pos = query_get_value(select @the_pos as pos, pos, 1); |
| 95 |
let $the_file = query_get_value(select @the_file as file, file, 1); |
| 96 |
|
| 97 |
--connection slave |
| 98 |
|
| 99 |
reset slave; |
| 100 |
--eval CHANGE REPLICATION SOURCE to SOURCE_LOG_FILE="$the_file", SOURCE_LOG_POS=$the_pos; |
| 101 |
|
| 102 |
--enable_result_log |
| 103 |
--enable_query_log |