rpl_rotate_logs.test 4.3 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
# Test is run with max_binlog_size=2048 to force automatic rotation of the
6 7 8 9 10 11 12 13
# 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
14

unknown's avatar
unknown committed
15
connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
16
--disable_warnings
unknown's avatar
unknown committed
17
drop table if exists t1, t2, t3, t4;
18
--enable_warnings
19
connect (slave,localhost,root,,test,$SLAVE_MYPORT,$SLAVE_MYSOCK);
20 21
system cat /dev/null > $MYSQLTEST_VARDIR/slave-data/master.info;
system chmod 000 $MYSQLTEST_VARDIR/slave-data/master.info;
unknown's avatar
unknown committed
22
connection slave;
23
--disable_warnings
unknown's avatar
unknown committed
24
drop table if exists t1, t2, t3, t4;
25
--enable_warnings
unknown's avatar
unknown committed
26 27 28

# START SLAVE will fail because it can't read the file (mode 000)
# (system error 13)
unknown's avatar
unknown committed
29
--replace_result $MYSQL_TEST_DIR TESTDIR
30
--error 1105,1105,29
31
start slave;
32
system chmod 600  $MYSQLTEST_VARDIR/slave-data/master.info;
33 34 35
# 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
36
--error 1201
37
start slave;
38
--replace_result $MASTER_MYPORT MASTER_PORT
unknown's avatar
unknown committed
39 40 41

# 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).
42 43
--error 1201
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
unknown's avatar
unknown committed
44
reset slave;
45
--replace_result $MASTER_MYPORT MASTER_PORT
unknown's avatar
unknown committed
46
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; 
47 48 49
connection master;
reset master;
connection slave;
50
start slave;
unknown's avatar
unknown committed
51
connection master;
52 53 54 55 56 57

#
# Test FLUSH LOGS
#
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables");
58 59
create table t1 (s text);
insert into t1 values('Could not break slave'),('Tried hard');
60
sync_slave_with_master;
61
--replace_result $MASTER_MYPORT MASTER_PORT
62
--replace_column 1 # 8 # 9 # 23 # 33 #
63
show slave status;
64
select * from t1;
unknown's avatar
unknown committed
65 66
connection master;
flush logs;
unknown's avatar
unknown committed
67
create table t2(m int not null auto_increment primary key);
68
insert into t2 values (34),(67),(123);
unknown's avatar
unknown committed
69
flush logs;
70
show binary logs;
71
create table t3 select * from temp_table;
72

73
sync_slave_with_master;
74 75 76 77 78 79 80 81 82 83 84

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;
85
insert into t2 values(1234);
86

87 88
#same value on the master
connection master;
unknown's avatar
unknown committed
89 90
set insert_id=1234;
insert into t2 values(NULL);
91
connection slave;
92
wait_for_slave_to_stop;
93

94
#restart slave skipping one event
unknown's avatar
unknown committed
95
set global sql_slave_skip_counter=1;
96
start slave;
97

98
connection master;
99

unknown's avatar
unknown committed
100
#let slave catch up
101
sync_slave_with_master;
unknown's avatar
unknown committed
102
connection master;
unknown's avatar
unknown committed
103
purge master logs to 'master-bin.000002';
104 105 106
show master logs;
# we just tests if synonyms are accepted
purge binary logs to 'master-bin.000002';
unknown's avatar
unknown committed
107
show binary logs;
108
# sleeping 10 seconds or more would make the slave believe connection is down
109
--real_sleep 1
110
purge master logs before now();
111
show binary logs;
112
insert into t2 values (65);
113
sync_slave_with_master;
114
--replace_result $MASTER_MYPORT MASTER_PORT
115
--replace_column 1 # 8 # 9 # 23 # 33 #
116
show slave status;
117
select * from t2;
118 119 120 121 122

#
# Test forcing the replication log to rotate
# 

unknown's avatar
unknown committed
123
connection master;
124 125
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables part 2");
126
let $1=100;
127

128
create table t3 (n int);
unknown's avatar
unknown committed
129
disable_query_log;
130 131
while ($1)
{
132 133
#eval means expand $ expressions
 eval insert into t3 values($1 + 4);
134 135
 dec $1;
}
unknown's avatar
unknown committed
136
enable_query_log;
137
select count(*) from t3 where n >= 4;
138
create table t4 select * from temp_table;
139
show binary logs;
unknown's avatar
unknown committed
140
show master status;
141 142 143
save_master_pos;
connection slave;
sync_with_master;
144 145
select * from t4;

146
--replace_result $MASTER_MYPORT MASTER_PORT
147
--replace_column 1 # 8 # 9 # 23 # 33 #
unknown's avatar
unknown committed
148
show slave status;
149 150 151
# because of concurrent insert, the table may not be up to date
# if we do not lock
lock tables t3 read;
152
select count(*) from t3 where n >= 4;
153
unlock tables;
154 155
#clean up
connection master;
156
drop table if exists t1,t2,t3,t4;
157
sync_slave_with_master;
158

159
# End of 4.1 tests