📄 rpl_ndb_idempotent.test
字号:
--source include/have_ndb.inc--source include/have_binlog_format_row.inc--source include/master-slave.inc## Currently test only works with ndb since it retrieves "old"# binlog positions with cluster_replication.binlog_index and apply_status;## create a table with one rowCREATE TABLE t1 (c1 CHAR(15), c2 CHAR(15), c3 INT, PRIMARY KEY (c3)) ENGINE = NDB ;INSERT INTO t1 VALUES ("row1","will go away",1);SELECT * FROM t1 ORDER BY c3;# sync slave and retrieve epochsync_slave_with_master;--replace_column 1 <the_epoch>SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status;let $the_epoch= `select @the_epoch` ;SELECT * FROM t1 ORDER BY c3;# get the master binlog pos from the epochconnection master;--replace_result $the_epoch <the_epoch>--replace_column 1 <the_pos>eval SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) FROM cluster_replication.binlog_index WHERE epoch = $the_epoch ;let $the_pos= `SELECT @the_pos` ;let $the_file= `SELECT @the_file` ;# insert some more valuesINSERT INTO t1 VALUES ("row2","will go away",2),("row3","will change",3),("row4","D",4);DELETE FROM t1 WHERE c3 = 1;UPDATE t1 SET c2="should go away" WHERE c3 = 2;UPDATE t1 SET c2="C" WHERE c3 = 3;DELETE FROM t1 WHERE c3 = 2;SELECT * FROM t1 ORDER BY c3;# check that we have it on the slave--sync_slave_with_master--connection slaveSELECT * FROM t1 ORDER BY c3;--replace_result $MASTER_MYPORT MASTER_PORT--replace_column 1 <Slave_IO_State> 7 <Read_Master_Log_Pos> 8 <Relay_Log_File> 9 <Relay_Log_Pos> 16 <Replicate_Ignore_Table> 22 <Exec_Master_Log_Pos> 23 <Relay_Log_Space> 33 <Seconds_Behind_Master>SHOW SLAVE STATUS;# stop slave and reset position to before the last changesSTOP SLAVE;--replace_result $the_pos <the_pos>eval CHANGE MASTER TO master_log_file = '$the_file', master_log_pos = $the_pos ;--replace_result $MASTER_MYPORT MASTER_PORT--replace_column 1 <Slave_IO_State> 7 <Read_Master_Log_Pos> 8 <Relay_Log_File> 9 <Relay_Log_Pos> 16 <Replicate_Ignore_Table> 22 <Exec_Master_Log_Pos> 23 <Relay_Log_Space> 33 <Seconds_Behind_Master>SHOW SLAVE STATUS;# start the slave again# -> same events should have been applied again# e.g. inserting rows that already there# deleting a row which is not there# updating a row which is not thereSTART SLAVE;--connection masterSELECT * FROM t1 ORDER BY c3;--sync_slave_with_master--connection slaveSELECT * FROM t1 ORDER BY c3;STOP SLAVE;## cleanup#--connection masterDROP TABLE t1;RESET master;--connection slaveDROP TABLE t1;RESET slave;START SLAVE;## Test that we can handle update of a row that does not exist on the slave# will trigger usage of AO_IgnoreError on slave side so that the INSERT# still succeeds even if the replication of the UPDATE generates an error.#--connection masterCREATE TABLE t1 (c1 CHAR(15) NOT NULL, c2 CHAR(15) NOT NULL, c3 INT NOT NULL, PRIMARY KEY (c3)) ENGINE = NDB ;INSERT INTO t1 VALUES ("row1","remove on slave",1);--sync_slave_with_master--connection slaveDELETE FROM t1;--connection masterBEGIN;UPDATE t1 SET c2="does not exist" WHERE c3=1;INSERT INTO t1 VALUES ("row2","new on slave",2);COMMIT;--sync_slave_with_master--connection slaveSELECT * FROM t1;--replace_result $MASTER_MYPORT MASTER_PORT--replace_column 1 <Slave_IO_State> 7 <Read_Master_Log_Pos> 8 <Relay_Log_File> 9 <Relay_Log_Pos> 16 <Replicate_Ignore_Table> 22 <Exec_Master_Log_Pos> 23 <Relay_Log_Space> 33 <Seconds_Behind_Master>SHOW SLAVE STATUS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -