Skip to content

Commit 04bf6fd

Browse files
committed
MDEV-36909 : Assertion `client_state.transaction().active()' failed in int wsrep_thd_append_key(THD*, const wsrep_key*, int, Wsrep_service_key_type)
Problem was that when trigger was executed it accessed non-transactional table using Aria-engine. To support simple DML for Aria we use TOI and befoare TOI was started existing wsrep transaction is rolled back. In the following operation on transactional engine in same statement wsrep transaction is not active anymore leading to assertion. However, this is incorrect if there is active wsrep transaction that has done changes. Instead we should refuse statement if transactional commit is not supported.
1 parent fb49d8a commit 04bf6fd

File tree

6 files changed

+136
-16
lines changed

6 files changed

+136
-16
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
connection node_2;
2+
connection node_1;
3+
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
4+
INSERT INTO t1 VALUES (1),(2);
5+
CREATE TABLE t2 (a INT) ENGINE=Aria;
6+
CREATE TRIGGER trg AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NEW.a);
7+
SET GLOBAL wsrep_mode=replicate_aria;
8+
UPDATE t1 SET a=10;
9+
ERROR HY000: Transactional commit not supported by involved engine(s)
10+
SELECT * FROM t1;
11+
a
12+
1
13+
2
14+
SELECT * FROM t2;
15+
a
16+
connection node_2;
17+
SELECT * FROM t1;
18+
a
19+
1
20+
2
21+
SELECT * FROM t2;
22+
a
23+
connection node_1;
24+
DROP TRIGGER trg;
25+
DROP TABLE t1,t2;
26+
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
27+
INSERT INTO t1 VALUES (1),(2);
28+
CREATE TABLE t2 (a INT) ENGINE=InnoDB;
29+
CREATE TRIGGER trg AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NEW.a);
30+
UPDATE t1 SET a=10;
31+
SELECT * FROM t1;
32+
a
33+
10
34+
10
35+
SELECT * FROM t2;
36+
a
37+
10
38+
10
39+
connection node_2;
40+
SELECT * FROM t1;
41+
a
42+
10
43+
10
44+
SELECT * FROM t2;
45+
a
46+
10
47+
10
48+
connection node_1;
49+
DROP TRIGGER trg;
50+
DROP TABLE t1,t2;
51+
call mtr.add_suppression("WSREP: Replication of non-transactional engines is experimental. Storage engine Aria for table \'test\'\.\'t2\' is not supported in Galera");
52+
SET GLOBAL wsrep_mode=DEFAULT;

mysql-test/suite/galera/r/galera_strict_require_innodb.result

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
connection node_2;
22
connection node_1;
3-
call mtr.add_suppression("WSREP: wsrep_mode = STRICT_REPLICATION enabled\\. Storage engine ");
3+
call mtr.add_suppression("WSREP: wsrep_mode = STRICT_REPLICATION enabled");
44
CREATE TABLE t1(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=INNODB;
55
CREATE TABLE t2(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=MYISAM;
66
CREATE TABLE t3(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=ARIA;
@@ -9,7 +9,11 @@ SET GLOBAL log_warnings=2;
99
SET GLOBAL wsrep_mode = "STRICT_REPLICATION,REPLICATE_MYISAM,REPLICATE_ARIA";
1010
INSERT INTO t1 values (1,'innodb1');
1111
INSERT INTO t2 values (1,'myisam1');
12+
Warnings:
13+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
1214
INSERT INTO t3 values (1,'aria1');
15+
Warnings:
16+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
1317
INSERT INTO t4 values (1,'memory1');
1418
Warnings:
1519
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
@@ -24,6 +28,8 @@ Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria
2428
SET GLOBAL log_warnings=1;
2529
INSERT INTO t1 values (3,'innodb3');
2630
INSERT INTO t2 values (3,'myisam3');
31+
Warnings:
32+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
2733
INSERT INTO t3 values (3,'aria3');
2834
Warnings:
2935
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
@@ -33,55 +39,71 @@ Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMO
3339
include/assert_grep.inc [WSREP: wsrep_mode = STRICT_REPLICATION enabled.]
3440
SET GLOBAL log_warnings=2;
3541
INSERT INTO t2 values (4,'myisam3');
42+
Warnings:
43+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
3644
INSERT INTO t3 values (4,'aria2');
3745
Warnings:
3846
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
3947
INSERT INTO t4 values (4,'memory2');
4048
Warnings:
4149
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
4250
INSERT INTO t2 values (5,'myisam3');
51+
Warnings:
52+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
4353
INSERT INTO t3 values (5,'aria2');
4454
Warnings:
4555
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
4656
INSERT INTO t4 values (5,'memory2');
4757
Warnings:
4858
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
4959
INSERT INTO t2 values (6,'myisam3');
60+
Warnings:
61+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
5062
INSERT INTO t3 values (6,'aria2');
5163
Warnings:
5264
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
5365
INSERT INTO t4 values (6,'memory2');
5466
Warnings:
5567
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
5668
INSERT INTO t2 values (7,'myisam3');
69+
Warnings:
70+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
5771
INSERT INTO t3 values (7,'aria2');
5872
Warnings:
5973
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
6074
INSERT INTO t4 values (7,'memory2');
6175
Warnings:
6276
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
6377
INSERT INTO t2 values (8,'myisam3');
78+
Warnings:
79+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
6480
INSERT INTO t3 values (8,'aria2');
6581
Warnings:
6682
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
6783
INSERT INTO t4 values (8,'memory2');
6884
Warnings:
6985
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
7086
INSERT INTO t2 values (9,'myisam3');
87+
Warnings:
88+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
7189
INSERT INTO t3 values (9,'aria2');
7290
Warnings:
7391
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
7492
INSERT INTO t4 values (9,'memory2');
7593
Warnings:
7694
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
7795
INSERT INTO t2 values (10,'myisam3');
96+
Warnings:
97+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
7898
INSERT INTO t3 values (10,'aria2');
7999
Warnings:
80100
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
81101
INSERT INTO t4 values (10,'memory2');
82102
Warnings:
83103
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
84104
INSERT INTO t2 values (11,'myisam3');
105+
Warnings:
106+
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
85107
INSERT INTO t3 values (11,'aria2');
86108
Warnings:
87109
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera

mysql-test/suite/galera/r/mdev-30653.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ id val
4343
connection node_2;
4444
select * from t1;
4545
id val
46-
1 23
46+
1 24
4747
select * from t2;
4848
id val
4949
2 42
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--source include/galera_cluster.inc
2+
--source include/have_innodb.inc
3+
4+
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
5+
INSERT INTO t1 VALUES (1),(2);
6+
CREATE TABLE t2 (a INT) ENGINE=Aria;
7+
CREATE TRIGGER trg AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NEW.a);
8+
SET GLOBAL wsrep_mode=replicate_aria;
9+
--error ER_ERROR_DURING_COMMIT
10+
UPDATE t1 SET a=10;
11+
SELECT * FROM t1;
12+
SELECT * FROM t2;
13+
14+
--connection node_2
15+
SELECT * FROM t1;
16+
SELECT * FROM t2;
17+
18+
--connection node_1
19+
DROP TRIGGER trg;
20+
DROP TABLE t1,t2;
21+
22+
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
23+
INSERT INTO t1 VALUES (1),(2);
24+
CREATE TABLE t2 (a INT) ENGINE=InnoDB;
25+
CREATE TRIGGER trg AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NEW.a);
26+
UPDATE t1 SET a=10;
27+
SELECT * FROM t1;
28+
SELECT * FROM t2;
29+
30+
--connection node_2
31+
SELECT * FROM t1;
32+
SELECT * FROM t2;
33+
34+
--connection node_1
35+
DROP TRIGGER trg;
36+
DROP TABLE t1,t2;
37+
38+
call mtr.add_suppression("WSREP: Replication of non-transactional engines is experimental. Storage engine Aria for table \'test\'\.\'t2\' is not supported in Galera");
39+
SET GLOBAL wsrep_mode=DEFAULT;

mysql-test/suite/galera/t/galera_strict_require_innodb.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
--source include/galera_cluster.inc
1818
--source include/have_innodb.inc
1919
--source include/have_aria.inc
20+
--source include/force_restart.inc
2021

21-
call mtr.add_suppression("WSREP: wsrep_mode = STRICT_REPLICATION enabled\\. Storage engine ");
22+
call mtr.add_suppression("WSREP: wsrep_mode = STRICT_REPLICATION enabled");
2223

2324
CREATE TABLE t1(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=INNODB;
2425
CREATE TABLE t2(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=MYISAM;
@@ -47,7 +48,7 @@ INSERT INTO t3 values (3,'aria3');
4748
INSERT INTO t4 values (3,'memory3');
4849

4950
# test warnings
50-
--let $assert_count = 3
51+
--let $assert_count = 5
5152
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
5253
--let $assert_text = WSREP: wsrep_mode = STRICT_REPLICATION enabled.
5354
--let $assert_select = WSREP: wsrep_mode = STRICT_REPLICATION enabled.

sql/wsrep_mysqld.cc

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,25 +1472,31 @@ bool wsrep_check_mode_after_open_table (THD *thd,
14721472
wsrep_push_warning(thd, WSREP_REQUIRE_PRIMARY_KEY, hton, tables);
14731473
}
14741474

1475+
if (wsrep_check_mode(WSREP_MODE_STRICT_REPLICATION))
1476+
{
1477+
/* Table is not an InnoDB table and strict replication is requested*/
1478+
wsrep_push_warning(thd, WSREP_REQUIRE_INNODB, hton, tables);
1479+
}
1480+
14751481
// Check are we inside a transaction
1476-
bool not_used;
1477-
uint rw_ha_count= ha_check_and_coalesce_trx_read_only(thd, thd->transaction->all.ha_list, true, &not_used);
1478-
bool changes= wsrep_has_changes(thd);
1482+
const bool changes= wsrep_has_changes(thd);
1483+
const bool active= wsrep_is_active(thd);
1484+
1485+
// We should not start TOI if transaction has made already
1486+
// changes and is active
1487+
if (changes && active)
1488+
{
1489+
my_message(ER_ERROR_DURING_COMMIT, "Transactional commit not supported "
1490+
"by involved engine(s)", MYF(0));
1491+
wsrep_push_warning(thd, WSREP_EXPERIMENTAL, hton, tables);
1492+
return false;
1493+
}
14791494

14801495
// Roll back current stmt if exists
14811496
wsrep_before_rollback(thd, true);
14821497
wsrep_after_rollback(thd, true);
14831498
wsrep_after_statement(thd);
14841499

1485-
// If there is updates, they would be lost above rollback
1486-
if (rw_ha_count > 0 && changes)
1487-
{
1488-
my_message(ER_ERROR_DURING_COMMIT, "Transactional commit not supported "
1489-
"by involved engine(s)", MYF(0));
1490-
wsrep_push_warning(thd, WSREP_EXPERIMENTAL, hton, tables);
1491-
return false;
1492-
}
1493-
14941500
WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (tables));
14951501
}
14961502
} else if (db_type != DB_TYPE_UNKNOWN &&

0 commit comments

Comments
 (0)