Debian Codegraph @

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

raw
1
2 # BUG#34582: FLUSH LOGS does not close and reopen the binlog index
3 # file
4 #
5 # WHAT
6 # ====
7 #
8 # We want to test that FLUSH LOGS closes and reopens binlog index
9 # file.
10 #
11 # HOW
12 # ===
13 #
14 # PREPARE:
15 # 1. create some binlog events
16 # 2. show index content, binlog events and binlog contents
17 # for binlog.000001
18 # 3. copy the binlog.000001 to binlog-b34582.000001
19 # 4. change the index file so that binlog.000001 is replaced
20 # with binlog-b34582.000001
21 # 5. FLUSH the logs so that new index is closed and reopened
22 #
23 # ASSERTIONS:
24 # 1. index file contents shows binlog-b34582.000001 and
25 # binlog.000002
26 # 1. show binary logs shows current index entries
27 # 2. binlog contents for binlog-b34582.000001 are displayed
28 # 3. Purge binlogs up to the latest one succeeds
29 # 4. SHOW BINARY LOGS presents the latest one only after purging
30 # 5. Purged binlogs files don't exist in the filesystem
31 # 6. Not purged binlog file exists in the filesystem
32 #
33 # CLEAN UP:
34 # 1. RESET MASTER
35 #
36
37 -- source include/have_log_bin.inc
38
39 RESET MASTER;
40
41 -- let $datadir= `SELECT @@datadir`
42 -- let $index=$datadir/binlog.index
43 -- chmod 0644 $index
44
45 # action: issue one command so that binlog gets some event
46 CREATE TABLE t1 (a int);
47
48 -- echo ### assertion: index file contains regular entries
49 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
50 -- eval SET @index=LOAD_FILE('$index')
51 -- replace_regex /\.[\\\/]binlog/binlog/
52 SELECT @index;
53
54 --echo ### assertion: show original binlogs
55 -- source include/show_binary_logs.inc
56
57 --echo ### assertion: binlog contents from regular entries
58 -- source include/show_binlog_events.inc
59
60 # action: copy binlogs to other names and change entries in index file
61 -- copy_file $datadir/binlog.000001 $datadir/binlog-b34582.000001
62 let INDEX_FILE=$index;
63 perl;
64 $file= $ENV{'INDEX_FILE'};
65 open(FILE, ">$file") || die "Unable to open $file.";
66 truncate(FILE,0);
67 close ($file);
68 EOF
69
70 -- append_file $index
71 binlog-b34582.000001
72 EOF
73
74 # action: should cause rotation, and creation of new binlogs
75 FLUSH LOGS;
76
77 # file is not used anymore - remove it (mysql closed on flush logs).
78 -- remove_file $datadir/binlog.000001
79
80 -- echo ### assertion: index file contains renamed binlog and the new one
81 -- chmod 0644 $index
82 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
83 -- eval SET @index=LOAD_FILE('$index')
84 -- replace_regex /\.[\\\/]binlog/binlog/
85 SELECT @index;
86
87 -- echo ### assertion: original binlog content still exists, despite we
88 -- echo ### renamed and changed the index file
89 -- source include/show_binlog_events.inc
90
91 -- echo ### assertion: user changed binlog index shows correct entries
92 -- source include/show_binary_logs.inc
93
94 DROP TABLE t1;
95
96 -- echo ### assertion: purging binlogs up to binlog created after instrumenting index file should work
97 -- let $current_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
98 -- eval PURGE BINARY LOGS TO '$current_binlog'
99
100 -- echo ### assertion: show binary logs should only contain latest binlog
101 -- source include/show_binary_logs.inc
102
103 -- echo ### assertion: assert that binlog files were indeed purged (using file_exists calls)
104 -- error 1
105 -- file_exists $datadir/binlog-b34852.000001
106
107 -- echo ### assertion: assert that not purged binlog file exists
108 -- file_exists $datadir/$current_binlog
109
110 -- echo ### assertion: show index file contents and these should match show binary logs issued above
111 -- chmod 0644 $index
112 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
113 -- eval SET @index=LOAD_FILE('$index')
114 -- replace_regex /\.[\\\/]binlog/binlog/
115 SELECT @index;
116
117 RESET MASTER;