Skip to content
Permalink
Browse files

MDEV-8075: DROP TEMPORARY TABLE not marked as ddl, causing optimistic…

… parallel replication to fail

CREATE/DROP TEMPORARY TABLE are not safe to optimistically replicate in
parallel with other transactions, so they need to be marked as "ddl" in the
binlog.

This was already done for stand-alone CREATE/DROP TEMPORARY. But temporary
tables can also be created and dropped inside a BEGIN...END transaction, and
such transactions were not marked as ddl. Nor was the DROP TEMPORARY TABLE
statement emitted implicitly when a client connection is closed.

So this patch adds such ddl mark for the missing cases.

The difference to Kristian's original patch is mainly a fix in
mysql_trans_commit_alter_copy_data() to remember the unsafe_rollback_flags
over the temporary commit.
  • Loading branch information...
knielsen authored and montywi committed May 29, 2017
1 parent da7604a commit 228479a28ce7e4c91f96962159fccc8dc71b5a36
@@ -0,0 +1,85 @@
# Test the markings on GTID events (ddl, waited, trans,
# @@skip_parallel_replication) that are used to control parallel
# replication on the slave.

--source include/have_innodb.inc

RESET MASTER;
--source include/wait_for_binlog_checkpoint.inc

set time_zone="+02:00";
--let $stable_stamp= `SELECT UNIX_TIMESTAMP("2020-01-21 15:32:22")`
eval set timestamp=$stable_stamp;

CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
--let $binlog_pos1=query_get_value(SHOW MASTER STATUS, Position, 1)
/* GTID */ INSERT INTO t1 VALUES (1,0);
/* GTID */ BEGIN;
/* GTID */ INSERT INTO t1 VALUES (2,0);
/* GTID */ ALTER TABLE t1 ADD c INT;
/* GTID */ INSERT INTO t1 VALUES (3,0,0);
/* GTID */ COMMIT;
/* GTID */ BEGIN;
/* GTID */ UPDATE t1 SET b=1, c=1 WHERE a=2;
/* GTID */ CREATE TEMPORARY TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
/* GTID */ INSERT INTO t2 VALUES (4,10), (5,20);
/* GTID */ INSERT INTO t1 SELECT a, 2, b FROM t2;
/* GTID */ DROP TEMPORARY TABLE t2;
/* GTID */ INSERT INTO t1 VALUES (6, 3, 0);
/* GTID */ COMMIT;
/* GTID */ CREATE TEMPORARY TABLE t3 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ BEGIN;
/* GTID */ DELETE FROM t1 WHERE a=5;
/* GTID */ INSERT INTO t3 VALUES (7);
/* GTID */ INSERT INTO t1 SELECT a, 4, 0 FROM t3;
/* GTID */ UPDATE t1 SET c=1 WHERE a=7;
/* GTID */ DROP TEMPORARY TABLE t3;
/* GTID */ COMMIT;
/* GTID */ CREATE TEMPORARY TABLE t4 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ BEGIN;
/* GTID */ INSERT INTO t1 VALUES (8, 5, 0);
/* GTID */ ALTER TABLE t4 ADD b INT;
/* GTID */ INSERT INTO t1 VALUES (9, 5, 1);
/* GTID */ COMMIT;
connect (tmp_con,localhost,root,,);
eval set timestamp=$stable_stamp;
/* GTID */ INSERT INTO t1 VALUES (10, 6, 0);
/* GTID */ BEGIN;
/* GTID */ CREATE TEMPORARY TABLE t5 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ INSERT INTO t1 VALUES (11, 7, 0);
/* GTID */ COMMIT;
--let $before_drop_pos=query_get_value(SHOW MASTER STATUS, Position, 1)
disconnect tmp_con;
connection default;

# We need to wait for the implicit DROP TEMPORARY TABLE to be logged after
# tmp_con disconnect, otherwise we get sporadic test failures.
--let $wait_condition= SELECT variable_value > $before_drop_pos FROM information_schema.global_status WHERE variable_name = 'binlog_snapshot_position'
--source include/wait_condition.inc

--let $binlog_pos2=query_get_value(SHOW MASTER STATUS, Position, 1)

--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;

--let $MYSQLD_DATADIR= `select @@datadir`
--let $file= $MYSQLTEST_VARDIR/tmp/binlog_parallel_replication_marks.out
--let OUTPUT_FILE=$file
exec $MYSQL_BINLOG --start_position=$binlog_pos1 --stop_position=$binlog_pos2 $MYSQLD_DATADIR/$binlog_file > $file;

perl;
my $file= $ENV{'OUTPUT_FILE'};
open F, "<", $file
or die "Unable to open file '$file': $!\n";
while (<F>) {
s/^#\d+ \d+:\d+:\d+ /# /;
s/GTID \d+-\d+-\d+/GTID #-#-#/;
s/end_log_pos \d+/end_log_pos #/;
s/table id \d+/table id #/;
s/mapped to number \d+/mapped to number #/;
print if /GTID|BEGIN|COMMIT|Table_map|Write_rows|Update_rows|Delete_rows|generated by server|40005 TEMPORARY/;
}
close F;
EOF

