| 1 |
# |
| 2 |
# This test tests the operation of transaction replay with a scenario |
| 3 |
# where two subsequent write sets being applied conflict with local transaction |
| 4 |
# in commit phase. The conflict is "false positive" confict on GAP lock in |
| 5 |
# secondary unique index. |
| 6 |
# The first applier will cause BF abort for the local committer, which |
| 7 |
# starts replaying because of positive certification. |
| 8 |
# In buggy version, the test scenario continues so that while the local transaction |
| 9 |
# is replaying, the latter applier experiences similar UK GAP lock conflict |
| 10 |
# and forces the replayer to abort second time. |
| 11 |
# In fixed version, this latter replayer BF abort should not happen. |
| 12 |
# |
| 13 |
|
| 14 |
--source include/galera_cluster.inc |
| 15 |
--source include/have_innodb.inc |
| 16 |
--source include/have_debug_sync.inc |
| 17 |
--source include/galera_have_debug_sync.inc |
| 18 |
|
| 19 |
|
| 20 |
--let $expected_wsrep_local_replays = `SELECT VARIABLE_VALUE+1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'` |
| 21 |
|
| 22 |
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 int, f3 int, unique key keyj (f2)); |
| 23 |
INSERT INTO t1 VALUES (1, 1, 0); |
| 24 |
INSERT INTO t1 VALUES (3, 3, 0); |
| 25 |
INSERT INTO t1 VALUES (10, 10, 0); |
| 26 |
|
| 27 |
# we will need 2 appliers threads for applyin two writes ets in parallel in node1 |
| 28 |
# and 1 applier thread for handling replaying |
| 29 |
SET GLOBAL wsrep_slave_threads = 3; |
| 30 |
SET GLOBAL DEBUG_DBUG = "d,sync.wsrep_apply_cb"; |
| 31 |
|
| 32 |
--connection node_1 |
| 33 |
# starting a transaction, which deletes and inserts the middle row in test table |
| 34 |
# this will be victim of false positive conflict with appliers |
| 35 |
SET SESSION wsrep_sync_wait=0; |
| 36 |
START TRANSACTION; |
| 37 |
|
| 38 |
DELETE FROM t1 WHERE f2 = 3; |
| 39 |
INSERT INTO t1 VALUES (3, 3, 1); |
| 40 |
|
| 41 |
# Control connection to manage sync points for appliers |
| 42 |
--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 |
| 43 |
--connection node_1a |
| 44 |
SET SESSION wsrep_sync_wait=0; |
| 45 |
|
| 46 |
# send from node 2 first an INSERT transaction, which will conflict on GAP lock in node 1 |
| 47 |
--connection node_2 |
| 48 |
INSERT INTO t1 VALUES (5, 5, 2); |
| 49 |
|
| 50 |
--connection node_1a |
| 51 |
# wait to see the INSERT in apply_cb sync point |
| 52 |
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached"; |
| 53 |
|
| 54 |
# first applier seen in wait point, set sync point for the second INSERT |
| 55 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 56 |
--source include/galera_set_sync_point.inc |
| 57 |
|
| 58 |
--connection node_2 |
| 59 |
# send second insert into same GAP in test table |
| 60 |
INSERT INTO t1 VALUES (4, 4, 2); |
| 61 |
|
| 62 |
--connection node_1a |
| 63 |
# wait for the second insert to arrive in his sync point |
| 64 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 65 |
--source include/galera_wait_sync_point.inc |
| 66 |
--source include/galera_clear_sync_point.inc |
| 67 |
|
| 68 |
# both appliers are now waiting in separate sync points |
| 69 |
|
| 70 |
# Block the local commit, send the COMMIT and wait until it gets blocked |
| 71 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 72 |
--source include/galera_set_sync_point.inc |
| 73 |
|
| 74 |
--connection node_1 |
| 75 |
--send COMMIT |
| 76 |
|
| 77 |
--connection node_1a |
| 78 |
# wait for the local commit to enter in commit monitor wait state |
| 79 |
--let $galera_sync_point = apply_monitor_slave_enter_sync commit_monitor_master_enter_sync |
| 80 |
--source include/galera_wait_sync_point.inc |
| 81 |
--source include/galera_clear_sync_point.inc |
| 82 |
|
| 83 |
# release the local transaction to continue with commit |
| 84 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 85 |
--source include/galera_signal_sync_point.inc |
| 86 |
--source include/galera_clear_sync_point.inc |
| 87 |
|
| 88 |
# and now release the first applier, it should force local trx to abort |
| 89 |
SET GLOBAL DEBUG_DBUG = ""; |
| 90 |
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb"; |
| 91 |
SET GLOBAL debug_dbug = NULL; |
| 92 |
SET debug_sync='RESET'; |
| 93 |
|
| 94 |
# wait for BF abort to happen and replaying begin |
| 95 |
--let $wait_condition = SELECT VARIABLE_VALUE= $expected_wsrep_local_replays FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'; |
| 96 |
--let $wait_condition_on_error_output= SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'; |
| 97 |
--source include/wait_condition_with_debug.inc |
| 98 |
|
| 99 |
# set another sync point for second applier |
| 100 |
SET GLOBAL DEBUG_DBUG = "d,sync.wsrep_apply_cb"; |
| 101 |
|
| 102 |
# letting the second appier to move forward |
| 103 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 104 |
--source include/galera_signal_sync_point.inc |
| 105 |
|
| 106 |
# waiting until second applier is in wait state |
| 107 |
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached"; |
| 108 |
|
| 109 |
# stopping second applier before commit |
| 110 |
--let $galera_sync_point = commit_monitor_slave_enter_sync |
| 111 |
--source include/galera_set_sync_point.inc |
| 112 |
--source include/galera_clear_sync_point.inc |
| 113 |
|
| 114 |
# releasing the second insert, with buggy version it will conflict with |
| 115 |
# replayer |
| 116 |
SET GLOBAL DEBUG_DBUG = ""; |
| 117 |
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb"; |
| 118 |
SET GLOBAL debug_dbug = NULL; |
| 119 |
SET debug_sync='RESET'; |
| 120 |
|
| 121 |
# with fixed version, second applier has reached comit monitor, and we can |
| 122 |
# release it to complete |
| 123 |
--let $galera_sync_point = commit_monitor_slave_enter_sync |
| 124 |
--source include/galera_signal_sync_point.inc |
| 125 |
--source include/galera_clear_sync_point.inc |
| 126 |
|
| 127 |
# local commit should succeed |
| 128 |
--connection node_1 |
| 129 |
--reap |
| 130 |
|
| 131 |
SELECT * FROM t1; |
| 132 |
|
| 133 |
# returning original slave thread count |
| 134 |
SET GLOBAL wsrep_slave_threads = DEFAULT; |
| 135 |
|
| 136 |
--connection node_2 |
| 137 |
SELECT * FROM t1; |
| 138 |
|
| 139 |
# replicate some transactions, so that wsrep slave thread count can reach |
| 140 |
# original state in node 1 |
| 141 |
INSERT INTO t1 VALUES (7,7,7); |
| 142 |
INSERT INTO t1 VALUES (8,8,8); |
| 143 |
SELECT COUNT(*) FROM t1; |
| 144 |
SELECT * FROM t1; |
| 145 |
|
| 146 |
--connection node_1 |
| 147 |
--let $wait_condition = SELECT COUNT(*) = 7 FROM t1 |
| 148 |
--source include/wait_condition.inc |
| 149 |
SELECT COUNT(*) FROM t1; |
| 150 |
SELECT * FROM t1; |
| 151 |
|
| 152 |
DROP TABLE t1; |
| 153 |
|
| 154 |
################################################################################## |
| 155 |
# test scenario 2 |
| 156 |
# |
| 157 |
# commit order is now: INSERT-1, local COMMIT, INSERT-2 |
| 158 |
# while local trx is replaying, the latter applier has applied and is waiting |
| 159 |
# for commit. |
| 160 |
# The point in this scenario is to verify that replayer does not try to abort |
| 161 |
# the latter applier |
| 162 |
################################################################################# |
| 163 |
|
| 164 |
--echo test scenario 2 |
| 165 |
|
| 166 |
--connection node_1 |
| 167 |
--let $expected_wsrep_local_replays = `SELECT VARIABLE_VALUE+1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'` |
| 168 |
|
| 169 |
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 int, f3 int, unique key keyj (f2)); |
| 170 |
INSERT INTO t1 VALUES (1, 1, 0); |
| 171 |
INSERT INTO t1 VALUES (3, 3, 0); |
| 172 |
INSERT INTO t1 VALUES (10, 10, 0); |
| 173 |
|
| 174 |
# we will need 2 appliers threads for applyin two writes sets in parallel in node1 |
| 175 |
# and 1 applier thread for handling replaying |
| 176 |
SET GLOBAL wsrep_slave_threads = 3; |
| 177 |
|
| 178 |
# set sync point for the first INSERT applier |
| 179 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 180 |
--source include/galera_set_sync_point.inc |
| 181 |
|
| 182 |
--connection node_1 |
| 183 |
# starting a transaction, which deletes and inserts the middle row in test table |
| 184 |
# this will be victim of false positive conflict with appliers |
| 185 |
SET SESSION wsrep_sync_wait=0; |
| 186 |
START TRANSACTION; |
| 187 |
|
| 188 |
DELETE FROM t1 WHERE f2 = 3; |
| 189 |
INSERT INTO t1 VALUES (3, 3, 1); |
| 190 |
|
| 191 |
# Control connection to manage sync points for appliers |
| 192 |
--connection node_1a |
| 193 |
SET SESSION wsrep_sync_wait=0; |
| 194 |
|
| 195 |
# send from node 2 first an INSERT transaction, which will conflict on GAP lock in node 1 |
| 196 |
--connection node_2 |
| 197 |
INSERT INTO t1 VALUES (5, 5, 2); |
| 198 |
|
| 199 |
--connection node_1a |
| 200 |
# wait to see the INSERT in apply_cb sync point |
| 201 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 202 |
--source include/galera_wait_sync_point.inc |
| 203 |
--source include/galera_clear_sync_point.inc |
| 204 |
|
| 205 |
# Block the local commit, send the COMMIT and wait until it gets blocked |
| 206 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 207 |
--source include/galera_set_sync_point.inc |
| 208 |
|
| 209 |
--connection node_1 |
| 210 |
--send COMMIT |
| 211 |
|
| 212 |
--connection node_1a |
| 213 |
# wait for the local commit to enter in commit monitor wait state |
| 214 |
--let $galera_sync_point = apply_monitor_slave_enter_sync commit_monitor_master_enter_sync |
| 215 |
--source include/galera_wait_sync_point.inc |
| 216 |
--source include/galera_clear_sync_point.inc |
| 217 |
|
| 218 |
# first applier is now waiting in before commit, and local trx in commit monitor |
| 219 |
|
| 220 |
# set sync point before replaying |
| 221 |
SET GLOBAL DEBUG_DBUG = "d,sync.wsrep_replay_cb"; |
| 222 |
|
| 223 |
# release the local transaction to continue with commit |
| 224 |
# it should advance and end up waiting in commit monitor for his turn |
| 225 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 226 |
--source include/galera_signal_sync_point.inc |
| 227 |
--source include/galera_clear_sync_point.inc |
| 228 |
|
| 229 |
# and now release the first applier, it should force local trx to abort |
| 230 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 231 |
--source include/galera_signal_sync_point.inc |
| 232 |
--source include/galera_clear_sync_point.inc |
| 233 |
|
| 234 |
# wait for BF abort to happen and replaying begin |
| 235 |
--let $wait_condition = SELECT VARIABLE_VALUE= $expected_wsrep_local_replays FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'; |
| 236 |
--let $wait_condition_on_error_output= SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'; |
| 237 |
--source include/wait_condition_with_debug.inc |
| 238 |
|
| 239 |
# replayer should now be in stopped in sync point |
| 240 |
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_replay_cb_reached"; |
| 241 |
|
| 242 |
# set sync point for the second INSERT |
| 243 |
--let $galera_sync_point = commit_monitor_slave_enter_sync |
| 244 |
--source include/galera_set_sync_point.inc |
| 245 |
|
| 246 |
--connection node_2 |
| 247 |
# send second insert into same GAP in test table |
| 248 |
INSERT INTO t1 VALUES (4, 4, 2); |
| 249 |
|
| 250 |
--connection node_1a |
| 251 |
# wait for the second applier to enter in commit monitor wait state |
| 252 |
--let $galera_sync_point = commit_monitor_slave_enter_sync |
| 253 |
--source include/galera_wait_sync_point.inc |
| 254 |
--source include/galera_clear_sync_point.inc |
| 255 |
|
| 256 |
# and, letting the second appier to move forward, it will stop naturally |
| 257 |
# to wait for commit order after replayer's commit |
| 258 |
--let $galera_sync_point = commit_monitor_slave_enter_sync |
| 259 |
--source include/galera_signal_sync_point.inc |
| 260 |
--source include/galera_clear_sync_point.inc |
| 261 |
|
| 262 |
# and now release the replayer, if all is good,it will commit before the second applier |
| 263 |
SET GLOBAL DEBUG_DBUG = ""; |
| 264 |
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_replay_cb"; |
| 265 |
SET GLOBAL debug_dbug = NULL; |
| 266 |
SET debug_sync='RESET'; |
| 267 |
|
| 268 |
# local commit should succeed |
| 269 |
--connection node_1 |
| 270 |
--reap |
| 271 |
|
| 272 |
--let $wait_condition = SELECT COUNT(*)=5 FROM t1; |
| 273 |
--source include/wait_condition.inc |
| 274 |
|
| 275 |
# returning original slave thread count |
| 276 |
SET GLOBAL wsrep_slave_threads = DEFAULT; |
| 277 |
|
| 278 |
--connection node_2 |
| 279 |
SELECT * FROM t1; |
| 280 |
|
| 281 |
# replicate some transactions, so that wsrep slave thread count can reach |
| 282 |
# original state in node 1 |
| 283 |
INSERT INTO t1 VALUES (7,7,7); |
| 284 |
INSERT INTO t1 VALUES (8,8,8); |
| 285 |
|
| 286 |
SELECT COUNT(*) FROM t1; |
| 287 |
SELECT * FROM t1; |
| 288 |
|
| 289 |
--connection node_1 |
| 290 |
--let $wait_condition = SELECT COUNT(*) = 7 FROM t1 |
| 291 |
--source include/wait_condition.inc |
| 292 |
SELECT COUNT(*) FROM t1; |
| 293 |
SELECT * FROM t1; |
| 294 |
|
| 295 |
DROP TABLE t1; |