| 1 |
# |
| 2 |
# Test SR BF abort for all sync points in master side code path |
| 3 |
# |
| 4 |
# The procedure in all test cases is the following: |
| 5 |
# 1) Start SR transaction on node 1, do INSERT + SELECT .. FOR UPDATE |
| 6 |
# 2) Set up sync point on node 1 to block slave thread processing |
| 7 |
# in apply monitor |
| 8 |
# 3) Do write on node 2 which will conflict with SELECT .. FOR UPDATE |
| 9 |
# 4) Set up desired sync point on master side and commit |
| 10 |
# 5) Wait until commit reaches master side sync point, clear sync points |
| 11 |
# and release all sync point waiters |
| 12 |
# 6) COMMIT on node 1 should return deadlock error |
| 13 |
# |
| 14 |
|
| 15 |
--connection node_1 |
| 16 |
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; |
| 17 |
|
| 18 |
--eval SET SESSION wsrep_trx_fragment_size = $wsrep_trx_fragment_size |
| 19 |
SET AUTOCOMMIT=OFF; |
| 20 |
|
| 21 |
INSERT INTO t1 VALUES (1); |
| 22 |
SELECT * FROM t1 FOR UPDATE; |
| 23 |
|
| 24 |
# Set up sync point |
| 25 |
--connection node_1a |
| 26 |
--let galera_sync_point = apply_monitor_slave_enter_sync |
| 27 |
--source include/galera_set_sync_point.inc |
| 28 |
|
| 29 |
# Conflicting insert |
| 30 |
--connection node_2 |
| 31 |
|
| 32 |
SET AUTOCOMMIT=ON; |
| 33 |
INSERT INTO t1 VALUES (2); |
| 34 |
|
| 35 |
--connection node_1a |
| 36 |
--source include/galera_wait_sync_point.inc |
| 37 |
--source include/galera_clear_sync_point.inc |
| 38 |
--let $galera_sync_point = $galera_sr_bf_abort_sync_point |
| 39 |
--source include/galera_set_sync_point.inc |
| 40 |
|
| 41 |
--connection node_1 |
| 42 |
if ($galera_sr_bf_abort_at_commit) |
| 43 |
{ |
| 44 |
--send COMMIT |
| 45 |
} |
| 46 |
if (!$galera_sr_bf_abort_at_commit) |
| 47 |
{ |
| 48 |
--send INSERT INTO t1 VALUES (3) |
| 49 |
} |
| 50 |
|
| 51 |
--connection node_1a |
| 52 |
|
| 53 |
--let $cmp = `SELECT STRCMP('apply_monitor_slave_enter_sync', '$galera_sr_bf_abort_sync_point') = -1` |
| 54 |
|
| 55 |
if ($cmp) |
| 56 |
{ |
| 57 |
--let $galera_sync_point = apply_monitor_slave_enter_sync $galera_sr_bf_abort_sync_point |
| 58 |
} |
| 59 |
if (!$cmp) |
| 60 |
{ |
| 61 |
--let $galera_sync_point = $galera_sr_bf_abort_sync_point apply_monitor_slave_enter_sync |
| 62 |
} |
| 63 |
--source include/galera_wait_sync_point.inc |
| 64 |
|
| 65 |
# Let conflicting insert proceed, make sure it hits abort_trx_end and |
| 66 |
# let both threads continue. |
| 67 |
|
| 68 |
--source include/galera_clear_sync_point.inc |
| 69 |
--let $galera_sync_point = abort_trx_end |
| 70 |
--source include/galera_set_sync_point.inc |
| 71 |
--let $galera_sync_point = apply_monitor_slave_enter_sync |
| 72 |
--source include/galera_signal_sync_point.inc |
| 73 |
--let $galera_sync_point = abort_trx_end $galera_sr_bf_abort_sync_point |
| 74 |
|
| 75 |
--source include/galera_wait_sync_point.inc |
| 76 |
--source include/galera_clear_sync_point.inc |
| 77 |
--let $galera_sync_point = abort_trx_end |
| 78 |
--source include/galera_signal_sync_point.inc |
| 79 |
--let $galera_sync_point = $galera_sr_bf_abort_sync_point |
| 80 |
--source include/galera_signal_sync_point.inc |
| 81 |
|
| 82 |
# Deadlock should now be retured by node_1 |
| 83 |
--connection node_1 |
| 84 |
if (!$galera_sr_bf_abort_at_commit) |
| 85 |
{ |
| 86 |
--error ER_LOCK_DEADLOCK |
| 87 |
--reap |
| 88 |
} |
| 89 |
if ($galera_sr_bf_abort_at_commit) |
| 90 |
{ |
| 91 |
--reap |
| 92 |
} |
| 93 |
|
| 94 |
ROLLBACK; |
| 95 |
|
| 96 |
# Release slave insert |
| 97 |
--connection node_1a |
| 98 |
--source include/galera_clear_sync_point.inc |
| 99 |
--let $galera_sync_point = abort_trx_end |
| 100 |
--source include/galera_signal_sync_point.inc |
| 101 |
|
| 102 |
# Verify that nodes are consistent |
| 103 |
|
| 104 |
# End result: |
| 105 |
# If the statement which was BF aborted was commit, |
| 106 |
# node_1 must replay the transaction so that the table |
| 107 |
# will have rows 1, 2. If it in turn was INSERT, |
| 108 |
# node_1 must abort the transaction so that only |
| 109 |
# INSERT ... VALUES (2) survives. |
| 110 |
|
| 111 |
--connection node_1 |
| 112 |
SELECT * FROM t1; |
| 113 |
if ($galera_sr_bf_abort_at_commit) |
| 114 |
{ |
| 115 |
SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 1; |
| 116 |
SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 2; |
| 117 |
} |
| 118 |
if (!$galera_sr_bf_abort_at_commit) |
| 119 |
{ |
| 120 |
SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 2; |
| 121 |
} |
| 122 |
--connection node_2 |
| 123 |
SELECT * FROM t1; |
| 124 |
if ($galera_sr_bf_abort_at_commit) |
| 125 |
{ |
| 126 |
SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 1; |
| 127 |
SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 2; |
| 128 |
} |
| 129 |
if (!$galera_sr_bf_abort_at_commit) |
| 130 |
{ |
| 131 |
SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 2; |
| 132 |
} |
| 133 |
|
| 134 |
--connection node_1 |
| 135 |
SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log; |
| 136 |
--connection node_2 |
| 137 |
SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log; |
| 138 |
|
| 139 |
# Delete entery to verify that node is unblocked |
| 140 |
--connection node_1 |
| 141 |
SET AUTOCOMMIT=ON; |
| 142 |
SET SESSION wsrep_trx_fragment_size = 0; |
| 143 |
DELETE FROM t1; |
| 144 |
|
| 145 |
DROP TABLE t1; |