rpl_rotate_logs.test 3.65 KB
Newer Older
1
#
2
# Test is run with max_binlog_size=2048 to force automatic rotation of the
3 4 5 6 7 8 9 10
# 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
11

unknown's avatar
unknown committed
12
connect (master,localhost,root,,test,$MASTER_MYPORT,master.sock);
13
--disable_warnings
unknown's avatar
unknown committed
14
drop table if exists t1, t2, t3, t4;
15
--enable_warnings
unknown's avatar
unknown committed
16
connect (slave,localhost,root,,test,$SLAVE_MYPORT,slave.sock);
unknown's avatar
unknown committed
17 18 19
system cat /dev/null > var/slave-data/master.info;
system chmod 000 var/slave-data/master.info;
connection slave;
20
--disable_warnings
unknown's avatar
unknown committed
21
drop table if exists t1, t2, t3, t4;
22
--enable_warnings
unknown's avatar
unknown committed
23
--error 1201
24
start slave;
unknown's avatar
unknown committed
25
system chmod 600 var/slave-data/master.info;
unknown's avatar
unknown committed
26
--error 1201
27
start slave;
28
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
unknown's avatar
unknown committed
29 30
# Will get error 13 on Unix systems becasue file is not readable
!eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
unknown's avatar
unknown committed
31
reset slave;
32
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
unknown's avatar
unknown committed
33
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; 
34 35 36
connection master;
reset master;
connection slave;
37
start slave;
unknown's avatar
unknown committed
38
connection master;
39 40 41 42 43 44

#
# Test FLUSH LOGS
#
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables");
45 46
create table t1 (s text);
insert into t1 values('Could not break slave'),('Tried hard');
47
sync_slave_with_master;
48
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
49
show slave status;
50
select * from t1;
unknown's avatar
unknown committed
51 52
connection master;
flush logs;
unknown's avatar
unknown committed
53
create table t2(m int not null auto_increment primary key);
54
insert into t2 values (34),(67),(123);
unknown's avatar
unknown committed
55
flush logs;
56
show binary logs;
57
create table t3 select * from temp_table;
58

59
sync_slave_with_master;
60 61 62 63 64 65 66 67 68 69 70

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

73 74 75
#same value on the master
connection master;
save_master_pos;
unknown's avatar
unknown committed
76 77
set insert_id=1234;
insert into t2 values(NULL);
78 79
connection slave;
sync_with_master;
80

81
wait_for_slave_to_stop;
82

83
#restart slave skipping one event
unknown's avatar
unknown committed
84
set global sql_slave_skip_counter=1;
85
start slave;
86

87
connection master;
88

unknown's avatar
unknown committed
89
#let slave catch up
90
sync_slave_with_master;
unknown's avatar
unknown committed
91
connection master;
unknown's avatar
unknown committed
92 93
purge master logs to 'master-bin.000002';
show binary logs;
94
--sleep 1;
unknown's avatar
unknown committed
95
purge logs before now();
96
show binary logs;
97
insert into t2 values (65);
98
sync_slave_with_master;
99
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
100
show slave status;
101
select * from t2;
102 103 104 105 106

#
# Test forcing the replication log to rotate
# 

unknown's avatar
unknown committed
107
connection master;
108 109
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables part 2");
110
let $1=100;
111

112
create table t3 (n int);
unknown's avatar
unknown committed
113
disable_query_log;
114 115
while ($1)
{
116 117
#eval means expand $ expressions
 eval insert into t3 values($1 + 4);
118 119
 dec $1;
}
unknown's avatar
unknown committed
120
enable_query_log;
121
create table t4 select * from temp_table;
122
show binary logs;
unknown's avatar
unknown committed
123
show master status;
124 125
save_master_pos;
connection slave;
126 127
#stop slave;
#start slave;
128
sync_with_master;
129 130
select * from t4;

131
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
unknown's avatar
unknown committed
132
show slave status;
133 134 135
# because of concurrent insert, the table may not be up to date
# if we do not lock
lock tables t3 read;
136
select count(*) from t3 where n >= 4;
137
unlock tables;
138 139
#clean up
connection master;
140
drop table if exists t1,t2,t3,t4;
141
sync_slave_with_master;