summaryrefslogtreecommitdiff
path: root/mysql-test/t/rpl_chain_temp_table.test
blob: 007b018e9d8ffaec2483a3ebd74f4adbd0dae94f (plain)
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
 # This test makes some assumptions about values of thread ids, which should be
# true if the servers have been restarted for this test. So we want to
# stop/restart servers. Note that if assumptions are wrong, the test will not
# fail; it will just fail to test the error-prone scenario.
# Using the manager is the only way to have more than one slave server.
# So you must run this test with --manager.

require_manager;
server_stop master;
server_start master;
server_stop slave;
server_start slave;
# no need for slave_sec (no assumptions on thread ids for this server).

source include/master-slave.inc;
connect (slave_sec,localhost,root,,test,0,slave.sock-1); 
connection master;
save_master_pos;
connection slave;
sync_with_master;
reset master;
save_master_pos;
connection slave_sec;
eval change master to master_host='127.0.0.1',master_port=$SLAVE_MYPORT, master_user='root';
start slave;
sync_with_master;

# :P now we have a chain ready-to-test.

connection master;
create temporary table t1 (a int);
save_master_pos;
connection slave;
sync_with_master;
connection master1;
create temporary table t1 (a int);
save_master_pos;
connection slave;
sync_with_master;
save_master_pos;

# First test:

connection slave_sec;
# Before BUG#1686 ("If 2 master threads with same-name temp table, slave makes
# bad binlog") was fixed, sync_with_master failed
sync_with_master;
show status like 'slave_open_temp_tables';

# 'master' and 'master1' usually have thread id 2-3 or 3-4.
# 'slave' and 'slave1' usually have thread id 2-3.
connection slave;
create temporary table t1 (a int);
connection slave1;
create temporary table t1 (a int);
# So it's likely that in the binlog of slave we get
# server_id=of_master thread_id=3 create temp...
# server_id=of_slave  thread_id=3 create temp...
# which would confuse slave-sec unless slave-sec uses server id to distinguish
# between temp tables (here thread id is obviously not enough to distinguish).

save_master_pos;

# Second test:

connection slave_sec;
# If we did not use the server id to distinguish between temp tables,
# sync_with_master would fail
sync_with_master;
show status like 'slave_open_temp_tables';

# Third test (BUG#1240 "slave of slave breaks when STOP SLAVE was issud on
# parent slave and temp tables").
stop slave;
connection slave;
insert into t1 values(1);
create table t2 as select * from t1;
save_master_pos;
connection slave_sec;
start slave;
sync_with_master;
show status like 'slave_open_temp_tables';
select * from t2;

# clean up
connection slave;
drop table t2;
save_master_pos;
connection slave_sec;
sync_with_master;

# On purpose, we don't delete the temporary tables explicitely.
# So temp tables remain on slave (remember they are not deleted when the slave
# SQL thread terminates). If you run this test with 
# --valgrind --valgrind-options=--show-reachable=yes 
# you will see if they get cleaned up at slave's shutdown (that is, if the
# memory they use is freed (it should) by mysqld before it terminates).
# If they wouldn't be cleaned up, you would see some "still reachable" blocks in
# Valgrind.