DROP TABLE t1;
@@ -0,0 +1,97 @@
RESET MASTER;
set time_zone="+02:00";
set timestamp=1579613542;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
/* GTID */ INSERT INTO t1 VALUES (1,0);
/* GTID */ BEGIN;
/* GTID */ INSERT INTO t1 VALUES (2,0);
/* GTID */ ALTER TABLE t1 ADD c INT;
/* GTID */ INSERT INTO t1 VALUES (3,0,0);
/* GTID */ COMMIT;
/* GTID */ BEGIN;
/* GTID */ UPDATE t1 SET b=1, c=1 WHERE a=2;
/* GTID */ CREATE TEMPORARY TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
/* GTID */ INSERT INTO t2 VALUES (4,10), (5,20);
/* GTID */ INSERT INTO t1 SELECT a, 2, b FROM t2;
/* GTID */ DROP TEMPORARY TABLE t2;
/* GTID */ INSERT INTO t1 VALUES (6, 3, 0);
/* GTID */ COMMIT;
/* GTID */ CREATE TEMPORARY TABLE t3 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ BEGIN;
/* GTID */ DELETE FROM t1 WHERE a=5;
/* GTID */ INSERT INTO t3 VALUES (7);
/* GTID */ INSERT INTO t1 SELECT a, 4, 0 FROM t3;
/* GTID */ UPDATE t1 SET c=1 WHERE a=7;
/* GTID */ DROP TEMPORARY TABLE t3;
/* GTID */ COMMIT;
/* GTID */ CREATE TEMPORARY TABLE t4 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ BEGIN;
/* GTID */ INSERT INTO t1 VALUES (8, 5, 0);
/* GTID */ ALTER TABLE t4 ADD b INT;
/* GTID */ INSERT INTO t1 VALUES (9, 5, 1);
/* GTID */ COMMIT;
set timestamp=1579613542;
/* GTID */ INSERT INTO t1 VALUES (10, 6, 0);
/* GTID */ BEGIN;
/* GTID */ CREATE TEMPORARY TABLE t5 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ INSERT INTO t1 VALUES (11, 7, 0);
/* GTID */ COMMIT;
FLUSH LOGS;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
/* GTID */ ALTER TABLE t1 ADD c INT
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Update_rows: table id # flags: STMT_END_F
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Delete_rows: table id # flags: STMT_END_F
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Update_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
# server id 1 end_log_pos # Table_map: `test`.`t1` mapped to number #
# server id 1 end_log_pos # Write_rows: table id # flags: STMT_END_F
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `t5`
DROP TABLE t1;
@@ -0,0 +1,96 @@
RESET MASTER;
set time_zone="+02:00";
set timestamp=1579613542;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
/* GTID */ INSERT INTO t1 VALUES (1,0);
/* GTID */ BEGIN;
/* GTID */ INSERT INTO t1 VALUES (2,0);
/* GTID */ ALTER TABLE t1 ADD c INT;
/* GTID */ INSERT INTO t1 VALUES (3,0,0);
/* GTID */ COMMIT;
/* GTID */ BEGIN;
/* GTID */ UPDATE t1 SET b=1, c=1 WHERE a=2;
/* GTID */ CREATE TEMPORARY TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
/* GTID */ INSERT INTO t2 VALUES (4,10), (5,20);
/* GTID */ INSERT INTO t1 SELECT a, 2, b FROM t2;
/* GTID */ DROP TEMPORARY TABLE t2;
/* GTID */ INSERT INTO t1 VALUES (6, 3, 0);
/* GTID */ COMMIT;
/* GTID */ CREATE TEMPORARY TABLE t3 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ BEGIN;
/* GTID */ DELETE FROM t1 WHERE a=5;
/* GTID */ INSERT INTO t3 VALUES (7);
/* GTID */ INSERT INTO t1 SELECT a, 4, 0 FROM t3;
/* GTID */ UPDATE t1 SET c=1 WHERE a=7;
/* GTID */ DROP TEMPORARY TABLE t3;
/* GTID */ COMMIT;
/* GTID */ CREATE TEMPORARY TABLE t4 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ BEGIN;
/* GTID */ INSERT INTO t1 VALUES (8, 5, 0);
/* GTID */ ALTER TABLE t4 ADD b INT;
/* GTID */ INSERT INTO t1 VALUES (9, 5, 1);
/* GTID */ COMMIT;
set timestamp=1579613542;
/* GTID */ INSERT INTO t1 VALUES (10, 6, 0);
/* GTID */ BEGIN;
/* GTID */ CREATE TEMPORARY TABLE t5 (a INT PRIMARY KEY) ENGINE=InnoDB;
/* GTID */ INSERT INTO t1 VALUES (11, 7, 0);
/* GTID */ COMMIT;
FLUSH LOGS;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
/* GTID */ INSERT INTO t1 VALUES (1,0)
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
/* GTID */ INSERT INTO t1 VALUES (2,0)
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
/* GTID */ ALTER TABLE t1 ADD c INT
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
/* GTID */ INSERT INTO t1 VALUES (3,0,0)
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
BEGIN
/* GTID */ UPDATE t1 SET b=1, c=1 WHERE a=2
/* GTID */ CREATE TEMPORARY TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB
/* GTID */ INSERT INTO t2 VALUES (4,10), (5,20)
/* GTID */ INSERT INTO t1 SELECT a, 2, b FROM t2
DROP TEMPORARY TABLE `t2` /* generated by server */
/* GTID */ INSERT INTO t1 VALUES (6, 3, 0)
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
/* GTID */ CREATE TEMPORARY TABLE t3 (a INT PRIMARY KEY) ENGINE=InnoDB
# server id 1 end_log_pos # GTID #-#-# ddl
BEGIN
/* GTID */ DELETE FROM t1 WHERE a=5
/* GTID */ INSERT INTO t3 VALUES (7)
/* GTID */ INSERT INTO t1 SELECT a, 4, 0 FROM t3
/* GTID */ UPDATE t1 SET c=1 WHERE a=7
DROP TEMPORARY TABLE `t3` /* generated by server */
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
/* GTID */ CREATE TEMPORARY TABLE t4 (a INT PRIMARY KEY) ENGINE=InnoDB
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
/* GTID */ INSERT INTO t1 VALUES (8, 5, 0)
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
/* GTID */ ALTER TABLE t4 ADD b INT
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
/* GTID */ INSERT INTO t1 VALUES (9, 5, 1)
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# trans
BEGIN
/* GTID */ INSERT INTO t1 VALUES (10, 6, 0)
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
BEGIN
/* GTID */ CREATE TEMPORARY TABLE t5 (a INT PRIMARY KEY) ENGINE=InnoDB
/* GTID */ INSERT INTO t1 VALUES (11, 7, 0)
COMMIT/*!*/;
# server id 1 end_log_pos # GTID #-#-# ddl
DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `t5`
DROP TABLE t1;
@@ -0,0 +1,3 @@
--source include/have_log_bin.inc
--source include/have_binlog_format_row.inc
--source include/binlog_parallel_replication_marks.test
@@ -0,0 +1,3 @@
--source include/have_log_bin.inc
--source include/have_binlog_format_mixed_or_statement.inc
--source include/binlog_parallel_replication_marks.test
@@ -496,6 +496,53 @@ a b
57 7
58 8
59 9
*** MDEV-8075: DROP TEMPORARY TABLE not marked as ddl, causing optimistic parallel replication to fail ***
include/stop_slave.inc
INSERT INTO t1 VALUES (40, 10);
CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (41);
BEGIN;
INSERT INTO t2 SELECT a, 20 FROM t1;
DROP TEMPORARY TABLE t1;
COMMIT;
INSERT INTO t1 VALUES (42, 10);
include/save_master_gtid.inc
SELECT * FROM t1 WHERE a >= 40 ORDER BY a;
a b
40 10
42 10
SELECT * FROM t2 WHERE a >= 40 ORDER BY a;
a b
41 20
50 0
51 1
52 2
53 3
54 4
55 5
56 6
57 7
58 8
59 9
include/start_slave.inc
include/sync_with_master_gtid.inc
SELECT * FROM t1 WHERE a >= 40 ORDER BY a;
a b
40 10
42 10
SELECT * FROM t2 WHERE a >= 40 ORDER BY a;
a b
41 20
50 0
51 1
52 2
53 3
54 4
55 5
56 6
57 7
58 8
59 9
include/stop_slave.inc
SET GLOBAL slave_parallel_mode=@old_parallel_mode;
SET GLOBAL slave_parallel_threads=@old_parallel_threads;
@@ -456,6 +456,30 @@ SELECT * FROM t2 WHERE a >= 50 ORDER BY a;
SELECT * FROM t2 WHERE a >= 50 ORDER BY a;


--echo *** MDEV-8075: DROP TEMPORARY TABLE not marked as ddl, causing optimistic parallel replication to fail ***

--connection server_2
--source include/stop_slave.inc

--connection server_1
INSERT INTO t1 VALUES (40, 10);
CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (41);
BEGIN;
INSERT INTO t2 SELECT a, 20 FROM t1;
DROP TEMPORARY TABLE t1;
COMMIT;
INSERT INTO t1 VALUES (42, 10);
--source include/save_master_gtid.inc
SELECT * FROM t1 WHERE a >= 40 ORDER BY a;
SELECT * FROM t2 WHERE a >= 40 ORDER BY a;

--connection server_2
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
SELECT * FROM t1 WHERE a >= 40 ORDER BY a;
SELECT * FROM t2 WHERE a >= 40 ORDER BY a;

# Clean up.

--connection server_2

0 comments on commit 228479a

Please sign in to comment.
You can’t perform that action at this time.