Commit 0c9aaecc authored by Luis Soares's avatar Luis Soares

BUG#38826 Race in MYSQL_LOG::purge_logs is impossible to debug in production

BUG#39325 Server crash inside MYSQL_LOG::purge_first_log halts replicaiton

The patch reverses the order of the purging and updating events for log and
relay-log.info/index files respectively.

This solves the problem of having holes caused by crashes happening between updating
info/index files and purging logs.

This patch also contains an aditional test case for testing the crashing before purge logs.
      
NOTE1: This is a combined patch for BUG#38826 and BUG#39325. This patch is based on
bugteam tree and takes into account reviewers suggestions.

NOTE2: Merge from 5.0-bugteam
parents 3059c95c 5726574b
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
let $counter= 500; let $counter= 500;
while ($mysql_errno) while ($mysql_errno)
{ {
--error 0,2002,2006 --error 0,2002,2006,2003
show status; show status;
dec $counter; dec $counter;
......
...@@ -21,6 +21,7 @@ flush logs; ...@@ -21,6 +21,7 @@ flush logs;
*** must be a warning master-bin.000001 was not found *** *** must be a warning master-bin.000001 was not found ***
Warnings: Warnings:
Warning 1612 Being purged log MYSQLTEST_VARDIR/log/master-bin.000001 was not found Warning 1612 Being purged log MYSQLTEST_VARDIR/log/master-bin.000001 was not found
Warning 1612 Being purged log MYSQLTEST_VARDIR/log/master-bin.000001 was not found
*** must show one record, of the active binlog, left in the index file after PURGE *** *** must show one record, of the active binlog, left in the index file after PURGE ***
show binary logs; show binary logs;
Log_name File_size Log_name File_size
......
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
stop slave;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (id INT);
start slave;
SET GLOBAL debug= "+d,crash_before_purge_logs";
FLUSH LOGS;
ERROR HY000: Lost connection to MySQL server during query
start slave;
--source include/master-slave.inc
--source include/have_debug.inc
--disable_reconnect
# We have to sync with master, to ensure slave had time to start properly
# # before we stop it. If not, we get errors about UNIX_TIMESTAMP() in the
# log.
sync_slave_with_master;
stop slave;
--source include/wait_for_slave_to_stop.inc
# ON MASTER
connection master;
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (id INT);
let $1=100;
disable_query_log;
begin;
while ($1)
{
eval INSERT INTO t1 VALUES( $1 );
dec $1;
}
DROP TABLE t1;
save_master_pos;
enable_query_log;
## ON SLAVE
connection slave;
start slave;
--source include/wait_for_slave_to_start.inc
sync_with_master 0;
connection master;
save_master_pos;
connection slave;
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/slave0.expect
SET GLOBAL debug= "+d,crash_before_purge_logs";
--error 2013
# try to rotate logs
FLUSH LOGS;
--enable_reconnect
--source include/wait_until_connected_again.inc
start slave;
--source include/wait_for_slave_to_start.inc
sync_with_master 0;
This diff is collapsed.
...@@ -233,6 +233,13 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -233,6 +233,13 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
pthread_cond_t update_cond; pthread_cond_t update_cond;
ulonglong bytes_written; ulonglong bytes_written;
IO_CACHE index_file; IO_CACHE index_file;
/*
purge_temp is a temp file used in purge_logs so that the index file
can be updated before deleting files from disk, yielding better crash
recovery. It is created on demand the first time purge_logs is called
and then reused for subsequent calls. It is cleaned up in cleanup().
*/
IO_CACHE purge_temp;
char index_file_name[FN_REFLEN]; char index_file_name[FN_REFLEN];
/* /*
The max size before rotation (usable only if log_type == LOG_BIN: binary The max size before rotation (usable only if log_type == LOG_BIN: binary
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment