rpl_rotate_logs.test 5.51 KB
Newer Older
1 2 3
# This test uses chmod, can't be run with root permissions
-- source include/not_as_root.inc

4 5
-- source include/have_log_bin.inc

6
#
7
# Test is run with max_binlog_size=2048 to force automatic rotation of the
8 9 10 11 12 13 14 15
# binary log
# Tests done:
# - Check that slaves reports correct failures if master.info has strange
#   modes/information
# - Automatic binary log rotation
# - Ensure that temporary tables works over flush logs and binary log
#   changes
# - Test creating a duplicate key error and recover from it
16

17
# Requires statement logging
18
-- source include/have_binlog_format_mixed_or_statement.inc
19

unknown's avatar
unknown committed
20
connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
21
--disable_warnings
unknown's avatar
unknown committed
22
drop table if exists t1, t2, t3, t4;
23
--enable_warnings
24
connect (slave,localhost,root,,test,$SLAVE_MYPORT,$SLAVE_MYSOCK);
25
# Create empty file
unknown's avatar
unknown committed
26 27
let $MYSQLD_SLAVE_DATADIR= `select @@datadir`;
write_file $MYSQLD_SLAVE_DATADIR/master.info;
28
EOF
unknown's avatar
unknown committed
29
chmod 0000 $MYSQLD_SLAVE_DATADIR/master.info;
unknown's avatar
unknown committed
30
connection slave;
31
--disable_warnings
unknown's avatar
unknown committed
32
drop table if exists t1, t2, t3, t4;
33
--enable_warnings
unknown's avatar
unknown committed
34 35 36

# START SLAVE will fail because it can't read the file (mode 000)
# (system error 13)
unknown's avatar
unknown committed
37
--replace_result $MYSQL_TEST_DIR TESTDIR
38
--error 1105,1105,29
39
start slave;
unknown's avatar
unknown committed
40
chmod 0600  $MYSQLD_SLAVE_DATADIR/master.info;
41 42 43
# It will fail again because the file is empty so the slave cannot get valuable
# info about how to connect to the master from it (failure in
# init_strvar_from_file() in init_master_info()).
unknown's avatar
unknown committed
44
--error 1201
45
start slave;
46
--replace_result $MASTER_MYPORT MASTER_PORT
unknown's avatar
unknown committed
47 48 49

# CHANGE MASTER will fail because it first parses master.info before changing
# it (so when master.info is bad, people have to use RESET SLAVE first).
50 51
--error 1201
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
unknown's avatar
unknown committed
52
reset slave;
53
--replace_result $MASTER_MYPORT MASTER_PORT
unknown's avatar
unknown committed
54
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; 
55 56 57
connection master;
reset master;
connection slave;
58
start slave;
unknown's avatar
unknown committed
59
connection master;
60 61 62 63 64 65

#
# Test FLUSH LOGS
#
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables");
66 67
create table t1 (s text);
insert into t1 values('Could not break slave'),('Tried hard');
68
sync_slave_with_master;
69 70 71
let $status_items= Master_Log_File, Relay_Master_Log_File;
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
72
select * from t1;
unknown's avatar
unknown committed
73 74
connection master;
flush logs;
unknown's avatar
unknown committed
75
create table t2(m int not null auto_increment primary key);
76
insert into t2 values (34),(67),(123);
unknown's avatar
unknown committed
77
flush logs;
unknown's avatar
unknown committed
78
source include/show_binary_logs.inc;
79
create table t3 select * from temp_table;
80

81
sync_slave_with_master;
82 83 84 85 86 87 88 89 90 91 92

select * from t3;
connection master;
drop table temp_table, t3;

#
# Now lets make some duplicate key mess and see if we can recover from it
#

# First insert a value on the slave
connection slave;
93
insert into t2 values(1234);
94

95 96
#same value on the master
connection master;
unknown's avatar
unknown committed
97 98
set insert_id=1234;
insert into t2 values(NULL);
99
connection slave;
100
--source include/wait_for_slave_sql_to_stop.inc
101

102
#restart slave skipping one event
unknown's avatar
unknown committed
103
set global sql_slave_skip_counter=1;
104
start slave;
105

106
connection master;
107

unknown's avatar
unknown committed
108
#let slave catch up
109
sync_slave_with_master;
unknown's avatar
unknown committed
110
connection master;
unknown's avatar
unknown committed
111
purge master logs to 'master-bin.000002';
unknown's avatar
unknown committed
112
source include/show_master_logs.inc;
113 114
# we just tests if synonyms are accepted
purge binary logs to 'master-bin.000002';
unknown's avatar
unknown committed
115
source include/show_binary_logs.inc;
116

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
# Set the purge time 1 second after the last modify time of master-bin.000002.
perl;
open F, ">>".$ENV{'MYSQLTEST_VARDIR'}.'/tmp/rpl_rotate_logs.tmp' or die "Tmp file rpl_rotate_logs.tmp not found";
my $binlogpath = $ENV{'MYSQLTEST_VARDIR'}.'/mysqld.1/data/master-bin.000002';
my @array = stat($binlogpath);
my $filemodifytime = $array[9];
my @t = localtime $filemodifytime;
my $modifytime = sprintf "%04u-%02u-%02u %02u:%02u:%02u",$t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$t[0];
printf F ("let \$tmpval = %s;",$modifytime);
close F;
EOF

--source $MYSQLTEST_VARDIR/tmp/rpl_rotate_logs.tmp
remove_file $MYSQLTEST_VARDIR/tmp/rpl_rotate_logs.tmp;

132
--disable_result_log
133 134
--replace_result $tmpval tmpval
--eval SELECT @time_for_purge:=DATE_ADD('$tmpval', INTERVAL 1 SECOND)
135 136 137
--enable_result_log

purge master logs before (@time_for_purge);
unknown's avatar
unknown committed
138
source include/show_binary_logs.inc;
139
insert into t2 values (65);
140
sync_slave_with_master;
141 142
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
143
select * from t2;
144 145 146 147 148

#
# Test forcing the replication log to rotate
# 

unknown's avatar
unknown committed
149
connection master;
150 151
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables part 2");
152
let $1=100;
153

154
create table t3 (n int);
unknown's avatar
unknown committed
155
disable_query_log;
156 157
while ($1)
{
158 159
#eval means expand $ expressions
 eval insert into t3 values($1 + 4);
160 161
 dec $1;
}
unknown's avatar
unknown committed
162
enable_query_log;
163
select count(*) from t3 where n >= 4;
164
create table t4 select * from temp_table;
unknown's avatar
unknown committed
165 166
source include/show_binary_logs.inc;
source include/show_master_status.inc;
167 168 169
save_master_pos;
connection slave;
sync_with_master;
170 171
select * from t4;

172 173
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
174 175 176
# because of concurrent insert, the table may not be up to date
# if we do not lock
lock tables t3 read;
177
select count(*) from t3 where n >= 4;
178
unlock tables;
179 180
#clean up
connection master;
181
drop table if exists t1,t2,t3,t4;
182
sync_slave_with_master;
183

184 185 186 187 188 189 190 191 192 193 194 195 196
--echo End of 4.1 tests

#
# Bug #29420: crash with show and purge binlogs
#
--error 1220
show binlog events in 'non existing_binlog_file';
purge master logs before now();
--error 1220
show binlog events in '';
purge master logs before now();

--echo End of 5.0 tests