Skip to content

Commit c42c423

Browse files
sjaakolaJan Lindström
authored andcommitted
MDEV-20225 BF aborting SP execution (#1394)
* MDEV-20225 BF aborting SP execution When stored procedure execution was chosen as victim for a BF abort, the old implemnetationn called for rollback immediately when execution was inside SP isntruction. Technically this happened in wsrep_after_statement() call, which identified the need for a rollback. The problem was that MariaDB does not accept rollback (nor commit) inside sub statement, there are several asserts about it, checking for THD::in_sub_stmt. This patch contains a fix, which skips calling wsrep_after_statement() for SP execution, which is marked as BF must abort. Instead, we return error code to upper level, where rollback will eventually happen, ouside of SP execution. Also, appending the affected trigger table (dropped or created) in the populated key set for the write set, which prevents parallel applying of other transactions working on the same table. * MDEV-20225 BF aborting SP execution, second patch First PR missed 4 commits, which are now squashed in this patch: - Added galera_sp_bf_abort test. A MTR test case which will reproduce BF-BF conflict if all keys corresponding to affected tables are not assigned for DROP TRIGGER. - Fixed incorrect use of sync pointsin MDEV-20225 - Added condition for SQLCOM_DROP_TRIGGER in wsrep_can_run_in_toi() to make it replicate. * MDEV-20225 BF aborting SP execution, third patch The galera_trigger.test caused a situation, where SP invocation caused a trigger to fire, and the trigger executed as sub statement SP, and was BF aborted by applier. because of wsrep_after_statement() was called for the sub-statement level, it ended up in exeuting rollback and asserted there. Thus fix will catch sub-statement level SP execution, and avoids calling wsrep_after_statement()
1 parent dc588e3 commit c42c423

File tree

7 files changed

+537
-45
lines changed

7 files changed

+537
-45
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
connection node_2;
2+
connection node_1;
3+
CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
4+
CREATE TABLE t2 (f1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT, f2 INT) ENGINE=InnoDB;
5+
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NULL, NEW.f1);
6+
connection node_2;
7+
SET SESSION wsrep_sync_wait = 0;
8+
SET GLOBAL wsrep_slave_threads = 2;
9+
SET GLOBAL debug_dbug = 'd,sync.mdev_20225';
10+
DROP TRIGGER tr1;
11+
connection node_2;
12+
connection node_1;
13+
INSERT INTO t1 VALUES (NULL);
14+
connection node_2;
15+
SET GLOBAL debug_dbug = 'RESET';
16+
SET DEBUG_SYNC = 'now SIGNAL signal.mdev_20225_continue';
17+
SET DEBUG_SYNC = 'RESET';
18+
SET GLOBAL wsrep_slave_threads = 1;
19+
SHOW TRIGGERS;
20+
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
21+
DROP TABLE t1;
22+
DROP TABLE t2;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# MDEV-20225 - Verify that DROP TRIGGER gets keys assigned corresponding
3+
# to all affected tables.
4+
#
5+
6+
--source include/galera_cluster.inc
7+
--source include/have_innodb.inc
8+
9+
CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
10+
CREATE TABLE t2 (f1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT, f2 INT) ENGINE=InnoDB;
11+
12+
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NULL, NEW.f1);
13+
14+
--connection node_2
15+
SET SESSION wsrep_sync_wait = 0;
16+
SET GLOBAL wsrep_slave_threads = 2;
17+
SET GLOBAL debug_dbug = 'd,sync.mdev_20225';
18+
19+
--let $galera_connection_name = node_1a
20+
--let $galera_server_number = 1
21+
--source include/galera_connect.inc
22+
DROP TRIGGER tr1;
23+
24+
--connection node_2
25+
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE = 'debug sync point: now'
26+
--source include/wait_condition.inc
27+
28+
29+
--connection node_1
30+
INSERT INTO t1 VALUES (NULL);
31+
# We must rely on sleep here. If the bug is fixed, the second applier
32+
# is not allowed to go past apply monitor which would trigger the bug,
33+
# so there is no sync point or condition to wait.
34+
--sleep 1
35+
36+
--connection node_2
37+
SET GLOBAL debug_dbug = 'RESET';
38+
SET DEBUG_SYNC = 'now SIGNAL signal.mdev_20225_continue';
39+
SET DEBUG_SYNC = 'RESET';
40+
SET GLOBAL wsrep_slave_threads = 1;
41+
42+
# Trigger should now be dropped on node_2.
43+
SHOW TRIGGERS;
44+
45+
DROP TABLE t1;
46+
DROP TABLE t2;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
#
3+
# Issue an INSERT for gap between 1 and 3 to node_2 and wait until it hits
4+
# apply monitor sync point on node_1
5+
#
6+
7+
--connection node_1a
8+
--let $galera_sync_point = apply_monitor_slave_enter_sync
9+
--source include/galera_set_sync_point.inc
10+
11+
--connection node_2
12+
--eval $galera_sp_bf_abort_conflict
13+
14+
--connection node_1a
15+
--source include/galera_wait_sync_point.inc
16+
--source include/galera_clear_sync_point.inc
17+
18+
# Send a procedure to node_1 which should take a gap lock between
19+
# rows 1 and 3. It does not conflict with INSERT from node_2 in
20+
# certification. Park the UPDATE after replicate and let INSERT to
21+
# continue applying, generating a BF abort.
22+
23+
--let $galera_sync_point = after_replicate_sync
24+
--source include/galera_set_sync_point.inc
25+
26+
--connection node_1
27+
--send_eval CALL $galera_sp_bf_abort_proc
28+
29+
--connection node_1a
30+
--let $galera_sync_point = after_replicate_sync apply_monitor_slave_enter_sync
31+
--source include/galera_wait_sync_point.inc
32+
--source include/galera_clear_sync_point.inc
33+
34+
--let $galera_sync_point = apply_monitor_slave_enter_sync
35+
--source include/galera_signal_sync_point.inc
36+
--let $galera_sync_point = after_replicate_sync
37+
--source include/galera_signal_sync_point.inc
38+

0 commit comments

Comments
 (0)