1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
include/master-slave.inc
[connection master]
MDEV-31482: Lock wait timeout with INSERT-SELECT, autoinc, and statement-based replication
include/rpl_connect.inc [creating slave2]
include/rpl_connect.inc [creating slave3]
connection master;
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
CREATE TABLE t1 (a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT, INDEX (c)) ENGINE=InnoDB;
INSERT INTO t1 (b,c) VALUES (0, 1), (0, 1), (0, 2), (0,3), (0, 5), (0, 7), (0, 8);
CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t2 VALUES (10,1), (20,2), (30,3), (40,4), (50,5);
CREATE TABLE t3 (a VARCHAR(20) PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t3 VALUES ('row for T1', 0), ('row for T2', 0), ('row for T3', 0);
include/save_master_gtid.inc
connection slave;
include/sync_with_master_gtid.inc
include/stop_slave.inc
set @@global.slave_parallel_threads= 3;
set @@global.slave_parallel_mode= OPTIMISTIC;
set @@global.innodb_lock_wait_timeout= 20;
connection master;
BEGIN;
UPDATE t3 SET b=b+1 where a="row for T1";
INSERT INTO t1(b, c) SELECT 1, t2.b FROM t2 WHERE a=10;
Warnings:
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statements writing to a table with an auto-increment column after selecting from another table are unsafe because the order in which rows are retrieved determines what (if any) rows will be written. This order cannot be predicted and may differ on master and the slave
COMMIT;
DELETE FROM t1 WHERE c >= 4 and c < 6;
BEGIN;
UPDATE t3 SET b=b+1 where a="row for T3";
INSERT INTO t1(b, c) SELECT 3, t2.b FROM t2 WHERE a >= 20 AND a <= 40;
Warnings:
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statements writing to a table with an auto-increment column after selecting from another table are unsafe because the order in which rows are retrieved determines what (if any) rows will be written. This order cannot be predicted and may differ on master and the slave
COMMIT;
include/save_master_gtid.inc
connection slave1;
BEGIN;
SELECT * FROM t3 WHERE a="row for T1" FOR UPDATE;
a b
row for T1 0
connection slave2;
BEGIN;
SELECT * FROM t3 WHERE a="row for T3" FOR UPDATE;
a b
row for T3 0
connection slave3;
BEGIN;
DELETE FROM t2 WHERE a=30;
connection slave;
include/start_slave.inc
connection slave2;
ROLLBACK;
connection slave1;
ROLLBACK;
connection slave3;
ROLLBACK;
connection slave;
include/sync_with_master_gtid.inc
SELECT * FROM t1 ORDER BY a;
a b c
1 0 1
2 0 1
3 0 2
4 0 3
6 0 7
7 0 8
8 1 1
9 3 2
10 3 3
11 3 4
SELECT * FROM t2 ORDER BY a;
a b
10 1
20 2
30 3
40 4
50 5
SELECT * FROM t3 ORDER BY a;
a b
row for T1 1
row for T2 0
row for T3 1
connection master;
CALL mtr.add_suppression("Unsafe statement written to the binary log using statement format");
DROP TABLE t1, t2, t3;
connection slave;
include/stop_slave.inc
SET @@global.slave_parallel_threads= 0;
SET @@global.slave_parallel_mode= optimistic;
SET @@global.innodb_lock_wait_timeout= 50;
include/start_slave.inc
SELECT @@GLOBAL.innodb_autoinc_lock_mode;
@@GLOBAL.innodb_autoinc_lock_mode
1
include/rpl_end.inc
|