| 1 |
################################################################################ |
| 2 |
# |
| 3 |
# ==== Purpose ==== |
| 4 |
# |
| 5 |
# On a group with an inbound channel on the primary, receiving transactions |
| 6 |
# T1, T2 in this order, if T2 is delivered/certified before T1, and a |
| 7 |
# View_change occurs between the delivery of T2 and T1, verify that the primary |
| 8 |
# bypasses replica-preserve-commit-order and allows T2 to commit before T1. |
| 9 |
# |
| 10 |
# Footnote: |
| 11 |
# The mechanism to bypass replica-preserve-commit-order is necessary in order to |
| 12 |
# avoid the following deadlock, which would occur otherwise: |
| 13 |
# 1. T2 waits for T1 to commit, because of replica-preserve-commit-order |
| 14 |
# 2. T1 waits for the View_change, because transactions delivered/certified |
| 15 |
# after a view_change must also commit after the view_change (using the |
| 16 |
# BGC ticket manager). |
| 17 |
# 3. The view change waits for T2, because transactions delivered/certified |
| 18 |
# before a view_change must also commit before the view_change (using the |
| 19 |
# BGC ticket manager) |
| 20 |
# |
| 21 |
# ==== Requirements ==== |
| 22 |
# |
| 23 |
# Given transactions T1, T2 are delivered in reverse order with a view_change |
| 24 |
# between them: |
| 25 |
# |
| 26 |
# R1. T2 should commit before T1 |
| 27 |
# R2. T2 should emit an error message |
| 28 |
# R3. A transactions following the View_change must respect |
| 29 |
# replica-preserve-commit-order |
| 30 |
# |
| 31 |
# ==== Test steps ==== |
| 32 |
# |
| 33 |
# 0. The test requires 4 servers: |
| 34 |
# server1: group primary with a inbound channel replicating from server3 |
| 35 |
# server2: secondary |
| 36 |
# server3: secondary |
| 37 |
# server4: standalone server |
| 38 |
# 1. server1: Bootstrap group. |
| 39 |
# Start an inbound channel that replicates from server4. |
| 40 |
# 2. server2: join the group. |
| 41 |
# 3. server1: use LOCK TABLES to ensure that T1 will be blocked |
| 42 |
# 4. server4: commit T1 and T2 |
| 43 |
# 5. server1: wait until T2 blocks waiting on commit order |
| 44 |
# 6. server3: join the group |
| 45 |
# 7. server1: wait until T2 has committed (which it does because the joining |
| 46 |
# server forces it to violate replica-preserve-commit-order). |
| 47 |
# Verify that no transaction blocks waiting for commit order any more. |
| 48 |
# Verify that T1 has not committed yet. |
| 49 |
# Verify that gtid_executed is 1 element smaller on server1 than server4. |
| 50 |
# Verify that there is a warning in the error log. |
| 51 |
# 8. server4: commit transaction T3 on table t2. |
| 52 |
# 9. server1: wait until T3 blocks waiting for commit order |
| 53 |
# Verify that t2 still contains only one row |
| 54 |
#10. server1: UNLOCK TABLES |
| 55 |
# Wait for T2 and T3 to finish |
| 56 |
#11. Clean up. |
| 57 |
################################################################################ |
| 58 |
|
| 59 |
--source include/only_mts_replica_parallel_type_logical_clock.inc |
| 60 |
--let $option_name = replica_parallel_workers |
| 61 |
--let $option_operator = > |
| 62 |
--let $option_value = 1 |
| 63 |
--source include/only_with_option.inc |
| 64 |
--let $group_replication_group_name = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa |
| 65 |
--source include/have_group_replication_plugin.inc |
| 66 |
--let $rpl_group_replication_single_primary_mode = 1 |
| 67 |
--let $rpl_skip_group_replication_start = 1 |
| 68 |
--let $rpl_server_count = 4 |
| 69 |
--let $rpl_gtid_utils = 1 |
| 70 |
--source include/group_replication.inc |
| 71 |
|
| 72 |
--let $assert_escape = 1 |
| 73 |
|
| 74 |
--echo # Bootstrap group with server1 as primary and server2, server3 as secondaries. |
| 75 |
--let $rpl_connection_name = server1 |
| 76 |
--source include/rpl_connection.inc |
| 77 |
--source include/start_and_bootstrap_group_replication.inc |
| 78 |
|
| 79 |
--echo # Create inbound channel from server4 to server1 |
| 80 |
--replace_result $SERVER_MYPORT_4 SERVER_4_PORT |
| 81 |
--eval CHANGE REPLICATION SOURCE TO SOURCE_HOST='127.0.0.1', SOURCE_USER='root', SOURCE_AUTO_POSITION=1, SOURCE_PORT=$SERVER_MYPORT_4 FOR CHANNEL 'ch1' |
| 82 |
--let $rpl_channel_name = 'ch1' |
| 83 |
--source include/start_slave.inc |
| 84 |
--let $rpl_channel_name = |
| 85 |
|
| 86 |
--echo # Create tables |
| 87 |
--let $rpl_connection_name = server4 |
| 88 |
--source include/rpl_connection.inc |
| 89 |
CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY); |
| 90 |
CREATE TABLE t2 (c1 INT NOT NULL PRIMARY KEY); |
| 91 |
--let $sync_slave_connection= server1 |
| 92 |
--source include/sync_slave_sql_with_master.inc |
| 93 |
|
| 94 |
--echo # Make server2 join the group |
| 95 |
--let $rpl_connection_name = server2 |
| 96 |
--source include/rpl_connection.inc |
| 97 |
--source include/start_group_replication.inc |
| 98 |
|
| 99 |
--echo # Take a lock on the primary so that T1 will be blocked |
| 100 |
--let $rpl_connection_name = server_1_1 |
| 101 |
--source include/rpl_connection.inc |
| 102 |
LOCK TABLES t1 WRITE; |
| 103 |
|
| 104 |
--echo # Commit transaction T1 on table t1, then transaction T2 on t2. |
| 105 |
--let $rpl_connection_name = server4 |
| 106 |
--source include/rpl_connection.inc |
| 107 |
INSERT INTO t1 VALUES (1); |
| 108 |
INSERT INTO t2 VALUES (2); |
| 109 |
--let $source_gtid_executed = `SELECT @@global.gtid_executed` |
| 110 |
|
| 111 |
--echo # Wait until T2 is waiting for T1 to commit. |
| 112 |
--let $rpl_connection_name = server1 |
| 113 |
--source include/rpl_connection.inc |
| 114 |
--let $wait_condition = SELECT COUNT(*) = 1 FROM performance_schema.threads WHERE PROCESSLIST_STATE = 'Waiting for preceding transaction to commit' |
| 115 |
--source include/wait_condition.inc |
| 116 |
|
| 117 |
--source include/save_error_log_position.inc |
| 118 |
|
| 119 |
--echo # Join server3 to the group |
| 120 |
--let $rpl_connection_name = server3 |
| 121 |
--source include/rpl_connection.inc |
| 122 |
--source include/start_group_replication.inc |
| 123 |
|
| 124 |
--echo # Wait for T2 to commit on server1 |
| 125 |
--let $rpl_connection_name = server1 |
| 126 |
--source include/rpl_connection.inc |
| 127 |
--let $wait_condition = SELECT COUNT(*) = 1 FROM test.t2 |
| 128 |
--source include/wait_condition.inc |
| 129 |
|
| 130 |
--let $wait_condition = SELECT COUNT(*) = 0 FROM performance_schema.threads WHERE PROCESSLIST_STATE = 'Waiting for preceding transaction to commit' |
| 131 |
--source include/wait_condition.inc |
| 132 |
|
| 133 |
--let $error_pattern = The transaction '[a-z0-9\-]*:[0-9]*' will commit out of order with respect to its source to follow the group global order |
| 134 |
--source include/assert_error_log.inc |
| 135 |
|
| 136 |
--echo # Verify that t1 is still not committed |
| 137 |
|
| 138 |
--let $assert_text = There should be one missing GTID |
| 139 |
--let $assert_cond = [SELECT GTID_COUNT(GTID_SUBTRACT('$source_gtid_executed', @@global.gtid_executed))] = 1 |
| 140 |
--source include/assert.inc |
| 141 |
|
| 142 |
--let $rpl_connection_name = server_1_1 |
| 143 |
--source include/rpl_connection.inc |
| 144 |
--let $assert_text = t1 should still be empty |
| 145 |
--let $assert_cond = [SELECT COUNT(*) FROM test.t1] = 0 |
| 146 |
--source include/assert.inc |
| 147 |
|
| 148 |
--echo # Check that new transactions block as needed, *not* violating replica-preserve-commit-order |
| 149 |
--let $rpl_connection_name = server_4 |
| 150 |
--source include/rpl_connection.inc |
| 151 |
INSERT INTO t2 VALUES (3); |
| 152 |
|
| 153 |
--let $rpl_connection_name = server_1 |
| 154 |
--source include/rpl_connection.inc |
| 155 |
|
| 156 |
--let $wait_condition = SELECT COUNT(*) = 1 FROM performance_schema.threads WHERE PROCESSLIST_STATE = 'Waiting for preceding transaction to commit' |
| 157 |
--source include/wait_condition.inc |
| 158 |
|
| 159 |
--let $assert_text = t2 should still have only one element |
| 160 |
--let $assert_cond = [SELECT COUNT(*) FROM test.t2] = 1 |
| 161 |
--source include/assert.inc |
| 162 |
|
| 163 |
--echo # Unblock T1 and T3 and let them finish |
| 164 |
--let $rpl_connection_name = server_1_1 |
| 165 |
--source include/rpl_connection.inc |
| 166 |
UNLOCK TABLES; |
| 167 |
--source include/rpl_sync.inc |
| 168 |
|
| 169 |
--echo # Clean up |
| 170 |
--let $rpl_connection_name = server4 |
| 171 |
--source include/rpl_connection.inc |
| 172 |
DROP TABLE t1; |
| 173 |
DROP TABLE t2; |
| 174 |
--let $sync_slave_connection= server1 |
| 175 |
--source include/sync_slave_sql_with_master.inc |
| 176 |
|
| 177 |
--let $rpl_connection_name = server1 |
| 178 |
--source include/rpl_connection.inc |
| 179 |
--let $rpl_channel_name='ch1' |
| 180 |
--source include/stop_slave.inc |
| 181 |
--let $rpl_channel_name= |
| 182 |
RESET REPLICA ALL FOR CHANNEL 'ch1'; |
| 183 |
--source include/rpl_sync.inc |
| 184 |
|
| 185 |
--let $rpl_connection_name = server3 |
| 186 |
--source include/rpl_connection.inc |
| 187 |
--source include/stop_group_replication.inc |
| 188 |
|
| 189 |
--let $rpl_connection_name = server2 |
| 190 |
--source include/rpl_connection.inc |
| 191 |
--source include/stop_group_replication.inc |
| 192 |
|
| 193 |
--let $rpl_connection_name = server1 |
| 194 |
--source include/rpl_connection.inc |
| 195 |
--source include/stop_group_replication.inc |
| 196 |
|
| 197 |
--source include/group_replication_end.inc |