Skip to content

Commit aec79c5

Browse files
committed
Merge 10.6 into 10.11
2 parents 057c83a + 1c9caba commit aec79c5

File tree

9 files changed

+327
-13
lines changed

9 files changed

+327
-13
lines changed

sql/log_event_server.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6348,7 +6348,11 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi)
63486348
slave_rows_error_report(ERROR_LEVEL, thd->is_error() ? 0 : error,
63496349
rgi, thd, table, get_type_str(),
63506350
RPL_LOG_NAME, log_pos);
6351-
if (thd->slave_thread)
6351+
if (thd->slave_thread
6352+
#ifdef WITH_WSREP
6353+
|| (WSREP(thd) && wsrep_thd_is_applying(thd))
6354+
#endif /* WITH_WSREP */
6355+
)
63526356
free_root(thd->mem_root, MYF(MY_KEEP_PREALLOC));
63536357
}
63546358

storage/innobase/include/trx0purge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ class purge_sys_t
451451

452452
/** @return purge_sys.view or purge_sys.end_view */
453453
inline const ReadViewBase &view() const;
454+
455+
/** @return whether this is part of CHECK TABLE ... EXTENDED */
456+
bool is_extended() const noexcept { return latch < END_VIEW; }
454457
};
455458

456459
struct end_view_guard

storage/innobase/log/log0recv.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,10 +4065,8 @@ static void log_sort_flush_list() noexcept
40654065
for (size_t i= 0; i < idx; i++)
40664066
{
40674067
buf_page_t *b= list[i];
4068-
const lsn_t lsn{b->oldest_modification()};
4069-
if (lsn == 1)
4070-
continue;
4071-
DBUG_ASSERT(lsn > 2);
4068+
ut_d(const lsn_t lsn{b->oldest_modification()});
4069+
ut_ad(lsn == 1 || lsn > 2);
40724070
UT_LIST_ADD_LAST(buf_pool.flush_list, b);
40734071
}
40744072

