| 1 |
# |
| 2 |
# This test tests the operation of transaction replay. If a potentially |
| 3 |
# conflicting remote transaction arrives at just the right time during |
| 4 |
# the commit of a local transaction, the local transaction will be aborted |
| 5 |
# and replayed. |
| 6 |
# |
| 7 |
# Because the write set with higher sequence number cannot BF abort |
| 8 |
# the victim with lower sequence number, the conflicting remote transaction |
| 9 |
# must be executed first and must be allowed to proceed up to the apply |
| 10 |
# monitor before sending the COMMIT for the transaction to be replayed. |
| 11 |
# |
| 12 |
|
| 13 |
--source include/galera_cluster.inc |
| 14 |
--source include/have_innodb.inc |
| 15 |
--source include/have_debug_sync.inc |
| 16 |
--source include/galera_have_debug_sync.inc |
| 17 |
|
| 18 |
###################################################################### |
| 19 |
# |
| 20 |
# Scenario #1, the victim will have higher seqno and will be replayed |
| 21 |
# |
| 22 |
###################################################################### |
| 23 |
|
| 24 |
--let $wsrep_local_replays_old = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'` |
| 25 |
|
| 26 |
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)); |
| 27 |
INSERT INTO t1 VALUES (1, 'a'); |
| 28 |
INSERT INTO t1 VALUES (2, 'a'); |
| 29 |
|
| 30 |
--connection node_1 |
| 31 |
SET AUTOCOMMIT=ON; |
| 32 |
START TRANSACTION; |
| 33 |
|
| 34 |
UPDATE t1 SET f2 = 'b' WHERE f1 = 1; |
| 35 |
SELECT * FROM t1 WHERE f1 = 2 FOR UPDATE; |
| 36 |
|
| 37 |
# Block the applier on node #1 and issue a conflicting update on node #2 |
| 38 |
--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 |
| 39 |
SET SESSION wsrep_sync_wait=0; |
| 40 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 41 |
--source include/galera_set_sync_point.inc |
| 42 |
|
| 43 |
--connection node_2 |
| 44 |
UPDATE t1 SET f2 = 'c' WHERE f1 = 2; |
| 45 |
|
| 46 |
--connection node_1a |
| 47 |
--source include/galera_wait_sync_point.inc |
| 48 |
--source include/galera_clear_sync_point.inc |
| 49 |
|
| 50 |
# Block the commit, send the COMMIT and wait until it gets blocked |
| 51 |
|
| 52 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 53 |
--source include/galera_set_sync_point.inc |
| 54 |
|
| 55 |
--connection node_1 |
| 56 |
--send COMMIT |
| 57 |
|
| 58 |
--connection node_1a |
| 59 |
|
| 60 |
--let $galera_sync_point = apply_monitor_slave_enter_sync commit_monitor_master_enter_sync |
| 61 |
--source include/galera_wait_sync_point.inc |
| 62 |
--source include/galera_clear_sync_point.inc |
| 63 |
|
| 64 |
# Let the conflicting UPDATE proceed and wait until it hits abort_trx_end. |
| 65 |
# The victim transaction still sits in commit_monitor_master_sync_point. |
| 66 |
|
| 67 |
--let $galera_sync_point = abort_trx_end |
| 68 |
--source include/galera_set_sync_point.inc |
| 69 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 70 |
--source include/galera_signal_sync_point.inc |
| 71 |
--let $galera_sync_point = abort_trx_end commit_monitor_master_enter_sync |
| 72 |
--source include/galera_wait_sync_point.inc |
| 73 |
|
| 74 |
# Let the transactions proceed |
| 75 |
--source include/galera_clear_sync_point.inc |
| 76 |
--let $galera_sync_point = abort_trx_end |
| 77 |
--source include/galera_signal_sync_point.inc |
| 78 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 79 |
--source include/galera_signal_sync_point.inc |
| 80 |
|
| 81 |
# Commit succeeds |
| 82 |
--connection node_1 |
| 83 |
--reap |
| 84 |
|
| 85 |
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'b'; |
| 86 |
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c'; |
| 87 |
|
| 88 |
# wsrep_local_replays has increased by 1 |
| 89 |
--let $wsrep_local_replays_new = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'` |
| 90 |
--disable_query_log |
| 91 |
--eval SELECT $wsrep_local_replays_new - $wsrep_local_replays_old = 1 AS wsrep_local_replays; |
| 92 |
--enable_query_log |
| 93 |
|
| 94 |
--connection node_2 |
| 95 |
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'b'; |
| 96 |
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c'; |
| 97 |
|
| 98 |
DROP TABLE t1; |
| 99 |
|
| 100 |
######################################################################### |
| 101 |
# |
| 102 |
# Scenario #2, the victim will have lower seqno and will not be replayed |
| 103 |
# |
| 104 |
######################################################################### |
| 105 |
|
| 106 |
--connection node_1 |
| 107 |
|
| 108 |
--let $wsrep_local_replays_old = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'` |
| 109 |
|
| 110 |
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)); |
| 111 |
INSERT INTO t1 VALUES (1, 'a'); |
| 112 |
INSERT INTO t1 VALUES (2, 'a'); |
| 113 |
|
| 114 |
--connection node_1 |
| 115 |
SET AUTOCOMMIT=ON; |
| 116 |
START TRANSACTION; |
| 117 |
|
| 118 |
UPDATE t1 SET f2 = 'b' WHERE f1 = 1; |
| 119 |
SELECT * FROM t1 WHERE f1 = 2 FOR UPDATE; |
| 120 |
|
| 121 |
# Block the commit, send the COMMIT and wait until it gets blocked |
| 122 |
|
| 123 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 124 |
--source include/galera_set_sync_point.inc |
| 125 |
|
| 126 |
--connection node_1 |
| 127 |
--send COMMIT |
| 128 |
|
| 129 |
--connection node_1a |
| 130 |
|
| 131 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 132 |
--source include/galera_wait_sync_point.inc |
| 133 |
--source include/galera_clear_sync_point.inc |
| 134 |
|
| 135 |
|
| 136 |
# Set sync point at the end of BF abort, issue a conflicting update |
| 137 |
# and wait for the conflicting update to hit the sync point. |
| 138 |
--let $galera_sync_point = abort_trx_end |
| 139 |
--source include/galera_set_sync_point.inc |
| 140 |
|
| 141 |
--connection node_2 |
| 142 |
UPDATE t1 SET f2 = 'c' WHERE f1 = 2; |
| 143 |
|
| 144 |
--connection node_1a |
| 145 |
--let $galera_sync_point = abort_trx_end commit_monitor_master_enter_sync |
| 146 |
--source include/galera_wait_sync_point.inc |
| 147 |
--source include/galera_clear_sync_point.inc |
| 148 |
|
| 149 |
# Let the transactions proceed |
| 150 |
--source include/galera_clear_sync_point.inc |
| 151 |
--let $galera_sync_point = abort_trx_end |
| 152 |
--source include/galera_signal_sync_point.inc |
| 153 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 154 |
--source include/galera_signal_sync_point.inc |
| 155 |
|
| 156 |
# Commit succeeds |
| 157 |
--connection node_1 |
| 158 |
--reap |
| 159 |
|
| 160 |
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'b'; |
| 161 |
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c'; |
| 162 |
|
| 163 |
# wsrep_local_replays should have not increased |
| 164 |
--let $wsrep_local_replays_new = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'` |
| 165 |
--disable_query_log |
| 166 |
--eval SELECT $wsrep_local_replays_new - $wsrep_local_replays_old = 0 AS wsrep_local_replays; |
| 167 |
--enable_query_log |
| 168 |
|
| 169 |
--connection node_2 |
| 170 |
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'b'; |
| 171 |
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c'; |
| 172 |
|
| 173 |
DROP TABLE t1; |
| 174 |
|
| 175 |
|
| 176 |
######################################## |
| 177 |
# |
| 178 |
# test replaying of prepared statements |
| 179 |
# |
| 180 |
######################################## |
| 181 |
|
| 182 |
--connection node_1 |
| 183 |
|
| 184 |
--let $wsrep_local_replays_old = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'` |
| 185 |
|
| 186 |
CREATE TABLE t1 (i int primary key, j int) ENGINE=INNODB; |
| 187 |
INSERT INTO t1 VALUES (1, 0), (3, 0); |
| 188 |
SELECT * FROM t1; |
| 189 |
SET AUTOCOMMIT=ON; |
| 190 |
PREPARE stmt1 FROM "UPDATE t1 SET j = 1 where i > 0"; |
| 191 |
|
| 192 |
|
| 193 |
# Block the applier on node #1 and issue a conflicting update on node #2 |
| 194 |
--connection node_1a |
| 195 |
SET SESSION wsrep_sync_wait=0; |
| 196 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 197 |
--source include/galera_set_sync_point.inc |
| 198 |
|
| 199 |
--connection node_2 |
| 200 |
INSERT INTO t1 VALUES(2,2); |
| 201 |
|
| 202 |
--connection node_1a |
| 203 |
--source include/galera_wait_sync_point.inc |
| 204 |
--source include/galera_clear_sync_point.inc |
| 205 |
|
| 206 |
# Block the commit, send the EXECUTE stmt1 and wait until it gets blocked |
| 207 |
|
| 208 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 209 |
--source include/galera_set_sync_point.inc |
| 210 |
|
| 211 |
--connection node_1 |
| 212 |
SET SESSION wsrep_sync_wait=0; |
| 213 |
--send EXECUTE stmt1 |
| 214 |
|
| 215 |
--connection node_1a |
| 216 |
|
| 217 |
--let $galera_sync_point = apply_monitor_slave_enter_sync commit_monitor_master_enter_sync |
| 218 |
--source include/galera_wait_sync_point.inc |
| 219 |
--source include/galera_clear_sync_point.inc |
| 220 |
|
| 221 |
# Let the conflicting INSERT proceed and wait until it hits abort_trx_end. |
| 222 |
# The victim transaction still sits in commit_monitor_master_sync_point. |
| 223 |
|
| 224 |
--let $galera_sync_point = abort_trx_end |
| 225 |
--source include/galera_set_sync_point.inc |
| 226 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 227 |
--source include/galera_signal_sync_point.inc |
| 228 |
--let $galera_sync_point = abort_trx_end commit_monitor_master_enter_sync |
| 229 |
--source include/galera_wait_sync_point.inc |
| 230 |
|
| 231 |
# Let the transactions proceed |
| 232 |
--source include/galera_clear_sync_point.inc |
| 233 |
--let $galera_sync_point = abort_trx_end |
| 234 |
--source include/galera_signal_sync_point.inc |
| 235 |
--let $galera_sync_point = commit_monitor_master_enter_sync |
| 236 |
--source include/galera_signal_sync_point.inc |
| 237 |
|
| 238 |
# Commit succeeds |
| 239 |
--connection node_1 |
| 240 |
--reap |
| 241 |
SET SESSION wsrep_sync_wait=7; |
| 242 |
SELECT * FROM t1; |
| 243 |
|
| 244 |
--connection node_2 |
| 245 |
SELECT * FROM t1; |
| 246 |
|
| 247 |
--connection node_1 |
| 248 |
# wsrep_local_replays has increased by 1 |
| 249 |
--let $wsrep_local_replays_new = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'` |
| 250 |
--disable_query_log |
| 251 |
--eval SELECT $wsrep_local_replays_new - $wsrep_local_replays_old = 1 AS wsrep_local_replays; |
| 252 |
--enable_query_log |
| 253 |
|
| 254 |
DEALLOCATE PREPARE stmt1; |
| 255 |
DROP TABLE t1; |