Debian Codegraph @

mysql-test/suite/binlog/t/binlog_delete_and_flush_index.test

raw
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= `SELECT @@datadir`
41 -- let $index=$datadir/master-bin.index
42 -- chmod 0644 $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_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
49 -- eval SET @index=LOAD_FILE('$index')
50 -- replace_regex /\.[\\\/]master/master/
51 SELECT @index;
52
53 --echo ### assertion: show original binlogs
54 -- source include/show_binary_logs.inc
55
56 --echo ### assertion: binlog contents from regular entries
57 -- source include/show_binlog_events.inc
58
59 # action: copy binlogs to other names and change entries in index file
60 -- copy_file $datadir/master-bin.000001 $datadir/master-bin-b34582.000001
61 let INDEX_FILE=$index;
62 perl;
63 $file= $ENV{'INDEX_FILE'};
64 open(FILE, ">$file") || die "Unable to open $file.";
65 truncate(FILE,0);
66 close ($file);
67 EOF
68
69 -- append_file $index
70 master-bin-b34582.000001
71 EOF
72
73 # action: should cause rotation, and creation of new binlogs
74 FLUSH LOGS;
75
76 # file is not used anymore - remove it (mysql closed on flush logs).
77 -- remove_file $datadir/master-bin.000001
78
79 -- echo ### assertion: index file contains renamed binlog and the new one
80 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
81 -- eval SET @index=LOAD_FILE('$index')
82 -- replace_regex /\.[\\\/]master/master/
83 SELECT @index;
84
85 -- echo ### assertion: original binlog content still exists, despite we
86 -- echo ### renamed and changed the index file
87 -- source include/show_binlog_events.inc
88
89 -- echo ### assertion: user changed binlog index shows correct entries
90 -- source include/show_binary_logs.inc
91
92 DROP TABLE t1;
93
94 -- echo ### assertion: purging binlogs up to binlog created after instrumenting index file should work
95 -- let $current_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
96 -- eval PURGE BINARY LOGS TO '$current_binlog'
97
98 -- echo ### assertion: show binary logs should only contain latest binlog
99 -- source include/show_binary_logs.inc
100
101 -- echo ### assertion: assert that binlog files were indeed purged (using file_exists calls)
102 -- error 1
103 -- file_exists $datadir/master-bin-b34852.000001
104
105 -- echo ### assertion: assert that not purged binlog file exists
106 -- file_exists $datadir/$current_binlog
107
108 -- echo ### assertion: show index file contents and these should match show binary logs issued above
109 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
110 -- eval SET @index=LOAD_FILE('$index')
111 -- replace_regex /\.[\\\/]master/master/
112 SELECT @index;
113
114 RESET MASTER;