diff --git a/include/my_dbug.h b/include/my_dbug.h index 354c4feb8a0..7040f59246d 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -93,6 +93,10 @@ extern void _db_unlock_file_(void); extern FILE *_db_fp_(void); extern void _db_flush_(); +extern void parallel_reader_copy_dbug_keyword_list(CODE_STATE **dst_ptr, CODE_STATE **src_ptr); + +extern void parallel_reader_reset_dbug_keyword_list(CODE_STATE **cs_ptr); + #ifdef __cplusplus #if defined(__GNUC__) diff --git a/mysql-test/r/disable_parallel_copy_ddl_functional_index_issue3625.result b/mysql-test/r/disable_parallel_copy_ddl_functional_index_issue3625.result new file mode 100644 index 00000000000..99ce2a805fa --- /dev/null +++ b/mysql-test/r/disable_parallel_copy_ddl_functional_index_issue3625.result @@ -0,0 +1,8 @@ +SET SESSION txsql_parallel_copy_ddl=ON; +CREATE TABLE t1 (fld1 INT, fld2 DATETIME NOT NULL) ENGINE= INNODB; +INSERT INTO t1 VALUES(1, '2000-01-01'); +INSERT INTO t1 VALUES(2, '2001-01-01'); +INSERT INTO t1 VALUES(3, '2002-01-01'); +ALTER TABLE t1 ADD INDEX idx_sale_month ((MONTH(fld2))), ALGORITHM= COPY; +ALTER TABLE t1 DROP INDEX idx_sale_month, ALGORITHM= COPY; +DROP TABLE t1; diff --git a/mysql-test/r/disable_parallel_copy_ddl_generated_column.result b/mysql-test/r/disable_parallel_copy_ddl_generated_column.result new file mode 100644 index 00000000000..e2f7c993f78 --- /dev/null +++ b/mysql-test/r/disable_parallel_copy_ddl_generated_column.result @@ -0,0 +1,13 @@ +SET SESSION txsql_parallel_copy_ddl=ON; +CREATE TABLE t1 ( +id INT PRIMARY KEY, +a INT, +b INT GENERATED ALWAYS AS (a + 1) VIRTUAL +) ENGINE=INNODB; +INSERT INTO t1 (id, a) VALUES (1, 10), (2, 20), (3, 30); +ALTER TABLE t1 ADD COLUMN c INT, ALGORITHM=COPY; +DROP TABLE t1; +CREATE TABLE t2 (id INT PRIMARY KEY, a INT) ENGINE=INNODB; +INSERT INTO t2 VALUES (1, 10), (2, 20), (3, 30); +ALTER TABLE t2 ADD COLUMN c INT, ALGORITHM=COPY; +DROP TABLE t2; diff --git a/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.csi b/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.csi new file mode 100644 index 00000000000..86d001bc510 --- /dev/null +++ b/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.csi @@ -0,0 +1,28 @@ +CREATE TABLE articles ( +id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, +title VARCHAR(200), +content TEXT, +FULLTEXT INDEX ft_index (title, content) WITH PARSER ngram +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +drop procedure if exists populate; +create procedure populate(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO articles (title, content) VALUES +('MySQL Full-Text Search', 'This article explains how to use full-text search in MySQL.'), +('Understanding MySQL', 'MySQL is a popular relational database management system.'), +('Advanced MySQL Techniques', 'Learn advanced techniques for optimizing MySQL performance.'); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +CALL populate(0, 10000); +set session debug = '+d,sync_fts_trx_create'; +SET SESSION txsql_parallel_copy_ddl = ON; +ALTER TABLE articles ENGINE=innodb, algorithm=copy; +set session debug = '-d,sync_fts_trx_create'; +drop table articles; +drop procedure populate; diff --git a/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.ncdb b/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.ncdb new file mode 100644 index 00000000000..86d001bc510 --- /dev/null +++ b/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.ncdb @@ -0,0 +1,28 @@ +CREATE TABLE articles ( +id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, +title VARCHAR(200), +content TEXT, +FULLTEXT INDEX ft_index (title, content) WITH PARSER ngram +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +drop procedure if exists populate; +create procedure populate(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO articles (title, content) VALUES +('MySQL Full-Text Search', 'This article explains how to use full-text search in MySQL.'), +('Understanding MySQL', 'MySQL is a popular relational database management system.'), +('Advanced MySQL Techniques', 'Learn advanced techniques for optimizing MySQL performance.'); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +CALL populate(0, 10000); +set session debug = '+d,sync_fts_trx_create'; +SET SESSION txsql_parallel_copy_ddl = ON; +ALTER TABLE articles ENGINE=innodb, algorithm=copy; +set session debug = '-d,sync_fts_trx_create'; +drop table articles; +drop procedure populate; diff --git a/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.ncdb_pq b/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.ncdb_pq new file mode 100644 index 00000000000..86d001bc510 --- /dev/null +++ b/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.ncdb_pq @@ -0,0 +1,28 @@ +CREATE TABLE articles ( +id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, +title VARCHAR(200), +content TEXT, +FULLTEXT INDEX ft_index (title, content) WITH PARSER ngram +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +drop procedure if exists populate; +create procedure populate(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO articles (title, content) VALUES +('MySQL Full-Text Search', 'This article explains how to use full-text search in MySQL.'), +('Understanding MySQL', 'MySQL is a popular relational database management system.'), +('Advanced MySQL Techniques', 'Learn advanced techniques for optimizing MySQL performance.'); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +CALL populate(0, 10000); +set session debug = '+d,sync_fts_trx_create'; +SET SESSION txsql_parallel_copy_ddl = ON; +ALTER TABLE articles ENGINE=innodb, algorithm=copy; +set session debug = '-d,sync_fts_trx_create'; +drop table articles; +drop procedure populate; diff --git a/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.pq_csi b/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.pq_csi new file mode 100644 index 00000000000..86d001bc510 --- /dev/null +++ b/mysql-test/r/issue2284_fts_trx_create_crash_parallel_copy_ddl.pq_csi @@ -0,0 +1,28 @@ +CREATE TABLE articles ( +id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, +title VARCHAR(200), +content TEXT, +FULLTEXT INDEX ft_index (title, content) WITH PARSER ngram +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +drop procedure if exists populate; +create procedure populate(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO articles (title, content) VALUES +('MySQL Full-Text Search', 'This article explains how to use full-text search in MySQL.'), +('Understanding MySQL', 'MySQL is a popular relational database management system.'), +('Advanced MySQL Techniques', 'Learn advanced techniques for optimizing MySQL performance.'); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +CALL populate(0, 10000); +set session debug = '+d,sync_fts_trx_create'; +SET SESSION txsql_parallel_copy_ddl = ON; +ALTER TABLE articles ENGINE=innodb, algorithm=copy; +set session debug = '-d,sync_fts_trx_create'; +drop table articles; +drop procedure populate; diff --git a/mysql-test/r/parallel_copy_alter_table.result b/mysql-test/r/parallel_copy_alter_table.result index 15bbca0a657..ade221ce085 100644 Binary files a/mysql-test/r/parallel_copy_alter_table.result and b/mysql-test/r/parallel_copy_alter_table.result differ diff --git a/mysql-test/r/pcddl_trx_state_concurrency_issue3628.ncdb b/mysql-test/r/pcddl_trx_state_concurrency_issue3628.ncdb new file mode 100644 index 00000000000..e0e322c013d --- /dev/null +++ b/mysql-test/r/pcddl_trx_state_concurrency_issue3628.ncdb @@ -0,0 +1,21 @@ +SET SESSION txsql_parallel_copy_ddl=ON; +SET debug="+d,sync_row_mysql_handle_errors"; +CREATE TABLE t1(id int primary key, v int); +drop procedure if exists insert_t1; +create procedure insert_t1(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO t1 VALUES (i, i); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +CALL insert_t1(0, 20000); +UPDATE t1 SET v = 2 WHERE id = 9999; +ALTER TABLE t1 ADD UNIQUE INDEX k_1(v), algorithm=copy; +ERROR 23000: Can't write; duplicate key in table '#sql-394247_31' +DROP TABLE t1; +DROP PROCEDURE insert_t1; diff --git a/mysql-test/r/pcddl_trx_state_concurrency_issue3628.ncdb_pq b/mysql-test/r/pcddl_trx_state_concurrency_issue3628.ncdb_pq new file mode 100644 index 00000000000..a477e763cca --- /dev/null +++ b/mysql-test/r/pcddl_trx_state_concurrency_issue3628.ncdb_pq @@ -0,0 +1,21 @@ +SET SESSION txsql_parallel_copy_ddl=ON; +SET debug="+d,sync_row_mysql_handle_errors"; +CREATE TABLE t1(id int primary key, v int); +drop procedure if exists insert_t1; +create procedure insert_t1(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO t1 VALUES (i, i); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +CALL insert_t1(0, 20000); +UPDATE t1 SET v = 2 WHERE id = 9999; +ALTER TABLE t1 ADD UNIQUE INDEX k_1(v), algorithm=copy; +ERROR 23000: Can't write; duplicate key in table '#sql-395365_31' +DROP TABLE t1; +DROP PROCEDURE insert_t1; diff --git a/mysql-test/r/pcddl_trx_state_concurrency_issue3628.result b/mysql-test/r/pcddl_trx_state_concurrency_issue3628.result new file mode 100644 index 00000000000..9775f204e32 --- /dev/null +++ b/mysql-test/r/pcddl_trx_state_concurrency_issue3628.result @@ -0,0 +1,21 @@ +SET SESSION txsql_parallel_copy_ddl=ON; +SET debug="+d,sync_row_mysql_handle_errors"; +CREATE TABLE t1(id int primary key, v int); +drop procedure if exists insert_t1; +create procedure insert_t1(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO t1 VALUES (i, i); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +CALL insert_t1(0, 20000); +UPDATE t1 SET v = 2 WHERE id = 9999; +ALTER TABLE t1 ADD UNIQUE INDEX k_1(v), algorithm=copy; +ERROR 23000: Can't write; duplicate key in table '#sql-431ed_e' +DROP TABLE t1; +DROP PROCEDURE insert_t1; diff --git a/mysql-test/t/disable_parallel_copy_ddl_functional_index_issue3625.test b/mysql-test/t/disable_parallel_copy_ddl_functional_index_issue3625.test new file mode 100644 index 00000000000..9c098da34b1 --- /dev/null +++ b/mysql-test/t/disable_parallel_copy_ddl_functional_index_issue3625.test @@ -0,0 +1,20 @@ +SET SESSION txsql_parallel_copy_ddl=ON; + +CREATE TABLE t1 (fld1 INT, fld2 DATETIME NOT NULL) ENGINE= INNODB; + +INSERT INTO t1 VALUES(1, '2000-01-01'); +INSERT INTO t1 VALUES(2, '2001-01-01'); +INSERT INTO t1 VALUES(3, '2002-01-01'); +ALTER TABLE t1 ADD INDEX idx_sale_month ((MONTH(fld2))), ALGORITHM= COPY; + +--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err +--let SEARCH_PATTERN= Executing non-parallel copy DDL when txsql_parallel_copy_ddl=ON +--source include/search_pattern_in_file.inc + +ALTER TABLE t1 DROP INDEX idx_sale_month, ALGORITHM= COPY; + +--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err +--let SEARCH_PATTERN= \[TXSQL Parallel Copy DDL\] parallel_threads= +--source include/search_pattern_in_file.inc + +DROP TABLE t1; diff --git a/mysql-test/t/disable_parallel_copy_ddl_generated_column.test b/mysql-test/t/disable_parallel_copy_ddl_generated_column.test new file mode 100644 index 00000000000..d65efaaeb3a --- /dev/null +++ b/mysql-test/t/disable_parallel_copy_ddl_generated_column.test @@ -0,0 +1,35 @@ +# +# Verify that parallel copy DDL falls back to single-threaded copy when the +# target table contains a generated column. These expressions share a single +# Item tree across per-thread TABLE copies, evaluating them in parallel +# workers causes data races (e.g. Item_func_regexp::m_facade). +# + +SET SESSION txsql_parallel_copy_ddl=ON; + +--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err + +CREATE TABLE t1 ( + id INT PRIMARY KEY, + a INT, + b INT GENERATED ALWAYS AS (a + 1) VIRTUAL +) ENGINE=INNODB; + +INSERT INTO t1 (id, a) VALUES (1, 10), (2, 20), (3, 30); +ALTER TABLE t1 ADD COLUMN c INT, ALGORITHM=COPY; + +--let SEARCH_PATTERN= Executing non-parallel copy DDL when txsql_parallel_copy_ddl=ON +--source include/search_pattern_in_file.inc + +DROP TABLE t1; + +# Control: a plain table without any generated column must still take the +# parallel path. +CREATE TABLE t2 (id INT PRIMARY KEY, a INT) ENGINE=INNODB; +INSERT INTO t2 VALUES (1, 10), (2, 20), (3, 30); +ALTER TABLE t2 ADD COLUMN c INT, ALGORITHM=COPY; + +--let SEARCH_PATTERN= \[TXSQL Parallel Copy DDL\] parallel_threads= +--source include/search_pattern_in_file.inc + +DROP TABLE t2; diff --git a/mysql-test/t/issue2284_fts_trx_create_crash_parallel_copy_ddl.test b/mysql-test/t/issue2284_fts_trx_create_crash_parallel_copy_ddl.test new file mode 100644 index 00000000000..552c0e230f3 --- /dev/null +++ b/mysql-test/t/issue2284_fts_trx_create_crash_parallel_copy_ddl.test @@ -0,0 +1,39 @@ +--source include/have_debug.inc + +CONNECT (con1,localhost,root,,); + +CREATE TABLE articles ( + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + title VARCHAR(200), + content TEXT, + FULLTEXT INDEX ft_index (title, content) WITH PARSER ngram +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +delimiter |; +drop procedure if exists populate; +create procedure populate(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO articles (title, content) VALUES + ('MySQL Full-Text Search', 'This article explains how to use full-text search in MySQL.'), + ('Understanding MySQL', 'MySQL is a popular relational database management system.'), + ('Advanced MySQL Techniques', 'Learn advanced techniques for optimizing MySQL performance.'); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +delimiter ;| + +CALL populate(0, 10000); + +set session debug = '+d,sync_fts_trx_create'; +SET SESSION txsql_parallel_copy_ddl = ON; + +ALTER TABLE articles ENGINE=innodb, algorithm=copy; + +set session debug = '-d,sync_fts_trx_create'; +drop table articles; +drop procedure populate; diff --git a/mysql-test/t/parallel_copy_alter_table.test b/mysql-test/t/parallel_copy_alter_table.test index 35dd1d95fe2..8b1f5fbc466 100644 --- a/mysql-test/t/parallel_copy_alter_table.test +++ b/mysql-test/t/parallel_copy_alter_table.test @@ -116,7 +116,7 @@ drop table t1; --echo --echo ---echo #Case 11: parallel copy ddl doesn't support partition table now +--echo #Case 11: Test partition table CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL) PARTITION BY KEY (a) PARTITIONS 2; INSERT INTO t1 VALUES (0,1), (0,2); @@ -189,11 +189,11 @@ partition by range columns(a) partition p2 values less than ('c'), partition p3 values less than ('d')); insert into t1 values ('A'),('a'),('B'),('b'),('C'),('c'); -select * from t1 where a > 'B' collate latin1_bin; -select * from t1 where a <> 'B' collate latin1_bin; +select * from t1 where a > 'B' collate latin1_bin order by a; +select * from t1 where a <> 'B' collate latin1_bin order by a; alter table t1 remove partitioning; -select * from t1 where a > 'B' collate latin1_bin; -select * from t1 where a <> 'B' collate latin1_bin; +select * from t1 where a > 'B' collate latin1_bin order by a; +select * from t1 where a <> 'B' collate latin1_bin order by a; drop table t1; --echo @@ -367,7 +367,106 @@ drop table t1; --echo --echo ---echo #Case : test parallel copy ddl with a large amount of data +--echo #Case 25: #Test generated column +CREATE TABLE t (a int(11), b int(11), + c int(11) GENERATED ALWAYS AS (a+b) VIRTUAL, + d int(11) GENERATED ALWAYS AS (a+b) VIRTUAL); +INSERT INTO t(a,b) VALUES(1,2); +ALTER TABLE t DROP d, ADD e varchar(10); +ALTER TABLE t ADD d int, ADD f char(10) AS ('aaa'); +ALTER TABLE t CHANGE d dd int, CHANGE f ff varchar(10) AS ('bbb'); +ALTER TABLE t DROP c, DROP ff; +ALTER TABLE t ADD c int(11) as (a+b), ADD f varchar(10) as ('aaa'); +ALTER TABLE t CHANGE c c int(11) as (a), CHANGE f f varchar(10) as('bbb'); +ALTER TABLE t CHANGE c c int(11) as (a) after f; +ALTER TABLE t CHANGE b b int(11) after c; +DROP TABLE t; + +--echo +--echo +--echo #Case 26: #Added columns mixed with virtual GC and other columns +create table t1 (a int); +insert into t1 values(1); +alter table t1 add column (b int generated always as (a+1) virtual, c int); +DROP TABLE t1; + +--echo +--echo +--echo #Case 27: #Test generated column +CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + j), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p)); +INSERT INTO t VALUES(11, 22, DEFAULT, "AAA", 8, DEFAULT, "XXX", DEFAULT); +INSERT INTO t VALUES(1, 2, DEFAULT, "uuu", 9, DEFAULT, "uu", DEFAULT); +INSERT INTO t VALUES(3, 4, DEFAULT, "uooo", 1, DEFAULT, "umm", DEFAULT); +alter table t add x int, add xx int generated ALWAYS AS(x); +DROP TABLE t; + +--echo +--echo +--echo #Case 28: #Test change column to auto-inc column +CREATE TABLE `t2` ( + `a` int(11) NOT NULL, + `b` char(4) DEFAULT NULL, + `f` float DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `f` (`f`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + insert into t2 values(1,'rbr',0.834772); + ALTER TABLE test.t2 CHANGE a a INT UNSIGNED NOT NULL AUTO_INCREMENT; + INSERT INTO test.t2 VALUES (NULL,'TEST',RAND()); +DROP TABLE t2; + +--echo +--echo +--echo #Case 29: #Test auto-inc column under concurrency of DDL and DML + +delimiter |; +#Procedure for alter(DDL) +CREATE PROCEDURE test.sp2 (IN start BIGINT) +BEGIN +SET @idx =start; +WHILE (@idx > 0) DO +ALTER TABLE test.t1 ADD n2 BIGINT; +ALTER TABLE test.t1 DROP COLUMN n2; +SET @idx = @idx - 1; +END WHILE; +END| + +#Procedure for INSERT +CREATE PROCEDURE test.sp1 (IN start BIGINT) +BEGIN +SET @idx =start; +WHILE (@idx > 0) DO +INSERT INTO test.t1 (c2,c3) VALUES(repeat('q',10),@idx); +SET @idx = @idx - 1; +END WHILE; +END| + +delimiter ;| + +connect (con1,localhost,root,,); + +connection default; +SET SESSION txsql_parallel_copy_ddl=ON; +CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY, c2 TEXT(1024), c3 INT); +--send call test.sp2(30); + +connection con1; +--send call test.sp1(300); +--reap + +connection default; +--reap + +CHECK TABLE t1; +DROP TABLE t1; +DROP PROCEDURE test.sp1; +DROP PROCEDURE test.sp2; + +SET SESSION txsql_parallel_copy_ddl=ON; + +--echo +--echo +--echo #Case 30: test parallel copy ddl with a large amount of data CREATE TABLE t1 (c1 char(127) PRIMARY KEY, c2 int, c3 char(127)) ENGINE=INNODB; let row_count=5000; --disable_query_log @@ -400,4 +499,219 @@ ALTER TABLE t1 encryption='Y'; --let $count_after = query_get_value(SELECT COUNT(*) FROM t1 WHERE c2 < 4000, COUNT(*), 1) assert($count_before == $count_after); +--echo +--echo #Case : test raise error +--echo +DROP TABLE t1; +CREATE TABLE t1(a varchar(5)); +--let $row_count=5000 +--disable_query_log +while ($row_count) +{ + --eval INSERT INTO t1 VALUES ('kkk'); + dec $row_count; +} +--enable_query_log +--error 1292 +ALTER TABLE t1 MODIFY COLUMN a DATETIME NOT NULL, ALGORITHM=COPY; + +--echo +--echo #Case : test when innodb_parallel_read_threads = 1 +--echo +DROP TABLE t1; +CREATE TABLE t1(a INT, b INT); +INSERT INTO t1 VALUES(1, 10), (2, 20), (3, 30); +SET SESSION txsql_parallel_copy_ddl=ON; +SET SESSION innodb_parallel_read_threads=1; +ALTER TABLE t1 ENGINE=INNODB, ALGORITHM=COPY; +SELECT * FROM t1 ORDER BY a; + +--echo +--echo #Clear environment +--echo +DROP TABLE t1; + + +SET SESSION innodb_parallel_read_threads=16; + +--echo +--echo +--echo #Case 31: Test partition table with datetime +CREATE TABLE t1 (c1 INT, c2 DATETIME NOT NULL) PARTITION BY KEY(c1) PARTITIONS 4; +INSERT INTO t1 VALUES(1, '2000-01-01'); +INSERT INTO t1 VALUES(1001, '2001-01-01'); +INSERT INTO t1 VALUES(2001, '2002-01-01'); +ALTER TABLE t1 ADD COLUMN c3 DATETIME, ALGORITHM= COPY; +ALTER TABLE t1 MODIFY c2 DATETIME NOT NULL FIRST, ALGORITHM= COPY; +SELECT * FROM t1; +DROP TABLE t1; + +--echo +--echo +--echo #Case 32: Test partition table change column to different name +CREATE TABLE `t1` ( + `a` INT DEFAULT NULL, + `b` VARCHAR(30) DEFAULT NULL, + `c` DOUBLE DEFAULT NULL +) PARTITION BY KEY(a) PARTITIONS 3; +INSERT INTO t1 VALUES(1, 'abcd', 1.234); +ALTER TABLE t1 RENAME COLUMN b TO c, CHANGE COLUMN c d FLOAT; +SELECT * FROM t1; +DROP TABLE t1; + +--echo +--echo +--echo #Case 32: Test alter table engine=innodb +CREATE TABLE t1 ( + a int PRIMARY KEY, + b VARCHAR(6), + INDEX b3(b(3)) +) PARTITION BY KEY(a) PARTITIONS 4; +INSERT INTO t1 VALUES(1,'foo'),(2,'foobar'); +SELECT * FROM t1 WHERE b LIKE 'foob%'; +ALTER TABLE t1 ENGINE=INNODB, ALGORITHM=COPY; +SELECT * FROM t1 WHERE b LIKE 'foob%'; +DROP TABLE t1; + +--echo +--echo +--echo #Case 32: Test alter table subpartition +CREATE TABLE t1(a int primary key, b int) +PARTITION BY RANGE (a) +SUBPARTITION BY HASH (a) SUBPARTITIONS 2 +( + PARTITION p0 VALUES LESS THAN (10) + (SUBPARTITION sp0, + SUBPARTITION sp1), + PARTITION p1 VALUES LESS THAN (20) + (SUBPARTITION sp2, + SUBPARTITION sp3), + PARTITION p2 VALUES LESS THAN (30) + (SUBPARTITION sp4, + SUBPARTITION sp5) +); +delimiter |; +drop procedure if exists insert_t; +create procedure insert_t(in num int) +begin +declare i int default 0; +set autocommit=0; +repeat +insert into t1 values(i, i); +set i=i+1; +until i=num +end repeat; +commit; +set autocommit=1; +end | +delimiter ;| +CALL insert_t(29); +ALTER TABLE t1 ENGINE=INNODB, ALGORITHM=COPY; +DROP TABLE t1; + +--echo +--echo +--echo #Case 33: Test parallel copy ddl with a large amount of data with partition table +CREATE TABLE t1 (c1 char(127) PRIMARY KEY, c2 int, c3 char(127)) +PARTITION BY KEY(c1) PARTITIONS 4; +let row_count=5000; +--disable_query_log +while ($row_count) +{ + --let $c2=`select 1 + floor(rand()*10000 % 10000)` + --eval INSERT INTO t1 VALUES (LPAD($row_count, 127, 0), $c2, LPAD($row_count, 127, 0)); + dec $row_count; +} +--enable_query_log +--let $count_before = query_get_value(SELECT COUNT(*) FROM t1 WHERE c2 < 4000, COUNT(*), 1) + +set session innodb_parallel_read_threads=16; +ALTER TABLE t1 change column c2 c2 bigint, change column c3 c3 int, drop primary key, add index idx(c2); + +SHOW CREATE TABLE t1; + +--let $count_after = query_get_value(SELECT COUNT(*) FROM t1 WHERE c2 < 4000, COUNT(*), 1) +assert($count_before == $count_after); + +set session innodb_parallel_read_threads=8; +ALTER TABLE t1 change column c2 c2 char(10); + +ALTER TABLE t1 change column c2 c2 bigint; +--let $count_after = query_get_value(SELECT COUNT(*) FROM t1 WHERE c2 < 4000, COUNT(*), 1) +assert($count_before == $count_after); + +set session innodb_parallel_read_threads=5; +ALTER TABLE t1 encryption='Y'; +--let $count_after = query_get_value(SELECT COUNT(*) FROM t1 WHERE c2 < 4000, COUNT(*), 1) +assert($count_before == $count_after); + DROP TABLE t1; + +--echo +--echo +--echo #Case 33: Test foreign key +CREATE TABLE t1 (id BIGINT PRIMARY KEY, a VARCHAR(255)); +CREATE TABLE t2 (id BIGINT, fid BIGINT, b VARCHAR(255)); +INSERT INTO t1 VALUES(1, 'aaa'), (2, 'bbb'); +INSERT INTO t2 VALUES(1001, 1, 'abcde'), (1002, 2, 'efghi'); +ALTER TABLE t2 ADD FOREIGN KEY fk_t2_fid_t1_id (fid) REFERENCES t1 (id); +SELECT * FROM t2; +DROP TABLE t2; +CREATE TABLE t2 (id BIGINT, fid BIGINT, b VARCHAR(255)); +INSERT INTO t2 VALUES(1001, 1, 'abcde'), (1002, 3, 'efghi'); +--disable_result_log +--error 1452 +ALTER TABLE t2 ADD FOREIGN KEY fk_t2_fid_t1_id (fid) REFERENCES t1 (id); +--enable_result_log +DROP TABLE t2; +CREATE TABLE t2 (id BIGINT, fid BIGINT, b VARCHAR(255)) +PARTITION BY KEY (id) PARTITIONS 4; +INSERT INTO t2 VALUES(1001, 1, 'abcde'), (1002, 2, 'efghi'); +--error 1506 +ALTER TABLE t2 ADD FOREIGN KEY fk_t2_fid_t1_id (fid) REFERENCES t1 (id); +DROP TABLE t1, t2; + +--echo +--echo +--echo #Case 33: Checksum table +SET SESSION txsql_parallel_copy_ddl=OFF; +CREATE TABLE t1 (c1 char(127) PRIMARY KEY, c2 int, c3 char(127)) +PARTITION BY KEY(c1) PARTITIONS 4; +let row_count=5000; +--disable_query_log +while ($row_count) +{ + --let $c2=`select 1 + floor(rand()*10000 % 10000)` + --eval INSERT INTO t1 VALUES (LPAD($row_count, 127, 0), $c2, LPAD($row_count, 127, 0)); + dec $row_count; +} +--enable_query_log +CREATE TABLE t2 LIKE t1; +INSERT INTO t2 SELECT * FROM t1; + +ALTER TABLE t1 change column c2 c2 bigint, change column c3 c3 int, drop primary key, add index idx(c2); +--let $sum11 = query_get_value(CHECKSUM TABLE t1, Checksum, 1) +ALTER TABLE t1 change column c2 c2 char(10); +--let $sum12 = query_get_value(CHECKSUM TABLE t1, Checksum, 1) +ALTER TABLE t1 change column c2 c2 bigint; +--let $sum13 = query_get_value(CHECKSUM TABLE t1, Checksum, 1) +ALTER TABLE t1 encryption='Y'; +--let $sum14 = query_get_value(CHECKSUM TABLE t1, Checksum, 1) + +SET SESSION txsql_parallel_copy_ddl=ON; +SET SESSION innodb_parallel_read_threads=16; +ALTER TABLE t2 change column c2 c2 bigint, change column c3 c3 int, drop primary key, add index idx(c2); +--let $sum21 = query_get_value(CHECKSUM TABLE t2, Checksum, 1) +ALTER TABLE t2 change column c2 c2 char(10); +--let $sum22 = query_get_value(CHECKSUM TABLE t2, Checksum, 1) +ALTER TABLE t2 change column c2 c2 bigint; +--let $sum23 = query_get_value(CHECKSUM TABLE t2, Checksum, 1) +ALTER TABLE t2 encryption='Y'; +--let $sum24 = query_get_value(CHECKSUM TABLE t2, Checksum, 1) +assert($sum11 == $sum21); +assert($sum12 == $sum22); +assert($sum13 == $sum23); +assert($sum14 == $sum24); + +DROP TABLE t1, t2; +DROP PROCEDURE insert_t; diff --git a/mysql-test/t/pcddl_trx_state_concurrency_issue3628.test b/mysql-test/t/pcddl_trx_state_concurrency_issue3628.test new file mode 100644 index 00000000000..ed1e74459fa --- /dev/null +++ b/mysql-test/t/pcddl_trx_state_concurrency_issue3628.test @@ -0,0 +1,29 @@ +SET SESSION txsql_parallel_copy_ddl=ON; +SET debug="+d,sync_row_mysql_handle_errors"; +CREATE TABLE t1(id int primary key, v int); + +delimiter |; +drop procedure if exists insert_t1; +create procedure insert_t1(IN start INT, IN end INT) +begin +declare i int default start; +SET autocommit=0; +repeat +INSERT INTO t1 VALUES (i, i); +set i=i+1; +until i=end +end repeat; +SET autocommit=1; +end | +delimiter ;| + +CALL insert_t1(0, 20000); + +# Simulate duplicate key. +UPDATE t1 SET v = 2 WHERE id = 9999; + +--error 1022 +ALTER TABLE t1 ADD UNIQUE INDEX k_1(v), algorithm=copy; + +DROP TABLE t1; +DROP PROCEDURE insert_t1; diff --git a/mysys/dbug.cc b/mysys/dbug.cc index bbf4fde6ba2..b5d0214613b 100644 --- a/mysys/dbug.cc +++ b/mysys/dbug.cc @@ -1781,6 +1781,45 @@ int _db_keyword_(CODE_STATE *cs, const char *keyword, int strict) { return result; } +void parallel_reader_copy_dbug_keyword_list(CODE_STATE **dst_ptr, + CODE_STATE **src_ptr) { + if (*dst_ptr == nullptr || *src_ptr == nullptr) { + return; + } + + CODE_STATE *dst = *dst_ptr; + CODE_STATE *src = *src_ptr; + + if (dst->stack == &init_settings) { + PushState(dst); + assert(dst->stack->keywords == nullptr); + native_rw_rdlock(&THR_LOCK_init_settings); + + dst->stack->out_file = stderr; + dst->stack->functions = ListCopy(init_settings.functions); + dst->stack->p_functions = ListCopy(init_settings.p_functions); + dst->stack->processes = ListCopy(init_settings.processes); + + native_rw_unlock(&THR_LOCK_init_settings); + + dst->stack->keywords = ListCopy(src->stack->keywords); + dst->stack->flags |= DEBUG_ON; + } +} + +void parallel_reader_reset_dbug_keyword_list(CODE_STATE **cs_ptr) { + if (*cs_ptr == nullptr) { + return; + } + + CODE_STATE *cs = *cs_ptr; + + if (cs->stack != &init_settings) { + FreeState(cs, cs->stack, 1); + cs->stack= &init_settings; + } +} + /* * FUNCTION * diff --git a/sql/handler.h b/sql/handler.h index 5cb902537b7..946421d0f16 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -3608,7 +3608,7 @@ class Alter_inplace_info { class Alter_copy_info { public: - Alter_copy_info() : handler_ctx(nullptr) {} + Alter_copy_info() : handler_ctx(nullptr), fallback(false) {} ~Alter_copy_info() {} /** @@ -3618,6 +3618,9 @@ class Alter_copy_info { @see copy_alter_handler_ctx for information about object lifecycle. */ copy_alter_handler_ctx *handler_ctx; + + // Whether need fallback from parallel copy ddl to normal way. + bool fallback; }; struct HA_CHECK_OPT { @@ -6284,10 +6287,6 @@ class handler { ha_copy_alter_info, create, found); } - void ha_prepare_copy_alter(Alter_copy_info *ha_copy_alter_info) { - return prepare_copy_alter(ha_copy_alter_info); - } - /** Public function wrapping the actual handler call. Allows us to enforce asserts regardless of handler implementation. @@ -6430,11 +6429,6 @@ class handler { return 0; } - virtual void prepare_copy_alter( - Alter_copy_info *ha_copy_alter_info [[maybe_unused]]) { - return; - } - /** Commit or rollback the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the storage engine. diff --git a/sql/mysqld.cc b/sql/mysqld.cc index a34a2b2797c..8c415a25c8a 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1025,6 +1025,9 @@ ulonglong cdb_page_cache_cleaning_window = 16 * 1024 * 1024; bool cdb_page_cache_cleaning_redo = true; bool cdb_page_cache_cleaning_binlog = true; +PSI_mutex_key key_LOCK_push_warning; +PSI_mutex_key key_LOCK_internal_handler; + #define mysqld_charset &my_charset_latin1 #define mysqld_default_locale_name "en_US" @@ -4020,7 +4023,7 @@ void my_message_sql(uint error, const char *str, myf MyFlags) { assert(strncmp(str, "MyISAM table", 12) == 0); error = ER_UNKNOWN_ERROR; } else if (error == ER_SYNC_TIMEOUT ) { - /* TDSQL: In order to maintain compatibility, the error + /* TDSQL: In order to maintain compatibility, the error code must be the same as ER_XA_RBTIMEOUT. */ error = ER_XA_RBTIMEOUT; } @@ -4686,9 +4689,9 @@ SHOW_VAR com_status_vars[] = { (char*) offsetof(System_status_var, com_stat[(uint) SQLCOM_SHOW_CDB_SQL_FILTERS]), SHOW_LONG_STATUS, SHOW_SCOPE_ALL}, - {"show_cdb_outline_info", - (char*) offsetof(System_status_var, - com_stat[(uint) SQLCOM_SHOW_OUTLINE_INFO]), + {"show_cdb_outline_info", + (char*) offsetof(System_status_var, + com_stat[(uint) SQLCOM_SHOW_OUTLINE_INFO]), SHOW_LONG_STATUS, SHOW_SCOPE_ALL}, {"show_auto_stats_task_status", (char*) offsetof(System_status_var, @@ -4697,7 +4700,7 @@ SHOW_VAR com_status_vars[] = { {"show_auto_stats_node_status", (char*) offsetof(System_status_var, com_stat[(uint) SQLCOM_SHOW_STATS_NODE]), - SHOW_LONG_STATUS, SHOW_SCOPE_ALL}, + SHOW_LONG_STATUS, SHOW_SCOPE_ALL}, {"shutdown", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHUTDOWN]), SHOW_LONG_STATUS, SHOW_SCOPE_ALL}, @@ -12385,7 +12388,7 @@ static void delete_dictionary_tablespace() { dd::upgrade_57::Upgrade_status().remove(); } -static bool init_outline_builder_to_memory() +static bool init_outline_builder_to_memory() { THD *thd; bool return_val = false; @@ -12426,11 +12429,11 @@ static bool init_outline_builder_to_memory() strlen(get_field(&mem, table_list.table->field[2]))); op.m_outline_query.assign(get_field(&mem, table_list.table->field[3]), strlen(get_field(&mem, table_list.table->field[3]))); - if (cdb_outline_builder.construct_param_positions(thd, op)) + if (cdb_outline_builder.construct_param_positions(thd, op)) break; if (cdb_outline_loader.load_outline_info(digest_hash, op)) break; - } + } iterator.reset(); // table_list.table->m_needs_reopen = true; diff --git a/sql/mysqld.h b/sql/mysqld.h index f0b823691fe..c153c51e508 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -81,6 +81,9 @@ extern int mysql_admin_tool_set_priority(ulonglong os_thread_id, int priority); extern my_thread_os_id_t admin_listener_os_thread_id; extern bool admin_tool_valid; +extern PSI_mutex_key key_LOCK_push_warning; +extern PSI_mutex_key key_LOCK_internal_handler; + class Rpl_global_filter; class Rpl_acf_configuration_handler; class Source_IO_monitor; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index b419a3fcebf..c904730fc64 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -825,6 +825,8 @@ THD::THD(bool enable_plugins) mysql_mutex_init(key_LOCK_current_cond, &LOCK_current_cond, MY_MUTEX_INIT_FAST); mysql_cond_init(key_COND_thr_lock, &COND_thr_lock); + mysql_mutex_init(key_LOCK_push_warning, &LOCK_push_warning, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_internal_handler, &LOCK_internal_handler, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_thd_done, &m_thd_lock_done, MY_MUTEX_INIT_FAST); mysql_cond_init(key_COND_thd_done, &m_thd_stage_cond_commit_order); @@ -968,30 +970,63 @@ bool THD::set_db(const LEX_CSTRING &new_db) { } void THD::push_internal_handler(Internal_error_handler *handler) { + if (is_doing_parallel_copy_data) { + mysql_mutex_lock(&LOCK_internal_handler); + } + if (m_internal_handler) { handler->m_prev_internal_handler = m_internal_handler; m_internal_handler = handler; } else m_internal_handler = handler; + + if (is_doing_parallel_copy_data) { + mysql_mutex_unlock(&LOCK_internal_handler); + } } bool THD::handle_condition(uint sql_errno, const char *sqlstate, Sql_condition::enum_severity_level *level, const char *msg) { - if (!m_internal_handler) return false; + if (is_doing_parallel_copy_data) { + mysql_mutex_lock(&LOCK_internal_handler); + } + + if (!m_internal_handler) { + if (is_doing_parallel_copy_data) { + mysql_mutex_unlock(&LOCK_internal_handler); + } + return false; + } for (Internal_error_handler *error_handler = m_internal_handler; error_handler; error_handler = error_handler->m_prev_internal_handler) { - if (error_handler->handle_condition(this, sql_errno, sqlstate, level, msg)) + if (error_handler->handle_condition(this, sql_errno, sqlstate, level, msg)) { + if (is_doing_parallel_copy_data) { + mysql_mutex_unlock(&LOCK_internal_handler); + } return true; + } + } + if (is_doing_parallel_copy_data) { + mysql_mutex_unlock(&LOCK_internal_handler); } return false; } Internal_error_handler *THD::pop_internal_handler() { + if (is_doing_parallel_copy_data) { + mysql_mutex_lock(&LOCK_internal_handler); + } + assert(m_internal_handler != nullptr); Internal_error_handler *popped_handler = m_internal_handler; m_internal_handler = m_internal_handler->m_prev_internal_handler; + + if (is_doing_parallel_copy_data) { + mysql_mutex_unlock(&LOCK_internal_handler); + } + return popped_handler; } @@ -1068,9 +1103,20 @@ Sql_condition *THD::raise_condition(uint sql_errno, const char *sqlstate, const char *msg, bool fatal_error) { DBUG_TRACE; + DBUG_EXECUTE_IF("thd_raise_condition_block", sleep(2);); + + if (is_doing_parallel_copy_data) { + mysql_mutex_lock(&LOCK_push_warning); + } + if (!(variables.option_bits & OPTION_SQL_NOTES) && - (level == Sql_condition::SL_NOTE)) + (level == Sql_condition::SL_NOTE)) { + if (is_doing_parallel_copy_data) { + mysql_mutex_unlock(&LOCK_push_warning); + } return nullptr; + } + assert(sql_errno != 0); if (sql_errno == 0) /* Safety in release build */ @@ -1085,7 +1131,12 @@ Sql_condition *THD::raise_condition(uint sql_errno, const char *sqlstate, } MYSQL_LOG_ERROR(sql_errno, PSI_ERROR_OPERATION_RAISED); - if (handle_condition(sql_errno, sqlstate, &level, msg)) return nullptr; + if (handle_condition(sql_errno, sqlstate, &level, msg)) { + if (is_doing_parallel_copy_data) { + mysql_mutex_unlock(&LOCK_push_warning); + } + return nullptr; + } Diagnostics_area *da = get_stmt_da(); if (level == Sql_condition::SL_ERROR) { @@ -1119,6 +1170,9 @@ Sql_condition *THD::raise_condition(uint sql_errno, const char *sqlstate, sql_errno == ER_STD_BAD_ALLOC_ERROR))) { cond = da->push_warning(this, sql_errno, sqlstate, level, msg); } + if (is_doing_parallel_copy_data) { + mysql_mutex_unlock(&LOCK_push_warning); + } return cond; } @@ -1542,6 +1596,8 @@ THD::~THD() { mysql_mutex_destroy(&LOCK_thd_security_ctx); mysql_mutex_destroy(&LOCK_current_cond); mysql_mutex_destroy(&LOCK_group_replication_connection_mutex); + mysql_mutex_destroy(&LOCK_push_warning); + mysql_mutex_destroy(&LOCK_internal_handler); mysql_cond_destroy(&COND_thr_lock); mysql_mutex_destroy(&m_thd_lock_done); @@ -3871,3 +3927,6 @@ bool THD::can_delay_commit() const { } /* Changes from TXSQL end. */ + +// 定义 THD 类的静态成员变量 +thread_local uint32 THD::trx_error_state = 10; diff --git a/sql/sql_class.h b/sql/sql_class.h index 453773dff11..2c185304530 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1824,6 +1824,15 @@ class THD : public MDL_context_owner, */ mysql_cond_t COND_thr_lock; + public: + bool is_doing_parallel_copy_data = false; + + static thread_local uint32 trx_error_state; + + mysql_mutex_t LOCK_push_warning; + + mysql_mutex_t LOCK_internal_handler; + private: /** Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 47da062ac92..149a1448650 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -18666,6 +18666,17 @@ bool mysql_trans_commit_alter_copy_data(THD *thd) { return error; } +static bool check_if_table_has_functional_index(TABLE *to) { + for (uint i = 0; i < to->s->keys; ++i) { + const KEY &index = to->key_info[i]; + if (index.is_functional_index()) { + return true; + } + } + + return false; +} + /* In the following cases, we don't use parallel copy ddl: 1. Turn off txsql_parallel_copy_ddl; @@ -18678,6 +18689,7 @@ In the following cases, we don't use parallel copy ddl: latch, and during insert, it will do row_ins_check_foreign_constraints, which maybe try to acquire the same latch when the parent is in the same table. In this case, crash will happen. + 8. Table doesn't have functional indexes. Example, CREATE TABLE t3( @@ -18706,10 +18718,15 @@ static bool check_if_can_use_parallel_copy_ddl(THD *thd, TABLE *from, TABLE *to, to->file->table_type(), "InnoDB") == 0 && !alter_ctx->is_tmp_table() && order == nullptr && !is_auto_inc - && (!from->part_info && !to->part_info) - && table_def->foreign_keys()->empty() - && const_cast(old_table_def)->foreign_keys()->empty() - && !is_multi_value) { + && (table_def && table_def->foreign_keys()->empty()) + && (old_table_def && old_table_def->foreign_keys().empty()) + && !is_multi_value && !check_if_table_has_functional_index(to)) { + /* Generated columns and generated-default columns share a single + Item tree across per-thread TABLE copies, evaluating them in parallel + workers causes data races. Fall back to single-threaded copy. */ + if (to->s->vfields > 0 || to->s->gen_def_field_count > 0) { + return false; + } return true; } return res; @@ -18921,13 +18938,6 @@ static int copy_data_between_tables( if (check_if_can_use_parallel_copy_ddl(thd, from, to, alter_ctx, order, is_auto_inc, is_multi_value, table_def, old_table_def)) { - - to->file->ha_prepare_copy_alter(&ha_copy_alter_info); - - ha_copy_alter_info.handler_ctx->init(alter_ctx->new_db, alter_ctx->db, - alter_ctx->table_name, alter_ctx->tmp_name, - alter_ctx->get_path(), - alter_ctx->get_tmp_path()); if (!(error = iterator->Read())) { /* Return error if source table isn't empty. @@ -18944,17 +18954,40 @@ static int copy_data_between_tables( error = 1; goto err; } - } + ha_copy_alter_info.handler_ctx = new copy_alter_handler_ctx(); + ha_copy_alter_info.handler_ctx->init(alter_ctx->new_db, alter_ctx->db, + alter_ctx->table_name, alter_ctx->tmp_name, + alter_ctx->get_path(), + alter_ctx->get_tmp_path()); + + error = from->file->ha_parallel_copy_data_between_tables(from, to, table_def, + old_table_def, + &ha_copy_alter_info, + create, found_count); + + delete ha_copy_alter_info.handler_ctx; + + if (ha_copy_alter_info.fallback) { + if (iterator->Init()) { + error= 1; + goto err; + } + thd->get_stmt_da()->reset_current_row_for_condition(); + goto fallback; + } - error = from->file->ha_parallel_copy_data_between_tables(from, to, table_def, - old_table_def, - &ha_copy_alter_info, - create, found_count); - mysql_stage_set_work_completed(psi, found_count); - thd->get_stmt_da()->set_current_row_for_condition(found_count); + mysql_stage_set_work_completed(psi, found_count); + thd->get_stmt_da()->set_current_row_for_condition(found_count); + } } else { - while (!(error = iterator->Read())) { +fallback: + if (thd->variables.txsql_parallel_copy_ddl) { + sql_print_information( + "[TXSQL] Executing non-parallel copy DDL when " + "txsql_parallel_copy_ddl=ON."); + } + while (!(error = iterator->Read())) { if (thd->killed) { thd->send_kill_message(); error = 1; diff --git a/sql/sql_thd_api.cc b/sql/sql_thd_api.cc index ba2b7c51fe2..0c6c0042b65 100644 --- a/sql/sql_thd_api.cc +++ b/sql/sql_thd_api.cc @@ -331,6 +331,10 @@ static void set_thd_stage_info(MYSQL_THD thd, const PSI_stage_info *new_stage, const unsigned int calling_line) { if (thd == nullptr) thd = current_thd; + if (thd->is_doing_parallel_copy_data) { + return; + } + thd->enter_stage(new_stage, old_stage, calling_func, calling_file, calling_line); } diff --git a/sql/sql_thd_internal_api.cc b/sql/sql_thd_internal_api.cc index fbe7c2b751b..c388aa0070d 100644 --- a/sql/sql_thd_internal_api.cc +++ b/sql/sql_thd_internal_api.cc @@ -418,4 +418,29 @@ bool thd_is_unnested_single_table_stmt(const THD *thd) { thd->lex->current_query_block()->outer_query_block() == nullptr && select->get_table_list()->is_base_table() && select->leaf_table_count == 1); -} \ No newline at end of file +} + +bool thd_parallel_copy_ddl(THD* thd) { + if (thd == nullptr) return false; + return thd->variables.txsql_parallel_copy_ddl; +} + +void thd_start_parallel_copy_data(THD *thd) { + thd->is_doing_parallel_copy_data = true; +} + +void thd_end_parallel_copy_data(THD *thd) { + thd->is_doing_parallel_copy_data = false; +} + +bool thd_is_parallel_copy_data(THD *thd) { + return thd->is_doing_parallel_copy_data; +} + +uint32 thd_get_trx_error_state(THD *thd) { + return thd->trx_error_state; +} + +void thd_set_trx_error_state(THD *thd, uint32 trx_error_state) { + thd->trx_error_state = trx_error_state; +} diff --git a/sql/sql_thd_internal_api.h b/sql/sql_thd_internal_api.h index 86b59f7cb3b..8ab0c30a457 100644 --- a/sql/sql_thd_internal_api.h +++ b/sql/sql_thd_internal_api.h @@ -321,4 +321,15 @@ bool add_auto_statistics_task(const char* db_name, */ bool thd_is_unnested_single_table_stmt(const THD *thd); +bool thd_parallel_copy_ddl(THD* thd); + +void thd_start_parallel_copy_data(THD *thd); + +void thd_end_parallel_copy_data(THD *thd); + +bool thd_is_parallel_copy_data(THD *thd); + +uint32 thd_get_trx_error_state(THD *thd); + +void thd_set_trx_error_state(THD *thd, uint32 trx_error_state); #endif // SQL_THD_INTERNAL_API_INCLUDED diff --git a/storage/innobase/api/api0api.cc b/storage/innobase/api/api0api.cc index 7702e32e306..4c7f9d1694b 100644 --- a/storage/innobase/api/api0api.cc +++ b/storage/innobase/api/api0api.cc @@ -1030,7 +1030,7 @@ static inline ib_err_t ib_insert_row_with_lock_retry( row_ins_step(thr); - err = trx->error_state; + err = get_trx_error_state(trx); if (err != DB_SUCCESS) { que_thr_stop_for_mysql(thr); @@ -1336,7 +1336,7 @@ static inline ib_err_t ib_update_row_with_lock_retry( row_upd_step(thr); - err = trx->error_state; + err = get_trx_error_state(trx); if (err != DB_SUCCESS) { que_thr_stop_for_mysql(thr); @@ -1412,7 +1412,7 @@ static inline ib_err_t ib_execute_update_query_graph( } } else if (err == DB_RECORD_NOT_FOUND) { - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } trx->op_info = ""; diff --git a/storage/innobase/api/api0misc.cc b/storage/innobase/api/api0misc.cc index 5d7b0252dde..608b4bcabc8 100644 --- a/storage/innobase/api/api0misc.cc +++ b/storage/innobase/api/api0misc.cc @@ -66,11 +66,11 @@ bool ib_handle_errors(dberr_t *new_err, trx_t *trx, que_thr_t *thr, trx_savept_t *savept, bool is_sdi) { dberr_t err; handle_new_error: - err = trx->error_state; + err = get_trx_error_state(trx); ut_a(err != DB_SUCCESS); - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); switch (err) { case DB_LOCK_WAIT_TIMEOUT: @@ -97,7 +97,7 @@ bool ib_handle_errors(dberr_t *new_err, trx_t *trx, que_thr_t *thr, case DB_LOCK_WAIT: lock_wait_suspend_thread(thr); - if (trx->error_state != DB_SUCCESS) { + if (get_trx_error_state(trx) != DB_SUCCESS) { que_thr_stop_for_mysql(thr); goto handle_new_error; @@ -126,13 +126,13 @@ bool ib_handle_errors(dberr_t *new_err, trx_t *trx, que_thr_t *thr, ut_error; } - if (trx->error_state != DB_SUCCESS) { - *new_err = trx->error_state; + if (get_trx_error_state(trx) != DB_SUCCESS) { + *new_err = get_trx_error_state(trx); } else { *new_err = err; } - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); return false; } diff --git a/storage/innobase/ddl/ddl0ddl.cc b/storage/innobase/ddl/ddl0ddl.cc index 246cc2956c5..03965f24141 100644 --- a/storage/innobase/ddl/ddl0ddl.cc +++ b/storage/innobase/ddl/ddl0ddl.cc @@ -230,7 +230,7 @@ dict_index_t *create_index(trx_t *trx, dict_table_t *table, trx_is_strict(trx)); if (err != DB_SUCCESS) { - trx->error_state = err; + set_trx_error_state(trx, err); dict_sys_mutex_enter(); return nullptr; } @@ -248,7 +248,7 @@ dict_index_t *create_index(trx_t *trx, dict_table_t *table, fts_cache_index_cache_remove(table, index); } - trx->error_state = err; + set_trx_error_state(trx, err); return nullptr; } diff --git a/storage/innobase/ddl/ddl0loader.cc b/storage/innobase/ddl/ddl0loader.cc index 9446c9e6397..025b9d3d3e5 100644 --- a/storage/innobase/ddl/ddl0loader.cc +++ b/storage/innobase/ddl/ddl0loader.cc @@ -482,7 +482,7 @@ dberr_t Loader::build_all() noexcept { DBUG_EXECUTE_IF("ib_build_indexes_too_many_concurrent_trxs", err = DB_TOO_MANY_CONCURRENT_TRXS; - m_ctx.m_trx->error_state = err;); + set_trx_error_state(m_ctx.m_trx, err);); if (m_ctx.m_fts.m_ptr != nullptr) { /* Clean up FTS psort related resource */ diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index 53813c34d01..8f2a95c9dc2 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -199,7 +199,7 @@ static dberr_t dict_stats_exec_sql(pars_info_t *pinfo, const char *sql, DBUG_EXECUTE_IF( "stats_index_error", if (!trx_started) { err = DB_STATS_DO_NOT_EXIST; - trx->error_state = DB_STATS_DO_NOT_EXIST; + set_trx_error_state(trx, DB_STATS_DO_NOT_EXIST); }); if (!trx_started && err == DB_SUCCESS) { @@ -214,7 +214,7 @@ static dberr_t dict_stats_exec_sql(pars_info_t *pinfo, const char *sql, trx_rollback_to_savepoint(trx, nullptr); trx->dict_operation_lock_mode = 0; trx->op_info = ""; - ut_a(trx->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(trx) == DB_SUCCESS); } if (trx_started) { diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 3008ac05948..8a35cd26db3 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -29,6 +29,7 @@ this program; if not, write to the Free Software Foundation, Inc., ***********************************************************************/ #include +#include #include #include @@ -450,7 +451,7 @@ static bool fts_load_user_stopword( ib::warn(ER_IB_MSG_462) << "Lock wait timeout reading user" " stopword table. Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { ib::error(ER_IB_MSG_463) << "Error '" << ut_strerr(error) << "' while reading user stopword" @@ -1849,7 +1850,7 @@ static dict_table_t *fts_create_one_common_table(trx_t *trx, } if (error != DB_SUCCESS) { - trx->error_state = error; + set_trx_error_state(trx, error); new_table = nullptr; ib::warn(ER_IB_MSG_465) << "Failed to create FTS common table " << fts_table_name; @@ -2037,7 +2038,7 @@ static dict_table_t *fts_create_one_index_table(trx_t *trx, } if (error != DB_SUCCESS) { - trx->error_state = error; + set_trx_error_state(trx, error); new_table = nullptr; ib::warn(ER_IB_MSG_466) << "Failed to create FTS index table " << table_name; @@ -2639,7 +2640,12 @@ void fts_trx_add_op(trx_t *trx, dict_table_t *table, doc_id_t doc_id, fts_trx_table_t *stmt_ftt; if (!trx->fts_trx) { - trx->fts_trx = fts_trx_create(trx); + if (current_thd && thd_is_parallel_copy_data(current_thd)) { + std::call_once(*trx->fts_trx_create_once_flag, + [&trx]() { trx->fts_trx = fts_trx_create(trx); }); + } else { + trx->fts_trx = fts_trx_create(trx); + } } tran_ftt = fts_trx_init(trx, table, trx->fts_trx->savepoints); @@ -5012,7 +5018,7 @@ ulint fts_get_rows_count(fts_table_t *fts_table) /*!< in: fts table to read */ ib::warn(ER_IB_MSG_478) << "lock wait timeout reading" " FTS table. Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { ib::error(ER_IB_MSG_479) << "(" << ut_strerr(error) << ") while reading FTS table."; diff --git a/storage/innobase/fts/fts0opt.cc b/storage/innobase/fts/fts0opt.cc index 59148e11888..e8ced9ebfdc 100644 --- a/storage/innobase/fts/fts0opt.cc +++ b/storage/innobase/fts/fts0opt.cc @@ -527,7 +527,7 @@ dberr_t fts_index_fetch_nodes( ib::warn(ER_IB_MSG_486) << "lock wait timeout reading" " FTS index. Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { ib::error(ER_IB_MSG_487) << "(" << ut_strerr(error) << ") while reading FTS index."; @@ -832,7 +832,7 @@ static void fts_zip_deflate_end( deflateEnd(zip->zp); fts_zip_init(zip); - optim->trx->error_state = DB_SUCCESS; + set_trx_error_state(optim->trx, DB_SUCCESS); } else { ib::error(ER_IB_MSG_490) << "(" << ut_strerr(error) << ") while reading document."; @@ -1673,11 +1673,11 @@ static void fts_optimize_words( ib::warn(ER_IB_MSG_495) << "Lock wait timeout during optimize." " Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else if (error == DB_DEADLOCK) { ib::warn(ER_IB_MSG_496) << "Deadlock during optimize. Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { optim->done = true; /* Exit the loop. */ } diff --git a/storage/innobase/fts/fts0que.cc b/storage/innobase/fts/fts0que.cc index ae4bfe180cd..6cb265b5300 100644 --- a/storage/innobase/fts/fts0que.cc +++ b/storage/innobase/fts/fts0que.cc @@ -2018,7 +2018,7 @@ fts_query_find_term( ib::warn(ER_IB_MSG_506) << "lock wait timeout reading FTS" " index. Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { ib::error(ER_IB_MSG_507) << error << " while reading FTS index."; @@ -2135,7 +2135,7 @@ fts_query_total_docs_containing_term( ib::warn(ER_IB_MSG_508) << "lock wait timeout reading FTS" " index. Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { ib::error(ER_IB_MSG_509) << error << " while reading FTS index."; @@ -2216,7 +2216,7 @@ fts_query_terms_in_document( ib::warn(ER_IB_MSG_510) << "lock wait timeout reading FTS" " doc id table. Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { ib::error(ER_IB_MSG_511) << error << " while reading FTS" " doc id table."; diff --git a/storage/innobase/fts/fts0sql.cc b/storage/innobase/fts/fts0sql.cc index d68ec767fe7..a993add095f 100644 --- a/storage/innobase/fts/fts0sql.cc +++ b/storage/innobase/fts/fts0sql.cc @@ -256,7 +256,7 @@ dberr_t fts_eval_sql(trx_t *trx, /*!< in: transaction */ que_run_threads(thr); - return (trx->error_state); + return (get_trx_error_state(trx)); } /** Construct the column specification part of the SQL string for selecting the diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 8fb93dd7c96..950511d9b9e 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -470,8 +470,6 @@ class ha_innobase : public handler { Alter_copy_info *ha_copy_alter_info, List &create, ulong &found) override; - void prepare_copy_alter(Alter_copy_info *ha_copy_alter_info) override; - /** Commit or rollback the changes made during prepare_inplace_alter_table() and inplace_alter_table() inside the storage engine. Note that the allowed level of concurrency diff --git a/storage/innobase/handler/ha_innopart.h b/storage/innobase/handler/ha_innopart.h index 30a4e32fbec..9233a3f9efc 100644 --- a/storage/innobase/handler/ha_innopart.h +++ b/storage/innobase/handler/ha_innopart.h @@ -1177,5 +1177,10 @@ class ha_innopart : public ha_innobase, public: bool prepare_backquery(THD *thd, time_t t) override; + + int parallel_copy_data_between_tables(TABLE *from, TABLE *to, + dd::Table *new_dd_tab, const dd::Table *old_dd_tab, + Alter_copy_info *ha_copy_alter_info, + List &create, ulong &found) override; }; #endif /* ha_innopart_h */ diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 45000665368..bdecaf02390 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -344,8 +344,6 @@ struct ha_innobase_copy_ctx : public copy_alter_handler_ctx { struct ha_innobase_copy_ctx_t { mem_heap_t * copy_heap; - row_prebuilt_t * copy_prebuilt; - row_prebuilt_t * from_prebuilt; THD * copy_thd; @@ -356,12 +354,10 @@ struct ha_innobase_copy_ctx_t { TABLE * from_table, * to_table; - void init(dict_table_t * new_inno_table, dict_table_t *old_inno_table, - TABLE *from, TABLE *to, - row_prebuilt_t * prebuilt, row_prebuilt_t * old_prebuilt, - THD * thd, dd::Table *new_dd_tab, const dd::Table *old_dd_tab, - ha_innobase_copy_ctx *copy_ctx, List create) { - + void init(dict_table_t *old_inno_table, TABLE *from, TABLE *to, + row_prebuilt_t *old_prebuilt, THD *thd, dd::Table *new_dd_tab, + const dd::Table *old_dd_tab, copy_alter_handler_ctx *copy_ctx, + List create, bool & auto_increment_field_copied) { copy_heap = mem_heap_create(1024, UT_LOCATION_HERE); from_table = open_table_uncached(thd, copy_ctx->get_path(), copy_ctx->db, @@ -380,27 +376,20 @@ struct ha_innobase_copy_ctx_t { to_table->column_bitmaps_set_no_signal(&to_table->s->all_set, &to_table->s->all_set); - copy_prebuilt = row_create_prebuilt(new_inno_table, to->s->reclength); - - copy_prebuilt->default_rec = to->s->default_values; - ut_ad(copy_prebuilt->default_rec); - - /* Use same trx as original prebuilt. */ - copy_prebuilt->trx = prebuilt->trx; + from_prebuilt = nullptr; + if (old_inno_table) { + from_prebuilt = row_create_prebuilt(old_inno_table, from->s->reclength); + from_prebuilt->default_rec = from->s->default_values; + ut_ad(from_prebuilt->default_rec); - copy_prebuilt->m_mysql_table = to; + from_prebuilt->trx = old_prebuilt->trx; - build_copy_template(copy_prebuilt, true, to_table); + from_prebuilt->m_mysql_table = from; - from_prebuilt = row_create_prebuilt(old_inno_table, from->s->reclength); - from_prebuilt->default_rec = from->s->default_values; - ut_ad(from_prebuilt->default_rec); - - from_prebuilt->trx = old_prebuilt->trx; - - from_prebuilt->m_mysql_table = from; + build_copy_template(from_prebuilt, true, from_table); + } - build_copy_template(from_prebuilt, true, from_table); + to_table->next_number_field = to_table->found_next_number_field; copy_thd = thd; @@ -442,12 +431,17 @@ struct ha_innobase_copy_ctx_t { continue; } if (def->field) { - const char * cmp_name = (*ptr)->field_name; + if (*ptr == to_table->next_number_field) { + auto_increment_field_copied = true; + } + + const char *cmp_name = (*ptr)->field_name; if (def->change) { cmp_name = def->change; } for (Field **from_it = from_table->field; *from_it; from_it++) { - if (my_strcasecmp(system_charset_info, (*from_it)->field_name, cmp_name) == 0) { + if (my_strcasecmp(system_charset_info, (*from_it)->field_name, + cmp_name) == 0) { (copy_end++)->set(*ptr, *from_it); break; } @@ -471,10 +465,10 @@ struct ha_innobase_copy_ctx_t { mem_heap_free(copy_heap); /* Do not close the table. */ - copy_prebuilt->table = nullptr; - row_prebuilt_free(copy_prebuilt, false); - from_prebuilt->table = nullptr; - row_prebuilt_free(from_prebuilt, false); + if (from_prebuilt) { + from_prebuilt->table = nullptr; + row_prebuilt_free(from_prebuilt, false); + } destroy_array(copy, to_table->s->fields); @@ -1810,87 +1804,73 @@ void ha_innobase::parallel_scan_end(void *parallel_scan_ctx) { ut::delete_(parallel_reader); } -void ha_innobase::prepare_copy_alter(Alter_copy_info *ha_copy_alter_info) { - ha_copy_alter_info->handler_ctx = new (m_user_thd->mem_root) - ha_innobase_copy_ctx(m_prebuilt); - ha_innobase_copy_ctx *ctx [[maybe_unused]] = - static_cast(ha_copy_alter_info->handler_ctx); - assert(ctx); - if (m_prebuilt->mysql_template == nullptr) { - build_template(true); - } - row_get_prebuilt_insert_row(m_prebuilt); -} - /* @return error status (zero on success, HA_ERR_* error code on error) */ int ha_innobase::parallel_copy_data_between_tables( - TABLE *from, TABLE *to, dd::Table *new_dd_tab, - const dd::Table *old_dd_tab, - Alter_copy_info *ha_copy_alter_info, - List &create, ulong &found) { + TABLE *from, TABLE *to, dd::Table *new_dd_tab, const dd::Table *old_dd_tab, + Alter_copy_info *ha_copy_alter_info, List &create, + ulong &found) { dberr_t err = DB_SUCCESS; if (dict_table_is_discarded(m_prebuilt->table)) { return (HA_ERR_NO_SUCH_TABLE); } size_t num_threads; - THD * thd = current_thd; - mem_heap_t * heap = mem_heap_create(1024, UT_LOCATION_HERE); + THD *thd = current_thd; + mem_heap_t *heap = mem_heap_create(1024, UT_LOCATION_HERE); dict_index_t *clust_index = m_prebuilt->table->first_index(); + int constraint_err = 0; ha_innobase_copy_ctx *ctx = static_cast(ha_copy_alter_info->handler_ctx); - row_prebuilt_t * new_prebuilt = ctx->prebuilt; - auto trx = m_prebuilt->trx; - - innobase_register_trx(ht, ha_thd(), trx); - - trx_start_if_not_started_xa(trx, false, UT_LOCATION_HERE); - + trx_start_if_not_started_xa(trx, true, UT_LOCATION_HERE); trx_assign_read_view(trx); if (trx_is_interrupted(trx)) { mem_heap_free(heap); - ib::error(ER_IB_MSG_1004) << "Trx is interrupted, parallel copy data is stopped."; - return (true); + ib::error(ER_IB_MSG_1004) + << "Trx is interrupted, parallel copy data is stopped."; + return (DB_INTERRUPTED); } trx->op_info = "parallel copying data between tables"; - // all threads one trx and one que_thr_t. - // que_thr_t *thr = pars_complete_graph_for_exec(nullptr, trx, heap, m_prebuilt); - num_threads = thd_parallel_read_threads(m_prebuilt->trx->mysql_thd); - num_threads = - Parallel_reader::available_threads(num_threads, false); + num_threads = Parallel_reader::available_threads(num_threads, false); - if (num_threads == 0) { + if (num_threads <= 1) + { mem_heap_free(heap); - ib::error(ER_IB_MSG_1004) << "No enough parallel reader threads."; - return (true); + if (num_threads == 0) { + ib::warn() << "No enough parallel reader threads."; + } + ha_copy_alter_info->fallback = true; + return (DB_INTERRUPTED); } - sql_print_information("[TXSQL Parallel Copy DDL] parallel_threads=%u, "\ - "sql=%s.", num_threads, thd->query().str); + sql_print_information( + "[TXSQL Parallel Copy DDL] parallel_threads=%u, " + "sql=%s.", + num_threads, thd->query().str); + dict_table_t *old_inno_table = dd_table_open_on_id( + old_dd_tab->se_private_id(), thd, nullptr, false, true); - dict_table_t * new_inno_table = dd_table_open_on_id(new_dd_tab->se_private_id(), - thd, nullptr, false, true); - dict_table_t * old_inno_table = dd_table_open_on_id(old_dd_tab->se_private_id(), - thd, nullptr, false, true); - ha_innobase_copy_ctx_t ** ctx_array = ut::new_arr_withkey( - UT_NEW_THIS_FILE_PSI_KEY, ut::Count{num_threads}); + bool auto_increment_field_copied = 0; + + ha_innobase_copy_ctx_t **ctx_array = + ut::new_arr_withkey(UT_NEW_THIS_FILE_PSI_KEY, + ut::Count{num_threads}); for (size_t i = 0; i < num_threads; i++) { - ctx_array[i] = ut::new_withkey(UT_NEW_THIS_FILE_PSI_KEY); - ctx_array[i]->init(new_inno_table, old_inno_table, - from, to, new_prebuilt, m_prebuilt, - thd, new_dd_tab, old_dd_tab, ctx, create); + ctx_array[i] = + ut::new_withkey(UT_NEW_THIS_FILE_PSI_KEY); + ctx_array[i]->init(old_inno_table, from, to, m_prebuilt, thd, new_dd_tab, + old_dd_tab, ctx, create, auto_increment_field_copied); } Parallel_reader::Scan_range full_scan; @@ -1899,10 +1879,11 @@ int ha_innobase::parallel_copy_data_between_tables( std::atomic total_recs{0}; std::atomic global_err{DB_SUCCESS}; + const char *origin_stack = thd->thread_stack; + auto process_row = [&](const Parallel_reader::Ctx *ctx) { - dberr_t error = DB_SUCCESS; + int error; const rec_t *mrec = ctx->m_rec; - // row_ext_t *ext = nullptr; const size_t thread_id = ctx->thread_id(); char my_stack; thd->thread_stack = &my_stack; // remember where our stack is @@ -1916,9 +1897,8 @@ int ha_innobase::parallel_copy_data_between_tables( current_thd = thd; - mem_heap_t * row_heap = ctx_array[thread_id]->copy_heap; - row_prebuilt_t * from_prebuilt = ctx_array[thread_id]->from_prebuilt; - row_prebuilt_t * to_prebuilt = ctx_array[thread_id]->copy_prebuilt; + mem_heap_t *row_heap = ctx_array[thread_id]->copy_heap; + row_prebuilt_t *from_prebuilt = ctx_array[thread_id]->from_prebuilt; Copy_field *copy = ctx_array[thread_id]->copy; Copy_field *copy_end = ctx_array[thread_id]->copy_end; @@ -1926,8 +1906,8 @@ int ha_innobase::parallel_copy_data_between_tables( Field **gen_fields = ctx_array[thread_id]->gen_fields; Field **gen_fields_end = ctx_array[thread_id]->gen_fields_end; - TABLE * from_table = ctx_array[thread_id]->from_table; - TABLE * to_table = ctx_array[thread_id]->to_table; + TABLE *from_table = ctx_array[thread_id]->from_table; + TABLE *to_table = ctx_array[thread_id]->to_table; /* Conver rec_t to MySQL record */ @@ -1936,28 +1916,34 @@ int ha_innobase::parallel_copy_data_between_tables( rec_offs_init(offsets_); - offsets = rec_get_offsets(mrec, clust_index, offsets, - ULINT_UNDEFINED, UT_LOCATION_HERE, &row_heap); + offsets = rec_get_offsets(mrec, clust_index, offsets, ULINT_UNDEFINED, + UT_LOCATION_HERE, &row_heap); - byte * mysql_rec; + byte *mysql_rec; ulint bufsize = std::max(UNIV_PAGE_SIZE, from_prebuilt->mysql_row_len); mysql_rec = static_cast( ut::malloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, bufsize)); - if (!row_sel_store_mysql_rec(mysql_rec, from_prebuilt, mrec, - nullptr, true, clust_index, - clust_index, offsets, false, nullptr, - from_prebuilt->blob_heap)) { - ut::free(mysql_rec); - global_err.store(DB_ERROR); - return DB_ERROR; + if (!row_sel_store_mysql_rec(mysql_rec, from_prebuilt, mrec, nullptr, true, + clust_index, clust_index, offsets, false, + nullptr, from_prebuilt->blob_heap)) { + ut::free(mysql_rec); + global_err.store(DB_ERROR); + return DB_ERROR; } memcpy(from_table->record[0], mysql_rec, from_table->s->reclength); innobase_rec_reset(to_table); + if (to_table->next_number_field) { + if (auto_increment_field_copied) + to_table->autoinc_field_has_explicit_non_null_value = true; + else + to_table->next_number_field->reset(); + } + for (Copy_field *copy_ptr = copy; copy_ptr != copy_end; copy_ptr++) { copy_ptr->invoke_do_copy(); } @@ -1990,45 +1976,75 @@ int ha_innobase::parallel_copy_data_between_tables( } if (thd->is_killed()) { + thd->send_kill_message(); ut::free(mysql_rec); global_err.store(DB_ERROR); return DB_ERROR; } - error = row_insert_for_mysql((byte *)to_table->record[0], to_prebuilt); - int res_code = convert_error_code_to_mysql(error, 0, ha_thd()); - if (res_code) { - if (!to_table->file->is_ignorable_error(res_code)) { + error = to_table->file->ha_write_row(to_table->record[0]); + + to_table->autoinc_field_has_explicit_non_null_value = false; + + if (error) { + if (!to_table->file->is_ignorable_error(error)) { /* Not a duplicate key error. */ - to_table->file->print_error(res_code, MYF(0)); + to_table->file->print_error(error, MYF(0)); } else { /* Report duplicate key error. */ - uint key_nr = to_table->file->get_dup_key(res_code); + uint key_nr = to_table->file->get_dup_key(error); if ((int)key_nr >= 0) { const char *err_msg = ER_THD(thd, ER_DUP_ENTRY_WITH_KEY_NAME); - if (key_nr == 0 && (to_table->key_info[0].key_part[0].field->is_flag_set( - AUTO_INCREMENT_FLAG))) + if (key_nr == 0 && + (to_table->key_info[0].key_part[0].field->is_flag_set( + AUTO_INCREMENT_FLAG))) err_msg = ER_THD(thd, ER_DUP_ENTRY_AUTOINCREMENT_CASE); print_keydup_error( - to_table, key_nr == MAX_KEY ? nullptr : &to_table->key_info[key_nr], err_msg, - MYF(0), from_table->s->table_name.str); + to_table, + key_nr == MAX_KEY ? nullptr : &to_table->key_info[key_nr], + err_msg, MYF(0), from_table->s->table_name.str); } else - to_table->file->print_error(res_code, MYF(0)); + to_table->file->print_error(error, MYF(0)); } } ut::free(mysql_rec); total_recs++; - return error; + if (error) + return DB_ERROR; + else + return DB_SUCCESS; }; + +#ifndef NDEBUG + CODE_STATE **thread_var_dbug = my_thread_var_dbug(); + + reader.set_start_callback( + [thread_var_dbug](Parallel_reader::Thread_ctx *thread_ctx) -> dberr_t { + parallel_reader_copy_dbug_keyword_list(my_thread_var_dbug(), + thread_var_dbug); + return DB_SUCCESS; + }); + + reader.set_finish_callback( + [](Parallel_reader::Thread_ctx *thread_ctx) -> dberr_t { + parallel_reader_reset_dbug_keyword_list(my_thread_var_dbug()); + return DB_SUCCESS; + }); +#endif /* !NDEBUG */ + err = reader.add_scan(trx, config, process_row); + thd_start_parallel_copy_data(thd); + if (err == DB_SUCCESS) { err = reader.run(num_threads); } + thd_end_parallel_copy_data(thd); + thd->thread_stack = origin_stack; + found = total_recs.load(); - dd_table_close(new_inno_table, thd, nullptr, false); dd_table_close(old_inno_table, thd, nullptr, false); if (ctx_array) { @@ -2043,10 +2059,9 @@ int ha_innobase::parallel_copy_data_between_tables( trx->op_info = ""; if (constraint_err) return constraint_err; - return (convert_error_code_to_mysql(err, 0, ha_thd())); + return (convert_error_code_to_mysql(err, 0, thd)); } - bool ha_innobase::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, const dd::Table *old_dd_tab @@ -5451,7 +5466,7 @@ template add_key_nums[a] = index_defs[a].m_key_number; if (!ctx->add_index[a]) { - error = ctx->trx->error_state; + error = get_trx_error_state(ctx->trx); assert(error != DB_SUCCESS); goto error_handling; } @@ -5664,7 +5679,7 @@ template error_handled: ctx->prebuilt->trx->error_index = nullptr; - ctx->trx->error_state = DB_SUCCESS; + set_trx_error_state(ctx->trx, DB_SUCCESS); if (!dict_locked) { row_mysql_lock_data_dictionary(ctx->prebuilt->trx, UT_LOCATION_HERE); @@ -6894,7 +6909,7 @@ bool ha_innobase::inplace_alter_table_impl(TABLE *altered_table, /* prebuilt->table->n_ref_count can be anything here, given that we hold at most a shared lock on the table. */ m_prebuilt->trx->error_index = nullptr; - ctx->trx->error_state = DB_SUCCESS; + set_trx_error_state(ctx->trx, DB_SUCCESS); return true; }; @@ -7323,7 +7338,7 @@ but do not touch the data dictionary cache. } DBUG_EXECUTE_IF("ib_drop_foreign_error", my_error_innodb(DB_OUT_OF_FILE_SPACE, table_name, 0); - trx->error_state = DB_SUCCESS; return true;); + set_trx_error_state(trx, DB_SUCCESS); return true;); return false; } @@ -7611,7 +7626,7 @@ when rebuilding the table. } DBUG_EXECUTE_IF("ib_rename_column_error", my_error_innodb(DB_OUT_OF_FILE_SPACE, table_name, 0); - trx->error_state = DB_SUCCESS; trx->op_info = ""; + set_trx_error_state(trx, DB_SUCCESS); trx->op_info = ""; return true;); DBUG_EXECUTE_IF("ib_ddl_crash_before_rename", DBUG_SUICIDE();); @@ -7762,17 +7777,17 @@ the table. DBUG_EXECUTE_IF("ib_rename_column_error", my_error_innodb(DB_OUT_OF_FILE_SPACE, table_name, 0); - trx->error_state = DB_SUCCESS; trx->op_info = ""; + set_trx_error_state(trx, DB_SUCCESS); trx->op_info = ""; return true;); DBUG_EXECUTE_IF("ib_resize_column_error", my_error_innodb(DB_OUT_OF_FILE_SPACE, table_name, 0); - trx->error_state = DB_SUCCESS; trx->op_info = ""; + set_trx_error_state(trx, DB_SUCCESS); trx->op_info = ""; return true;); DBUG_EXECUTE_IF( "ib_rename_index_fail1", my_error_innodb(DB_DEADLOCK, table_name, 0); - trx->error_state = DB_SUCCESS; trx->op_info = ""; return true;); + set_trx_error_state(trx, DB_SUCCESS); trx->op_info = ""; return true;); return false; } @@ -10899,6 +10914,183 @@ enum_alter_inplace_result ha_innopart::check_if_supported_inplace_alter( ha_alter_info); } +int ha_innopart::parallel_copy_data_between_tables( + TABLE *from, TABLE *to, dd::Table *new_dd_tab, const dd::Table *old_dd_tab, + Alter_copy_info *ha_copy_alter_info, List &create, + ulong &found) { + + if (dict_table_is_discarded(m_prebuilt->table)) { + return (HA_ERR_NO_SUCH_TABLE); + } + + int ret = 0; + THD *thd = current_thd; + copy_alter_handler_ctx *ctx = ha_copy_alter_info->handler_ctx; + + void *scan_ctx; + size_t num_threads; + + if ((ret = parallel_scan_init(scan_ctx, &num_threads, true))) { + return ret; + } + + sql_print_information( + "[TXSQL] parallel_threads=%u, " + "sql=%s.", + num_threads, thd->query().str); + + bool auto_increment_field_copied = 0; + + ha_innobase_copy_ctx_t **ctx_array = + ut::new_arr_withkey(UT_NEW_THIS_FILE_PSI_KEY, + ut::Count{num_threads}); + + for (size_t i = 0; i < num_threads; i++) { + ctx_array[i] = + ut::new_withkey(UT_NEW_THIS_FILE_PSI_KEY); + ctx_array[i]->init(nullptr, from, to, m_prebuilt, thd, new_dd_tab, + old_dd_tab, ctx, create, auto_increment_field_copied); + } + + Parallel_reader_adapter::Init_fn init_fn = + [&thd](void *cookie, ulong ncols, ulong row_len, const ulong *col_offsets, + const ulong *null_byte_offsets, + const ulong *null_bitmasks) -> bool { + current_thd = thd; + return false; + }; + + std::atomic total_recs{0}; + + const char *origin_stack = thd->thread_stack; + + Parallel_reader_adapter::Load_fn load_fn = + [&auto_increment_field_copied, &total_recs](void *cookie, uint nrows, void *rowdata, + uint64_t partition_id) -> bool { + int error; + + THD *thd = current_thd; + char my_stack; + thd->thread_stack = &my_stack; // remember where our stack is + + ha_innobase_copy_ctx_t *ctx = static_cast(cookie); + + Copy_field *copy = ctx->copy; + Copy_field *copy_end = ctx->copy_end; + + Field **gen_fields = ctx->gen_fields; + Field **gen_fields_end = ctx->gen_fields_end; + + TABLE *from_table = ctx->from_table; + TABLE *to_table = ctx->to_table; + + byte *buffer = static_cast(rowdata); + + for (uint i = 0; i < nrows; i++) { + byte *mysql_rec = buffer + from_table->s->reclength * i; + + memcpy(from_table->record[0], mysql_rec, from_table->s->reclength); + + innobase_rec_reset(to_table); + + if (to_table->next_number_field) { + if (auto_increment_field_copied) + to_table->autoinc_field_has_explicit_non_null_value = true; + else + to_table->next_number_field->reset(); + } + + for (Copy_field *copy_ptr = copy; copy_ptr != copy_end; copy_ptr++) { + copy_ptr->invoke_do_copy(); + } + + if (thd->is_error()) { + return true; + } + + for (auto ptr = gen_fields; ptr != gen_fields_end; ptr++) { + Item *expr_item; + if ((*ptr)->is_gcol()) { + expr_item = (*ptr)->gcol_info->expr_item; + } else { + assert((*ptr)->has_insert_default_general_value_expression()); + expr_item = (*ptr)->m_default_val_expr->expr_item; + } + expr_item->save_in_field(*ptr, false); + if (thd->is_error()) { + return true; + } + } + // store the check constraint result error code + if (invoke_table_check_constraints(thd, to_table)) { + return true; + } + + if (thd->is_killed()) { + thd->send_kill_message(); + return true; + } + + error = to_table->file->ha_write_row(to_table->record[0]); + + to_table->autoinc_field_has_explicit_non_null_value = false; + + if (error) { + if (!to_table->file->is_ignorable_error(error)) { + /* Not a duplicate key error. */ + to_table->file->print_error(error, MYF(0)); + } else { + /* Report duplicate key error. */ + uint key_nr = to_table->file->get_dup_key(error); + if ((int)key_nr >= 0) { + const char *err_msg = ER_THD(thd, ER_DUP_ENTRY_WITH_KEY_NAME); + if (key_nr == 0 && + (to_table->key_info[0].key_part[0].field->is_flag_set( + AUTO_INCREMENT_FLAG))) + err_msg = ER_THD(thd, ER_DUP_ENTRY_AUTOINCREMENT_CASE); + print_keydup_error( + to_table, + key_nr == MAX_KEY ? nullptr : &to_table->key_info[key_nr], + err_msg, MYF(0), from_table->s->table_name.str); + } else + to_table->file->print_error(error, MYF(0)); + } + return true; + } + + total_recs++; + } + + return false; + }; + + Parallel_reader_adapter::End_fn end_fn = [](void *cookie) {}; + + thd_start_parallel_copy_data(thd); + + if ((ret = parallel_scan(scan_ctx, reinterpret_cast(ctx_array), init_fn, load_fn, end_fn))) { + goto error; + } + + found = total_recs.load(); + +error: + thd_end_parallel_copy_data(thd); + thd->thread_stack = origin_stack; + parallel_scan_end(scan_ctx); + + if (ctx_array) { + for (size_t i = 0; i < num_threads; i++) { + ctx_array[i]->destroy(); + ut::delete_(ctx_array[i]); + } + ut::delete_arr(ctx_array); + ctx_array = nullptr; + } + + return ret; +} + /** Prepare in-place ALTER for table. Allows InnoDB to update internal structures with concurrent writes blocked (provided that check_if_supported_inplace_alter() diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index 73602efa129..a414e5eb96d 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -3106,7 +3106,7 @@ static dberr_t i_s_fts_index_table_fill_selected( ib::warn(ER_IB_MSG_601) << "Lock wait timeout reading" " FTS index. Retrying!"; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { ib::error(ER_IB_MSG_602) << "Error occurred while reading" " FTS index: " diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index ba461d6559c..48a003dc4b0 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -56,6 +56,8 @@ this program; if not, write to the Free Software Foundation, Inc., #include "srv0srv.h" #include "dict0mem.h" +#include "sql/current_thd.h" +#include "sql_thd_internal_api.h" // Forward declaration struct mtr_t; @@ -763,7 +765,9 @@ struct trx_t { Therefore in innobase_kill_connection. We don't increment this counter via TrxInInnoDB. */ - uint32_t in_depth; /*!< Track nested TrxInInnoDB + /* [TXSQL Parallel Copy DDL] modify this member into an atomic one + since there are multi threads that will modify it. */ + std::atomic in_depth; /*!< Track nested TrxInInnoDB count */ uint32_t in_innodb; /*!< if the thread is executing @@ -1107,6 +1111,7 @@ struct trx_t { /*------------------------------*/ uint32_t flush_tables; /*!< if "covering" the FLUSH TABLES", count of tables being flushed. */ + std::once_flag *fts_trx_create_once_flag; /*------------------------------*/ bool internal; /*!< true if it is a system/internal @@ -1122,7 +1127,7 @@ struct trx_t { const char *start_file; /*!< Filename where it was started */ #endif /* UNIV_DEBUG */ - std::atomic n_ref; /*!< Count of references, protected + std::atomic n_ref; /*!< Count of references, protected by trx_t::mutex. We can't release the locks nor commit the transaction until this reference is 0. We can change @@ -1204,7 +1209,7 @@ struct trx_t { @return true iff in this transaction's isolation level locks on records which do not match the WHERE clause are released */ bool releases_non_matching_rows() const { return skip_gap_locks(); } - + inline uint64_t get_hash_val() const { return (reinterpret_cast(this)) >> 4; } @@ -1666,6 +1671,22 @@ class TrxInInnoDB { trx_t *m_trx; }; +static inline void set_trx_error_state(trx_t *trx, dberr_t error_state) { + if (UNIV_UNLIKELY(current_thd && thd_is_parallel_copy_data(current_thd))) { + thd_set_trx_error_state(current_thd, static_cast(error_state)); + } else { + trx->error_state = error_state; + } +} + +static inline dberr_t get_trx_error_state(const trx_t *trx) { + if (UNIV_UNLIKELY(current_thd && thd_is_parallel_copy_data(current_thd))) { + return (dberr_t)thd_get_trx_error_state(current_thd); + } else { + return trx->error_state; + } +} + /** Check if transaction is internal XA transaction @param[in] trx transaction @return true, iff internal XA transaction. */ diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index eee2853ca03..c0f94bceb94 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -2234,7 +2234,7 @@ static const lock_t *lock_rec_has_to_wait_for_granted( for (size_t i = new_granted_index; i < granted.size(); ++i) { const auto granted_lock = granted[i]; - ut_ad(granted_lock->trx->error_state != DB_DEADLOCK); + ut_ad(get_trx_error_state(granted_lock->trx) != DB_DEADLOCK); ut_ad(!granted_lock->trx->lock.was_chosen_as_deadlock_victim); if (lock_has_to_wait(wait_lock, granted_lock)) { @@ -2307,7 +2307,7 @@ static void lock_rec_grant_by_heap_no(lock_t *in_lock, ulint heap_no) { } ut_d(seen_waiting_lock = true); const auto trx = lock->trx; - if (trx->error_state == DB_DEADLOCK || + if (get_trx_error_state(trx) == DB_DEADLOCK || trx->lock.was_chosen_as_deadlock_victim) { return (true); } @@ -4387,7 +4387,7 @@ dberr_t lock_table_for_trx(dict_table_t *table, trx_t *trx, err = lock_table(0, table, mode, thr); - trx->error_state = err; + set_trx_error_state(trx, err); if (err == DB_SUCCESS) { que_thr_stop_for_mysql_no_error(thr, trx); diff --git a/storage/innobase/lock/lock0wait.cc b/storage/innobase/lock/lock0wait.cc index 51956e36988..bd0e0a8ad90 100644 --- a/storage/innobase/lock/lock0wait.cc +++ b/storage/innobase/lock/lock0wait.cc @@ -266,7 +266,7 @@ lock_wait_in_hot_row_update_queue(que_thr_t *thr) trx_mutex_enter(trx); - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); slot = lock_wait_table_reserve_slot(thr, std::chrono::seconds{100000000}); @@ -342,7 +342,7 @@ lock_wait_in_hot_row_update_queue(que_thr_t *thr) trx->hot_update_status = HOT_UPDATE_STATUS_RUNNING; trx_mutex_exit(trx); if (trx_is_interrupted(trx)) { - trx->error_state = DB_INTERRUPTED; + set_trx_error_state(trx, DB_INTERRUPTED); } } @@ -369,7 +369,7 @@ void lock_wait_suspend_thread(que_thr_t *thr) { trx_mutex_enter(trx); - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); if (thr->state == QUE_THR_RUNNING) { ut_ad(thr->is_active); @@ -378,7 +378,7 @@ void lock_wait_suspend_thread(que_thr_t *thr) { was chosen as a deadlock victim: no need to suspend */ if (trx->lock.was_chosen_as_deadlock_victim) { - trx->error_state = DB_DEADLOCK; + set_trx_error_state(trx, DB_DEADLOCK); trx->lock.was_chosen_as_deadlock_victim = false; ut_d(trx->lock.in_rollback = true); @@ -492,17 +492,17 @@ void lock_wait_suspend_thread(que_thr_t *thr) { } /* The transaction is chosen as deadlock victim during sleep. */ - if (trx->error_state == DB_DEADLOCK) { + if (get_trx_error_state(trx) == DB_DEADLOCK) { ut_d(trx->lock.in_rollback = true); return; } - if (trx->error_state == DB_LOCK_WAIT_TIMEOUT) { + if (get_trx_error_state(trx) == DB_LOCK_WAIT_TIMEOUT) { MONITOR_INC(MONITOR_TIMEOUT); } if (trx_is_interrupted(trx)) { - trx->error_state = DB_INTERRUPTED; + set_trx_error_state(trx, DB_INTERRUPTED); } } @@ -561,7 +561,7 @@ static void lock_wait_release_thread_if_suspended(que_thr_t *thr) { if (thr->slot != nullptr && thr->slot->in_use && thr->slot->thr == thr) { if (trx->lock.was_chosen_as_deadlock_victim) { - trx->error_state = DB_DEADLOCK; + set_trx_error_state(trx, DB_DEADLOCK); trx->lock.was_chosen_as_deadlock_victim = false; ut_d(trx->lock.in_rollback = true); @@ -636,8 +636,8 @@ static void lock_wait_try_cancel(trx_t *trx, bool timeout) { current query. We set error_state to DB_DEADLOCK only: 1) before the transaction reserves a slot. But, we know it's in a slot. 2) when wait_lock is already set to nullptr. But, it's not nullptr. */ - ut_ad(trx->error_state != DB_DEADLOCK); - trx->error_state = DB_LOCK_WAIT_TIMEOUT; + ut_ad(get_trx_error_state(trx) != DB_DEADLOCK); + set_trx_error_state(trx, DB_LOCK_WAIT_TIMEOUT); /* This flag can't be set, as we always call the lock_cancel_waiting_and_release() immediately after setting it, which either prevents the trx from going to sleep or resets the wait_lock, and diff --git a/storage/innobase/que/que0que.cc b/storage/innobase/que/que0que.cc index 3a626ea6936..51ade2b0361 100644 --- a/storage/innobase/que/que0que.cc +++ b/storage/innobase/que/que0que.cc @@ -603,8 +603,8 @@ bool que_thr_stop(que_thr_t *thr) { trx->lock.wait_thr = thr; thr->state = QUE_THR_LOCK_WAIT; - } else if (trx->error_state != DB_SUCCESS && - trx->error_state != DB_LOCK_WAIT) { + } else if (get_trx_error_state(trx) != DB_SUCCESS && + get_trx_error_state(trx) != DB_LOCK_WAIT) { /* Error handling built for the MySQL interface */ thr->state = QUE_THR_COMPLETED; @@ -662,7 +662,7 @@ static void que_thr_dec_refer_count( in this case we have to do it here, otherwise nobody does it. */ - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); *next_thr = thr; @@ -692,8 +692,8 @@ void que_thr_stop_for_mysql(que_thr_t *thr) /*!< in: query thread */ trx_mutex_enter(trx); if (thr->state == QUE_THR_RUNNING) { - if (trx->error_state != DB_SUCCESS && trx->error_state != DB_LOCK_WAIT && - trx->error_state != DB_LOCK_WAIT_HOT_ROW_UPDATE) { + if (get_trx_error_state(trx) != DB_SUCCESS && get_trx_error_state(trx) != DB_LOCK_WAIT && + get_trx_error_state(trx) != DB_LOCK_WAIT_HOT_ROW_UPDATE) { /* Error handling built for the MySQL interface */ thr->state = QUE_THR_COMPLETED; } else { @@ -708,7 +708,7 @@ void que_thr_stop_for_mysql(que_thr_t *thr) /*!< in: query thread */ } ut_ad(thr->is_active == true); - ut_ad(trx->lock.n_active_thrs == 1); + ut_ad(thd_parallel_copy_ddl(trx->mysql_thd) || trx->lock.n_active_thrs == 1); ut_ad(thr->graph->n_active_thrs == 1); thr->is_active = false; @@ -746,7 +746,7 @@ void que_thr_move_to_run_state_for_mysql( void que_thr_stop_for_mysql_no_error(que_thr_t *thr, trx_t *trx) { ut_ad(thr->state == QUE_THR_RUNNING); ut_ad(thr->is_active == true); - // ut_ad(trx->lock.n_active_thrs == 1); + ut_ad(thd_parallel_copy_ddl(trx->mysql_thd) || trx->lock.n_active_thrs == 1); ut_ad(thr->graph->n_active_thrs == 1); ut_a(thr->magic_n == QUE_THR_MAGIC_N); @@ -849,7 +849,7 @@ static inline que_thr_t *que_thr_step(que_thr_t *thr) /*!< in: query thread */ trx = thr_get_trx(thr); ut_ad(thr->state == QUE_THR_RUNNING); - ut_a(trx->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(trx) == DB_SUCCESS); thr->resource++; @@ -931,7 +931,7 @@ static inline que_thr_t *que_thr_step(que_thr_t *thr) /*!< in: query thread */ } if (thr) { - ut_a(thr_get_trx(thr)->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(thr_get_trx(thr)) == DB_SUCCESS); } return (thr); @@ -944,7 +944,7 @@ static void que_run_threads_low(que_thr_t *thr) /*!< in: query thread */ que_thr_t *next_thr; ut_ad(thr->state == QUE_THR_RUNNING); - ut_a(thr_get_trx(thr)->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(thr_get_trx(thr)) == DB_SUCCESS); ut_ad(!trx_mutex_own(thr_get_trx(thr))); /* cumul_resource counts how much resources the OS thread (NOT the @@ -969,7 +969,7 @@ static void que_run_threads_low(que_thr_t *thr) /*!< in: query thread */ trx_mutex_enter(trx); - ut_a(next_thr == nullptr || trx->error_state == DB_SUCCESS); + ut_a(next_thr == nullptr || get_trx_error_state(trx) == DB_SUCCESS); if (next_thr != thr) { ut_a(next_thr == nullptr); @@ -997,7 +997,7 @@ void que_run_threads(que_thr_t *thr) /*!< in: query thread */ ut_ad(!trx_mutex_own(thr_get_trx(thr))); loop: - ut_a(thr_get_trx(thr)->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(thr_get_trx(thr)) == DB_SUCCESS); que_run_threads_low(thr); @@ -1015,7 +1015,7 @@ void que_run_threads(que_thr_t *thr) /*!< in: query thread */ ut_a(thr_get_trx(thr)->id != 0); - if (thr_get_trx(thr)->error_state != DB_SUCCESS) { + if (get_trx_error_state(thr_get_trx(thr)) != DB_SUCCESS) { /* thr was chosen as a deadlock victim or there was a lock wait timeout */ @@ -1043,7 +1043,7 @@ dberr_t que_eval_sql(pars_info_t *info, const char *sql, trx_t *trx) { DBUG_TRACE; DBUG_PRINT("que_eval_sql", ("query: %s", sql)); - ut_a(trx->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(trx) == DB_SUCCESS); mutex_enter(&pars_mutex); @@ -1063,9 +1063,9 @@ dberr_t que_eval_sql(pars_info_t *info, const char *sql, trx_t *trx) { que_graph_free(graph); - ut_a(trx->error_state != 0); + ut_a(get_trx_error_state(trx) != 0); - return trx->error_state; + return get_trx_error_state(trx); } /** Initialise the query sub-system. */ diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index bdb290607e4..1038e40fb62 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -4853,7 +4853,7 @@ dberr_t row_import_for_mysql(dict_table_t *table, dd::Table *table_def, row_mysql_lock_data_dictionary(trx, UT_LOCATION_HERE); - DBUG_EXECUTE_IF("ib_import_internal_error", trx->error_state = DB_ERROR; + DBUG_EXECUTE_IF("ib_import_internal_error", set_trx_error_state(trx, DB_ERROR); err = DB_ERROR; ib_errf(trx->mysql_thd, IB_LOG_LEVEL_ERROR, ER_INTERNAL_ERROR, "While importing table %s", table->name.m_name); diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 298ea4a6ba1..d10eeeffedb 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -1699,7 +1699,7 @@ dberr_t row_ins_check_foreign_constraint( when it goes out of this scope. */ ib_dec_in_dtor dec(check_table->n_foreign_key_checks_running); - trx->error_state = err; + set_trx_error_state(trx, err); que_thr_stop_for_mysql(thr); @@ -1712,8 +1712,8 @@ dberr_t row_ins_check_foreign_constraint( lock_wait_suspend_thread(thr); - if (trx->error_state != DB_SUCCESS) { - err = trx->error_state; + if (get_trx_error_state(trx) != DB_SUCCESS) { + err = get_trx_error_state(trx); goto exit_func; } @@ -3600,7 +3600,7 @@ static inline void row_ins_get_row_from_query_block( case DB_SUCCESS: break; case DB_DUPLICATE_KEY: - thr_get_trx(thr)->error_state = DB_DUPLICATE_KEY; + set_trx_error_state(thr_get_trx(thr), DB_DUPLICATE_KEY); thr_get_trx(thr)->error_index = node->index; [[fallthrough]]; default: @@ -3721,7 +3721,7 @@ que_thr_t *row_ins_step(que_thr_t *thr) /*!< in: query thread */ err = row_ins(node, thr); error_handling: - trx->error_state = err; + set_trx_error_state(trx, err); if (err != DB_SUCCESS) { /* err == DB_LOCK_WAIT or SQL error detected */ diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 73e1ea699f5..7eb64584c9b 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -2373,11 +2373,11 @@ static dberr_t write_merge_buf_to_file( file_mutex.unlock(); if (!row_merge_write(file->fd, my_offset, block)) { - err = DB_TEMP_FILE_WRITE_FAIL; + err = DB_TEMP_FILE_WRITE_FAIL; trx->error_key_num = idx; return err; } - UNIV_MEM_INVALID(&block[0], srv_sort_buf_size); + UNIV_MEM_INVALID(&block[0], srv_sort_buf_size); return err; } @@ -5429,7 +5429,7 @@ dberr_t row_merge_build_indexes( const_cast (sort_idx)->cached_offs_pddl.reset(); #ifdef UNIV_DEBUG_PARALLEL_DDL - ib::info() << "[TXSQL PARALLEL DDL] Build btree finished, costs(" + ib::info() << "[TXSQL PARALLEL DDL] Build btree finished, costs(" << std::chrono::duration_cast( std::chrono::steady_clock::now() - start_build_btree_time).count() << ") ms."; diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index d4baa986f35..ba1e6249b07 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -1471,11 +1471,13 @@ bool row_mysql_handle_errors( dberr_t err; handle_new_error: - err = trx->error_state; + DBUG_EXECUTE_IF("sync_row_mysql_handle_errors_issue3628", sleep(5);); + + err = get_trx_error_state(trx); ut_a(err != DB_SUCCESS); - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); switch (err) { case DB_LOCK_WAIT_TIMEOUT: @@ -1519,7 +1521,7 @@ bool row_mysql_handle_errors( lock_wait_suspend_thread(thr); - if (trx->error_state != DB_SUCCESS) { + if (get_trx_error_state(trx) != DB_SUCCESS) { que_thr_stop_for_mysql(thr); goto handle_new_error; @@ -1577,13 +1579,13 @@ bool row_mysql_handle_errors( << "Unknown error code " << err << ": " << ut_strerr(err); } - if (trx->error_state != DB_SUCCESS) { - *new_err = trx->error_state; + if (get_trx_error_state(trx) != DB_SUCCESS) { + *new_err = get_trx_error_state(trx); } else { *new_err = err; } - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); return (false); } @@ -2058,7 +2060,7 @@ dberr_t row_lock_table_autoinc_for_mysql( err = lock_table(0, prebuilt->table, LOCK_AUTO_INC, thr); - trx->error_state = err; + set_trx_error_state(trx, err); if (err != DB_SUCCESS) { que_thr_stop_for_mysql(thr); @@ -2116,7 +2118,7 @@ dberr_t row_lock_table(row_prebuilt_t *prebuilt) { lock_table(0, prebuilt->table, static_cast(prebuilt->select_lock_type), thr); - trx->error_state = err; + set_trx_error_state(trx, err); if (err != DB_SUCCESS) { que_thr_stop_for_mysql(thr); @@ -2365,7 +2367,7 @@ static dberr_t row_insert_for_mysql_using_cursor(const byte *mysql_rec, } } - thr_get_trx(thr)->error_state = DB_SUCCESS; + set_trx_error_state(thr_get_trx(thr), DB_SUCCESS); return (err); } @@ -2465,7 +2467,7 @@ static dberr_t row_insert_for_mysql_using_ins_graph(const byte *mysql_rec, DEBUG_SYNC_C("ib_after_row_insert_step"); - err = trx->error_state; + err = get_trx_error_state(trx); if (err != DB_SUCCESS) { error_exit: @@ -2502,7 +2504,7 @@ static dberr_t row_insert_for_mysql_using_ins_graph(const byte *mysql_rec, if (doc_id <= 0) { ib::error(ER_IB_MSG_980) << "FTS Doc ID must be large than 0"; err = DB_FTS_INVALID_DOCID; - trx->error_state = DB_FTS_INVALID_DOCID; + set_trx_error_state(trx, DB_FTS_INVALID_DOCID); goto error_exit; } @@ -2515,7 +2517,7 @@ static dberr_t row_insert_for_mysql_using_ins_graph(const byte *mysql_rec, << " for table " << table->name; err = DB_FTS_INVALID_DOCID; - trx->error_state = DB_FTS_INVALID_DOCID; + set_trx_error_state(trx, DB_FTS_INVALID_DOCID); goto error_exit; } @@ -2533,14 +2535,20 @@ static dberr_t row_insert_for_mysql_using_ins_graph(const byte *mysql_rec, " exceed or equal to " << FTS_DOC_ID_MAX_STEP; err = DB_FTS_INVALID_DOCID; - trx->error_state = DB_FTS_INVALID_DOCID; + set_trx_error_state(trx, DB_FTS_INVALID_DOCID); goto error_exit; } } if (table->skip_alter_undo) { if (trx->fts_trx == nullptr) { - trx->fts_trx = fts_trx_create(trx); + DBUG_EXECUTE_IF("sync_fts_trx_create", sleep(1);); + if (current_thd && current_thd->is_doing_parallel_copy_data) { + std::call_once(*trx->fts_trx_create_once_flag, + [&trx]() { trx->fts_trx = fts_trx_create(trx); }); + } else { + trx->fts_trx = fts_trx_create(trx); + } } fts_trx_table_t ftt; @@ -3128,7 +3136,7 @@ static dberr_t row_del_upd_for_mysql_using_cursor(row_prebuilt_t *prebuilt) { } } - thr_get_trx(thr)->error_state = DB_SUCCESS; + set_trx_error_state(thr_get_trx(thr), DB_SUCCESS); cursors_t::iterator end = delete_entries.end(); for (cursors_t::iterator it = delete_entries.begin(); it != end; ++it) { it->close(); @@ -3236,13 +3244,13 @@ static dberr_t row_update_for_mysql_using_upd_graph(const byte *mysql_rec, thr->fk_cascade_depth = 0; row_upd_step(thr); - err = trx->error_state; + err = get_trx_error_state(trx); if (err != DB_SUCCESS) { que_thr_stop_for_mysql(thr); if (err == DB_RECORD_NOT_FOUND) { - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); trx->op_info = ""; if (thr->fk_cascade_depth > 0) { @@ -3485,7 +3493,7 @@ dberr_t row_update_cascade_for_mysql( different row deletes */ thr->fk_cascade_depth = 0; - err = trx->error_state; + err = get_trx_error_state(trx); /* Note that the cascade node is a subnode of another InnoDB query graph node. We do a normal lock wait in this node, but @@ -3502,8 +3510,8 @@ dberr_t row_update_cascade_for_mysql( or this transaction is picked as a victim in selective deadlock resolution */ - if (trx->error_state != DB_SUCCESS) { - return (trx->error_state); + if (get_trx_error_state(trx) != DB_SUCCESS) { + return (get_trx_error_state(trx)); } /* Retry operation after a normal lock wait */ @@ -3640,7 +3648,7 @@ dberr_t row_create_table_for_mysql(dict_table_t *&table, /* Assign table id and build table space. */ err = dict_build_table_def(table, create_info, trx); if (err != DB_SUCCESS) { - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); trx->op_info = ""; trx->dict_operation = TRX_DICT_OP_NONE; dict_mem_table_free(table); @@ -3722,7 +3730,7 @@ dberr_t row_create_table_for_mysql(dict_table_t *&table, << " because the tablespace is full"; } - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); /* Still do it here so that the table can always be freed */ if (dd_table_open_on_name_in_mem(table->name.m_name, false)) { @@ -3740,7 +3748,7 @@ dberr_t row_create_table_for_mysql(dict_table_t *&table, break; default: - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); dict_mem_table_free(table); table = nullptr; break; @@ -4395,11 +4403,11 @@ static dberr_t row_discard_tablespace(trx_t *trx, dict_table_t *table, default: /* We need to rollback the disk changes, something failed. */ - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); trx_rollback_to_savepoint(trx, nullptr); - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } return (err); @@ -4500,7 +4508,7 @@ dberr_t row_mysql_lock_table( err = lock_table(0, table, mode, thr); - trx->error_state = err; + set_trx_error_state(trx, err); if (err == DB_SUCCESS) { que_thr_stop_for_mysql_no_error(thr, trx); @@ -5121,7 +5129,7 @@ dberr_t row_rename_table_for_mysql(const char *old_name, const char *new_name, " the table exists, and DROP TABLE will" " succeed."; } - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); } else { /* The following call will also rename the .ibd data file if the table is stored in a single-table tablespace */ @@ -5129,7 +5137,7 @@ dberr_t row_rename_table_for_mysql(const char *old_name, const char *new_name, err = dict_table_rename_in_cache(table, new_name, !table->refresh_fk && !new_is_tmp); if (err != DB_SUCCESS) { - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); goto funct_exit; } diff --git a/storage/innobase/row/row0px.cc b/storage/innobase/row/row0px.cc index a7466fd052e..f5ef21fcf5a 100644 --- a/storage/innobase/row/row0px.cc +++ b/storage/innobase/row/row0px.cc @@ -1270,7 +1270,7 @@ dberr_t PX_Ctx::row_search_px(uchar *buf, row_prebuilt_t *prebuilt) { lock_wait_or_error: pcur->store_position(&mtr); - prebuilt->trx->error_state = err; + set_trx_error_state(prebuilt->trx, err); mtr_has_extra_clust_latch = false; goto func_exit; diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index e970d2d075c..e9145d3c2ae 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -1008,7 +1008,7 @@ static inline dberr_t sel_set_rtr_rec_lock( case DB_LOCK_WAIT: re_scan: mtr_commit(mtr); - trx->error_state = err; + set_trx_error_state(trx, err); que_thr_stop_for_mysql(thr); thr->lock_state = QUE_THR_LOCK_ROW; if (row_mysql_handle_errors(&err, trx, thr, nullptr)) { @@ -2168,7 +2168,7 @@ que_thr_t *row_sel_step(que_thr_t *thr) /*!< in: query thread */ trx_t *trx; trx = thr_get_trx(thr); - trx->error_state = err; + set_trx_error_state(trx, err); return (nullptr); } @@ -2202,7 +2202,7 @@ que_thr_t *row_sel_step(que_thr_t *thr) /*!< in: query thread */ thr->graph->last_sel_node = node; if (err != DB_SUCCESS) { - thr_get_trx(thr)->error_state = err; + set_trx_error_state(thr_get_trx(thr), err); return (nullptr); } @@ -2252,7 +2252,7 @@ que_thr_t *fetch_step(que_thr_t *thr) /*!< in: query thread */ if (sel_node->state == SEL_NODE_CLOSED) { ib::error(ER_IB_MSG_1027) << "fetch called on a closed cursor"; - thr_get_trx(thr)->error_state = DB_ERROR; + set_trx_error_state(thr_get_trx(thr), DB_ERROR); return (nullptr); } @@ -6373,7 +6373,7 @@ dberr_t row_search_mvcc(byte *buf, page_cur_mode_t mode, mtr_commit(&mtr); mtr_has_extra_clust_latch = false; - trx->error_state = err; + set_trx_error_state(trx, err); /* The following is a patch for MySQL */ diff --git a/storage/innobase/row/row0undo.cc b/storage/innobase/row/row0undo.cc index e2a6f86e84b..398392ae389 100644 --- a/storage/innobase/row/row0undo.cc +++ b/storage/innobase/row/row0undo.cc @@ -361,7 +361,7 @@ que_thr_t *row_undo_step(que_thr_t *thr) /*!< in: query thread */ err = row_undo(node, thr); - trx->error_state = err; + set_trx_error_state(trx, err); if (err != DB_SUCCESS) { /* SQL error detected */ diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index d11efae6745..f0059a8a0b2 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -3299,7 +3299,7 @@ que_thr_t *row_upd_step(que_thr_t *thr) /*!< in: query thread */ err = row_upd(node, thr); error_handling: - trx->error_state = err; + set_trx_error_state(trx, err); if (err != DB_SUCCESS) { return nullptr; diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc index 9e634e3ada7..fbbceee72bf 100644 --- a/storage/innobase/trx/trx0roll.cc +++ b/storage/innobase/trx/trx0roll.cc @@ -97,7 +97,7 @@ static void trx_rollback_to_savepoint_low( assert_trx_nonlocking_or_in_list(trx); } - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); if (trx_is_rseg_updated(trx)) { ut_ad(trx->rsegs.m_redo.rseg != nullptr || @@ -125,7 +125,7 @@ static void trx_rollback_to_savepoint_low( MONITOR_INC(MONITOR_TRX_ROLLBACK_SAVEPOINT); } - ut_a(trx->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(trx) == DB_SUCCESS); ut_a(trx->lock.que_state == TRX_QUE_RUNNING); mem_heap_free(heap); @@ -150,7 +150,7 @@ dberr_t trx_rollback_to_savepoint( trx_rollback_to_savepoint_low(trx, savept); - return (trx->error_state); + return (get_trx_error_state(trx)); } /** Rollback a transaction used in MySQL. @@ -169,9 +169,9 @@ static dberr_t trx_rollback_for_mysql_low( trx->op_info = ""; - ut_a(trx->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(trx) == DB_SUCCESS); - return (trx->error_state); + return (get_trx_error_state(trx)); } /** Rollback a transaction used in MySQL diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index b488d9ad50c..1bac58ecd71 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -179,7 +179,7 @@ static void trx_init(trx_t *trx) { trx->ddl_operation = false; - trx->error_state = DB_SUCCESS; + set_trx_error_state(trx, DB_SUCCESS); trx->error_key_num = ULINT_UNDEFINED; @@ -257,6 +257,11 @@ static void trx_init(trx_t *trx) { trx->lock.hu_rec_id.m_space_id = UINT32_UNDEFINED; trx->lock.hu_rec_id.m_page_no = UINT32_UNDEFINED; trx->lock.hu_rec_id.m_heap_no = UINT32_UNDEFINED; + + if (trx->fts_trx_create_once_flag) { + ut::delete_(trx->fts_trx_create_once_flag); + } + trx->fts_trx_create_once_flag = ut::new_(); } /** For managing the life-cycle of the trx_t instance that we get @@ -272,7 +277,7 @@ struct TrxFactory { ut::zalloc_withkey() in Pool::Pool() which would not call the constructors of the trx_t members. */ new (trx) trx_t(); - + trx->read_view = new ReadView(); ut_a(!trx->rw_trx_hash_pins); @@ -296,7 +301,7 @@ struct TrxFactory { mutex_create(LATCH_ID_TRX, &trx->mutex); mutex_create(LATCH_ID_TRX_UNDO, &trx->undo_mutex); mutex_create(LATCH_ID_TRX_VIEW, &trx->view_mutex); - + lock_trx_alloc_locks(trx); } @@ -324,6 +329,9 @@ struct TrxFactory { ut_a(UT_LIST_GET_LEN(trx->lock.trx_locks) == 0); + ut::delete_(trx->fts_trx_create_once_flag); + trx->fts_trx_create_once_flag = nullptr; + ut::delete_(trx->xid); ut::free(trx->detailed_error); @@ -358,7 +366,7 @@ struct TrxFactory { is added to the pool. @return true if all OK */ static bool debug(const trx_t *trx) { - ut_a(trx->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(trx) == DB_SUCCESS); ut_a(trx->magic_n == TRX_MAGIC_N); @@ -1055,7 +1063,7 @@ static void trx_resurrect(trx_rseg_t *rseg) { trx_sys->rw_trx_hash.insert(trx); trx_sys->rw_trx_hash.put_pins(trx); } - + trx_resurrect_table_ids(trx, &trx->rsegs.m_redo, undo); } } @@ -1275,7 +1283,7 @@ static void trx_start_low( ut_ad(trx->start_file != nullptr); ut_ad(trx->roll_limit == 0); ut_ad(!trx->lock.in_rollback); - ut_ad(trx->error_state == DB_SUCCESS); + ut_ad(get_trx_error_state(trx) == DB_SUCCESS); ut_ad(trx->rsegs.m_redo.rseg == nullptr); ut_ad(trx->rsegs.m_noredo.rseg == nullptr); ut_ad(trx_state_eq(trx, TRX_STATE_NOT_STARTED)); @@ -1379,7 +1387,7 @@ static void trx_start_low( /* Temporary rseg is assigned only if the transaction updates a temporary table */ DEBUG_SYNC_C("trx_sys_before_assign_id"); - + trx_sys->register_rw(trx); trx_sys_rw_trx_add(trx); @@ -1395,11 +1403,11 @@ static void trx_start_low( if (read_write) { trx_sys->register_rw(trx); trx_sys_rw_trx_add(trx); - } + } } } - ut_a(trx->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(trx) == DB_SUCCESS); trx->connect_broken = false; @@ -2083,7 +2091,7 @@ written */ trx_mutex_exit(trx); - ut_a(trx->error_state == DB_SUCCESS); + ut_a(get_trx_error_state(trx) == DB_SUCCESS); } /** Commits a transaction and a mini-transaction. @@ -2333,7 +2341,7 @@ void trx_commit_or_rollback_prepare(trx_t *trx) /*!< in/out: transaction */ trx->lock.que_state = TRX_QUE_RUNNING; } - ut_a(trx->lock.n_active_thrs == 1); + ut_ad(thd_parallel_copy_ddl(trx->mysql_thd) || trx->lock.n_active_thrs == 1); return; case TRX_STATE_COMMITTED_IN_MEMORY: @@ -3432,7 +3440,7 @@ void trx_set_rw_mode(trx_t *trx) /*!< in/out: transaction that is RW */ ut_ad(trx->rsegs.m_redo.rseg != nullptr); DEBUG_SYNC_C("trx_sys_before_assign_id"); - + trx_sys->register_rw(trx); /* So that we can see our own changes. */