|
| 1 | +# ==== Purpose ==== |
| 2 | +# |
| 3 | +# Test verifies that there are no duplicate entries in binlog (i.e a safe |
| 4 | +# statement which follows an unsafe statement gets logged in both row format |
| 5 | +# and statement format resulting in duplicate entry) when binlog-format=MIXED |
| 6 | +# and LOCK TABLES are enabled. |
| 7 | +# |
| 8 | +# ==== Implementation ==== |
| 9 | +# |
| 10 | +# Steps: |
| 11 | +# 1 - Create three tables t1,t2 and t3 with AUTO_INCREMENT on. |
| 12 | +# 2 - Create a trigger on table t3, so that trigger execution results in |
| 13 | +# unsafe statement. Note query that modifies autoinc column in |
| 14 | +# sub-statement can make the master and slave inconsistent. Hence they |
| 15 | +# are logged in row format. |
| 16 | +# 3 - Lock tables t1,t2 and t3. |
| 17 | +# 4 - Execute an unsafe update which modifies tables t1 and t3. But since t2 |
| 18 | +# table is also locked its table map event also gets written into the |
| 19 | +# binary log during the execution of update. |
| 20 | +# 5 - Execute a safe DML operation using table 't2' and verify that master |
| 21 | +# doesn't report any assert. |
| 22 | +# 6 - Ensure that slave is in sync with master and data is consistent. |
| 23 | +# |
| 24 | +# ==== References ==== |
| 25 | +# |
| 26 | +# MDEV-19158: MariaDB 10.2.22 is writing duplicate entries into binary log |
| 27 | + |
| 28 | +--source include/have_binlog_format_mixed.inc |
| 29 | +--source include/master-slave.inc |
| 30 | + |
| 31 | +CREATE TABLE t1 (id mediumint(8) unsigned NOT NULL AUTO_INCREMENT, someLabel varchar(30) NOT NULL, flag tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (id)) Engine=MyISAM; |
| 32 | +CREATE TABLE t2 (id mediumint(8) unsigned NOT NULL AUTO_INCREMENT, data varchar(30) NOT NULL, status tinyint(1) NOT NULL, PRIMARY KEY (id)) Engine=MyISAM; |
| 33 | +CREATE TABLE t3 (id mediumint(8) unsigned NOT NULL AUTO_INCREMENT, t1id mediumint(8) unsigned NOT NULL, flag tinyint(1) NOT NULL DEFAULT 0, status tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (id)) Engine=MyISAM; |
| 34 | + |
| 35 | +INSERT INTO t1 ( id, someLabel, flag ) VALUES ( 1, 'ABC', 0 ); |
| 36 | + |
| 37 | +DELIMITER |; |
| 38 | + |
| 39 | +CREATE OR REPLACE TRIGGER doNothing |
| 40 | +BEFORE UPDATE ON t1 |
| 41 | +FOR EACH ROW |
| 42 | + BEGIN |
| 43 | + IF |
| 44 | + new.someLabel != old.someLabel |
| 45 | + THEN |
| 46 | + UPDATE t3 SET t3.flag = 0; |
| 47 | + END IF; |
| 48 | + END| |
| 49 | + |
| 50 | +DELIMITER ;| |
| 51 | + |
| 52 | +FLUSH LOGS; |
| 53 | + |
| 54 | +LOCK TABLES t1 WRITE, t2 WRITE; |
| 55 | +INSERT INTO t2 (data, status) VALUES ('1', 4); |
| 56 | +UPDATE t1 SET flag = 1 WHERE id = 1; |
| 57 | +INSERT INTO t2 (data, status) VALUES ('2', 4); |
| 58 | +UNLOCK TABLES; |
| 59 | + |
| 60 | +sync_slave_with_master; |
| 61 | + |
| 62 | +let $diff_tables= master:t1, slave:t1; |
| 63 | +--source include/diff_tables.inc |
| 64 | +let $diff_tables= master:t2, slave:t2; |
| 65 | +--source include/diff_tables.inc |
| 66 | +let $diff_tables= master:t3, slave:t3; |
| 67 | +--source include/diff_tables.inc |
| 68 | + |
| 69 | +--connection master |
| 70 | +DROP TABLE t1, t2, t3; |
| 71 | + |
| 72 | +--source include/rpl_end.inc |
0 commit comments