Debian Codegraph @

mysql-test/suite/rpl_nogtid/t/rpl_binlog_index.test

raw
1 # ==== Purpose ====
2 #
3 # Test that server can work fine after moving binlog or relay log
4 # files to another directory and setting binlog or relay log paths to
5 # the new path.
6 #
7 # ==== Method ====
8 #
9 # Start replication, and then shutdown the master, move the binary
10 # logs and the log index file to a another directory and then restart
11 # the server with option to set the new binlog directory. After master
12 # restarted successfully, do the similar on slave to check the relay
13 # log of slave.
14 #
15 # ==== Reference ====
16 #
17 # BUG#12133 master.index file keeps mysqld from starting if bin log has been moved
18 # BUG#42576 Relay logs in relay-log.info&localhost-relay-bin.index not processed after move
19
20 --source include/not_group_replication_plugin.inc
21 source include/master-slave.inc;
22 # There is no need to run this test case on all binlog format
23 source include/have_binlog_format_row.inc;
24
25 # Since this test relies heavily on filesystem operations (like
26 # moving files around, backslashes and so forth) we avoid messing
27 # around with windows access violations for not cluttering the
28 # test case any further. It is prepared to support windows, but
29 # it is not 100% compliant.
30 --source include/not_windows.inc
31
32 # This test takes long time, so only run it with the --big-test mtr-flag.
33 --source include/big_test.inc
34
35
36 connection master;
37 --let $master_datadir= `select @@datadir`
38 connection slave;
39 --let $slave_datadir= `select @@datadir`
40 connection master;
41 --let $dirname= `select uuid()`
42 --let $tmpdir= $MYSQLTEST_VARDIR/tmp/$dirname
43 --mkdir $tmpdir
44
45 CREATE TABLE t1 (a INT);
46 # flush to generate one more binlog file.
47 FLUSH BINARY LOGS;
48 INSERT INTO t1 VALUES (1);
49
50 sync_slave_with_master;
51 --source include/stop_slave.inc
52 #
53 # Test on master
54 #
55 connection master;
56 --echo # Shutdown master
57 --let $rpl_server_number=1
58 source include/rpl_stop_server.inc;
59
60 --echo # Move the master binlog files and the index file to a new place
61 --move_file $master_datadir/master-bin.000001 $tmpdir/master-bin.000001
62 --move_file $master_datadir/master-bin.000002 $tmpdir/master-bin.000002
63 --move_file $master_datadir/master-bin.index $tmpdir/master-bin.index
64
65 --echo # Restart master with log-bin option set to the new path
66 --let $rpl_server_parameters=--log-bin=$tmpdir/master-bin
67 --let $include_silent=1
68 source include/rpl_start_server.inc;
69 --let $include_silent=0
70
71 --echo # Master has restarted successfully
72 --connection slave
73 --source include/start_slave.inc
74 --connection master
75 #
76 # Test master can handle old format with directory path in index file
77 #
78 --let $is_windows= `select convert(@@version_compile_os using latin1) in ('Win32', 'Win64', 'Windows')`
79
80 # write_var_to_file.inc will call SELECT INTO DUMPFILE, which has to be
81 # done before shutdown the server
82 --echo # Create the master-bin.index file with the old format
83 --let $write_to_file= $master_datadir/master-bin.index
84 if ($is_windows)
85 {
86 --let $write_var= .\\\\master-bin.000001\n.\\\\master-bin.000002\n.\\\\master-bin.000003\n
87 }
88 if (!$is_windows)
89 {
90 --let $write_var= ./master-bin.000001\n./master-bin.000002\n./master-bin.000003\n
91 }
92 --disable_query_log
93 source include/write_var_to_file.inc;
94 --enable_query_log
95 --sync_slave_with_master
96 --source include/stop_slave.inc
97 --connection master
98
99 --echo # Shutdown master
100 --let $rpl_server_number=1
101 source include/rpl_stop_server.inc;
102
103 --echo # Move back the master binlog files
104 --move_file $tmpdir/master-bin.000001 $master_datadir/master-bin.000001
105 --move_file $tmpdir/master-bin.000002 $master_datadir/master-bin.000002
106 --move_file $tmpdir/master-bin.000003 $master_datadir/master-bin.000003
107
108 --echo # Remove the unneeded master-bin.index file
109 --remove_file $tmpdir/master-bin.index
110
111 --echo # Restart master with log-bin option set to default
112 --let $rpl_server_parameters=--log-bin=$master_datadir/master-bin
113 --let $include_silent=1
114 source include/rpl_start_server.inc;
115 --let $include_silent=0
116
117 --echo # Master has restarted successfully
118
119 --connection slave
120 --source include/start_slave.inc
121 --sync_with_master
122 --connection master
123 --let $rpl_server_number= 2
124 --source include/rpl_stop_server.inc
125
126 # switch to master because the slave has been shutdown
127 # and relocate_binlogs requires a running server to do
128 # SQL operations
129 --connection master
130
131 --let $relocate_disable_query_log= 1
132 --let $relocate_is_windows= $is_windows
133 --let $relocate_from=$slave_datadir
134 --let $relocate_into=$tmpdir
135
136 --echo # relocate binlogs
137 --let $relocate_index_file=$slave_datadir/slave-bin.index
138 --source include/relocate_binlogs.inc
139
140 --echo # relocate relay logs
141 --let $relocate_index_file=$slave_datadir/slave-relay-bin.index
142 --source include/relocate_binlogs.inc
143
144 --echo # Restart slave with options log-bin, relay-log set to the new paths
145 --let $rpl_server_parameters=--log-bin=$tmpdir/slave-bin --relay-log=$tmpdir/slave-relay-bin
146 --let $include_silent=1
147 --let $rpl_server_number= 2
148 source include/rpl_start_server.inc;
149 --let $include_silent=0
150
151 --connection slave
152
153 --echo # Slave server has restarted successfully
154 --source include/start_slave.inc
155 --source include/stop_slave.inc
156
157 connection master;
158 FLUSH LOGS;
159 INSERT INTO t1 VALUES (2);
160 INSERT INTO t1 VALUES (2);
161 INSERT INTO t1 VALUES (2);
162 INSERT INTO t1 VALUES (2);
163
164 FLUSH LOGS;
165
166 connection slave;
167 FLUSH LOGS;
168 --source include/start_slave.inc
169 connection master;
170 sync_slave_with_master;
171 --let $diff_tables= master:t1,slave:t1
172 source include/diff_tables.inc;
173
174 connection master;
175 DROP TABLE t1;
176 --sync_slave_with_master
177 --source include/stop_slave.inc
178 --let $rpl_server_number= 2
179 --source include/rpl_stop_server.inc
180
181 --connection master
182
183 --let $relocate_from=$tmpdir
184 --let $relocate_into=$slave_datadir
185 --let $relocate_recreate_index= 1
186
187 # binlogs
188 --let $relocate_index_file=$tmpdir/slave-bin.index
189 --source include/relocate_binlogs.inc
190
191 # relay logs
192
193 # since the complete fix for the relocation of logs is
194 # done in BUG#13428851 it does not help here to try
195 # to start the slave as it would fail (relay-log.info is
196 # tainted with the full path in the RELAY_LOG_FILE position).
197 # Instead, we reset the slave and let the test clean up.
198
199 if (!`SELECT @@GLOBAL.relay_log_info_repository = 'TABLE'`)
200 {
201 --let $relocate_fix_relay_log_info= $slave_datadir/relay-log.info
202 }
203 if (`SELECT @@GLOBAL.relay_log_info_repository = 'TABLE'`)
204 {
205 --let $relocate_fix_relay_log_info=
206 }
207
208 --let $relocate_index_file=$tmpdir/slave-relay-bin.index
209 --source include/relocate_binlogs.inc
210
211 --echo # remove tmpdir
212 --remove_files_wildcard $tmpdir *
213 --rmdir $tmpdir
214
215 --echo # restarted with previous slave settings
216 --let $rpl_server_parameters=--log-bin=$slave_datadir/slave-bin --relay-log=$slave_datadir/slave-relay-bin
217 --let $include_silent=1
218 --let $rpl_server_number= 2
219 --source include/rpl_start_server.inc
220 --let $include_silent=0
221
222 --connection slave
223
224 # Fix the relay log info name if the server was using tables instead of files
225 # as this was not fixed in the relocate_binlogs.inc file
226 if (`SELECT @@GLOBAL.relay_log_info_repository = 'TABLE'`)
227 {
228 --disable_query_log
229 SET SQL_LOG_BIN=0;
230
231 # On server startup, the slave info tables are initialized,
232 # and also a verification of the relay log files is done.
233 # Since the tables still have the old value for the relay_log_name
234 # field, the server will complain. We need to suppress these
235 # warnings so that the test does not fail.
236 call mtr.add_suppression("Failed to open the relay log");
237 call mtr.add_suppression("Could not find target log file mentioned in applier metadata in the index file");
238 call mtr.add_suppression("Failed to initialize the connection metadata structure");
239 call mtr.add_suppression("Failed to create or recover replication info repositories.");
240
241 --let $path_separator=/
242 if ($is_windows)
243 {
244 --let $path_separator=\
245 }
246 --let $relay_log_name= `SELECT Relay_log_name FROM mysql.slave_relay_log_info LIMIT 1`
247 --let $new_relay_log_name= `SELECT RIGHT(RTRIM("$relay_log_name"), LOCATE("$path_separator",REVERSE(RTRIM("$relay_log_name"))) -1)`
248 --eval UPDATE mysql.slave_relay_log_info SET Relay_log_name='$slave_datadir$path_separator$new_relay_log_name'
249 SET SQL_LOG_BIN=1;
250
251 --let $path_separator=
252 --let $relay_log_name=
253 --let $new_relay_log_name=
254 --let $relocate_fix_relay_log_info=
255
256 --enable_query_log
257
258 # Due to changes on slave start procedure (relay log initialization
259 # error requires RESET SLAVE or server restart) we need to restart
260 # server to relay log file change be considered.
261 --let $include_silent= 1
262 --let $rpl_server_number= 2
263 --source include/rpl_restart_server.inc
264 --let $include_silent= 0
265 }
266
267 # The slave will restart if we have fixed the relay-log.info
268 # correctly
269 --source include/start_slave.inc
270
271 --connection master
272 --source include/rpl_end.inc