| 1 |
-- source include/have_multi_ndb.inc |
| 2 |
-- source include/have_binlog_format_row.inc |
| 3 |
|
| 4 |
## |
| 5 |
# Testing of flush tables with read lock and Ndb |
| 6 |
# |
| 7 |
# Not complete, but aims to capture some of the |
| 8 |
# Ndb behaviour, including |
| 9 |
# |
| 10 |
# - FLUSH TABLES WITH READ LOCK affects only 1 |
| 11 |
# server attached to a cluster, others can |
| 12 |
# continue to write to tables |
| 13 |
# - FLUSH TABLES WITH READ LOCK blocks binlogging |
| 14 |
# on the server where it runs |
| 15 |
# - FLUSH TABLES WITH READ LOCK does not affect |
| 16 |
# binlogging on other servers on the cluster |
| 17 |
# - FLUSH TABLES WITH READ LOCK does not wait |
| 18 |
# for all previously committed transactions |
| 19 |
# to be included in the local Binlog before |
| 20 |
# locking the local Binlog. |
| 21 |
# |
| 22 |
|
| 23 |
--connection server1 |
| 24 |
reset master; |
| 25 |
|
| 26 |
--connection server2 |
| 27 |
reset master; |
| 28 |
|
| 29 |
--connection server1 |
| 30 |
|
| 31 |
--echo Initial setup |
| 32 |
--echo Create some tables and put some data in them |
| 33 |
use test; |
| 34 |
|
| 35 |
create table test.ndbt1 (a int primary key, b int) engine=ndb; |
| 36 |
create table test.myisamt3s1 (a int primary key, b int) engine=myisam; |
| 37 |
|
| 38 |
--connection server2 |
| 39 |
create table test.myisamt3s2 (a int primary key, b int) engine=myisam; |
| 40 |
|
| 41 |
--connection server1 |
| 42 |
|
| 43 |
insert into ndbt1 values (1,1); |
| 44 |
|
| 45 |
--echo Show + reset Binlog contents on Server 1 |
| 46 |
--source include/show_binlog_events.inc |
| 47 |
reset master; |
| 48 |
|
| 49 |
--echo Show + reset Binlog contents on Server 2 |
| 50 |
--connection server2 |
| 51 |
--source include/show_binlog_events.inc |
| 52 |
reset master; |
| 53 |
|
| 54 |
--echo Now perform MyIsam table change followed by |
| 55 |
--echo flush tables with read lock on Server 1 |
| 56 |
--connection server1 |
| 57 |
|
| 58 |
insert into test.myisamt3s1 values (3,3); |
| 59 |
FLUSH TABLES WITH READ LOCK; |
| 60 |
|
| 61 |
--echo The MyIsam change definitely will be in the local |
| 62 |
--echo binlog as it occurred 'before' the lock |
| 63 |
--source include/show_binlog_events.inc |
| 64 |
|
| 65 |
--echo Show that Ndb and local tables are still |
| 66 |
--echo Read-Write from Server2 |
| 67 |
--connection server2 |
| 68 |
use test; |
| 69 |
insert into ndbt1 values (4,4); |
| 70 |
|
| 71 |
--echo Look at the Binlog events on Server 2 - contains |
| 72 |
--echo rows written at Server2 |
| 73 |
--source include/show_binlog_events.inc |
| 74 |
|
| 75 |
insert into myisamt3s2 values (5,5); |
| 76 |
|
| 77 |
--echo Look at the Binlog events on Server 2 - contains |
| 78 |
--echo rows written at Server2 |
| 79 |
--source include/show_binlog_events.inc |
| 80 |
|
| 81 |
--echo Now look at the Binlog events on Server 1 |
| 82 |
--connection server1 |
| 83 |
# Note that this will not block waiting for binlog |
| 84 |
# sync as the latest ndb transaction from the p.o.v |
| 85 |
# of Server 1 is already in the binlog. |
| 86 |
--source include/show_binlog_events.inc |
| 87 |
|
| 88 |
--echo Now remove the read lock at server 1 |
| 89 |
unlock tables; |
| 90 |
|
| 91 |
--echo Local event to ensure show binlog events sees |
| 92 |
--echo 'latest' binlog |
| 93 |
|
| 94 |
insert into ndbt1 values (6,6); |
| 95 |
|
| 96 |
--echo Show that server 1 binlog now contains all the relevant |
| 97 |
--echo events. |
| 98 |
--source include/show_binlog_events.inc |
| 99 |
|
| 100 |
--echo Reset both binlogs; |
| 101 |
--connection server1 |
| 102 |
reset master; |
| 103 |
|
| 104 |
--connection server2 |
| 105 |
reset master; |
| 106 |
|
| 107 |
--connection server1 |
| 108 |
|
| 109 |
--echo Now show that a Server 1 Ndb update can |
| 110 |
--echo be committed, but won't always make it to |
| 111 |
--echo the Binlog |
| 112 |
|
| 113 |
--echo This is not 100% guaranteed as in theory |
| 114 |
--echo a commit can occur, and be Binlogged before |
| 115 |
--echo the read lock stops the binlog injector. |
| 116 |
--echo but in reality its very likely |
| 117 |
--echo To remove any uncertainty we loop until |
| 118 |
--echo we see a case where a committed ndb insert |
| 119 |
--echo is not binlogged by the server. |
| 120 |
--echo We do this work on Server2 as it doesn't have |
| 121 |
--echo a read lock :) |
| 122 |
|
| 123 |
create table ndbt2 (a int primary key, b varchar(100)) engine=ndb; |
| 124 |
|
| 125 |
--disable_query_log |
| 126 |
--disable_result_log |
| 127 |
|
| 128 |
let $not_proven = 1; |
| 129 |
let $server1_has_insert = 0; |
| 130 |
let $server2_has_insert = 0; |
| 131 |
|
| 132 |
while ($not_proven) |
| 133 |
{ |
| 134 |
--connection server1 |
| 135 |
let $SERVER1_DATADIR= `select @@datadir;`; |
| 136 |
delete from test.ndbt2; |
| 137 |
reset master; |
| 138 |
|
| 139 |
--connection server2 |
| 140 |
let $SERVER2_DATADIR= `select @@datadir;`; |
| 141 |
delete from test.ndbt2; |
| 142 |
reset master; |
| 143 |
|
| 144 |
--connection server1 |
| 145 |
|
| 146 |
insert into test.ndbt2 values (123, "A most unlikely sequence if I may say so"); |
| 147 |
flush tables with read lock; |
| 148 |
|
| 149 |
# Allow some time(100ms) to elapse to let the insert reach server 2 binlog |
| 150 |
--sleep 0.1 |
| 151 |
|
| 152 |
--connection server2 |
| 153 |
#--echo Disable binlogging of the binlog examination on server2 |
| 154 |
set sql_log_bin=0; |
| 155 |
|
| 156 |
create table raw_binlog_rows_server1 (txt varchar(1000)); |
| 157 |
create table raw_binlog_rows_server2 (txt varchar(1000)); |
| 158 |
|
| 159 |
--exec $MYSQL_BINLOG --verbose $SERVER1_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog1.sql |
| 160 |
--eval load data local infile '$MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog1.sql' into table raw_binlog_rows_server1 columns terminated by '\n'; |
| 161 |
--exec $MYSQL_BINLOG --verbose $SERVER2_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog2.sql |
| 162 |
--eval load data local infile '$MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog2.sql' into table raw_binlog_rows_server2 columns terminated by '\n'; |
| 163 |
|
| 164 |
|
| 165 |
let $server1_has_insert = `select @s1_has_ins:=count(1) > 0 from raw_binlog_rows_server1 where txt like '%A most unlikely sequence if I may say so%'`; |
| 166 |
let $server2_has_insert = `select @s2_has_ins:=count(1) > 0 from raw_binlog_rows_server2 where txt like '%A most unlikely sequence if I may say so%'`; |
| 167 |
|
| 168 |
# We succeed when server 1 does not have the insert, but server 2 does. |
| 169 |
select @proven:= (@s1_has_ins = 0 and @s2_has_ins != 0); |
| 170 |
let $not_proven = `select @proven = 0`; |
| 171 |
|
| 172 |
drop table raw_binlog_rows_server1; |
| 173 |
drop table raw_binlog_rows_server2; |
| 174 |
|
| 175 |
set sql_log_bin=1; |
| 176 |
|
| 177 |
--connection server1 |
| 178 |
unlock tables; |
| 179 |
} |
| 180 |
|
| 181 |
--enable_result_log |
| 182 |
--enable_query_log |
| 183 |
|
| 184 |
--echo Outcome |
| 185 |
--echo Server 1 has insert : $server1_has_insert |
| 186 |
--echo Server 2 has insert : $server2_has_insert |
| 187 |
|
| 188 |
--echo Now cleanup |
| 189 |
--connection server1 |
| 190 |
drop table ndbt1; |
| 191 |
drop table ndbt2; |
| 192 |
drop table myisamt3s1; |
| 193 |
|
| 194 |
--connection server2 |
| 195 |
drop table myisamt3s2; |
| 196 |
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp ndb_binlog_mysqlbinlog*.sql |
| 197 |
|