Debian Codegraph @

mysql-test/suite/binlog/t/innodb_rc_insert_before_delete.test

raw
1 --source include/have_innodb.inc
2 --source include/have_debug.inc
3 --source include/have_debug_sync.inc
4 --source include/have_binlog_format_mixed.inc
5 --source include/count_sessions.inc
6
7 RESET MASTER;
8
9 # MDEV-30010 merely adds is a Read-Committed version MDEV-30225 test
10 # solely to prove the RC isolation yields ROW binlog format as it is
11 # supposed to:
12 # https://mariadb.com/kb/en/unsafe-statements-for-statement-based-replication/#isolation-levels.
13 # The original MDEV-30225 test is adapted to the RC to create
14 # a similar safisticated scenario which does not lead to any deadlock though.
15
16 --connect (pause_purge,localhost,root)
17 START TRANSACTION WITH CONSISTENT SNAPSHOT;
18
19 --connection default
20 CREATE TABLE t (pk int PRIMARY KEY, sk INT UNIQUE) ENGINE=InnoDB;
21 INSERT INTO t VALUES (10, 100);
22
23 --connect (con1,localhost,root)
24 BEGIN; # trx 0
25 SELECT * FROM t WHERE sk = 100 FOR UPDATE;
26
27 --connect (con2,localhost,root)
28 SET DEBUG_SYNC="lock_wait_start SIGNAL insert_wait_started";
29 # trx 1 is locked on try to read the record in secondary index during duplicates
30 # check. It's the first in waiting queue, that's why it will be woken up firstly
31 # when trx 0 commits.
32 --send INSERT INTO t VALUES (5, 100) # trx 1
33
34 --connect (con3,localhost,root)
35 SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
36 SET DEBUG_SYNC="now WAIT_FOR insert_wait_started";
37 SET DEBUG_SYNC="lock_wait_start SIGNAL delete_started_waiting";
38 # trx 2 can delete (5, 100) on master, but not on slave, as on slave trx 1
39 # can insert (5, 100) after trx 2 positioned it's cursor. Trx 2 lock is placed
40 # in waiting queue after trx 1 lock, but its persistent cursor position was
41 # stored on (100, 10) record in secondary index before suspending. After trx 1
42 # is committed, trx 2 will restore persistent cursor position on (100, 10). As
43 # (100, 5) secondary index record was inserted before (100, 10) in logical
44 # order, and (100, 10) record is delete-marked, trx 2 just continues scanning.
45 #
46 # Note. There can be several records with the same key in unique secondary
47 # index, but only one of them must be non-delete-marked. That's why when we do
48 # point query, cursor position is set in the first record in logical order, and
49 # then records are iterated until either non-delete-marked record is found or
50 # all records with the same unique fields are iterated.
51
52 # to prepare showing interesting binlog events
53 --let $binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1)
54 --let $binlog_file=query_get_value(SHOW MASTER STATUS, File, 1)
55 BEGIN;
56 --send UPDATE t SET sk = 200 WHERE sk = 100; # trx 2
57
58 --connection con1
59 SET DEBUG_SYNC="now WAIT_FOR delete_started_waiting";
60 DELETE FROM t WHERE sk=100; # trx 0
61 COMMIT;
62 --disconnect con1
63
64 --connection con2
65 --reap
66 --disconnect con2
67
68 --connection con3
69 --error 0
70 --reap
71 if (`SELECT ROW_COUNT() > 0`)
72 {
73 --echo unexpected effective UPDATE
74 --die
75 }
76 --echo must be logged in ROW format as the only event of trx 2 (con3)
77 INSERT INTO t VALUES (11, 101);
78 COMMIT;
79 --source include/show_binlog_events.inc
80 --disconnect con3
81
82 --connection default
83 # If the bug is not fixed, we will see the row inserted by trx 1 here. This can
84 # cause duplicate key error on slave, when some other trx tries in insert row
85 # with the same secondary key, as was inserted by trx 1, and not deleted by trx
86 # 2.
87 SELECT * FROM t;
88
89 --disconnect pause_purge
90 SET DEBUG_SYNC="RESET";
91 DROP TABLE t;
92 --source include/wait_until_count_sessions.inc