Debian Codegraph @

mysql-test/suite/ndb_binlog/t/ndb_binlog_purge_lock.inc

raw
1 # Testing that purging rows in ndb_binlog_index doesn't block parallel inserts
2 --source include/have_ndb.inc
3 --source include/have_log_bin.inc
4
5 # Require that ndb_binlog_index is using Innodb
6 let $using_innodb =
7 `select engine = 'InnoDB'
8 from information_schema.tables
9 where table_name = 'ndb_binlog_index'`;
10 # echo using_innodb: $using_innodb;
11 if (!$using_innodb)
12 {
13 die The ndb_binlog_index table is not using Innodb;
14 }
15
16 connect (con1,localhost,root,,);
17 connect (con2,localhost,root,,);
18 connect (con3,localhost,root,,);
19 connect (con4,localhost,root,,);
20
21 connection default;
22
23 --echo First initialize the binlog
24 reset master;
25
26 --disable_warnings
27 DROP TABLE IF EXISTS t1;
28 --enable_warnings
29
30 --echo Test that binlog purging doesn't use table lock on ndb_binlog_index
31
32 --echo Put some real stuff in the Binlog.
33 create table test.t1 (
34 pk integer primary key auto_increment,
35 a varchar(1000)
36 ) engine=ndb;
37 insert into test.t1 values (NULL, repeat('BJC', 300));
38 insert into test.t1 select NULL, a from test.t1;
39 insert into test.t1 select NULL, a from test.t1;
40 insert into test.t1 select NULL, a from test.t1;
41 insert into test.t1 select NULL, a from test.t1;
42 insert into test.t1 select NULL, a from test.t1;
43 insert into test.t1 select NULL, a from test.t1;
44 insert into test.t1 select NULL, a from test.t1;
45 insert into test.t1 select NULL, a from test.t1;
46 insert into test.t1 select NULL, a from test.t1;
47 insert into test.t1 select NULL, a from test.t1;
48 insert into test.t1 select NULL, a from test.t1;
49
50 --source include/wait_for_ndb_committed_to_binlog.inc
51
52 let $master_log_file = query_get_value("SHOW MASTER STATUS", "File", 1);
53 eval
54 select trim(trailing "$master_log_file" from File)
55 from mysql.ndb_binlog_index
56 where epoch in (select max(epoch) from mysql.ndb_binlog_index)
57 into @file_prefix;
58 eval select concat(@file_prefix, "$master_log_file") into @file1;
59
60 --echo Have at least 100 epoch rows
61 select count(*)/100 > 0 from mysql.ndb_binlog_index where File=@file1;
62
63 --echo Flush log to get onto the next file...
64 FLUSH LOGS;
65
66 let $master_log_file2 = query_get_value("SHOW MASTER STATUS", "File", 1);
67 eval select concat(@file_prefix, "$master_log_file2") into @file2;
68
69 create table test.files(file1 varchar(255), file2 varchar(255));
70 insert into test.files values(@file1, @file2);
71
72 disable_query_log;
73 connection con1;
74 select file1 from test.files into @file1;
75 select file2 from test.files into @file2;
76
77 connection con2;
78 select file1 from test.files into @file1;
79 select file2 from test.files into @file2;
80
81 connection con3;
82 select file1 from test.files into @file1;
83 select file2 from test.files into @file2;
84
85 connection con4;
86 select file1 from test.files into @file1;
87 select file2 from test.files into @file2;
88 enable_query_log;
89
90 connection con1;
91 # Create a temporary tables and select the "keys" for one row
92 # in mysql.ndb_binlog_index into that table. Then select
93 # the "keys" into MySQL Server variables for further usage
94 # in the "locking" query
95 --echo Pick one row from ndb_binlog_index
96 CREATE TEMPORARY TABLE my_ndb_binlog_index (
97 epoch BIGINT UNSIGNED NOT NULL,
98 orig_server_id INT UNSIGNED NOT NULL,
99 orig_epoch BIGINT UNSIGNED NOT NULL
100 );
101 insert into my_ndb_binlog_index
102 select epoch, orig_server_id, orig_epoch
103 from mysql.ndb_binlog_index
104 where File=@file1 limit 1;
105 select epoch from my_ndb_binlog_index into @epoch;
106 select orig_server_id from my_ndb_binlog_index into @orig_server_id;
107 select orig_epoch from my_ndb_binlog_index into @orig_epoch;
108
109 --echo Lock one row to block purge
110 start transaction;
111 select count(1) from mysql.ndb_binlog_index
112 where epoch = @epoch and
113 orig_server_id = @orig_server_id and
114 orig_epoch = @orig_epoch and
115 File=@file1 for update;
116
117 connection con2;
118 --echo Check that there are no rows in the next file
119 select count(*)=0 from mysql.ndb_binlog_index where File=@file2;
120 --echo Start the purge that will get stuck on one row
121 --send_eval PURGE BINARY LOGS TO '$master_log_file2'
122
123 connection con3;
124 --echo Wait 10 sec for purge to run into the row lock
125 sleep 10;
126 --echo Now we should still have some rows in the first file (since the purge is stuck)
127 select count(*)>0 from mysql.ndb_binlog_index where File=@file1;
128 --echo Insert some more rows
129 insert into test.t1 select NULL, a from test.t1;
130 --echo Wait for rows to be committed to binlog
131 --source include/wait_for_ndb_committed_to_binlog.inc
132 --echo Now we see rows in the next file (which means there is no table lock)
133 select count(*)>0 from mysql.ndb_binlog_index where File=@file2;
134
135 connection con1;
136 --echo Release the purge
137 commit;
138
139 connection con2;
140 --reap
141 --echo Purge done
142
143 connection con4;
144 --echo Now we should have no rows in the first file
145 select count(*)=0 from mysql.ndb_binlog_index where File=@file1 into @result;
146 select @result;
147
148 # Debugging windows failures...
149 let $result=query_get_value(select @result as r, r, 1);
150
151 if (!$result)
152 {
153 --echo Unexpected rows in first file, dumping context
154 select * from mysql.ndb_binlog_index;
155 select @file1;
156 select @file2;
157 --connection con1
158 select * from my_ndb_binlog_index;
159 --echo Master log file $master_log_file
160 --echo Master log file2 $master_log_file2
161 SHOW BINARY LOGS;
162 --echo If Binary log entry exists following
163 --echo should succeed, else fail
164 --eval PURGE BINARY LOGS TO '$master_log_file2'
165 select * from mysql.ndb_binlog_index;
166 }
167 # /Debugging windows failures...
168
169 --echo Now we still should see rows in the next file
170 select count(*)>0 from mysql.ndb_binlog_index where File=@file2;
171
172 connection default;
173 --echo cleanup
174 drop table test.t1, test.files;
175
176 --echo Done
177