| 1 |
--echo *** Test that group-committed transactions on the master can replicate in parallel on the slave. *** |
| 2 |
|
| 3 |
--source include/have_innodb.inc |
| 4 |
--source include/have_debug.inc |
| 5 |
--source include/have_debug_sync.inc |
| 6 |
--source include/have_binlog_format_statement.inc |
| 7 |
--source include/master-slave.inc |
| 8 |
|
| 9 |
# Test various aspects of parallel replication. |
| 10 |
|
| 11 |
--connection server_1 |
| 12 |
# The function does nothing on the master, and on the slave it injects the |
| 13 |
# desired debug_sync action(s). |
| 14 |
SET sql_log_bin=0; |
| 15 |
--delimiter || |
| 16 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 17 |
RETURNS INT DETERMINISTIC |
| 18 |
BEGIN |
| 19 |
RETURN x; |
| 20 |
END |
| 21 |
|| |
| 22 |
--delimiter ; |
| 23 |
SET sql_log_bin=1; |
| 24 |
|
| 25 |
--connection server_2 |
| 26 |
--source include/stop_slave.inc |
| 27 |
SET sql_log_bin=0; |
| 28 |
--delimiter || |
| 29 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 30 |
RETURNS INT DETERMINISTIC |
| 31 |
BEGIN |
| 32 |
IF d1 != '' THEN |
| 33 |
SET debug_sync = d1; |
| 34 |
END IF; |
| 35 |
IF d2 != '' THEN |
| 36 |
SET debug_sync = d2; |
| 37 |
END IF; |
| 38 |
RETURN x; |
| 39 |
END |
| 40 |
|| |
| 41 |
--delimiter ; |
| 42 |
SET sql_log_bin=1; |
| 43 |
|
| 44 |
# We need to restart all parallel threads for the new global setting to |
| 45 |
# be copied to the session-level values. |
| 46 |
SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; |
| 47 |
SET GLOBAL slave_parallel_threads=10; |
| 48 |
CHANGE MASTER TO master_use_gtid=slave_pos; |
| 49 |
--source include/start_slave.inc |
| 50 |
|
| 51 |
--connection server_1 |
| 52 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 53 |
CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; |
| 54 |
# Create some sentinel rows so that the rows inserted in parallel fall into |
| 55 |
# separate gaps and do not cause gap lock conflicts. |
| 56 |
INSERT INTO t3 VALUES (1,1), (3,3), (5,5), (7,7); |
| 57 |
--save_master_pos |
| 58 |
--connection server_2 |
| 59 |
--sync_with_master |
| 60 |
|
| 61 |
|
| 62 |
# We want to test that the transactions can execute out-of-order on |
| 63 |
# the slave, but still end up committing in-order, and in a single |
| 64 |
# group commit. |
| 65 |
# |
| 66 |
# The idea is to group-commit three transactions together on the master: |
| 67 |
# A, B, and C. On the slave, C will execute the insert first, then A, |
| 68 |
# and then B. But B manages to complete before A has time to commit, so |
| 69 |
# all three end up committing together. |
| 70 |
# |
| 71 |
# So we start by setting up some row locks that will block transactions |
| 72 |
# A and B from executing, allowing C to run first. |
| 73 |
|
| 74 |
--connect (con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,) |
| 75 |
BEGIN; |
| 76 |
INSERT INTO t3 VALUES (2,102); |
| 77 |
--connect (con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) |
| 78 |
BEGIN; |
| 79 |
INSERT INTO t3 VALUES (4,104); |
| 80 |
|
| 81 |
# On the master, queue three INSERT transactions as a single group commit. |
| 82 |
--connect (con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 83 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; |
| 84 |
SET binlog_format=statement; |
| 85 |
send INSERT INTO t3 VALUES (2, foo(12, |
| 86 |
'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued1 WAIT_FOR slave_cont1', |
| 87 |
'')); |
| 88 |
|
| 89 |
--connection server_1 |
| 90 |
SET debug_sync='now WAIT_FOR master_queued1'; |
| 91 |
|
| 92 |
--connect (con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 93 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; |
| 94 |
SET binlog_format=statement; |
| 95 |
send INSERT INTO t3 VALUES (4, foo(14, |
| 96 |
'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued2', |
| 97 |
'')); |
| 98 |
|
| 99 |
--connection server_1 |
| 100 |
SET debug_sync='now WAIT_FOR master_queued2'; |
| 101 |
|
| 102 |
--connect (con_temp5,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 103 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; |
| 104 |
SET binlog_format=statement; |
| 105 |
send INSERT INTO t3 VALUES (6, foo(16, |
| 106 |
'group_commit_waiting_for_prior SIGNAL slave_queued3', |
| 107 |
'')); |
| 108 |
|
| 109 |
--connection server_1 |
| 110 |
SET debug_sync='now WAIT_FOR master_queued3'; |
| 111 |
SET debug_sync='now SIGNAL master_cont1'; |
| 112 |
|
| 113 |
--connection con_temp3 |
| 114 |
REAP; |
| 115 |
--connection con_temp4 |
| 116 |
REAP; |
| 117 |
--connection con_temp5 |
| 118 |
REAP; |
| 119 |
SET debug_sync='RESET'; |
| 120 |
|
| 121 |
--connection server_1 |
| 122 |
SELECT * FROM t3 ORDER BY a; |
| 123 |
--let $binlog_file= master-bin.000001 |
| 124 |
--source include/show_binlog_events.inc |
| 125 |
|
| 126 |
# First, wait until insert 3 is ready to queue up for group commit, but is |
| 127 |
# waiting for insert 2 to commit before it can do so itself. |
| 128 |
--connection server_2 |
| 129 |
SET debug_sync='now WAIT_FOR slave_queued3'; |
| 130 |
|
| 131 |
# Next, let insert 1 proceed, and allow it to queue up as the group commit |
| 132 |
# leader, but let it wait for insert 2 to also queue up before proceeding. |
| 133 |
--connection con_temp1 |
| 134 |
ROLLBACK; |
| 135 |
--connection server_2 |
| 136 |
SET debug_sync='now WAIT_FOR slave_queued1'; |
| 137 |
|
| 138 |
# Now let insert 2 proceed and queue up. |
| 139 |
--connection con_temp2 |
| 140 |
ROLLBACK; |
| 141 |
--connection server_2 |
| 142 |
SET debug_sync='now WAIT_FOR slave_queued2'; |
| 143 |
# And finally, we can let insert 1 proceed and do the group commit with all |
| 144 |
# three insert transactions together. |
| 145 |
SET debug_sync='now SIGNAL slave_cont1'; |
| 146 |
|
| 147 |
# Wait for the commit to complete and check that all three transactions |
| 148 |
# group-committed together (will be seen in the binlog as all three having |
| 149 |
# cid=# on their GTID event). |
| 150 |
--let $wait_condition= SELECT COUNT(*) = 3 FROM t3 WHERE a IN (2,4,6) |
| 151 |
--source include/wait_condition.inc |
| 152 |
SELECT * FROM t3 ORDER BY a; |
| 153 |
--let $binlog_file= slave-bin.000001 |
| 154 |
--source include/show_binlog_events.inc |
| 155 |
|
| 156 |
|
| 157 |
# Clean up. |
| 158 |
--connection server_2 |
| 159 |
--source include/stop_slave.inc |
| 160 |
SET GLOBAL slave_parallel_threads=@old_parallel_threads; |
| 161 |
--source include/start_slave.inc |
| 162 |
SET DEBUG_SYNC= 'RESET'; |
| 163 |
|
| 164 |
--connection server_1 |
| 165 |
DROP function foo; |
| 166 |
DROP TABLE t3; |
| 167 |
SET DEBUG_SYNC= 'RESET'; |
| 168 |
|
| 169 |
--disable_connect_log |
| 170 |
--source include/rpl_end.inc |