1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#
# 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
#
connect (master,localhost,root,,test,0,master.sock);
drop table if exists t1, t2, t3, t4;
connect (slave,localhost,root,,test,0,slave.sock);
system cat /dev/null > var/slave-data/master.info;
system chmod 000 var/slave-data/master.info;
connection slave;
drop table if exists t1, t2, t3, t4;
--error 1201
slave start;
system chmod 600 var/slave-data/master.info;
--error 1201
slave start;
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
# 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';
reset slave;
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
connection master;
reset master;
connection slave;
slave start;
connection master;
#
# Test FLUSH LOGS
#
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables");
create table t1 (s text);
insert into t1 values('Could not break slave'),('Tried hard');
save_master_pos;
connection slave;
sync_with_master;
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
show slave status;
select * from t1;
connection master;
flush logs;
drop table if exists t2;
create table t2(m int not null auto_increment primary key);
insert into t2 values (34),(67),(123);
flush logs;
show master logs;
create table t3 select * from temp_table;
save_master_pos;
connection slave;
sync_with_master;
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;
insert into t2 values(1234);
#same value on the master
connection master;
save_master_pos;
set insert_id=1234;
insert into t2 values(NULL);
connection slave;
sync_with_master;
wait_for_slave_to_stop;
#restart slave skipping one event
set global sql_slave_skip_counter=1;
slave start;
connection master;
save_master_pos;
#let slave catch up
connection slave;
sync_with_master;
connection master;
purge master logs to 'master-bin.003';
show master logs;
insert into t2 values (65);
save_master_pos;
connection slave;
sync_with_master;
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
show slave status;
select * from t2;
#
# Test forcing the replication log to rotate
#
connection master;
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables part 2");
let $1=100;
drop table if exists t3;
create table t3 (n int);
disable_query_log;
while ($1)
{
#eval means expand $ expressions
eval insert into t3 values($1 + 4);
dec $1;
}
enable_query_log;
create table t4 select * from temp_table;
show master logs;
show master status;
save_master_pos;
connection slave;
#slave stop;
#slave start;
sync_with_master;
select * from t4;
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
show slave status;
# because of concurrent insert, the table may not be up to date
# if we do not lock
lock tables t3 read;
select count(*) from t3 where n >= 4;
unlock tables;
#clean up
connection master;
drop table if exists t1,t2,t3,t4;
save_master_pos;
connection slave;
sync_with_master;
|