1# include/wait_for_purge.inc
2#
3# SUMMARY
4#
5#    Repeatedly attempt to purge binlogs up to a specific point, until
6#    SHOW BINARY LOGS shows it has succeeded.
7#    This can be useful to avoid races where slaves are stopped but the
8#    corresponding binlog dump thread on the master has not yet terminated.
9#    Async binlog checkpoints can also delay purge.
10#
11#    Note that it may be necessary to inject at least one event in the binlog
12#    after stopping slaves, or master may not detect stop of slave for a long
13#    time (or forever), depending on details of test case, if replication
14#    heartbeat is enabled, etc.
15#
16# USAGE:
17#
18#    --let $purge_binlogs_to=master-bin.000003
19#    --source include/wait_for_purge.inc
20#
21# SIDE EFFECTS:
22#
23#    Disables --query_log while running, enables it afterwards.
24
25--echo include/wait_for_purge.inc "$purge_binlogs_to"
26
27let $_wait_count= 300;
28let $_done= 0;
29
30--disable_query_log
31while ($_wait_count)
32{
33  dec $_wait_count;
34  eval PURGE BINARY LOGS TO "$purge_binlogs_to";
35  let $_cur_binlog= query_get_value(SHOW BINARY LOGS, Log_name, 1);
36  if (`SELECT "$_cur_binlog" = "$purge_binlogs_to"`)
37  {
38    let $_done= 1;
39    let $_wait_count= 0;
40  }
41  if ($_wait_count)
42  {
43    real_sleep 0.1;
44  }
45}
46
47if (!$_done)
48{
49  SHOW FULL PROCESSLIST;
50  eval SHOW BINARY LOGS;
51  --die ERROR: failed while waiting for binlog purge to $purge_binlogs_to
52}
53--enable_query_log
54