19
19
drop table if exists t1, t2;
21
set debug_sync='RESET';
21
23
connect (addconroot, localhost, root,,);
24
connect (addconroot2, localhost, root,,);
22
25
connection default;
23
26
create table t1 (n1 int, n2 int, n3 int,
27
30
create table t2 (i int);
29
# Starting from 5.1 we have runtime settable @@debug variable,
30
# which can be used for introducing delays at certain points of
31
# statement execution, so we don't need many rows in 't1' to make
32
# this test repeatable.
33
32
alter table t1 disable keys;
35
insert into t1 values (RAND()*1000, RAND()*1000, RAND()*1000);
33
insert into t1 values (1, 2, 3);
38
35
# Later we use binlog to check the order in which statements are
39
36
# executed so let us reset it first.
41
set session debug="+d,sleep_alter_enable_indexes";
38
set debug_sync='alter_table_enable_indexes SIGNAL parked WAIT_FOR go';
42
39
--send alter table t1 enable keys;
43
40
connection addconroot;
41
# Wait until ALTER TABLE acquires metadata lock.
42
set debug_sync='now WAIT_FOR parked';
45
43
# This statement should not be blocked by in-flight ALTER and therefore
46
44
# should be executed and written to binlog before ALTER TABLE ... ENABLE KEYS
48
46
insert into t2 values (1);
49
47
# And this should wait until the end of ALTER TABLE ... ENABLE KEYS.
50
insert into t1 values (1, 1, 1);
53
set session debug="-d,sleep_alter_enable_indexes";
48
--send insert into t1 values (1, 1, 1);
49
connection addconroot2;
50
# Wait until the above INSERT INTO t1 is blocked due to ALTER
52
select count(*) = 1 from information_schema.processlist
53
where state = "Waiting for table metadata lock" and
54
info = "insert into t1 values (1, 1, 1)";
55
--source include/wait_condition.inc
56
# Resume ALTER execution.
57
set debug_sync='now SIGNAL go';
60
connection addconroot;
54
63
# Check that statements were executed/binlogged in correct order.
55
64
source include/show_binlog_events.inc;
58
67
drop tables t1, t2;
59
68
disconnect addconroot;
69
disconnect addconroot2;
70
set debug_sync='RESET';
62
72
--echo End of 5.0 tests
73
83
drop table if exists t1, t2, t3;
85
connect (addconroot, localhost, root,,);
86
connect (addconroot2, localhost, root,,);
75
88
create table t1 (i int);
76
89
# We are going to check that statements are logged in correct order
78
set session debug="+d,sleep_alter_before_main_binlog";
91
set debug_sync='alter_table_before_main_binlog SIGNAL parked WAIT_FOR go';
79
92
--send alter table t1 change i c char(10) default 'Test1';
80
connect (addconroot, localhost, root,,);
81
connection addconroot;
83
insert into t1 values ();
93
connection addconroot;
94
# Wait until ALTER TABLE acquires metadata lock.
95
set debug_sync='now WAIT_FOR parked';
96
--send insert into t1 values ();
97
connection addconroot2;
98
# Wait until the above INSERT INTO t1 is blocked due to ALTER
100
select count(*) = 1 from information_schema.processlist
101
where state = "Waiting for table metadata lock" and
102
info = "insert into t1 values ()";
103
--source include/wait_condition.inc
104
# Resume ALTER execution.
105
set debug_sync='now SIGNAL go';
108
connection addconroot;
112
set debug_sync='alter_table_before_main_binlog SIGNAL parked WAIT_FOR go';
87
113
--send alter table t1 change c vc varchar(100) default 'Test2';
88
114
connection addconroot;
90
rename table t1 to t2;
115
# Wait until ALTER TABLE acquires metadata lock.
116
set debug_sync='now WAIT_FOR parked';
117
--send rename table t1 to t2;
118
connection addconroot2;
119
# Wait until the above RENAME TABLE is blocked due to ALTER
121
select count(*) = 1 from information_schema.processlist
122
where state = "Waiting for table metadata lock" and
123
info = "rename table t1 to t2";
124
--source include/wait_condition.inc
125
# Resume ALTER execution.
126
set debug_sync='now SIGNAL go';
129
connection addconroot;
94
133
# And now tests for ALTER TABLE with RENAME clause. In this
95
134
# case target table name should be properly locked as well.
96
135
create table t1 (i int);
136
set debug_sync='alter_table_before_main_binlog SIGNAL parked WAIT_FOR go';
97
137
--send alter table t1 change i c char(10) default 'Test3', rename to t2;
98
138
connection addconroot;
100
insert into t2 values ();
139
# Wait until ALTER TABLE acquires metadata lock.
140
set debug_sync='now WAIT_FOR parked';
141
--send insert into t2 values();
142
connection addconroot2;
143
# Wait until the above INSERT INTO t2 is blocked due to ALTER
145
select count(*) = 1 from information_schema.processlist
146
where state = "Waiting for table metadata lock" and
147
info = "insert into t2 values()";
148
--source include/wait_condition.inc
149
# Resume ALTER execution.
150
set debug_sync='now SIGNAL go';
153
connection addconroot;
101
156
select * from t2;
104
157
--send alter table t2 change c vc varchar(100) default 'Test2', rename to t1;
105
158
connection addconroot;
107
161
rename table t1 to t3;
110
163
disconnect addconroot;
164
disconnect addconroot2;
112
set session debug="-d,sleep_alter_before_main_binlog";
166
set debug_sync='alter_table_before_main_binlog SIGNAL parked WAIT_FOR go';
167
set debug_sync='RESET';
114
169
# Check that all statements were logged in correct order
115
170
source include/show_binlog_events.inc;
118
173
--echo End of 5.1 tests