#At file:///home/lsoares/Workspace/mysql-server/bugfix/b34582/mysql-5.1-bugteam/ based on revid:joro@stripped
3024 Luis Soares 2009-07-21
BUG#34582: FLUSH LOGS does not close and reopen the binlog index
file
Issuing 'FLUSH LOGS' does not close and reopen indexfile.
Instead a SEEK_SET is performed.
This patch makes index file to be closed and reopened whenever a
rotation happens (FLUSH LOGS is issued or binary log exceeds
maximum configured size).
@ mysql-test/suite/binlog/r/binlog_delete_and_flush_index.result
Result file.
@ mysql-test/suite/binlog/t/binlog_delete_and_flush_index.test
Test case.
@ sql/log.cc
Added LOG_CLOSE_INDEX flag when calling MYSQL_BIN_LOG::close
from within MYSQL_BIN_LOG::new_file_impl (which should just be
called whenever a rotation is to happen - FLUSH LOGS issued or
binlog size exceeds the maximum configured).
added:
mysql-test/suite/binlog/r/binlog_delete_and_flush_index.result
mysql-test/suite/binlog/t/binlog_delete_and_flush_index.test
modified:
sql/log.cc
=== added file 'mysql-test/suite/binlog/r/binlog_delete_and_flush_index.result'
--- a/mysql-test/suite/binlog/r/binlog_delete_and_flush_index.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_delete_and_flush_index.result 2009-07-21 17:34:46 +0000
@@ -0,0 +1,29 @@
+RESET MASTER;
+FLUSH LOGS;
+FLUSH LOGS;
+FLUSH LOGS;
+### assertion: new binlog files exist due to FLUSH LOGS
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+master-bin.000003 #
+master-bin.000004 #
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/tmp/b34582-master-bin.index');
+### assertion: show index file contents and these should match show binary logs issued above
+SELECT @index;
+@index
+master-bin.000001
+master-bin.000002
+master-bin.000003
+master-bin.000004
+
+### assertion: purging binlogs up to binlog created after instrumenting index file should work
+PURGE BINARY LOGS TO 'master-bin.000004';
+### assertion: show binary logs should only contain latest binlog
+show binary logs;
+Log_name File_size
+master-bin.000004 #
+### assertion: assert that binlog files were indeed purged (using file_exists calls)
+### assertion: assert that not purged binlog file (master-bin.000004) exists
+RESET MASTER;
=== added file 'mysql-test/suite/binlog/t/binlog_delete_and_flush_index.test'
--- a/mysql-test/suite/binlog/t/binlog_delete_and_flush_index.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_delete_and_flush_index.test 2009-07-21 17:34:46 +0000
@@ -0,0 +1,91 @@
+# BUG#34582: FLUSH LOGS does not close and reopen the binlog index
+# file
+#
+# WHAT
+# ====
+#
+# We want to test that FLUSH LOGS closes and reopens binlog index
+# file.
+#
+# HOW
+# ===
+#
+# PREPARE:
+# 1. rotate the log 'FLUSH LOGS' (create new binlog file)
+# 2. copy the binlog index file to temporary file
+# 3. delete the original file
+# 4. move back copy to the place where the deleted file was
+# 5. rotate the log 'FLUSH LOGS' (create new binlog file)
+# 6. rotate the log 'FLUSH LOGS' (create new binlog file)
+#
+# ASSERTIONS:
+# 1. SHOW BINARY LOGS shows all log files created
+# 2. Show index file containing all binlog files created
+# 3. Purge binlogs up to the latest one succeeds
+# 4. SHOW BINARY LOGS presents the latest one only after purging
+# 5. Purged binlogs files don't exist in the filesystem
+# 6. Not purged binlog file exists in the filesystem
+#
+# CLEAN UP:
+# 1. RESET MASTER
+#
+
+-- source include/have_log_bin.inc
+
+RESET MASTER;
+
+-- let $datadir= `SELECT @@datadir`
+-- let $copy=$MYSQLTEST_VARDIR/tmp/b34582-master-bin.index
+-- let $index=$datadir/master-bin.index
+
+# action: should cause rotation and new entry in index file
+FLUSH LOGS;
+
+# action: copy, delete original and copy back the backed up index file
+-- copy_file $index $copy
+-- remove_file $index
+-- copy_file $copy $index
+-- remove_file $copy
+
+# action: should cause rotation and new entry in index file even if
+# index file was replaced externally
+FLUSH LOGS;
+
+# action: should cause rotation and new entry in index file even if
+# index file was replaced externally
+FLUSH LOGS;
+
+--echo ### assertion: new binlog files exist due to FLUSH LOGS
+-- source include/show_binary_logs.inc
+
+# prepare to load index file
+-- copy_file $index $copy
+-- chmod 0644 $copy
+-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+-- eval SET @index=LOAD_FILE('$copy')
+-- remove_file $copy
+
+-- echo ### assertion: show index file contents and these should match show binary logs issued above
+-- replace_regex /\.[\\\/]master/master/
+SELECT @index;
+
+-- echo ### assertion: purging binlogs up to binlog created after instrumenting index file should work
+-- let $current_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
+-- eval PURGE BINARY LOGS TO '$current_binlog'
+
+-- echo ### assertion: show binary logs should only contain latest binlog
+-- source include/show_binary_logs.inc
+
+-- echo ### assertion: assert that binlog files were indeed purged (using file_exists calls)
+-- error 1
+-- file_exists $datadir/master-bin.000001
+-- error 1
+-- file_exists $datadir/master-bin.000002
+-- error 1
+-- file_exists $datadir/master-bin.000003
+
+-- echo ### assertion: assert that not purged binlog file exists
+-- file_exists $datadir/$current_binlog
+
+# CLEAN UP
+RESET MASTER;
=== modified file 'sql/log.cc'
--- a/sql/log.cc 2009-07-10 23:12:13 +0000
+++ b/sql/log.cc 2009-07-21 17:34:46 +0000
@@ -3562,7 +3562,7 @@ void MYSQL_BIN_LOG::new_file_impl(bool n
}
old_name=name;
name=0; // Don't free name
- close(LOG_CLOSE_TO_BE_OPENED);
+ close(LOG_CLOSE_TO_BE_OPENED | LOG_CLOSE_INDEX);
/*
Note that at this point, log_state != LOG_CLOSED (important for is_open()).
@@ -3577,8 +3577,10 @@ void MYSQL_BIN_LOG::new_file_impl(bool n
trigger temp tables deletion on slaves.
*/
- open(old_name, log_type, new_name_ptr,
- io_cache_type, no_auto_events, max_size, 1);
+ /* reopen index binlog file, BUG#34582 */
+ if (!open_index_file(index_file_name, 0))
+ open(old_name, log_type, new_name_ptr,
+ io_cache_type, no_auto_events, max_size, 1);
my_free(old_name,MYF(0));
end:
Attachment: [text/bzr-bundle] bzr/luis.soares@sun.com-20090721173446-g89tjec7bmbiltz8.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-bugteam branch (luis.soares:3024) Bug#34582 | Luis Soares | 21 Jul |