|
| 1 | +################################################################################ |
| 2 | +# |
| 3 | +# PXC-5203: A session holding LOCK TABLES FOR BACKUP that then runs its own |
| 4 | +# DDL used to have the DDL replicated via Galera TOI *before* the local |
| 5 | +# backup-lock check rejected it. Peers applied the DDL successfully while the |
| 6 | +# originating node failed the statement locally -- a certification-vs-local |
| 7 | +# result divergence that made Galera raise an "Inconsistency detected" vote |
| 8 | +# and kick the node out of the cluster. |
| 9 | +# |
| 10 | +# This test proves the DDL is now rejected immediately, before it ever |
| 11 | +# reaches TOI/replication, so peers never see it and no divergence occurs. |
| 12 | +# It also proves LOCK INSTANCE FOR BACKUP (the ticket's "no problem" case) |
| 13 | +# keeps working exactly as before: same-session DDL still succeeds and |
| 14 | +# still replicates normally. |
| 15 | +# |
| 16 | +################################################################################ |
| 17 | +# 1. Create table t1 on node_1, wait for it on node_2. |
| 18 | +# 2. LOCK TABLES FOR BACKUP + same-session ALTER TABLE fails immediately with |
| 19 | +# ER_CANT_EXECUTE_WITH_BACKUP_LOCK; the index change never reaches node_2. |
| 20 | +# 3. After UNLOCK, the same ALTER TABLE succeeds and replicates normally. |
| 21 | +# 4. LOCK INSTANCE FOR BACKUP with same-session DDL is replicated. |
| 22 | +# 5. Cleanup. |
| 23 | +################################################################################ |
| 24 | +--source include/galera_cluster.inc |
| 25 | + |
| 26 | +--echo # |
| 27 | +--echo # 1. Create table t1 on node_1, wait for it on node_2. |
| 28 | +--echo # |
| 29 | + |
| 30 | +--connection node_1 |
| 31 | +CREATE TABLE t1 (id INT PRIMARY KEY, a INT, KEY k_a (a)) ENGINE=InnoDB; |
| 32 | +INSERT INTO t1 VALUES (1, 10), (2, 20), (3, 30); |
| 33 | + |
| 34 | +--connection node_2 |
| 35 | +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1' |
| 36 | +--source include/wait_condition.inc |
| 37 | + |
| 38 | +--echo # |
| 39 | +--echo # 2. LOCK TABLES FOR BACKUP, ALTER TABLE will fail, |
| 40 | +--echo # Assert transaction is not replicated. |
| 41 | +--echo # |
| 42 | + |
| 43 | +--connection node_1 |
| 44 | +LOCK TABLES FOR BACKUP; |
| 45 | +--error ER_CANT_EXECUTE_WITH_BACKUP_LOCK |
| 46 | +ALTER TABLE t1 DROP KEY k_a; |
| 47 | + |
| 48 | +--let $assert_text = k_a index must still exist on node_1 (statement rejected locally) |
| 49 | +--let $assert_cond = COUNT(*) = 1 FROM information_schema.statistics WHERE TABLE_NAME="t1" AND INDEX_NAME="k_a" AND TABLE_SCHEMA=DATABASE() |
| 50 | +--source include/assert.inc |
| 51 | + |
| 52 | +--connection node_2 |
| 53 | +--let $assert_text = k_a index must still exist on node_2 -- nothing was replicated |
| 54 | +--let $assert_cond = COUNT(*) = 1 FROM information_schema.statistics WHERE TABLE_NAME="t1" AND INDEX_NAME="k_a" AND TABLE_SCHEMA=DATABASE() |
| 55 | +--source include/assert.inc |
| 56 | + |
| 57 | +--let $assert_text = Cluster must still have both nodes (no inconsistency vote / node eviction) |
| 58 | +--let $assert_cond = (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME="wsrep_cluster_size") = 2 |
| 59 | +--source include/assert.inc |
| 60 | + |
| 61 | +--connection node_1 |
| 62 | +UNLOCK TABLES; |
| 63 | + |
| 64 | +--echo # |
| 65 | +--echo # 3. After UNLOCK, the same ALTER TABLE succeeds and replicates normally. |
| 66 | +--echo # |
| 67 | + |
| 68 | +ALTER TABLE t1 DROP KEY k_a; |
| 69 | + |
| 70 | +--connection node_2 |
| 71 | +--let $assert_text = k_a index must be dropped on node_2 after UNLOCK TABLES |
| 72 | +--let $assert_cond = COUNT(*) = 0 FROM information_schema.statistics WHERE TABLE_NAME="t1" AND INDEX_NAME="k_a" AND TABLE_SCHEMA=DATABASE() |
| 73 | +--source include/assert.inc |
| 74 | + |
| 75 | +--echo # |
| 76 | +--echo # 4. LOCK INSTANCE FOR BACKUP with same-session DDL is replicated. |
| 77 | +--echo # |
| 78 | + |
| 79 | +--connection node_1 |
| 80 | +ALTER TABLE t1 ADD KEY k_a (a); |
| 81 | + |
| 82 | +--connection node_2 |
| 83 | +--let $wait_condition = SELECT COUNT(*) = 1 FROM information_schema.statistics WHERE TABLE_NAME="t1" AND INDEX_NAME="k_a" AND TABLE_SCHEMA=DATABASE() |
| 84 | +--source include/wait_condition.inc |
| 85 | + |
| 86 | +--connection node_1 |
| 87 | +LOCK INSTANCE FOR BACKUP; |
| 88 | +ALTER TABLE t1 DROP KEY k_a; |
| 89 | +UNLOCK INSTANCE; |
| 90 | + |
| 91 | +--let $assert_text = k_a index must be dropped on node_1 -- LOCK INSTANCE FOR BACKUP allows same-session DDL |
| 92 | +--let $assert_cond = COUNT(*) = 0 FROM information_schema.statistics WHERE TABLE_NAME="t1" AND INDEX_NAME="k_a" AND TABLE_SCHEMA=DATABASE() |
| 93 | +--source include/assert.inc |
| 94 | + |
| 95 | +--connection node_2 |
| 96 | +--let $wait_condition = SELECT COUNT(*) = 0 FROM information_schema.statistics WHERE TABLE_NAME="t1" AND INDEX_NAME="k_a" AND TABLE_SCHEMA=DATABASE() |
| 97 | +--source include/wait_condition.inc |
| 98 | + |
| 99 | +--echo # |
| 100 | +--echo # 5. Cleanup. |
| 101 | +--echo # |
| 102 | + |
| 103 | +--connection node_1 |
| 104 | +DROP TABLE t1; |
0 commit comments