storage/innobase/trx/trx0rec.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,21 @@ static dberr_t trx_undo_prev_version(const rec_t *rec, dict_index_t *index,
22382238
byte* buf;
22392239

22402240
if (row_upd_changes_field_size_or_external(index, offsets, update)) {
2241+
/* When CHECK TABLE ... EXTENDED checks for orphan
2242+
records in secondary indexes, it normally covers some
2243+
history that is already being purged. This is safe as
2244+
long as the undo log records have not been freed yet.
2245+
2246+
However, BLOBs are only safe to access as long as the
2247+
purge_sys.view does not permit them to be freed. The
2248+
check.latch will freeze the purge_sys.view by blocking
2249+
purge_sys.clone_oldest_view() at the start of
2250+
trx_purge() or by blocking purge_sys.batch_cleanup()
2251+
at the end of trx_purge(). */
2252+
if (check.is_extended() && purge_sys.is_purgeable(trx_id)) {
2253+
return DB_SUCCESS;
2254+
}
2255+
22412256
/* We should confirm the existence of disowned external data,
22422257
if the previous version record is delete marked. If the trx_id
22432258
of the previous record is seen by purge view, we should treat
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# MDEV-37829 XA COMMIT ONE PHASE fails with "This xid does not
3+
# exist" if a trigger references a SPIDER table
4+
#
5+
for master_1
6+
for child2
7+
for child3
8+
set spider_same_server_link= 1;
9+
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
10+
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
11+
CREATE TABLE t (
12+
id INT auto_increment NOT NULL,
13+
name varchar(100) NULL,
14+
CONSTRAINT test_pk PRIMARY KEY (id)
15+
) ENGINE=InnoDB;
16+
Warnings:
17+
Warning 1280 Name 'test_pk' ignored for PRIMARY key.
18+
INSERT INTO t(id, name) VALUES(1,'test1');
19+
CREATE TABLE t2 (
20+
id INT auto_increment NOT NULL,
21+
name varchar(100) NULL,
22+
CONSTRAINT test2_pk PRIMARY KEY (id)
23+
) ENGINE=InnoDB;
24+
Warnings:
25+
Warning 1280 Name 'test2_pk' ignored for PRIMARY key.
26+
CREATE TABLE t3 (
27+
id INT auto_increment NOT NULL,
28+
name varchar(100) NULL,
29+
CONSTRAINT test3_pk PRIMARY KEY (id)
30+
) ENGINE=SPIDER COMMENT='wrapper "mysql", srv "srv", table "t2"';
31+
Warnings:
32+
Warning 1280 Name 'test3_pk' ignored for PRIMARY key.
33+
CREATE PROCEDURE tProc()
34+
BEGIN
35+
# This conditional logic is intentionally FALSE.
36+
# The SELECT on the SPIDER table will never run.
37+
SET @t := FALSE;
38+
IF @t = TRUE THEN
39+
SELECT name INTO @b FROM t3 WHERE id = 1;
40+
END IF;
41+
END$$
42+
CREATE TRIGGER t_au
43+
AFTER UPDATE
44+
ON t FOR EACH ROW
45+
BEGIN
46+
# This condition will also be false in our test case.
47+
IF NEW.name = '3' THEN
48+
CALL tProc();
49+
END IF;
50+
END$$
51+
SELECT "Using 2PC...";
52+
Using 2PC...
53+
Using 2PC...
54+
XA START 'TESTTRX_2P';
55+
UPDATE t SET name = 'abc' WHERE ID = 1;
56+
SHOW WARNINGS;
57+
Level Code Message
58+
XA END 'TESTTRX_2P';
59+
XA PREPARE 'TESTTRX_2P';
60+
XA COMMIT 'TESTTRX_2P';
61+
SELECT "Using 1PC...";
62+
Using 1PC...
63+
Using 1PC...
64+
XA START 'TESTTRX_1P';
65+
UPDATE t SET name = 'abc' WHERE ID = 1;
66+
SHOW WARNINGS;
67+
Level Code Message
68+
XA END 'TESTTRX_1P';
69+
XA COMMIT 'TESTTRX_1P' ONE PHASE;
70+
drop trigger t_au;
71+
drop procedure tProc;
72+
drop table t, t2, t3;
73+
drop server srv;
74+
for master_1
75+
for child2
76+
for child3

storage/spider/mysql-test/spider/bugfix/r/xa_cmd.result

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,79 @@ INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3434
XA END 'test';
3535
XA PREPARE 'test';
3636
XA COMMIT 'test';
37+
# MDEV-37829 XA COMMIT ONE PHASE fails with "This xid does not
38+
# exist" if a trigger references a SPIDER table
39+
#
40+
# Below we test a version of the MDEV-37829 case that is not a
41+
# no-op on the spider table
42+
XA START 'test1';
43+
INSERT INTO tbl_a (pkey) VALUES (100);
44+
XA END 'test1';
45+
XA COMMIT 'test1' ONE PHASE;
46+
select * from tbl_a;
47+
pkey
48+
0
49+
1
50+
2
51+
3
52+
4
53+
5
54+
6
55+
7
56+
8
57+
9
58+
100
59+
create table t (c int);
60+
insert into t values (1),(2);
61+
CREATE PROCEDURE tProc()
62+
BEGIN
63+
SET @t := TRUE;
64+
IF @t = TRUE THEN
65+
INSERT INTO tbl_a select max(pkey) + 1 from tbl_a;
66+
END IF;
67+
END$$
68+
CREATE TRIGGER t_au
69+
AFTER UPDATE
70+
ON t FOR EACH ROW
71+
BEGIN
72+
IF NEW.c < 50 THEN
73+
CALL tProc();
74+
END IF;
75+
END$$
76+
XA START 'test';
77+
update t set c = c + 1 where c = 1;
78+
XA END 'test';
79+
XA PREPARE 'test';
80+
XA COMMIT 'test';
81+
XA START 'test1';
82+
update t set c = c + 1 where c = 2;
83+
XA END 'test1';
84+
XA COMMIT 'test1' ONE PHASE;
85+
drop table t;
86+
select * from tbl_a;
87+
pkey
88+
0
89+
1
90+
2
91+
3
92+
4
93+
5
94+
6
95+
7
96+
8
97+
9
98+
100
99+
101
100+
102
101+
103
37102
connection child2_1;
38103
SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %';
39104
argument
40105
insert into `auto_test_remote`.`tbl_a`(`pkey`)values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)
106+
insert into `auto_test_remote`.`tbl_a`(`pkey`)values(100)
107+
insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`)values(101)
108+
insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`)values(102)
109+
insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`)values(103)
41110
SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %'
42111
SELECT pkey FROM tbl_a ORDER BY pkey;
43112
pkey
@@ -51,6 +120,10 @@ pkey
51120
7
52121
8
53122
9
123+
100
124+
101
125+
102
126+
103
54127

55128
deinit
56129
connection master_1;
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
--echo #
2+
--echo # MDEV-37829 XA COMMIT ONE PHASE fails with "This xid does not
3+
--echo # exist" if a trigger references a SPIDER table
4+
--echo #
5+
6+
--disable_query_log
7+
--disable_result_log
8+
--source ../../t/test_init.inc
9+
--enable_result_log
10+
--enable_query_log
11+
--source include/have_innodb.inc
12+
set spider_same_server_link= 1;
13+
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
14+
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
15+
16+
# See also spider/bugfix.xa_cmd for a case that is not a no-op on
17+
# the spider table
18+
19+
# 1. SETUP: Create local InnoDB tables and one remote SPIDER table
20+
21+
# Local table to be updated
22+
CREATE TABLE t (
23+
id INT auto_increment NOT NULL,
24+
name varchar(100) NULL,
25+
CONSTRAINT test_pk PRIMARY KEY (id)
26+
) ENGINE=InnoDB;
27+
28+
INSERT INTO t(id, name) VALUES(1,'test1');
29+
30+
# Remote table target
31+
CREATE TABLE t2 (
32+
id INT auto_increment NOT NULL,
33+
name varchar(100) NULL,
34+
CONSTRAINT test2_pk PRIMARY KEY (id)
35+
) ENGINE=InnoDB;
36+
37+
# SPIDER table pointing to the remote target
38+
CREATE TABLE t3 (
39+
id INT auto_increment NOT NULL,
40+
name varchar(100) NULL,
41+
CONSTRAINT test3_pk PRIMARY KEY (id)
42+
) ENGINE=SPIDER COMMENT='wrapper "mysql", srv "srv", table "t2"';
43+
44+
45+
# 2. SETUP: Create a procedure and trigger that reference the SPIDER table
46+
47+
DELIMITER $$;
48+
49+
CREATE PROCEDURE tProc()
50+
BEGIN
51+
# This conditional logic is intentionally FALSE.
52+
# The SELECT on the SPIDER table will never run.
53+
SET @t := FALSE;
54+
IF @t = TRUE THEN
55+
SELECT name INTO @b FROM t3 WHERE id = 1;
56+
END IF;
57+
END$$
58+
59+
CREATE TRIGGER t_au
60+
AFTER UPDATE
61+
ON t FOR EACH ROW
62+
BEGIN
63+
# This condition will also be false in our test case.
64+
IF NEW.name = '3' THEN
65+
CALL tProc();
66+
END IF;
67+
END$$
68+
69+
DELIMITER ;$$
70+
71+
72+
# 3. TEST CASE 1: Two-phase commit
73+
SELECT "Using 2PC...";
74+
XA START 'TESTTRX_2P';
75+
UPDATE t SET name = 'abc' WHERE ID = 1;
76+
SHOW WARNINGS;
77+
XA END 'TESTTRX_2P';
78+
XA PREPARE 'TESTTRX_2P';
79+
XA COMMIT 'TESTTRX_2P';
80+
81+
# 4. TEST CASE 2: One-phase commit
82+
83+
SELECT "Using 1PC...";
84+
XA START 'TESTTRX_1P';
85+
UPDATE t SET name = 'abc' WHERE ID = 1;
86+
SHOW WARNINGS;
87+
XA END 'TESTTRX_1P';
88+
XA COMMIT 'TESTTRX_1P' ONE PHASE;
89+
90+
drop trigger t_au;
91+
drop procedure tProc;
92+
drop table t, t2, t3;
93+
94+
drop server srv;
95+
--disable_query_log
96+
--disable_result_log
97+
--source ../../t/test_deinit.inc
98+
--enable_result_log
99+
--enable_query_log

storage/spider/mysql-test/spider/bugfix/t/xa_cmd.test

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,58 @@ XA END 'test';
5151
XA PREPARE 'test';
5252
XA COMMIT 'test';
5353

54+
--echo # MDEV-37829 XA COMMIT ONE PHASE fails with "This xid does not
55+
--echo # exist" if a trigger references a SPIDER table
56+
--echo #
57+
--echo # Below we test a version of the MDEV-37829 case that is not a
58+
--echo # no-op on the spider table
59+
60+
XA START 'test1';
61+
INSERT INTO tbl_a (pkey) VALUES (100);
62+
XA END 'test1';
63+
XA COMMIT 'test1' ONE PHASE;
64+
65+
select * from tbl_a;
66+
67+
create table t (c int);
68+
insert into t values (1),(2);
69+
70+
DELIMITER $$;
71+
72+
CREATE PROCEDURE tProc()
73+
BEGIN
74+
SET @t := TRUE;
75+
IF @t = TRUE THEN
76+
INSERT INTO tbl_a select max(pkey) + 1 from tbl_a;
77+
END IF;
78+
END$$
79+
80+
CREATE TRIGGER t_au
81+
AFTER UPDATE
82+
ON t FOR EACH ROW
83+
BEGIN
84+
IF NEW.c < 50 THEN
85+
CALL tProc();
86+
END IF;
87+
END$$
88+
89+
DELIMITER ;$$
90+
91+
XA START 'test';
92+
update t set c = c + 1 where c = 1;
93+
XA END 'test';
94+
XA PREPARE 'test';
95+
XA COMMIT 'test';
96+
97+
XA START 'test1';
98+
update t set c = c + 1 where c = 2;
99+
XA END 'test1';
100+
XA COMMIT 'test1' ONE PHASE;
101+
102+
drop table t;
103+
104+
select * from tbl_a;
105+
54106
--connection child2_1
55107
--disable_view_protocol
56108
--disable_ps2_protocol

0 commit comments

Comments
 (0)