Debian Codegraph @

mysql-test/suite/innodb/t/group_commit.test

raw
1 --source include/have_innodb.inc
2 --source include/have_debug_sync.inc
3 --source include/have_log_bin.inc
4
5 # Test some group commit code paths by using debug_sync to do controlled
6 # commits of 6 transactions: first 1 alone, then 3 as a group, then 2 as a
7 # group.
8 #
9 # Group 3 is allowed to race as far as possible ahead before group 2 finishes
10 # to check some edge case for concurrency control.
11
12 CREATE TABLE t1 (a VARCHAR(10) PRIMARY KEY) ENGINE=innodb;
13 # MDEV-515 takes X-lock on the table for the first insert.
14 # So concurrent insert won't happen on the table
15 INSERT INTO t1 VALUES(100);
16
17 --disable_cursor_protocol
18 SELECT variable_value INTO @commits FROM information_schema.global_status
19 WHERE variable_name = 'binlog_commits';
20 SELECT variable_value INTO @group_commits FROM information_schema.global_status
21 WHERE variable_name = 'binlog_group_commits';
22 --enable_cursor_protocol
23
24 connect(con1,localhost,root,,);
25 connect(con2,localhost,root,,);
26 connect(con3,localhost,root,,);
27 connect(con4,localhost,root,,);
28 connect(con5,localhost,root,,);
29 connect(con6,localhost,root,,);
30
31 # Start group1 (with one thread) doing commit, waiting for
32 # group2 to queue up before finishing.
33
34 connection con1;
35 SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group1_running WAIT_FOR group2_queued";
36 send INSERT INTO t1 VALUES ("con1");
37
38 # Make group2 (with three threads) queue up.
39 # Make sure con2 is the group commit leader for group2.
40 # Make group2 wait with running commit_ordered() until group3 has committed.
41
42 connection con2;
43 set DEBUG_SYNC= "now WAIT_FOR group1_running";
44 SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con2";
45 SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group2_running";
46 SET DEBUG_SYNC= "commit_after_release_LOCK_log WAIT_FOR group3_committed";
47 SET DEBUG_SYNC= "commit_after_group_run_commit_ordered SIGNAL group2_visible WAIT_FOR group2_checked";
48 send INSERT INTO t1 VALUES ("con2");
49 connection con3;
50 SET DEBUG_SYNC= "now WAIT_FOR group2_con2";
51 SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con3";
52 send INSERT INTO t1 VALUES ("con3");
53 connection con4;
54 SET DEBUG_SYNC= "now WAIT_FOR group2_con3";
55 SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con4";
56 send INSERT INTO t1 VALUES ("con4");
57
58 # When group2 is queued, let group1 continue and queue group3.
59
60 connection default;
61 SET DEBUG_SYNC= "now WAIT_FOR group2_con4";
62
63 # At this point, trasaction 1 is still not visible as commit_ordered() has not
64 # been called yet.
65 SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
66 SELECT * FROM t1 ORDER BY a;
67
68 SET DEBUG_SYNC= "now SIGNAL group2_queued";
69 connection con1;
70 reap;
71
72 # Now transaction 1 is visible.
73 connection default;
74 SELECT * FROM t1 ORDER BY a;
75
76 connection con5;
77 SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group3_con5";
78 SET DEBUG_SYNC= "commit_after_get_LOCK_log SIGNAL con5_leader WAIT_FOR con6_queued";
79 set DEBUG_SYNC= "now WAIT_FOR group2_running";
80 send INSERT INTO t1 VALUES ("con5");
81
82 connection con6;
83 SET DEBUG_SYNC= "now WAIT_FOR con5_leader";
84 SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL con6_queued";
85 send INSERT INTO t1 VALUES ("con6");
86
87 connection default;
88 SET DEBUG_SYNC= "now WAIT_FOR group3_con5";
89 # Still only transaction 1 visible, as group2 have not yet run commit_ordered().
90 SELECT * FROM t1 ORDER BY a;
91 SET DEBUG_SYNC= "now SIGNAL group3_committed";
92 SET DEBUG_SYNC= "now WAIT_FOR group2_visible";
93 # Now transactions 1-4 visible.
94 SELECT * FROM t1 ORDER BY a;
95 SET DEBUG_SYNC= "now SIGNAL group2_checked";
96
97 connection con2;
98 reap;
99
100 connection con3;
101 reap;
102
103 connection con4;
104 reap;
105
106 connection con5;
107 reap;
108
109 connection con6;
110 reap;
111
112 connection default;
113 # Check all transactions finally visible.
114 SELECT * FROM t1 ORDER BY a;
115
116 SELECT variable_value - @commits FROM information_schema.global_status
117 WHERE variable_name = 'binlog_commits';
118 SELECT variable_value - @group_commits FROM information_schema.global_status
119 WHERE variable_name = 'binlog_group_commits';
120
121 SET DEBUG_SYNC= 'RESET';
122 DROP TABLE t1;