| 1 |
# Testing various forms of idempotency for replication that should |
| 2 |
# work the same way under statement based as under row based. |
| 3 |
|
| 4 |
--source include/not_group_replication_plugin.inc |
| 5 |
source include/master-slave.inc; |
| 6 |
|
| 7 |
# Add suppression for expected warning(s) in slaves error log |
| 8 |
call mtr.add_suppression("Replica SQL.*Can.t find record in .t[12].* Error_code: 1032"); |
| 9 |
call mtr.add_suppression("Replica SQL.*Cannot delete or update a parent row: a foreign key constraint fails .* Error_code: 1451"); |
| 10 |
call mtr.add_suppression("Replica SQL.*Cannot add or update a child row: a foreign key constraint fails .* Error_code: 1452"); |
| 11 |
call mtr.add_suppression("Replica SQL.*Could not execute Write_rows event on table test.* Duplicate entry .1. for key .PRIMARY.* Error_code: 1062"); |
| 12 |
|
| 13 |
connection master; |
| 14 |
CREATE TABLE t1 (a INT PRIMARY KEY); |
| 15 |
CREATE TABLE t2 (a INT); |
| 16 |
INSERT INTO t1 VALUES (-1),(-2),(-3); |
| 17 |
INSERT INTO t2 VALUES (-1),(-2),(-3); |
| 18 |
--source include/sync_slave_sql_with_master.inc |
| 19 |
|
| 20 |
SET @old_replica_exec_mode= @@global.replica_exec_mode; |
| 21 |
SET @@global.replica_exec_mode= IDEMPOTENT; |
| 22 |
|
| 23 |
# A delete for a row that does not exist, the statement is |
| 24 |
# deliberately written to be idempotent for statement-based |
| 25 |
# replication as well. We test this towards both a table with a |
| 26 |
# primary key and without a primary key. |
| 27 |
|
| 28 |
connection slave; |
| 29 |
DELETE FROM t1 WHERE a = -2; |
| 30 |
DELETE FROM t2 WHERE a = -2; |
| 31 |
connection master; |
| 32 |
DELETE FROM t1 WHERE a = -2; |
| 33 |
DELETE FROM t2 WHERE a = -2; |
| 34 |
SELECT * FROM t1 ORDER BY a; |
| 35 |
SELECT * FROM t2 ORDER BY a; |
| 36 |
--source include/sync_slave_sql_with_master.inc |
| 37 |
SELECT * FROM t1 ORDER BY a; |
| 38 |
SELECT * FROM t2 ORDER BY a; |
| 39 |
--source include/check_slave_no_error.inc |
| 40 |
|
| 41 |
# An insert of a row that already exists. Since we are replacing the |
| 42 |
# row if it already exists, the most apropriate representation is |
| 43 |
# INSERT IGNORE. We only test this towards a table with a primary key, |
| 44 |
# since the other case does not make sense. |
| 45 |
|
| 46 |
INSERT IGNORE INTO t1 VALUES (-2); |
| 47 |
connection master; |
| 48 |
INSERT IGNORE INTO t1 VALUES (-2); |
| 49 |
SELECT * FROM t1 ORDER BY a; |
| 50 |
--source include/sync_slave_sql_with_master.inc |
| 51 |
SELECT * FROM t1 ORDER BY a; |
| 52 |
--source include/check_slave_no_error.inc |
| 53 |
|
| 54 |
|
| 55 |
# BUG#19958: RBR idempotency issue for UPDATE and DELETE |
| 56 |
|
| 57 |
# Statement-based and row-based replication have different behaviour |
| 58 |
# when updating a row with an explicit WHERE-clause that matches |
| 59 |
# exactly one row (or no row at all). For statement-based replication, |
| 60 |
# the statement is idempotent since the first time it is executed, it |
| 61 |
# will update exactly one row, and the second time it will not update |
| 62 |
# any row at all. This was not the case for row-based replication, so |
| 63 |
# we test under both row-based and statement-based replication both |
| 64 |
# for tables with and without primary keys. |
| 65 |
|
| 66 |
connection slave; |
| 67 |
UPDATE t1 SET a = 1 WHERE a = -1; |
| 68 |
UPDATE t2 SET a = 1 WHERE a = -1; |
| 69 |
connection master; |
| 70 |
UPDATE t1 SET a = 1 WHERE a = -1; |
| 71 |
UPDATE t2 SET a = 1 WHERE a = -1; |
| 72 |
SELECT * FROM t1 ORDER BY a; |
| 73 |
SELECT * FROM t2 ORDER BY a; |
| 74 |
--source include/sync_slave_sql_with_master.inc |
| 75 |
SELECT * FROM t1 ORDER BY a; |
| 76 |
SELECT * FROM t2 ORDER BY a; |
| 77 |
--source include/check_slave_no_error.inc |
| 78 |
|
| 79 |
connection master; |
| 80 |
DROP TABLE t1, t2; |
| 81 |
--source include/sync_slave_sql_with_master.inc |
| 82 |
|
| 83 |
SET @@global.replica_exec_mode= @old_replica_exec_mode; |
| 84 |
|
| 85 |
--source include/rpl_end.inc |