Debian Codegraph @

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

raw
1 # This test uses chmod, can't be run with root permissions
2 -- source include/not_as_root.inc
3 -- source include/not_group_replication_plugin.inc
4
5 # Requires statement logging
6 -- source include/have_binlog_format_mixed_or_statement.inc
7 --let $rpl_skip_change_master= 1
8 --let $rpl_skip_start_slave= 1
9 -- source include/master-slave.inc
10 #
11 # Test is run with max_binlog_size=4096 to force automatic rotation of the
12 # binary log
13 # Tests done:
14 # - Check that slaves reports correct failures if master.info has strange
15 # modes/information
16 # - Automatic binary log rotation
17 # - Ensure that temporary tables works over flush logs and binary log
18 # changes
19 # - Test creating a duplicate key error and recover from it
20
21 # Create empty file
22 connection slave;
23 let $MYSQLD_SLAVE_DATADIR= `select @@datadir`;
24 write_file $MYSQLD_SLAVE_DATADIR/master.info;
25 EOF
26 chmod 0000 $MYSQLD_SLAVE_DATADIR/master.info;
27
28 --disable_result_log
29 CALL mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.");
30 CALL mtr.add_suppression("Failed to open the existing info file");
31 CALL mtr.add_suppression("Error while reading from connection metadata repository");
32 CALL mtr.add_suppression("Failed to create a new info file");
33 CALL mtr.add_suppression("The replica coordinator and worker threads are stopped, possibly leaving data in inconsistent state");
34 --enable_result_log
35 --disable_query_log ONCE
36 CALL mtr.add_suppression("Error reading source configuration");
37
38
39 # START SLAVE will fail because it can't read the file (mode 000)
40 # (system error 13)
41 --replace_result $MYSQL_TEST_DIR TESTDIR
42 --error ER_CONNECTION_METADATA, 29
43 start slave;
44 chmod 0600 $MYSQLD_SLAVE_DATADIR/master.info;
45 # It will fail again because the file is empty so the slave cannot get valuable
46 # info about how to connect to the master from it (failure in
47 # init_strvar_from_file() in init_master_info()).
48 --error ER_CONNECTION_METADATA
49 start slave;
50 --replace_result $MASTER_MYPORT MASTER_PORT
51
52 # CHANGE MASTER will fail because it first parses master.info before changing
53 # it (so when master.info is bad, people have to use RESET SLAVE first).
54 --replace_column 2 ####
55 --error ER_CONNECTION_METADATA
56 eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root';
57 reset slave;
58 --replace_result $MASTER_MYPORT MASTER_PORT
59 --replace_column 2 ####
60 eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root';
61 connection master;
62 reset master;
63 connection slave;
64 start slave;
65 --source include/wait_for_slave_to_start.inc
66 connection master;
67
68 #
69 # Test FLUSH LOGS
70 #
71 create temporary table temp_table (a char(80) not null);
72 insert into temp_table values ("testing temporary tables");
73 create table t1 (s text);
74 insert into t1 values('Could not break slave'),('Tried hard');
75 --source include/sync_slave_sql_with_master.inc
76 let $status_items= Master_Log_File, Relay_Master_Log_File;
77 source include/show_slave_status.inc;
78 source include/check_slave_is_running.inc;
79
80 --let $assert_text= Table t1 should contain the first inserted line
81 --let $query_result= query_get_value(select * from t1, "s", 1)
82 --let $assert_cond= "$query_result" = "Could not break slave"
83 --source include/assert.inc
84
85 --let $assert_text= Table t1 should contain the second inserted line
86 --let $query_result= query_get_value(select * from t1, "s", 2)
87 --let $assert_cond= "$query_result" = "Tried hard"
88 --source include/assert.inc
89
90 connection master;
91 flush logs;
92 create table t2(m int not null auto_increment primary key);
93 insert into t2 values (34),(67),(123);
94 flush logs;
95 source include/show_binary_logs.inc;
96 create table t3 select * from temp_table;
97
98 --source include/sync_slave_sql_with_master.inc
99
100 --let $query_result= query_get_value(select * from t3, "a", 1)
101 --let $assert_text= Data in t3 should be equal to temp_table
102 --let $assert_cond= "$query_result" = "testing temporary tables"
103 --source include/assert.inc
104
105 connection master;
106 drop table temp_table, t3;
107
108 #
109 # Now lets make some duplicate key mess and see if we can recover from it
110 #
111
112 # First insert a value on the slave
113 #connection slave;
114 source include/sync_slave_sql_with_master.inc;
115 insert into t2 values(1234);
116
117 #same value on the master
118 connection master;
119 set insert_id=1234;
120 insert into t2 values(NULL);
121 connection slave;
122 # 1062 = ER_DUP_ENTRY
123 call mtr.add_suppression("Replica SQL.*Error .Duplicate entry .1234. for key .t2.PRIMARY.. on query.* Error_code: MY-001062");
124 --let $slave_sql_errno= 1062
125 --source include/wait_for_slave_sql_error_and_skip.inc
126
127 connection master;
128
129 #let slave catch up
130 --source include/sync_slave_sql_with_master.inc
131 connection master;
132 purge master logs to 'master-bin.000002';
133 source include/show_master_logs.inc;
134 # we just tests if synonyms are accepted
135 purge binary logs to 'master-bin.000002';
136 source include/show_binary_logs.inc;
137
138 # Set the purge time 1 second after the last modify time of master-bin.000002.
139 perl;
140 open F, ">>".$ENV{'MYSQLTEST_VARDIR'}.'/tmp/rpl_rotate_logs.tmp' or die "Tmp file rpl_rotate_logs.tmp not found";
141 my $binlogpath = $ENV{'MYSQLTEST_VARDIR'}.'/mysqld.1/data/master-bin.000002';
142 my @array = stat($binlogpath);
143 my $filemodifytime = $array[9];
144 my @t = localtime $filemodifytime;
145 my $modifytime = sprintf "%04u-%02u-%02u %02u:%02u:%02u",$t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$t[0];
146 printf F ("let \$tmpval = %s;",$modifytime);
147 close F;
148 EOF
149
150 --source $MYSQLTEST_VARDIR/tmp/rpl_rotate_logs.tmp
151 remove_file $MYSQLTEST_VARDIR/tmp/rpl_rotate_logs.tmp;
152
153 --disable_result_log
154 --replace_result $tmpval tmpval
155 --eval SELECT @time_for_purge:=DATE_ADD('$tmpval', INTERVAL 1 SECOND)
156 --enable_result_log
157
158 replace_regex /\.[\\\/]master/master/;
159 purge master logs before (@time_for_purge);
160 source include/show_binary_logs.inc;
161 insert into t2 values (65);
162 --source include/sync_slave_sql_with_master.inc
163 source include/show_slave_status.inc;
164 source include/check_slave_is_running.inc;
165
166 --let $assert_text= Table t2 should still contain the first inserted line after creation
167 --let $assert_cond= [select * from t2, m, 1] = 34
168 --source include/assert.inc
169
170 --let $assert_text= Table t2 should contain the line inserted after the purge
171 --let $assert_cond= [select * from t2, m, 2] = 65
172 --source include/assert.inc
173
174 --let $assert_text= Table t2 should still contain the second insert line after creation
175 --let $assert_cond= [select * from t2, m, 3] = 67
176 --source include/assert.inc
177
178 --let $assert_text= Table t2 should still contain the third inserted line after creation
179 --let $assert_cond= [select * from t2, m, 4] = 123
180 --source include/assert.inc
181
182 --let $assert_text= Table t2 should still contain the line from the duplicated key test
183 --let $assert_cond= [select * from t2, m, 5] = 1234
184 --source include/assert.inc
185
186 #
187 # Test forcing the replication log to rotate
188 #
189
190 connection master;
191 create temporary table temp_table (a char(80) not null);
192 insert into temp_table values ("testing temporary tables part 2");
193
194 # Generate some number of logs and prove rotation by comparing the first and the last
195 let $1=90;
196
197 let $first=query_get_value("SHOW MASTER STATUS", "File", 1);
198 create table t3 (n int);
199 disable_query_log;
200 while ($1)
201 {
202 #eval means expand $ expressions
203 eval insert into t3 values($1 + 4);
204 dec $1;
205 }
206 enable_query_log;
207
208 --let $assert_text= Table t3 should contain 90 lines on the master
209 --let $assert_cond= [select count(*) from t3 where n >= 4] = 90
210 --source include/assert.inc
211
212 create table t4 select * from temp_table;
213 let $last=query_get_value("SHOW MASTER STATUS", "File", 1);
214 if (`select '$first' like '$last'`)
215 {
216 --die No expected logs rotation
217 }
218 --source include/sync_slave_sql_with_master.inc
219
220 --let $query_result= query_get_value(select * from t4, "a", 1)
221 --let $assert_text= Data in t4 should be equal to temp_table
222 --let $assert_cond= "$query_result" = "testing temporary tables part 2"
223 --source include/assert.inc
224
225 source include/check_slave_is_running.inc;
226 # because of concurrent insert, the table may not be up to date
227 # if we do not lock
228 lock tables t3 read;
229
230 --let $assert_text= Table t3 should contain 90 lines on the slave
231 --let $assert_cond= [select count(*) from t3 where n >= 4] = 90
232 --source include/assert.inc
233
234 unlock tables;
235 #clean up
236 connection master;
237 drop table if exists t1,t2,t3,t4;
238 drop temporary table temp_table;
239 --source include/sync_slave_sql_with_master.inc
240
241 --echo End of 4.1 tests
242
243 #
244 # Bug #29420: crash with show and purge binlogs
245 #
246 # Wait for sql thread to relase the backup lock acquired during drop tables
247 --let $wait_condition = SELECT COUNT(*)= 0 FROM performance_schema.metadata_locks WHERE object_type= 'BACKUP LOCK'
248 --source include/wait_condition.inc
249
250 --error ER_ERROR_WHEN_EXECUTING_COMMAND
251 show binlog events in 'non existing_binlog_file';
252 replace_regex /\.[\\\/]slave/slave/;
253 purge master logs before now();
254 --error ER_ERROR_WHEN_EXECUTING_COMMAND
255 show binlog events in '';
256 replace_regex /\.[\\\/]slave/slave/;
257 purge master logs before now();
258
259 --echo End of 5.0 tests
260 --source include/rpl_end.inc