1# The include statement below is a temp one for tests that are yet to 2#be ported to run with InnoDB, 3#but needs to be kept for tests that would need MyISAM in future. 4--source include/force_myisam_default.inc 5 6######################################################## 7# Test binlog variants produced by Ndb 8# 9# 1) Updates logged as write_row events 10# Only primary key and updated columns included in the 11# event 12# 2) Updates logged as write_row_events 13# All columns included in the event 14# 3) Updates logged as update_row events 15# Only primary key and updated columns included in the 16# event 17# 4) Updates logged as update_row events 18# All columns included in the event 19# 20# Format variant (1) is the Ndb default. 21# 22# We use mysqlbinlog --verbose to check that the 23# generated binlog contents are as expected. 24# 25######################################################## 26-- source include/have_ndb.inc 27-- source include/have_binlog_format_row.inc 28 29# Setup connections 30connect(mysqld1,127.0.0.1,root,,test,$MASTER_MYPORT); 31connect(mysqld2,127.0.0.1,root,,test,$MASTER_MYPORT1); 32connect(mysqld3,127.0.0.1,root,,test,$MASTER_MYPORT2); 33connect(mysqld4,127.0.0.1,root,,test,$MASTER_MYPORT3); 34 35connection mysqld1; 36 37# Create the table we're going to use 38create table ba(ks int primary key, st int, lp int) engine = ndb; 39 40# Wait for each mysqld to startup binlogging 41--let $source_server=mysqld1 42--let $dest_server=mysqld2 43source suite/ndb_rpl/t/wait_schema_logging.inc; 44 45--let $source_server=mysqld1 46--let $dest_server=mysqld3 47source suite/ndb_rpl/t/wait_schema_logging.inc; 48 49--let $source_server=mysqld1 50--let $dest_server=mysqld4 51source suite/ndb_rpl/t/wait_schema_logging.inc; 52 53--disable_query_log 54connection mysqld1; 55reset master; 56connection mysqld2; 57reset master; 58connection mysqld3; 59reset master; 60connection mysqld4; 61reset master; 62--enable_query_log 63 64connection mysqld1; 65 66# Now make the inserts and update 67insert into ba values (1, 1, 1), (2,2,2), (3,3,3), (4,4,4); 68update ba set lp=40 where ks=4; # Update does not affect all columns 69delete from ba where ks=2; # Also a delete for fun 70 71--disable_query_log 72# Add an event-stream marker 73create table stream_marker(a int) engine=ndb; 74drop table stream_marker; 75--let $wait_binlog_event=stream_marker 76--enable_query_log 77 78# Now let's trim the Binlogs on each server 79 80connection mysqld1; 81--source include/wait_for_binlog_event.inc 82flush logs; 83connection mysqld2; 84--source include/wait_for_binlog_event.inc 85flush logs; 86connection mysqld3; 87--source include/wait_for_binlog_event.inc 88flush logs; 89connection mysqld4; 90--source include/wait_for_binlog_event.inc 91flush logs; 92 93# Empty the table 94delete from ba; 95 96# Now let's examine the contents of the first binlog 97# on each server 98# We'll also apply the Binlog and check that the 99# table contents are as expected in each case. 100# As each server is recording in a new binlog, the 101# new updates will go there. 102 103connection mysqld1; 104 105show variables like 'ndb_log_update%'; 106--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc 107 108--disable_query_log 109let $MYSQLD_DATADIR= `select @@datadir;`; 110--exec $MYSQL_BINLOG $MYSQLD_DATADIR/mysqld-bin.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 111--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 112 113--enable_query_log 114select * from ba order by ks; 115delete from ba; 116 117connection mysqld2; 118 119show variables like 'ndb_log_update%'; 120--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc 121 122--disable_query_log 123let $MYSQLD_DATADIR= `select @@datadir;`; 124--exec $MYSQL_BINLOG $MYSQLD_DATADIR/mysqld-bin.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 125--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 126 127--enable_query_log 128 129select * from ba order by ks; 130delete from ba; 131 132connection mysqld3; 133 134show variables like 'ndb_log_update%'; 135--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc 136 137--disable_query_log 138let $MYSQLD_DATADIR= `select @@datadir;`; 139--exec $MYSQL_BINLOG $MYSQLD_DATADIR/mysqld-bin.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 140--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 141 142--enable_query_log 143select * from ba order by ks; 144delete from ba; 145 146connection mysqld4; 147 148show variables like 'ndb_log_update%'; 149--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc 150 151--disable_query_log 152let $MYSQLD_DATADIR= `select @@datadir;`; 153--exec $MYSQL_BINLOG $MYSQLD_DATADIR/mysqld-bin.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 154--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 155 156--enable_query_log 157select * from ba order by ks; 158 159drop table ba; 160--disable_query_log 161flush logs; 162--enable_query_log 163 164# Bug#46662 165# Replicating changes to tables with unique indexes 166# The fix to bug#27378 results in the slave using NdbApi's write() 167# mechanism when applying WRITE_ROW events to tables with unique 168# indices. 169# 170# If this is not done then the slave attempts to partially use SQL 171# REPLACE semantics when applying WRITE_ROW events to tables with 172# unique indexes, which is not good and the slave fails with a 173# duplicate key error on the primary key. 174# 175# The fix to Bug#46662 aims to correct this, so that replicated 176# updates to tables with unique indices can work. 177# Note that other issues with replicating into tables with unique 178# indexes remain. 179# 180 181connection mysqld1; 182reset master; 183show variables like 'ndb_log_update%'; 184 185create table bah (tst int primary key, cvy int, sqs int, unique(sqs)) engine=ndb; 186 187insert into bah values (1,1,1); 188 189# Wait for epoch to complete in Binlog 190--disable_query_log 191create table dummy (a int primary key) engine=ndb; 192--enable_query_log 193 194# Now perform update 195# This will be logged as WRITE 196# Without ability to use NdbApi write() for replace, mysqlbinlog 197# application will fail with duplicate key error on insert. 198update bah set cvy= 2 where tst=1; 199 200select * from bah order by tst; 201 202# Wait for epoch to complete in Binlog 203--disable_query_log 204drop table dummy; 205flush logs; 206--enable_query_log 207 208drop table bah; 209 210# Now let's re-apply the binlog 211# Without fix, this fails with duplicate PK error 212--echo Manually applying captured binlog 213--disable_query_log 214let $MYSQLD_DATADIR= `select @@datadir;`; 215--exec $MYSQL_BINLOG $MYSQLD_DATADIR/mysqld-bin.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 216--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 217 218--enable_query_log 219select * from bah order by tst; 220 221drop table bah; 222 223# Bug #14615095 ERROR 839 'ILLEGAL NULL ATTRIBUTE' WHEN REPLAYING BINLOG 224# When applying WRITE_ROW events to tables where the rows are missing 225# any errors should be ignored 226 227connection mysqld1; 228reset master; 229show variables like '%log_update%'; 230 231CREATE TABLE `t1` ( 232 `charId` varchar(60) NOT NULL, 233 `enumId` enum('A','B','C') NOT NULL, 234 `val` bigint(20) NOT NULL, 235 `version` int(11) NOT NULL, 236 PRIMARY KEY (`charId`,`enumId`) 237 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1; 238 239INSERT INTO t1 VALUES ('', 'A', 0, 1); 240 241--disable_query_log 242# Add an event-stream marker 243create table stream_marker(a int) engine=ndb; 244drop table stream_marker; 245--let $wait_binlog_event=stream_marker 246--enable_query_log 247 248# Wait until the INSERT statement is confirmed to have made it into the current binary log 249--source include/wait_for_binlog_event.inc 250FLUSH LOGS; 251 252UPDATE t1 SET val = val + 1 WHERE charId = ''; 253 254--disable_query_log 255# Add an event-stream marker 256create table stream_marker(a int) engine=ndb; 257drop table stream_marker; 258--let $wait_binlog_event=stream_marker 259--enable_query_log 260 261# Wait until the UPDATE statement is confirmed to have made it into the current binary log 262--let $wait_binlog_file=mysqld-bin.000002 263--source include/wait_for_binlog_event.inc 264FLUSH LOGS; 265 266DELETE FROM t1 WHERE charId = ''; 267 268--disable_query_log 269# Add an event-stream marker 270create table stream_marker(a int) engine=ndb; 271drop table stream_marker; 272--let $wait_binlog_event=stream_marker 273--enable_query_log 274 275# Wait until the DELETE statement is confirmed to have made it into the current binary log 276--let $wait_binlog_file=mysqld-bin.000003 277--source include/wait_for_binlog_event.inc 278FLUSH LOGS; 279 280# Now let's re-apply the binlog from the UPDATE 281# Without fix, this fails with 'Illegal null attribute' 282--echo Manually applying captured binlog 283--disable_query_log 284let $MYSQLD_DATADIR= `select @@datadir;`; 285--exec $MYSQL_BINLOG $MYSQLD_DATADIR/mysqld-bin.000002 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 286--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 287 288--enable_query_log 289# Check that the table is still empty 290select * from t1; 291 292drop table t1; 293 294# Bug #14678088 CAN'T FIND RECORD IN 295# We need to be idempotent when applying binlog 296# test insert of existing row, update and delete 297# of non-existing row 298 299connection mysqld1; 300reset master; 301show variables like '%log_update%'; 302 303create table t1 (pk int not null primary key, name varchar(256)) engine = ndb; 304 305--disable_query_log 306# Add an event-stream marker 307create table stream_marker(a int) engine=ndb; 308drop table stream_marker; 309--let $wait_binlog_event=stream_marker 310--enable_query_log 311 312# Wait until all statements are confirmed to have made it into the current binary log 313--let $wait_binlog_file=mysqld-bin.000001 314--source include/wait_for_binlog_event.inc 315FLUSH LOGS; 316 317insert into t1 values (0, "zero"),(1,"one"),(2,"two"),(3,"three"),(4,"four"),(5,"five"),(6,"six"),(7,"seven"),(8,"eight"),(9,"nine"); 318select * from t1 order by pk; 319 320update t1 set name = "even" where pk in (0,2,4,6,8); 321update t1 set name = "odd" where pk in (1,3,5,7,9); 322 323delete from t1 where name = "odd"; 324 325select * from t1 order by pk; 326 327--disable_query_log 328# Add an event-stream marker 329create table stream_marker(a int) engine=ndb; 330drop table stream_marker; 331--let $wait_binlog_event=stream_marker 332--enable_query_log 333 334# Wait until all statements are confirmed to have made it into the current binary log 335--let $wait_binlog_file=mysqld-bin.000002 336--source include/wait_for_binlog_event.inc 337FLUSH LOGS; 338 339truncate t1; 340insert into t1 values (0, "zero"),(1,"one"),(2,"two"),(3,"three"),(4,"four"),(5,"five"),(6,"six"),(7,"seven"),(8,"eight"),(9,"nine"); 341select * from t1 order by pk; 342 343--disable_query_log 344# Add an event-stream marker 345create table stream_marker(a int) engine=ndb; 346drop table stream_marker; 347--let $wait_binlog_event=stream_marker 348--enable_query_log 349 350# Wait until all statements are confirmed to have made it into the current binary log 351--let $wait_binlog_file=mysqld-bin.000003 352--source include/wait_for_binlog_event.inc 353FLUSH LOGS; 354 355# Now let's re-apply the binlog INSERT,UPDATE,DELETE 356# Without fix, this fails with 'Illegal null attribute' 357--echo Manually applying captured binlog 358--disable_query_log 359let $MYSQLD_DATADIR= `select @@datadir;`; 360--exec $MYSQL_BINLOG $MYSQLD_DATADIR/mysqld-bin.000002 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 361--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql 362 363--enable_query_log 364select * from t1 order by pk; 365 366drop table t1; 367 368 369