rpl_rotate_logs.test 3.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#
# Test are run with max_binlog_size=2048 to force automatic rotation of the
# 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
#
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
12
connect (master,localhost,root,,test,$MASTER_MYPORT,master.sock);
13
drop table if exists t1, t2, t3, t4;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
14
connect (slave,localhost,root,,test,$SLAVE_MYPORT,slave.sock);
15 16 17
system cat /dev/null > var/slave-data/master.info;
system chmod 000 var/slave-data/master.info;
connection slave;
18
drop table if exists t1, t2, t3, t4;
19
# START SLAVE will fail because it can't read the file (mode 000) (system error 13)
20 21
--error 1201
slave start;
22
system chmod 600 var/slave-data/master.info;
23 24 25
# 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()).
26 27
--error 1201
slave start;
28
--replace_result $MASTER_MYPORT MASTER_PORT
29 30 31 32
# 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).
--error 1201
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
33
reset slave;
34
--replace_result $MASTER_MYPORT MASTER_PORT
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
35
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; 
36 37 38
connection master;
reset master;
connection slave;
39 40
slave start;
connection master;
41 42 43 44 45 46

#
# Test FLUSH LOGS
#
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables");
47 48
create table t1 (s text);
insert into t1 values('Could not break slave'),('Tried hard');
49
save_master_pos;
50
connection slave;
51
sync_with_master;
52
--replace_result $MASTER_MYPORT MASTER_PORT
53
--replace_column 18 #
54
show slave status;
55
select * from t1;
56 57
connection master;
flush logs;
58
create table t2(m int not null auto_increment primary key);
59
insert into t2 values (34),(67),(123);
60 61
flush logs;
show master logs;
62
create table t3 select * from temp_table;
63

64
save_master_pos;
65 66
connection slave;
sync_with_master;
67 68 69 70 71 72 73 74 75 76 77

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

80 81
#same value on the master
connection master;
82 83
set insert_id=1234;
insert into t2 values(NULL);
84
connection slave;
85
wait_for_slave_to_stop;
86

87
#restart slave skipping one event
88
set global sql_slave_skip_counter=1;
89
slave start;
90

91
connection master;
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
92
save_master_pos;
93

sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
94 95 96 97
#let slave catch up
connection slave;
sync_with_master;
connection master;
98 99
purge master logs to 'master-bin.003';
show master logs;
100
insert into t2 values (65);
101
save_master_pos;
102
connection slave;
103
sync_with_master;
104
--replace_result $MASTER_MYPORT MASTER_PORT
105
--replace_column 18 #
106
show slave status;
107
select * from t2;
108 109 110 111 112

#
# Test forcing the replication log to rotate
# 

113
connection master;
114 115
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables part 2");
116
let $1=100;
117

118
create table t3 (n int);
119
disable_query_log;
120 121
while ($1)
{
122 123
#eval means expand $ expressions
 eval insert into t3 values($1 + 4);
124 125
 dec $1;
}
126
enable_query_log;
127
select count(*) from t3 where n >= 4;
128
create table t4 select * from temp_table;
129
show master logs;
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
130
show master status;
131 132 133
save_master_pos;
connection slave;
sync_with_master;
134 135
select * from t4;

136
--replace_result $MASTER_MYPORT MASTER_PORT
137
--replace_column 18 #
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
138
show slave status;
139 140 141
# because of concurrent insert, the table may not be up to date
# if we do not lock
lock tables t3 read;
142
select count(*) from t3 where n >= 4;
143
unlock tables;
144 145
#clean up
connection master;
146
drop table if exists t1,t2,t3,t4;
147 148 149
save_master_pos;
connection slave;
sync_with_master;