Skip to content

Commit 60d93c6

Browse files
author
Luis Soares
committed
BUG#48738: merge local branch into mysql-5.0-bugteam latest.
2 parents c311450 + fe40b17 commit 60d93c6

File tree

3 files changed

+226
-4
lines changed

3 files changed

+226
-4
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
RESET MASTER;
2+
CREATE TABLE t1 (a int);
3+
### assertion: index file contains regular entries
4+
SET @index=LOAD_FILE('MYSQLD_DATADIR/master-bin.index');
5+
master-bin.000001
6+
7+
### assertion: show original binlogs
8+
show binary logs;
9+
Log_name File_size
10+
master-bin.000001 #
11+
### assertion: binlog contents from regular entries
12+
show binlog events from <binlog_start>;
13+
Log_name Pos Event_type Server_id End_log_pos Info
14+
master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a int)
15+
FLUSH LOGS;
16+
### assertion: index file contains renamed binlog and the new one
17+
SET @index=LOAD_FILE('MYSQLD_DATADIR/master-bin.index');
18+
master-bin-b34582.000001
19+
master-bin.000002
20+
21+
### assertion: original binlog content still exists, despite we
22+
### renamed and changed the index file
23+
show binlog events from <binlog_start>;
24+
Log_name Pos Event_type Server_id End_log_pos Info
25+
master-bin-b34582.000001 # Query # # use `test`; CREATE TABLE t1 (a int)
26+
### assertion: user changed binlog index shows correct entries
27+
show binary logs;
28+
Log_name File_size
29+
master-bin-b34582.000001 #
30+
master-bin.000002 #
31+
DROP TABLE t1;
32+
### assertion: purging binlogs up to binlog created after instrumenting index file should work
33+
PURGE BINARY LOGS TO 'master-bin.000002';
34+
### assertion: show binary logs should only contain latest binlog
35+
show binary logs;
36+
Log_name File_size
37+
master-bin.000002 #
38+
### assertion: assert that binlog files were indeed purged (using file_exists calls)
39+
### assertion: assert that not purged binlog file exists
40+
### assertion: show index file contents and these should match show binary logs issued above
41+
SET @index=LOAD_FILE('MYSQLD_DATADIR/master-bin.index');
42+
master-bin.000002
43+
44+
RESET MASTER;
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# BUG#34582: FLUSH LOGS does not close and reopen the binlog index
2+
# file
3+
#
4+
# WHAT
5+
# ====
6+
#
7+
# We want to test that FLUSH LOGS closes and reopens binlog index
8+
# file.
9+
#
10+
# HOW
11+
# ===
12+
#
13+
# PREPARE:
14+
# 1. create some binlog events
15+
# 2. show index content, binlog events and binlog contents
16+
# for mysql-bin.000001
17+
# 3. copy the mysql-bin.000001 to mysql-bin-b34582.000001
18+
# 4. change the index file so that mysql-bin.000001 is replaced
19+
# with mysql-bin-b34582.000001
20+
# 5. FLUSH the logs so that new index is closed and reopened
21+
#
22+
# ASSERTIONS:
23+
# 1. index file contents shows mysql-bin-b34582.000001 and
24+
# mysql-bin.000002
25+
# 1. show binary logs shows current index entries
26+
# 2. binlog contents for mysql-bin-b34582.000001 are displayed
27+
# 3. Purge binlogs up to the latest one succeeds
28+
# 4. SHOW BINARY LOGS presents the latest one only after purging
29+
# 5. Purged binlogs files don't exist in the filesystem
30+
# 6. Not purged binlog file exists in the filesystem
31+
#
32+
# CLEAN UP:
33+
# 1. RESET MASTER
34+
#
35+
36+
-- source include/have_log_bin.inc
37+
38+
RESET MASTER;
39+
40+
-- let $datadir= $MYSQLTEST_VARDIR/log
41+
-- let $index=$datadir/master-bin.index
42+
-- chmod 0666 $index
43+
44+
# action: issue one command so that binlog gets some event
45+
CREATE TABLE t1 (a int);
46+
47+
-- echo ### assertion: index file contains regular entries
48+
-- replace_regex /[\\\/].*master/MYSQLD_DATADIR\/master/
49+
-- eval SET @index=LOAD_FILE('$index')
50+
if (`SELECT convert(@@version_compile_os using latin1)
51+
IN ('Win32','Win64','Windows')`)
52+
{
53+
-- disable_query_log
54+
-- disable_result_log
55+
-- let $a= `SELECT REPLACE (@index, '$datadir\', '')`
56+
-- enable_result_log
57+
-- enable_query_log
58+
59+
-- echo $a
60+
61+
}
62+
if (!`SELECT convert(@@version_compile_os using latin1)
63+
IN ('Win32','Win64','Windows')`)
64+
{
65+
-- disable_query_log
66+
-- disable_result_log
67+
-- let $a= `SELECT REPLACE (@index, '$datadir/', '')`
68+
-- enable_result_log
69+
-- enable_query_log
70+
71+
-- echo $a
72+
}
73+
74+
--echo ### assertion: show original binlogs
75+
-- source include/show_binary_logs.inc
76+
77+
--echo ### assertion: binlog contents from regular entries
78+
-- source include/show_binlog_events.inc
79+
80+
# action: copy binlogs to other names and change entries in index file
81+
-- copy_file $datadir/master-bin.000001 $datadir/master-bin-b34582.000001
82+
-- let newbinfile=$datadir/master-bin-b34582.000001
83+
let INDEX_FILE=$index;
84+
perl;
85+
$newbinfile= $ENV{'newbinfile'};
86+
$file= $ENV{'INDEX_FILE'};
87+
open(FILE, ">$file") || die "Unable to open $file.";
88+
truncate(FILE,0);
89+
print FILE $newbinfile . "\n";
90+
close ($file);
91+
EOF
92+
93+
# action: should cause rotation, and creation of new binlogs
94+
FLUSH LOGS;
95+
96+
# file is not used anymore - remove it (mysql closed on flush logs).
97+
-- remove_file $datadir/master-bin.000001
98+
99+
-- echo ### assertion: index file contains renamed binlog and the new one
100+
-- replace_regex /[\\\/].*master/MYSQLD_DATADIR\/master/
101+
-- eval SET @index=LOAD_FILE('$index')
102+
if (`SELECT convert(@@version_compile_os using latin1)
103+
IN ('Win32','Win64','Windows')`)
104+
{
105+
-- disable_query_log
106+
-- disable_result_log
107+
-- let $a= `SELECT REPLACE (@index, '$datadir\', '')`
108+
-- enable_result_log
109+
-- enable_query_log
110+
111+
-- echo $a
112+
113+
}
114+
if (!`SELECT convert(@@version_compile_os using latin1)
115+
IN ('Win32','Win64','Windows')`)
116+
{
117+
-- disable_query_log
118+
-- disable_result_log
119+
-- let $a= `SELECT REPLACE (@index, '$datadir/', '')`
120+
-- enable_result_log
121+
-- enable_query_log
122+
123+
-- echo $a
124+
}
125+
126+
-- echo ### assertion: original binlog content still exists, despite we
127+
-- echo ### renamed and changed the index file
128+
-- source include/show_binlog_events.inc
129+
130+
-- echo ### assertion: user changed binlog index shows correct entries
131+
-- source include/show_binary_logs.inc
132+
133+
DROP TABLE t1;
134+
135+
-- echo ### assertion: purging binlogs up to binlog created after instrumenting index file should work
136+
-- let $current_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
137+
-- eval PURGE BINARY LOGS TO '$current_binlog'
138+
139+
-- echo ### assertion: show binary logs should only contain latest binlog
140+
-- source include/show_binary_logs.inc
141+
142+
-- echo ### assertion: assert that binlog files were indeed purged (using file_exists calls)
143+
-- error 1
144+
-- file_exists $datadir/master-bin-b34852.000001
145+
146+
-- echo ### assertion: assert that not purged binlog file exists
147+
-- file_exists $datadir/$current_binlog
148+
149+
-- echo ### assertion: show index file contents and these should match show binary logs issued above
150+
-- replace_regex /[\\\/].*master/MYSQLD_DATADIR\/master/
151+
-- eval SET @index=LOAD_FILE('$index')
152+
if (`SELECT convert(@@version_compile_os using latin1)
153+
IN ('Win32','Win64','Windows')`)
154+
{
155+
-- disable_query_log
156+
-- disable_result_log
157+
-- let $a= `SELECT REPLACE (@index, '$datadir\', '')`
158+
-- enable_result_log
159+
-- enable_query_log
160+
161+
-- echo $a
162+
163+
}
164+
if (!`SELECT convert(@@version_compile_os using latin1)
165+
IN ('Win32','Win64','Windows')`)
166+
{
167+
-- disable_query_log
168+
-- disable_result_log
169+
-- let $a= `SELECT REPLACE (@index, '$datadir/', '')`
170+
-- enable_result_log
171+
-- enable_query_log
172+
173+
-- echo $a
174+
}
175+
176+
RESET MASTER;

sql/log.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ void MYSQL_LOG::new_file(bool need_lock)
16351635
old_name=name;
16361636
save_log_type=log_type;
16371637
name=0; // Don't free name
1638-
close(LOG_CLOSE_TO_BE_OPENED);
1638+
close(LOG_CLOSE_TO_BE_OPENED | LOG_CLOSE_INDEX);
16391639

16401640
/*
16411641
Note that at this point, log_type != LOG_CLOSED (important for is_open()).
@@ -1649,9 +1649,11 @@ void MYSQL_LOG::new_file(bool need_lock)
16491649
Format_description_log_event written at server startup, which should
16501650
trigger temp tables deletion on slaves.
16511651
*/
1652-
1653-
open(old_name, save_log_type, new_name_ptr,
1654-
io_cache_type, no_auto_events, max_size, 1);
1652+
1653+
/* reopen index binlog file, BUG#34582 */
1654+
if (!open_index_file(index_file_name, 0))
1655+
open(old_name, save_log_type, new_name_ptr,
1656+
io_cache_type, no_auto_events, max_size, 1);
16551657
my_free(old_name,MYF(0));
16561658

16571659
end:

0 commit comments

Comments
 (0)