From 7bcacd767a5451e0ccf99b44950451ff9cf57019 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 13 Mar 2024 12:21:53 +0100 Subject: [PATCH 001/159] MDEV-21864 Commands start-all-slaves and stop-all-slaves are not listed in mysqladmin help Added commands to the help --- client/mysqladmin.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 05abec9fe61..4210a4f7939 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -1418,7 +1418,9 @@ static void usage(void) refresh Flush all tables and close and open logfiles\n\ shutdown Take server down\n\ status Gives a short status message from the server\n\ + start-all-slaves Start all slaves\n\ start-slave Start slave\n\ + stop-all-slaves Stop all slaves\n\ stop-slave Stop slave\n\ variables Prints variables available\n\ version Get version info from server"); From 0a6f46965af3e4d223facbc4870f6fdd182c464e Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Fri, 8 Mar 2024 22:18:44 +0100 Subject: [PATCH 002/159] MDEV-33475: --gtid-ignore-duplicate can double-apply event in case of parallel replication retry When rolling back and retrying a transaction in parallel replication, don't release the domain ownership (for --gtid-ignore-duplicates) as part of the rollback. Otherwise another master connection could grab the ownership and double-apply the transaction in parallel with the retry. Reviewed-by: Brandon Nesterenko Signed-off-by: Kristian Nielsen --- .../gtid_ignore_duplicates.result | 108 +++++++++++++++++- .../multi_source/gtid_ignore_duplicates.test | 68 ++++++++++- sql/rpl_parallel.cc | 15 ++- sql/rpl_rli.cc | 4 +- sql/rpl_rli.h | 2 +- 5 files changed, 185 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/multi_source/gtid_ignore_duplicates.result b/mysql-test/suite/multi_source/gtid_ignore_duplicates.result index e142ff8b981..88b525e21ff 100644 --- a/mysql-test/suite/multi_source/gtid_ignore_duplicates.result +++ b/mysql-test/suite/multi_source/gtid_ignore_duplicates.result @@ -174,6 +174,105 @@ a 10 11 12 +*** MDEV-33475: --gtid-ignore-duplicate can double-apply event in case of parallel replication retry +connection server_2; +STOP SLAVE "c2b"; +SET default_master_connection = "c2b"; +include/wait_for_slave_to_stop.inc +STOP SLAVE "a2b"; +SET default_master_connection = "a2b"; +include/wait_for_slave_to_stop.inc +connection server_1; +CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; +BEGIN; +INSERT INTO t2 VALUES (0, 0); +INSERT INTO t2 VALUES (1, 0); +INSERT INTO t2 VALUES (2, 0); +INSERT INTO t2 VALUES (3, 0); +INSERT INTO t2 VALUES (4, 0); +INSERT INTO t2 VALUES (5, 0); +INSERT INTO t2 VALUES (6, 0); +INSERT INTO t2 VALUES (7, 0); +INSERT INTO t2 VALUES (8, 0); +INSERT INTO t2 VALUES (9, 0); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (0+10, 100); +UPDATE t2 SET b=0 WHERE a<10; +INSERT INTO t2 VALUES (0+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (1+10, 100); +UPDATE t2 SET b=1 WHERE a<10; +INSERT INTO t2 VALUES (1+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (2+10, 100); +UPDATE t2 SET b=2 WHERE a<10; +INSERT INTO t2 VALUES (2+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (3+10, 100); +UPDATE t2 SET b=3 WHERE a<10; +INSERT INTO t2 VALUES (3+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (4+10, 100); +UPDATE t2 SET b=4 WHERE a<10; +INSERT INTO t2 VALUES (4+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (5+10, 100); +UPDATE t2 SET b=5 WHERE a<10; +INSERT INTO t2 VALUES (5+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (6+10, 100); +UPDATE t2 SET b=6 WHERE a<10; +INSERT INTO t2 VALUES (6+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (7+10, 100); +UPDATE t2 SET b=7 WHERE a<10; +INSERT INTO t2 VALUES (7+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (8+10, 100); +UPDATE t2 SET b=8 WHERE a<10; +INSERT INTO t2 VALUES (8+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (9+10, 100); +UPDATE t2 SET b=9 WHERE a<10; +INSERT INTO t2 VALUES (9+20, 200); +COMMIT; +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +COUNT(*) SUM(a) SUM(b) +30 435 3090 +include/save_master_gtid.inc +connection server_2; +SET @old_mode= @@GLOBAL.slave_parallel_mode; +SET GLOBAL slave_parallel_mode=aggressive; +SET default_master_connection = "a2b"; +START SLAVE; +include/wait_for_slave_to_start.inc +SET default_master_connection = "c2b"; +START SLAVE; +include/wait_for_slave_to_start.inc +include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +COUNT(*) SUM(a) SUM(b) +30 435 3090 +connection server_3; +include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +COUNT(*) SUM(a) SUM(b) +30 435 3090 +connection server_4; +include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +COUNT(*) SUM(a) SUM(b) +30 435 3090 *** Test also with not using parallel replication. connection server_1; SET default_master_connection = "b2a"; @@ -474,6 +573,7 @@ Warnings: Note 1938 SLAVE 'a2b' stopped Note 1938 SLAVE 'c2b' stopped SET GLOBAL slave_parallel_threads= @old_parallel; +SET GLOBAL slave_parallel_mode= @old_mode; SET GLOBAL gtid_ignore_duplicates= @old_ignore_duplicates; connection server_3; SET GLOBAL gtid_domain_id=0; @@ -491,22 +591,22 @@ Note 1938 SLAVE 'a2d' stopped SET GLOBAL slave_parallel_threads= @old_parallel; SET GLOBAL gtid_ignore_duplicates= @old_ignore_duplicates; connection server_1; -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; include/reset_master_slave.inc disconnect server_1; connection server_2; -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; include/reset_master_slave.inc disconnect server_2; connection server_3; -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; include/reset_master_slave.inc disconnect server_3; connection server_4; -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; include/reset_master_slave.inc disconnect server_4; diff --git a/mysql-test/suite/multi_source/gtid_ignore_duplicates.test b/mysql-test/suite/multi_source/gtid_ignore_duplicates.test index 3d2d151bd0d..cbc06920b41 100644 --- a/mysql-test/suite/multi_source/gtid_ignore_duplicates.test +++ b/mysql-test/suite/multi_source/gtid_ignore_duplicates.test @@ -173,6 +173,65 @@ SET default_master_connection = "a2b"; SELECT * FROM t1 WHERE a >= 10 ORDER BY a; +--echo *** MDEV-33475: --gtid-ignore-duplicate can double-apply event in case of parallel replication retry + +# Create a bunch of transactions that will cause conflicts and retries. +# The bug was that the retry code was not handling the --gtid-ignore-duplicates +# option, so events could be doubly-applied. + +--connection server_2 +STOP SLAVE "c2b"; +SET default_master_connection = "c2b"; +--source include/wait_for_slave_to_stop.inc +STOP SLAVE "a2b"; +SET default_master_connection = "a2b"; +--source include/wait_for_slave_to_stop.inc + +--connection server_1 +CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; +BEGIN; +--let $i= 0 +while ($i < 10) { + eval INSERT INTO t2 VALUES ($i, 0); + inc $i; +} +COMMIT; + +--let $i= 0 +while ($i < 10) { + BEGIN; + eval INSERT INTO t2 VALUES ($i+10, 100); + eval UPDATE t2 SET b=$i WHERE a<10; + eval INSERT INTO t2 VALUES ($i+20, 200); + COMMIT; + inc $i; +} + +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +--source include/save_master_gtid.inc + +--connection server_2 +SET @old_mode= @@GLOBAL.slave_parallel_mode; +SET GLOBAL slave_parallel_mode=aggressive; +SET default_master_connection = "a2b"; +START SLAVE; +--source include/wait_for_slave_to_start.inc +SET default_master_connection = "c2b"; +START SLAVE; +--source include/wait_for_slave_to_start.inc + +--source include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; + +--connection server_3 +--source include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; + +--connection server_4 +--source include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; + + --echo *** Test also with not using parallel replication. --connection server_1 @@ -414,6 +473,7 @@ SET GLOBAL gtid_domain_id=0; --sorted_result STOP ALL SLAVES; SET GLOBAL slave_parallel_threads= @old_parallel; +SET GLOBAL slave_parallel_mode= @old_mode; SET GLOBAL gtid_ignore_duplicates= @old_ignore_duplicates; --connection server_3 @@ -431,25 +491,25 @@ SET GLOBAL slave_parallel_threads= @old_parallel; SET GLOBAL gtid_ignore_duplicates= @old_ignore_duplicates; --connection server_1 -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; --source include/reset_master_slave.inc --disconnect server_1 --connection server_2 -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; --source include/reset_master_slave.inc --disconnect server_2 --connection server_3 -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; --source include/reset_master_slave.inc --disconnect server_3 --connection server_4 -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; --source include/reset_master_slave.inc --disconnect server_4 diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index ac96d92eb5d..84307a40418 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -211,6 +211,13 @@ finish_event_group(rpl_parallel_thread *rpt, uint64 sub_id, signal_error_to_sql_driver_thread(thd, rgi, err); thd->wait_for_commit_ptr= NULL; + /* + Calls to check_duplicate_gtid() must match up with + record_and_update_gtid() (or release_domain_owner() in error case). This + assertion tries to catch any missing release of the domain. + */ + DBUG_ASSERT(rgi->gtid_ignore_duplicate_state != rpl_group_info::GTID_DUPLICATE_OWNER); + mysql_mutex_lock(&entry->LOCK_parallel_entry); /* We need to mark that this event group started its commit phase, in case we @@ -868,7 +875,13 @@ do_retry: }); #endif - rgi->cleanup_context(thd, 1); + /* + We are still applying the event group, even though we will roll it back + and retry it. So for --gtid-ignore-duplicates, keep ownership of the + domain during the retry so another master connection will not try to take + over and duplicate apply the same event group (MDEV-33475). + */ + rgi->cleanup_context(thd, 1, 1 /* keep_domain_owner */); wait_for_pending_deadlock_kill(thd, rgi); thd->reset_killed(); thd->clear_error(); diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 95566b2f6c7..1af38be1787 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -2248,7 +2248,7 @@ delete_or_keep_event_post_apply(rpl_group_info *rgi, } -void rpl_group_info::cleanup_context(THD *thd, bool error) +void rpl_group_info::cleanup_context(THD *thd, bool error, bool keep_domain_owner) { DBUG_ENTER("rpl_group_info::cleanup_context"); DBUG_PRINT("enter", ("error: %d", (int) error)); @@ -2298,7 +2298,7 @@ void rpl_group_info::cleanup_context(THD *thd, bool error) Ensure we always release the domain for others to process, when using --gtid-ignore-duplicates. */ - if (gtid_ignore_duplicate_state != GTID_DUPLICATE_NULL) + if (gtid_ignore_duplicate_state != GTID_DUPLICATE_NULL && !keep_domain_owner) rpl_global_gtid_slave_state->release_domain_owner(this); } diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index 9fc1a384355..91628bee3c7 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -917,7 +917,7 @@ struct rpl_group_info } void clear_tables_to_lock(); - void cleanup_context(THD *, bool); + void cleanup_context(THD *, bool, bool keep_domain_owner= false); void slave_close_thread_tables(THD *); void mark_start_commit_no_lock(); void mark_start_commit(); From d7758debaee4f9f928e4fecfeea8c9df1964dce3 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Wed, 13 Mar 2024 20:07:04 +0700 Subject: [PATCH 003/159] MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed in st_select_lex::fix_prepare_information In case there is a view that queried from a stored routine or a prepared statement and this temporary table is dropped between executions of SP/PS, then it leads to hitting an assertion at the SELECT_LEX::fix_prepare_information. The fired assertion was added by the commit 85f2e4f8e8c82978bd9cc0af9bfd2b549ea04d65 (MDEV-32466: Potential memory leak on executing of create view statement). Firing of this assertion means memory leaking on execution of SP/PS. Moreover, if the added assert be commented out, different result sets can be produced by the statement SELECT * FROM the hidden table. Both hitting the assertion and different result sets have the same root cause. This cause is usage of temporary table's metadata after the table itself has been dropped. To fix the issue, reload the cache of stored routines. To do it cache of stored routines is reset at the end of execution of the function dispatch_command(). Next time any stored routine be called it will be loaded from the table mysql.proc. This happens inside the method Sp_handler::sp_cache_routine where loading of a stored routine is performed in case it missed in cache. Loading is performed unconditionally while previously it was controlled by the parameter lookup_only. By that reason the signature of the method Sroutine_hash_entry::sp_cache_routine was changed by removing unused parameter lookup_only. Clearing of sp caches affects the test main.lock_sync since it forces opening and locking the table mysql.proc but the test assumes that each statement locks its tables once during its execution. To keep this invariant the debug sync points with names "before_lock_tables_takes_lock" and "after_lock_tables_takes_lock" are not activated on handling the table mysql.proc --- mysql-test/main/ps.result | 13 ++++++++ mysql-test/main/ps.test | 12 +++++++ mysql-test/main/sp.result | 3 +- mysql-test/main/sp.test | 2 -- mysql-test/main/temp_table.result | 49 ++++++++++++++++++++++++++++ mysql-test/main/temp_table.test | 54 +++++++++++++++++++++++++++++++ sql/sp.cc | 22 ++++--------- sql/sp.h | 16 ++++----- sql/sp_cache.cc | 18 +++++++++++ sql/sql_base.cc | 18 ++++++++--- sql/sql_class.cc | 1 + sql/sql_class.h | 12 ++++++- sql/sql_parse.cc | 9 +++++- sql/sql_table.cc | 5 +++ 14 files changed, 200 insertions(+), 34 deletions(-) diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result index aeed24f253b..7b5b9779624 100644 --- a/mysql-test/main/ps.result +++ b/mysql-test/main/ps.result @@ -5982,6 +5982,19 @@ EXECUTE stmt USING DEFAULT; # Clean up DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; +# MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed. in st_select_lex::fix_prepare_information +CREATE TABLE t1 AS SELECT 1 f; +PREPARE stmt FROM 'SHOW CREATE TABLE t1'; +DROP TABLE t1; +EXECUTE stmt; +ERROR 42S02: Table 'test.t1' doesn't exist +CREATE VIEW t1 AS SELECT 1; +EXECUTE stmt; +View Create View character_set_client collation_connection +t1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `t1` AS select 1 AS `1` latin1 latin1_swedish_ci +# Clean up +DEALLOCATE PREPARE stmt; +DROP VIEW t1; # # End of 10.4 tests # diff --git a/mysql-test/main/ps.test b/mysql-test/main/ps.test index 61d1513fa0b..99a479f854c 100644 --- a/mysql-test/main/ps.test +++ b/mysql-test/main/ps.test @@ -5416,6 +5416,18 @@ EXECUTE stmt USING DEFAULT; DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; +--echo # MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed. in st_select_lex::fix_prepare_information +CREATE TABLE t1 AS SELECT 1 f; +PREPARE stmt FROM 'SHOW CREATE TABLE t1'; +DROP TABLE t1; +--error ER_NO_SUCH_TABLE +EXECUTE stmt; +CREATE VIEW t1 AS SELECT 1; +EXECUTE stmt; +--echo # Clean up +DEALLOCATE PREPARE stmt; +DROP VIEW t1; + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/sp.result b/mysql-test/main/sp.result index 2f733107e8a..bcd9e728921 100644 --- a/mysql-test/main/sp.result +++ b/mysql-test/main/sp.result @@ -7184,15 +7184,14 @@ CREATE VIEW t1 AS SELECT 10 AS f1; CALL p1(1); ERROR HY000: The target table t1 of the INSERT is not insertable-into CREATE TEMPORARY TABLE t1 (f1 INT); -# t1 still refers to the view since it was inlined CALL p1(2); -ERROR HY000: The target table t1 of the INSERT is not insertable-into DROP VIEW t1; # t1 now refers to the temporary table CALL p1(3); # Check which values were inserted into the temp table. SELECT * FROM t1; f1 +2 3 DROP TEMPORARY TABLE t1; DROP PROCEDURE p1; diff --git a/mysql-test/main/sp.test b/mysql-test/main/sp.test index 50d9a611db9..d417bc636d4 100644 --- a/mysql-test/main/sp.test +++ b/mysql-test/main/sp.test @@ -8633,8 +8633,6 @@ CALL p1(1); CREATE TEMPORARY TABLE t1 (f1 INT); ---echo # t1 still refers to the view since it was inlined ---error ER_NON_INSERTABLE_TABLE CALL p1(2); DROP VIEW t1; diff --git a/mysql-test/main/temp_table.result b/mysql-test/main/temp_table.result index 33ea1700474..bf5015d44d4 100644 --- a/mysql-test/main/temp_table.result +++ b/mysql-test/main/temp_table.result @@ -616,5 +616,54 @@ Tables_in_test # in 11.2 and above here should be listed above used temporary tables DROP TEMPORARY TABLE t1, t2; # +# MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed. in st_select_lex::fix_prepare_information +# +CREATE VIEW v1 AS SELECT 5; +CREATE PROCEDURE sp() SELECT * FROM v1; +CREATE TEMPORARY TABLE v1 as SELECT 7; +# sp() accesses the temporary table v1 that hides the view with the same name +# Therefore expected output is the row (7) +CALL sp(); +7 +7 +DROP TEMPORARY TABLE v1; +# After the temporary table v1 has been dropped the next invocation of sp() +# accesses the view v1. So, expected output is the row (5) +CALL sp(); +5 +5 +# Clean up +DROP VIEW v1; +DROP PROCEDURE sp; +# Another use case is when a temporary table hides a view is dropped +# inside a stored routine being called. +CREATE VIEW t1 AS SELECT 1; +CREATE PROCEDURE p1() +BEGIN +DROP TEMPORARY TABLE t1; +END +| +CREATE FUNCTION f1() RETURNS INT +BEGIN +CALL p1(); +RETURN 1; +END +| +CREATE TEMPORARY TABLE t1 AS SELECT 1 AS a; +PREPARE stmt FROM 'SELECT f1()'; +EXECUTE stmt; +f1() +1 +# The temporary table t1 has been dropped on first +# execution of the prepared statement 'stmt', +# next time this statement is run it results in issuing +# the error ER_BAD_TABLE_ERROR +EXECUTE stmt; +ERROR 42S02: Unknown table 'test.t1' +# Clean up +DROP VIEW t1; +DROP FUNCTION f1; +DROP PROCEDURE p1; +# # End of 10.4 tests # diff --git a/mysql-test/main/temp_table.test b/mysql-test/main/temp_table.test index e1e671f5ae9..3984b447e91 100644 --- a/mysql-test/main/temp_table.test +++ b/mysql-test/main/temp_table.test @@ -674,6 +674,60 @@ SHOW TABLES; DROP TEMPORARY TABLE t1, t2; +--echo # +--echo # MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed. in st_select_lex::fix_prepare_information +--echo # +CREATE VIEW v1 AS SELECT 5; +CREATE PROCEDURE sp() SELECT * FROM v1; +CREATE TEMPORARY TABLE v1 as SELECT 7; +--echo # sp() accesses the temporary table v1 that hides the view with the same name +--echo # Therefore expected output is the row (7) +CALL sp(); +DROP TEMPORARY TABLE v1; +--echo # After the temporary table v1 has been dropped the next invocation of sp() +--echo # accesses the view v1. So, expected output is the row (5) +CALL sp(); + +--echo # Clean up +DROP VIEW v1; +DROP PROCEDURE sp; + +--echo # Another use case is when a temporary table hides a view is dropped +--echo # inside a stored routine being called. + +CREATE VIEW t1 AS SELECT 1; + +--delimiter | +CREATE PROCEDURE p1() +BEGIN + DROP TEMPORARY TABLE t1; +END +| + +CREATE FUNCTION f1() RETURNS INT +BEGIN + CALL p1(); + RETURN 1; +END +| + +--delimiter ; + +CREATE TEMPORARY TABLE t1 AS SELECT 1 AS a; +PREPARE stmt FROM 'SELECT f1()'; +EXECUTE stmt; +--echo # The temporary table t1 has been dropped on first +--echo # execution of the prepared statement 'stmt', +--echo # next time this statement is run it results in issuing +--echo # the error ER_BAD_TABLE_ERROR +--error ER_BAD_TABLE_ERROR +EXECUTE stmt; + +--echo # Clean up +DROP VIEW t1; +DROP FUNCTION f1; +DROP PROCEDURE p1; + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/sp.cc b/sql/sp.cc index d25c7353ca4..d3b128d5c99 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1907,7 +1907,7 @@ Sp_handler::sp_show_create_routine(THD *thd, DBUG_EXECUTE_IF("cache_sp_in_show_create", /* Some tests need just need a way to cache SP without other side-effects.*/ - sp_cache_routine(thd, name, false, &sp); + sp_cache_routine(thd, name, &sp); sp->show_create_routine(thd, this); DBUG_RETURN(false); ); @@ -2331,7 +2331,7 @@ Sp_handler::sp_cache_routine_reentrant(THD *thd, int ret; Parser_state *oldps= thd->m_parser_state; thd->m_parser_state= NULL; - ret= sp_cache_routine(thd, name, false, sp); + ret= sp_cache_routine(thd, name, sp); thd->m_parser_state= oldps; return ret; } @@ -2738,7 +2738,6 @@ void sp_update_stmt_used_routines(THD *thd, Query_tables_list *prelocking_ctx, */ int Sroutine_hash_entry::sp_cache_routine(THD *thd, - bool lookup_only, sp_head **sp) const { char qname_buff[NAME_LEN*2+1+1]; @@ -2751,7 +2750,7 @@ int Sroutine_hash_entry::sp_cache_routine(THD *thd, */ DBUG_ASSERT(mdl_request.ticket || this == thd->lex->sroutines_list.first); - return m_handler->sp_cache_routine(thd, &name, lookup_only, sp); + return m_handler->sp_cache_routine(thd, &name, sp); } @@ -2763,9 +2762,6 @@ int Sroutine_hash_entry::sp_cache_routine(THD *thd, @param[in] thd Thread context. @param[in] name Name of routine. - @param[in] lookup_only Only check that the routine is in the cache. - If it's not, don't try to load. If it is present, - but old, don't try to reload. @param[out] sp Pointer to sp_head object for routine, NULL if routine was not found. @@ -2776,7 +2772,6 @@ int Sroutine_hash_entry::sp_cache_routine(THD *thd, int Sp_handler::sp_cache_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const { int ret= 0; @@ -2788,9 +2783,6 @@ int Sp_handler::sp_cache_routine(THD *thd, *sp= sp_cache_lookup(spc, name); - if (lookup_only) - DBUG_RETURN(SP_OK); - if (*sp) { sp_cache_flush_obsolete(spc, sp); @@ -2842,7 +2834,6 @@ int Sp_handler::sp_cache_routine(THD *thd, * name->m_db is a database name, e.g. "dbname" * name->m_name is a package-qualified name, e.g. "pkgname.spname" - @param lookup_only - don't load mysql.proc if not cached @param [OUT] sp - the result is returned here. @retval false - loaded or does not exists @retval true - error while loading mysql.proc @@ -2852,14 +2843,13 @@ int Sp_handler::sp_cache_package_routine(THD *thd, const LEX_CSTRING &pkgname_cstr, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const + sp_head **sp) const { DBUG_ENTER("sp_cache_package_routine"); DBUG_ASSERT(type() == TYPE_ENUM_FUNCTION || type() == TYPE_ENUM_PROCEDURE); sp_name pkgname(&name->m_db, &pkgname_cstr, false); sp_head *ph= NULL; int ret= sp_handler_package_body.sp_cache_routine(thd, &pkgname, - lookup_only, &ph); if (!ret) { @@ -2894,12 +2884,12 @@ Sp_handler::sp_cache_package_routine(THD *thd, int Sp_handler::sp_cache_package_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const + sp_head **sp) const { DBUG_ENTER("Sp_handler::sp_cache_package_routine"); Prefix_name_buf pkgname(thd, name->m_name); DBUG_ASSERT(pkgname.length); - DBUG_RETURN(sp_cache_package_routine(thd, pkgname, name, lookup_only, sp)); + DBUG_RETURN(sp_cache_package_routine(thd, pkgname, name, sp)); } diff --git a/sql/sp.h b/sql/sp.h index 56007a2fa72..75347464c8a 100644 --- a/sql/sp.h +++ b/sql/sp.h @@ -101,10 +101,10 @@ protected: int sp_cache_package_routine(THD *thd, const LEX_CSTRING &pkgname_cstr, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const; + sp_head **sp) const; int sp_cache_package_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const; + sp_head **sp) const; sp_head *sp_find_package_routine(THD *thd, const LEX_CSTRING pkgname_str, const Database_qualified_name *name, @@ -202,7 +202,7 @@ public: const Database_qualified_name *name, bool cache_only) const; virtual int sp_cache_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const; + sp_head **sp) const; int sp_cache_routine_reentrant(THD *thd, const Database_qualified_name *nm, @@ -283,9 +283,9 @@ class Sp_handler_package_procedure: public Sp_handler_procedure { public: int sp_cache_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const + sp_head **sp) const { - return sp_cache_package_routine(thd, name, lookup_only, sp); + return sp_cache_package_routine(thd, name, sp); } sp_head *sp_find_routine(THD *thd, const Database_qualified_name *name, @@ -332,9 +332,9 @@ class Sp_handler_package_function: public Sp_handler_function { public: int sp_cache_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const + sp_head **sp) const { - return sp_cache_package_routine(thd, name, lookup_only, sp); + return sp_cache_package_routine(thd, name, sp); } sp_head *sp_find_routine(THD *thd, const Database_qualified_name *name, @@ -632,7 +632,7 @@ public: const Sp_handler *m_handler; - int sp_cache_routine(THD *thd, bool lookup_only, sp_head **sp) const; + int sp_cache_routine(THD *thd, sp_head **sp) const; }; diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc index cfdfea9ae0a..c1b9815d26e 100644 --- a/sql/sp_cache.cc +++ b/sql/sp_cache.cc @@ -78,6 +78,8 @@ private: /* All routines in this cache */ HASH m_hashtable; +public: + void clear(); }; // class sp_cache #ifdef HAVE_PSI_INTERFACE @@ -313,6 +315,10 @@ sp_cache::cleanup() my_hash_free(&m_hashtable); } +void sp_cache::clear() +{ + my_hash_reset(&m_hashtable); +} void Sp_caches::sp_caches_clear() { @@ -321,3 +327,15 @@ void Sp_caches::sp_caches_clear() sp_cache_clear(&sp_package_spec_cache); sp_cache_clear(&sp_package_body_cache); } + +void Sp_caches::sp_caches_empty() +{ + if (sp_proc_cache) + sp_proc_cache->clear(); + if (sp_func_cache) + sp_func_cache->clear(); + if (sp_package_spec_cache) + sp_package_spec_cache->clear(); + if (sp_package_body_cache) + sp_package_body_cache->clear(); +} diff --git a/sql/sql_base.cc b/sql/sql_base.cc index e6a7110d45b..cffe1085302 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3563,7 +3563,7 @@ open_and_process_routine(THD *thd, Query_tables_list *prelocking_ctx, DBUG_RETURN(TRUE); /* Ensures the routine is up-to-date and cached, if exists. */ - if (rt->sp_cache_routine(thd, has_prelocking_list, &sp)) + if (rt->sp_cache_routine(thd, &sp)) DBUG_RETURN(TRUE); /* Remember the version of the routine in the parse tree. */ @@ -3604,7 +3604,7 @@ open_and_process_routine(THD *thd, Query_tables_list *prelocking_ctx, Validating routine version is unnecessary, since CALL does not affect the prepared statement prelocked list. */ - if (rt->sp_cache_routine(thd, false, &sp)) + if (rt->sp_cache_routine(thd, &sp)) DBUG_RETURN(TRUE); } } @@ -5566,13 +5566,23 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, uint flags) *(ptr++)= table->table; } - DEBUG_SYNC(thd, "before_lock_tables_takes_lock"); +#ifdef ENABLED_DEBUG_SYNC + if (!tables || + !(strcmp(tables->db.str, "mysql") == 0 && + strcmp(tables->table_name.str, "proc") == 0)) + DEBUG_SYNC(thd, "before_lock_tables_takes_lock"); +#endif if (! (thd->lock= mysql_lock_tables(thd, start, (uint) (ptr - start), flags))) DBUG_RETURN(TRUE); - DEBUG_SYNC(thd, "after_lock_tables_takes_lock"); +#ifdef ENABLED_DEBUG_SYNC + if (!tables || + !(strcmp(tables->db.str, "mysql") == 0 && + strcmp(tables->table_name.str, "proc") == 0)) + DEBUG_SYNC(thd, "after_lock_tables_takes_lock"); +#endif if (thd->lex->requires_prelocking() && thd->lex->sql_command != SQLCOM_LOCK_TABLES) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 179e2a1a9a5..4f7759716dc 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -848,6 +848,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) prepare_derived_at_open= FALSE; create_tmp_table_for_derived= FALSE; save_prep_leaf_list= FALSE; + reset_sp_cache= false; org_charset= 0; /* Restore THR_THD */ set_current_thd(old_THR_THD); diff --git a/sql/sql_class.h b/sql/sql_class.h index e849b21b95b..a6c56a6e023 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1,5 +1,4 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. Copyright (c) 2009, 2022, MariaDB Corporation. This program is free software; you can redistribute it and/or modify @@ -2268,6 +2267,11 @@ public: swap_variables(sp_cache*, sp_package_body_cache, rhs.sp_package_body_cache); } void sp_caches_clear(); + /** + Clear content of sp related caches. + Don't delete cache objects itself. + */ + void sp_caches_empty(); }; @@ -2569,6 +2573,12 @@ public: bool save_prep_leaf_list; + /** + The data member reset_sp_cache is to signal that content of sp_cache + must be reset (all items be removed from it). + */ + bool reset_sp_cache; + /* container for handler's private per-connection data */ Ha_data ha_data[MAX_HA]; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7ca63b06c6b..68e5cbc8ca3 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2402,6 +2402,7 @@ dispatch_end: { WSREP_DEBUG("THD is killed at dispatch_end"); } + wsrep_after_command_before_result(thd); if (wsrep_current_error(thd) && !wsrep_command_no_result(command)) { @@ -2429,6 +2430,12 @@ dispatch_end: #endif /* WITH_WSREP */ + if (thd->reset_sp_cache) + { + thd->sp_caches_empty(); + thd->reset_sp_cache= false; + } + if (do_end_of_statement) { DBUG_ASSERT(thd->derived_tables == NULL && @@ -6071,7 +6078,7 @@ mysql_execute_command(THD *thd) if (sph->sp_resolve_package_routine(thd, thd->lex->sphead, lex->spname, &sph, &pkgname)) return true; - if (sph->sp_cache_routine(thd, lex->spname, false, &sp)) + if (sph->sp_cache_routine(thd, lex->spname, &sp)) goto error; if (!sp || sp->show_routine_code(thd)) { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 4a4d6f9cca2..d6ccd03cd42 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2393,6 +2393,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, goto err; } table->table= 0; + thd->reset_sp_cache= true; } if ((drop_temporary && if_exists) || !real_table) @@ -2629,8 +2630,11 @@ log_query: } DBUG_PRINT("table", ("table: %p s: %p", table->table, table->table ? table->table->s : NULL)); + if (is_temporary_table(table)) + thd->reset_sp_cache= true; } DEBUG_SYNC(thd, "rm_table_no_locks_before_binlog"); + thd->thread_specific_used= TRUE; error= 0; err: @@ -5236,6 +5240,7 @@ int create_table_impl(THD *thd, const LEX_CSTRING &orig_db, if (is_trans != NULL) *is_trans= table->file->has_transactions(); + thd->reset_sp_cache= true; thd->thread_specific_used= TRUE; create_info->table= table; // Store pointer to table } From ae063e4ff58eab76f8ca7b09611f4cac0683f55b Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 1 Mar 2024 11:21:50 +0200 Subject: [PATCH 004/159] Fixed random failure in main.kill_processlist-6619 The problem was that SHOW PROCESSLIST was done before the command of the default connection was cleared. Reviewer: Sergei Golubchik --- mysql-test/main/kill_processlist-6619.result | 6 ++++++ mysql-test/main/kill_processlist-6619.test | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/mysql-test/main/kill_processlist-6619.result b/mysql-test/main/kill_processlist-6619.result index 7dd42790cc7..25831a1f63b 100644 --- a/mysql-test/main/kill_processlist-6619.result +++ b/mysql-test/main/kill_processlist-6619.result @@ -1,4 +1,8 @@ +SET DEBUG_SYNC='dispatch_command_end SIGNAL ready WAIT_FOR go'; +select 1; connect con1,localhost,root,,; +SET DEBUG_SYNC='now wait_for ready'; +SET DEBUG_SYNC='now signal go'; SHOW PROCESSLIST; Id User Host db Command Time State Info Progress # root # test Sleep # # NULL 0.000 @@ -6,6 +10,8 @@ Id User Host db Command Time State Info Progress SET DEBUG_SYNC='before_execute_sql_command SIGNAL ready WAIT_FOR go'; SHOW PROCESSLIST; connection default; +1 +1 SET DEBUG_SYNC='now WAIT_FOR ready'; KILL QUERY con_id; SET DEBUG_SYNC='now SIGNAL go'; diff --git a/mysql-test/main/kill_processlist-6619.test b/mysql-test/main/kill_processlist-6619.test index c272e68a877..7330c79acd8 100644 --- a/mysql-test/main/kill_processlist-6619.test +++ b/mysql-test/main/kill_processlist-6619.test @@ -4,7 +4,14 @@ --source include/not_embedded.inc --source include/have_debug_sync.inc +# This is to ensure that the following SHOW PROCESSLIST does not show the query +SET DEBUG_SYNC='dispatch_command_end SIGNAL ready WAIT_FOR go'; +--send select 1 + --connect (con1,localhost,root,,) +SET DEBUG_SYNC='now wait_for ready'; +SET DEBUG_SYNC='now signal go'; + --let $con_id = `SELECT CONNECTION_ID()` --replace_result Execute Query --replace_column 1 # 3 # 6 # 7 # @@ -12,6 +19,8 @@ SHOW PROCESSLIST; SET DEBUG_SYNC='before_execute_sql_command SIGNAL ready WAIT_FOR go'; send SHOW PROCESSLIST; --connection default +--reap + # We must wait for the SHOW PROCESSLIST query to have started before sending # the kill. Otherwise, the KILL may be lost since it is reset at the start of # query execution. From ef7abc881c770e7ee3f8c9611566697915a18c69 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Thu, 14 Mar 2024 22:48:12 +0100 Subject: [PATCH 005/159] MDEV-10793: MDEV-33292: main.kill_processlist-6619 fails sporadically in buildbot There were several races in the main.kill_processlist-6619 testcase: - Lingering connections from a previous test case could be visible in SHOW PROCESSLIST and cause .result diff. - A sync point "dispatch_command_end" was ineffective, as it was consumed at the end of the SET DEBUG command itself. - The signal from sync point "before_execute_sql_command" could override an earlier signal, causing DEBUG_SYNC timeout and test failure. - The final SHOW PROCESSLIST could occasionally see a connection in state "Busy" instead of the expected "Sleep". Signed-off-by: Kristian Nielsen --- mysql-test/main/kill_processlist-6619.result | 11 ++++++-- mysql-test/main/kill_processlist-6619.test | 29 +++++++++++++++++--- sql/sql_parse.cc | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/mysql-test/main/kill_processlist-6619.result b/mysql-test/main/kill_processlist-6619.result index 25831a1f63b..d93404e2e33 100644 --- a/mysql-test/main/kill_processlist-6619.result +++ b/mysql-test/main/kill_processlist-6619.result @@ -1,8 +1,15 @@ -SET DEBUG_SYNC='dispatch_command_end SIGNAL ready WAIT_FOR go'; -select 1; +SET DEBUG_SYNC='dispatch_command_end2 SIGNAL ready EXECUTE 3'; connect con1,localhost,root,,; SET DEBUG_SYNC='now wait_for ready'; +connection default; +SET DEBUG_SYNC='dispatch_command_end WAIT_FOR go EXECUTE 2'; +select 1; +connection con1; SET DEBUG_SYNC='now signal go'; +SET DEBUG_SYNC='now wait_for ready'; +SET DEBUG_SYNC='now signal go'; +SET DEBUG_SYNC='now wait_for ready'; +SET DEBUG_SYNC='RESET'; SHOW PROCESSLIST; Id User Host db Command Time State Info Progress # root # test Sleep # # NULL 0.000 diff --git a/mysql-test/main/kill_processlist-6619.test b/mysql-test/main/kill_processlist-6619.test index 7330c79acd8..9d523b2264b 100644 --- a/mysql-test/main/kill_processlist-6619.test +++ b/mysql-test/main/kill_processlist-6619.test @@ -4,13 +4,34 @@ --source include/not_embedded.inc --source include/have_debug_sync.inc -# This is to ensure that the following SHOW PROCESSLIST does not show the query -SET DEBUG_SYNC='dispatch_command_end SIGNAL ready WAIT_FOR go'; ---send select 1 +# Ensure no lingering connections from an earlier test run, which can very +# rarely still be visible in SHOW PROCESSLIST here. +--let $wait_condition= SELECT COUNT(*) = 1 from information_schema.processlist +--source include/wait_condition.inc +# This is to ensure that the following SHOW PROCESSLIST does not show the query +# +# The use of DEBUG_SYNC here is quite tricky, and there were several bugs in +# this test case before. The dispatch_command_end* sync points will trigger at +# the end of the statement that sets them, so we need to use EXECUTE 2/3 to +# make them trigger also during the "select 1" statement. And we need to use +# two separate sync points so that we can wait first and signal after; +# otherwise the last wait from dispatch_command_end may time out as its signal +# gets overridden from the later sync point "before_execute_sql_command". +# +SET DEBUG_SYNC='dispatch_command_end2 SIGNAL ready EXECUTE 3'; --connect (con1,localhost,root,,) SET DEBUG_SYNC='now wait_for ready'; +--connection default +SET DEBUG_SYNC='dispatch_command_end WAIT_FOR go EXECUTE 2'; +--send select 1 + +--connection con1 SET DEBUG_SYNC='now signal go'; +SET DEBUG_SYNC='now wait_for ready'; +SET DEBUG_SYNC='now signal go'; +SET DEBUG_SYNC='now wait_for ready'; +SET DEBUG_SYNC='RESET'; --let $con_id = `SELECT CONNECTION_ID()` --replace_result Execute Query @@ -36,7 +57,7 @@ SET DEBUG_SYNC='reset'; # Wait until default connection has reset query string let $wait_condition= SELECT COUNT(*) = 1 from information_schema.processlist - WHERE info is NULL; + WHERE Command = "Sleep" AND info is NULL; --source include/wait_condition.inc --replace_result Execute Query diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 68e5cbc8ca3..4d52e515710 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2504,6 +2504,7 @@ dispatch_end: MYSQL_COMMAND_DONE(res); } DEBUG_SYNC(thd,"dispatch_command_end"); + DEBUG_SYNC(thd,"dispatch_command_end2"); /* Check that some variables are reset properly */ DBUG_ASSERT(thd->abort_on_warning == 0); From f5df4482e0d6efa619a9cf61cf8ee68a030eb435 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 15 Mar 2024 13:32:22 +0530 Subject: [PATCH 006/159] MDEV-33214 Table is getting rebuild with ALTER TABLE ADD COLUMN Problem: ====== - InnoDB fail to do instant operation while adding the variable length column. Problem is that InnoDB wrongly assumes that variable character length can never part of externally stored page. Solution: ======== instant_alter_column_possible(): Variable length character field can be stored as externally stored page. --- .../innodb/r/instant_alter_extend.result | Bin 9115 -> 9503 bytes .../suite/innodb/t/instant_alter_extend.test | 13 +++++++++++++ storage/innobase/handler/handler0alter.cc | 6 +----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mysql-test/suite/innodb/r/instant_alter_extend.result b/mysql-test/suite/innodb/r/instant_alter_extend.result index 33a5f57c7b64609b71ec4960780c7a545e240e38..c22043eceb16df8e6475296e3873f461c247961e 100644 GIT binary patch delta 399 zcmZvY!D_-l5QdM1eTsn`l0aIrQK1k#tjSbU)}*Yf^d`~l+JLNJR(kY7JoFX%h}}qQ zd+6L|`1twezf3=#KQG?dBOc6iT-^@_2_1s0H+uzb2RmhLYj$u{n^U`Q;JvkP4*eO% zB?^#i!Vy@WLss$Syd)kubqcKNY)UeLOyW0VX`m?-rHnu)uwo*cF%i)C9EO19v?y_0 z7<0%ckmD0uatS@KKsi2H{n*EI7j|9NJ7v_d-mkZ9N{VuULiWKGSn7iL5*GoD{CczX z!zf51zfsx`Q}Wl?k-c=F2j`p1D30UM*$r=(Bo5ty@o6OrIh&7L)7jd%&;E(hBary& hzWc?Unq;L+NiM3FTMelz5lsUJ4K#ij-d)S;$QNEFZCC&R delta 7 OcmbR5HQRl|Y-Ioqr~^6x diff --git a/mysql-test/suite/innodb/t/instant_alter_extend.test b/mysql-test/suite/innodb/t/instant_alter_extend.test index 7258ba6d238..636527e598c 100644 --- a/mysql-test/suite/innodb/t/instant_alter_extend.test +++ b/mysql-test/suite/innodb/t/instant_alter_extend.test @@ -256,3 +256,16 @@ select * from t1; check table t1; drop database best; + +--echo # +--echo # MDEV-33214 Table is getting rebuild with +--echo # ALTER TABLE ADD COLUMN +--echo # +use test; +CREATE TABLE t1(f1 INT, f2 VARCHAR(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; +INSERT INTO t1 VALUES(1,'abc'),(2,'def'); +ALTER TABLE t1 ADD (f3 VARCHAR(5000), f4 VARCHAR(20)), ALGORITHM=instant; +ALTER TABLE t1 ADD f5 TEXT, ALGORITHM=INSTANT; +DROP TABLE t1; + +--echo # End of 10.4 tests diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 400828b41df..b5e1f31df28 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -1581,11 +1581,9 @@ instant_alter_column_possible( ut_ad(!is_null || nullable); n_nullable += nullable; n_add++; - uint l; + uint l = (*af)->pack_length(); switch ((*af)->type()) { case MYSQL_TYPE_VARCHAR: - l = reinterpret_cast - (*af)->get_length(); variable_length: if (l >= min_local_len) { max_size += blob_prefix @@ -1599,7 +1597,6 @@ instant_alter_column_possible( if (!is_null) { min_size += l; } - l = (*af)->pack_length(); max_size += l; lenlen += l > 255 ? 2 : 1; } @@ -1613,7 +1610,6 @@ instant_alter_column_possible( ((*af))->get_length(); goto variable_length; default: - l = (*af)->pack_length(); if (l > 255 && ib_table.not_redundant()) { goto variable_length; } From d912a6369c6f7f8ba233ac88436d59f6e420c368 Mon Sep 17 00:00:00 2001 From: mariadb-DebarunBanerjee Date: Thu, 14 Mar 2024 18:59:47 +0530 Subject: [PATCH 007/159] MDEV-31154 Fatal InnoDB error or assertion `!is_v' failure upon multi-update with indexed virtual column MDEV-33558 Fatal error InnoDB: Clustered record field for column x not found This is issue is about row ID filtering used with index on virtual column(s). We hit debug assert and crash while building the record template in Innodb. The primary reason is that we try to force the code path to use the ICP path. With ICP, we don't support index with virtual column and we validate it while index condition is pushed. Simplify the code for building template to handle both ICP and Row ID filtering by skipping virtual columns. --- mysql-test/main/rowid_filter_innodb.result | 99 ++++++++++++++++++++++ mysql-test/main/rowid_filter_innodb.test | 75 ++++++++++++++++ storage/innobase/handler/ha_innodb.cc | 83 +++++++++++------- 3 files changed, 228 insertions(+), 29 deletions(-) diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index 6248932d666..fcdcac56582 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -3769,4 +3769,103 @@ Warnings: Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1` AS `c1` from `test`.`t1` where !<`test`.`t1`.`c1`,`test`.`t1`.`pk`>((`test`.`t1`.`c1`,(/* select#2 */ select `test`.`t2`.`c1` from `test`.`t2` join `test`.`t1` `a1` where `test`.`t2`.`i1` = `test`.`t1`.`pk` and `test`.`t2`.`i1` between 3 and 5 and trigcond((`test`.`t1`.`c1`) = `test`.`t2`.`c1`)))) DROP TABLE t1,t2; +# +# MDEV-31154: Fatal InnoDB error or assertion `!is_v' failure upon multi-update with indexed virtual column +# +# Test with auto generated Primary Key +# +SET @save_optimizer_switch= @@optimizer_switch; +SET optimizer_switch='rowid_filter=on'; +CREATE TABLE t0(a int); +INSERT INTO t0 SELECT seq FROM seq_1_to_20; +ANALYZE TABLE t0 PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +test.t0 analyze status Engine-independent statistics collected +test.t0 analyze status OK +CREATE TABLE t1 ( +a int, +b int as (a * 2) VIRTUAL, +f char(200), /* Filler */ +key (b), +key (a) +) engine=innodb; +INSERT INTO t1 (a, f) SELECT seq, seq FROM seq_1_to_1000; +ANALYZE TABLE t1 PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +# Test for type 'ref|filter' +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 test.t0.a 1 (2%) Using where; Using rowid filter +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +count(*) +10 +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 test.t0.a 1 (2%) Using where; Using rowid filter +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +count(*) +10 +# Test for type 'range|filter' +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range|filter b,a b|a 5|5 NULL 49 (10%) Using where; Using rowid filter +SELECT count(*) FROM t1 WHERE a<100 and b <100; +count(*) +49 +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range|filter b,a b|a 5|5 NULL 49 (10%) Using where; Using rowid filter +SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +count(*) +49 +# Test with Primary Key +# +DROP TABLE t1; +CREATE TABLE t1 ( +p int PRIMARY KEY AUTO_INCREMENT, +a int, +b int as (a * 2) VIRTUAL, +f char(200), /* Filler */ +key (b), +key (a) +) engine=innodb; +INSERT INTO t1 (a, f) SELECT seq, seq FROM seq_1_to_1000; +ANALYZE TABLE t1 PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +# Test for type 'ref|filter' +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 test.t0.a 1 (2%) Using where; Using rowid filter +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +count(*) +10 +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 test.t0.a 1 (2%) Using where; Using rowid filter +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +count(*) +10 +# Test for type 'range|filter' +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range|filter b,a b|a 5|5 NULL 49 (10%) Using where; Using rowid filter +SELECT count(*) FROM t1 WHERE a<100 and b <100; +count(*) +49 +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range|filter b,a b|a 5|5 NULL 49 (10%) Using where; Using rowid filter +SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +count(*) +49 +SET optimizer_switch=@save_optimizer_switch; +DROP TABLE t0, t1; # End of 10.4 tests diff --git a/mysql-test/main/rowid_filter_innodb.test b/mysql-test/main/rowid_filter_innodb.test index d5f3e4d4a6b..9321f706cb6 100644 --- a/mysql-test/main/rowid_filter_innodb.test +++ b/mysql-test/main/rowid_filter_innodb.test @@ -1,6 +1,8 @@ --source include/no_valgrind_without_big.inc --source include/have_innodb.inc --source include/have_debug.inc +--source include/have_sequence.inc +--source include/innodb_stable_estimates.inc SET SESSION STORAGE_ENGINE='InnoDB'; @@ -677,4 +679,77 @@ eval EXPLAIN EXTENDED $q; DROP TABLE t1,t2; +--echo # +--echo # MDEV-31154: Fatal InnoDB error or assertion `!is_v' failure upon multi-update with indexed virtual column +--echo # + +--echo # Test with auto generated Primary Key +--echo # + +SET @save_optimizer_switch= @@optimizer_switch; +SET optimizer_switch='rowid_filter=on'; + +CREATE TABLE t0(a int); +INSERT INTO t0 SELECT seq FROM seq_1_to_20; +ANALYZE TABLE t0 PERSISTENT FOR ALL; + +CREATE TABLE t1 ( + a int, + b int as (a * 2) VIRTUAL, + f char(200), /* Filler */ + key (b), + key (a) +) engine=innodb; + +INSERT INTO t1 (a, f) SELECT seq, seq FROM seq_1_to_1000; +ANALYZE TABLE t1 PERSISTENT FOR ALL; + +--echo # Test for type 'ref|filter' +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; + +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; + +--echo # Test for type 'range|filter' +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100; +SELECT count(*) FROM t1 WHERE a<100 and b <100; + +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; + +--echo # Test with Primary Key +--echo # + +DROP TABLE t1; +CREATE TABLE t1 ( + p int PRIMARY KEY AUTO_INCREMENT, + a int, + b int as (a * 2) VIRTUAL, + f char(200), /* Filler */ + key (b), + key (a) +) engine=innodb; + +INSERT INTO t1 (a, f) SELECT seq, seq FROM seq_1_to_1000; +ANALYZE TABLE t1 PERSISTENT FOR ALL; + +--echo # Test for type 'ref|filter' +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; + +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; + +--echo # Test for type 'range|filter' +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100; +SELECT count(*) FROM t1 WHERE a<100 and b <100; + +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; + +SET optimizer_switch=@save_optimizer_switch; + +DROP TABLE t0, t1; + --echo # End of 10.4 tests diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 62fe6bda283..67bec7c031a 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -7730,26 +7730,55 @@ ha_innobase::build_template( ulint num_v = 0; - if (active_index != MAX_KEY - && active_index == pushed_idx_cond_keyno) { - m_prebuilt->idx_cond = this; - goto icp; - } else if (pushed_rowid_filter && rowid_filter_is_active) { -icp: - /* Push down an index condition or an end_range check. */ + /* MDEV-31154: For pushed down index condition we don't support virtual + column and idx_cond_push() does check for it. For row ID filtering we + don't need such restrictions but we get into trouble trying to use the + ICP path. + + 1. It should be fine to follow no_icp path if primary key is generated. + However, with user specified primary key(PK), the row is identified by + the PK and those columns need to be converted to mysql format in + row_search_idx_cond_check before doing the comparison. Since secondary + indexes always have PK appended in innodb, it works with current ICP + handling code when fetch_primary_key_cols is set to TRUE. + + 2. Although ICP comparison and Row ID comparison works on different + columns the current ICP code can be shared by both. + + 3. In most cases, it works today by jumping to goto no_icp when we + encounter a virtual column. This is hackish and already have some + issues as it cannot handle PK and all states are not reset properly, + for example, idx_cond_n_cols is not reset. + + 4. We already encountered MDEV-28747 m_prebuilt->idx_cond was being set. + + Neither ICP nor row ID comparison needs virtual columns and the code is + simplified to handle both. It should handle the issues. */ + + const bool pushed_down = active_index != MAX_KEY + && active_index == pushed_idx_cond_keyno; + + m_prebuilt->idx_cond = pushed_down ? this : nullptr; + + if (m_prebuilt->idx_cond || m_prebuilt->pk_filter) { + /* Push down an index condition, end_range check or row ID + filter */ for (ulint i = 0; i < n_fields; i++) { const Field* field = table->field[i]; const bool is_v = !field->stored_in_db(); - if (is_v && skip_virtual) { - num_v++; - continue; - } + bool index_contains = index->contains_col_or_prefix( is_v ? num_v : i - num_v, is_v); - if (is_v && index_contains) { - m_prebuilt->n_template = 0; - num_v = 0; - goto no_icp; + + if (is_v) { + if (index_contains) { + /* We want to ensure that ICP is not + used with virtual columns. */ + ut_ad(!pushed_down); + m_prebuilt->idx_cond = nullptr; + } + num_v++; + continue; } /* Test if an end_range or an index condition @@ -7769,7 +7798,7 @@ icp: which would be acceptable if end_range==NULL. */ if (build_template_needs_field_in_icp( index, m_prebuilt, index_contains, - is_v ? num_v : i - num_v, is_v)) { + i - num_v, false)) { if (!whole_row) { field = build_template_needs_field( index_contains, @@ -7778,15 +7807,10 @@ icp: fetch_primary_key_cols, index, table, i, num_v); if (!field) { - if (is_v) { - num_v++; - } continue; } } - ut_ad(!is_v); - mysql_row_templ_t* templ= build_template_field( m_prebuilt, clust_index, index, table, field, i - num_v, 0); @@ -7863,15 +7887,16 @@ icp: */ } - if (is_v) { - num_v++; - } } - ut_ad(m_prebuilt->idx_cond_n_cols > 0); - ut_ad(m_prebuilt->idx_cond_n_cols == m_prebuilt->n_template); - num_v = 0; + ut_ad(m_prebuilt->idx_cond_n_cols == m_prebuilt->n_template); + if (m_prebuilt->idx_cond_n_cols == 0) { + /* No columns to push down. It is safe to jump to np ICP + path. */ + m_prebuilt->idx_cond = nullptr; + goto no_icp; + } /* Include the fields that are not needed in index condition pushdown. */ @@ -7886,7 +7911,7 @@ icp: bool index_contains = index->contains_col_or_prefix( is_v ? num_v : i - num_v, is_v); - if (!build_template_needs_field_in_icp( + if (is_v || !build_template_needs_field_in_icp( index, m_prebuilt, index_contains, is_v ? num_v : i - num_v, is_v)) { /* Not needed in ICP */ @@ -7919,7 +7944,7 @@ icp: } else { no_icp: /* No index condition pushdown */ - m_prebuilt->idx_cond = NULL; + ut_ad(!m_prebuilt->idx_cond); ut_ad(num_v == 0); for (ulint i = 0; i < n_fields; i++) { From 5abf0fea519bbb11ca267e6b70bc804c6218e349 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 26 Jan 2024 14:37:26 +0100 Subject: [PATCH 008/159] mtr - synchronize output between different threads on Windows. An attempt to fix lost output sometimes seen on buildbot. --- mysql-test/lib/mtr_report.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mysql-test/lib/mtr_report.pm b/mysql-test/lib/mtr_report.pm index 97c48c19112..0c3c45f3b18 100644 --- a/mysql-test/lib/mtr_report.pm +++ b/mysql-test/lib/mtr_report.pm @@ -87,12 +87,16 @@ sub flush_out { $out_line = ""; } +use if $^O eq "MSWin32", "threads::shared"; +my $flush_lock :shared; + # Print to stdout sub print_out { if(IS_WIN32PERL) { $out_line .= $_[0]; # Flush buffered output on new lines. if (rindex($_[0], "\n") != -1) { + lock($flush_lock); flush_out(); } } else { From af85e2ba19c2bcf857d66cfa0991c0ea595c68b9 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 18 Mar 2024 22:07:32 +0100 Subject: [PATCH 009/159] MTR, Windows - remove --verbose-restart output on buildbot run MTR buildbot output suggest that buildbot can lose some stdout information by overwriting it with stderr, which is captured separately This is bad, since stdout contains information about failing test. So, this is an attempt to minimize the damage by excluding most frequent stderr messages - those about restart. --- mysql-test/collections/buildbot_suites.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/collections/buildbot_suites.bat b/mysql-test/collections/buildbot_suites.bat index 0880e0124dd..dac273a4033 100644 --- a/mysql-test/collections/buildbot_suites.bat +++ b/mysql-test/collections/buildbot_suites.bat @@ -1,5 +1,5 @@ if "%MTR_PARALLEL%"=="" set MTR_PARALLEL=%NUMBER_OF_PROCESSORS% -perl mysql-test-run.pl --verbose-restart --force --suite-timeout=120 --max-test-fail=10 --retry=3 --suite=^ +perl mysql-test-run.pl --force --suite-timeout=120 --max-test-fail=10 --retry=3 --suite=^ vcol,gcol,perfschema,^ main,^ innodb,^ From 2ba42483344f8b87368fa1794d18dfa329443dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 19 Mar 2024 08:07:41 +0200 Subject: [PATCH 010/159] Fix g++-14 -Wcalloc-transposed-args --- plugin/auth_pam/auth_pam_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/auth_pam/auth_pam_base.c b/plugin/auth_pam/auth_pam_base.c index 1e8f4a08def..153712df140 100644 --- a/plugin/auth_pam/auth_pam_base.c +++ b/plugin/auth_pam/auth_pam_base.c @@ -99,7 +99,7 @@ static int conv(int n, const struct pam_message **msg, freeing it is the responsibility of the caller */ if (*resp == 0) { - *resp = calloc(sizeof(struct pam_response), n); + *resp = calloc(n, sizeof(struct pam_response)); if (*resp == 0) return PAM_BUF_ERR; } From 83a87da430dc545a5ed33f7b9252cac283b385e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 19 Mar 2024 08:08:18 +0200 Subject: [PATCH 011/159] Fix g++-14 -Wmaybe-uninitialized --- storage/innobase/fts/fts0fts.cc | 7 ++----- storage/innobase/que/que0que.cc | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 499f826cea0..bc143da449d 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -5420,12 +5420,9 @@ fts_free( dict_table_t* table) /*!< in/out: table with FTS indexes */ { fts_t* fts = table->fts; - - fts->~fts_t(); - - mem_heap_free(fts->fts_heap); - table->fts = NULL; + mem_heap_free(fts->fts_heap); + fts->~fts_t(); } /*********************************************************************//** diff --git a/storage/innobase/que/que0que.cc b/storage/innobase/que/que0que.cc index 961d4804609..fb0c482fe39 100644 --- a/storage/innobase/que/que0que.cc +++ b/storage/innobase/que/que0que.cc @@ -450,15 +450,12 @@ que_graph_free_recursive( ins = static_cast(node); que_graph_free_recursive(ins->select); - ins->select = NULL; - - ins->~ins_node_t(); if (ins->entry_sys_heap != NULL) { mem_heap_free(ins->entry_sys_heap); - ins->entry_sys_heap = NULL; } + ins->~ins_node_t(); break; case QUE_NODE_PURGE: purge = static_cast(node); From 2a8c4ccf2e5e0a378b0ac52843c8baa5a75175e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 19 Mar 2024 08:09:31 +0200 Subject: [PATCH 012/159] Fix g++-14 -Wtemplate-id-cdtor --- plugin/versioning/versioning.cc | 8 ++++---- sql/item_cmpfunc.h | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/plugin/versioning/versioning.cc b/plugin/versioning/versioning.cc index 8b9fb74e77b..4ed847b0882 100644 --- a/plugin/versioning/versioning.cc +++ b/plugin/versioning/versioning.cc @@ -35,8 +35,8 @@ public: static Create_func_trt s_singleton; protected: - Create_func_trt() = default; - virtual ~Create_func_trt() = default; + Create_func_trt() = default; + virtual ~Create_func_trt() = default; }; template @@ -131,8 +131,8 @@ public: static Create_func_trt_trx_sees s_singleton; protected: - Create_func_trt_trx_sees() = default; - virtual ~Create_func_trt_trx_sees() = default; + Create_func_trt_trx_sees() = default; + virtual ~Create_func_trt_trx_sees() = default; }; template diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 1ae0e652e88..a8868c26899 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -3301,13 +3301,11 @@ template class LI, typename T> class Item_equal_iterator { protected: Item_equal *item_equal; - Item *curr_item; + Item *curr_item= nullptr; public: - Item_equal_iterator(Item_equal &item_eq) - :LI (item_eq.equal_items) + Item_equal_iterator(Item_equal &item_eq) + :LI (item_eq.equal_items), item_equal(&item_eq) { - curr_item= NULL; - item_equal= &item_eq; if (item_eq.with_const) { LI *list_it= this; From 59e7289b6ce93e52b251466e18a2e0eab8b47c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 19 Mar 2024 08:10:42 +0200 Subject: [PATCH 013/159] Fix g++-14 -Wmaybe-uninitialized --- sql/sql_repl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 437c594450d..2b82002afd5 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -222,7 +222,7 @@ static int fake_rotate_event(binlog_send_info *info, ulonglong position, char* p = info->log_file_name+dirname_length(info->log_file_name); uint ident_len = (uint) strlen(p); String *packet= info->packet; - ha_checksum crc; + ha_checksum crc= 0; /* reset transmit packet for the fake rotate event below */ if (reset_transmit_packet(info, info->flags, &ev_offset, &info->errmsg)) @@ -263,7 +263,7 @@ static int fake_gtid_list_event(binlog_send_info *info, { my_bool do_checksum; int err; - ha_checksum crc; + ha_checksum crc= 0; char buf[128]; String str(buf, sizeof(buf), system_charset_info); String* packet= info->packet; From 5d857499530055b6865fe23eaf0b52e1fe89da56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 21 Mar 2024 14:20:33 +0200 Subject: [PATCH 014/159] Cleanup: Remove unused DYN_BLOCK_FULL_FLAG This had become unused in commit 2e814d4702d71a04388386a9f591d14a35980bfe or mysql/mysql-server@eca5b0fc17a5bd6d4833d35a0d08c8549dd3b5ec. This cleanup affects mtr_buf_t::used(). --- storage/innobase/include/dyn0buf.h | 5 ++--- storage/innobase/include/dyn0types.h | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/storage/innobase/include/dyn0buf.h b/storage/innobase/include/dyn0buf.h index bd883eb796c..fdc2ebf3d92 100644 --- a/storage/innobase/include/dyn0buf.h +++ b/storage/innobase/include/dyn0buf.h @@ -60,7 +60,7 @@ public: ulint used() const MY_ATTRIBUTE((warn_unused_result)) { - return(static_cast(m_used & ~DYN_BLOCK_FULL_FLAG)); + return m_used; } /** @@ -153,8 +153,7 @@ public: /** Storage */ byte m_data[MAX_DATA_SIZE]; - /** number of data bytes used in this block; - DYN_BLOCK_FULL_FLAG is set when the block becomes full */ + /** number of data bytes used in this block */ uint32_t m_used; friend class mtr_buf_t; diff --git a/storage/innobase/include/dyn0types.h b/storage/innobase/include/dyn0types.h index 06d837081a1..40e3f4c1965 100644 --- a/storage/innobase/include/dyn0types.h +++ b/storage/innobase/include/dyn0types.h @@ -33,7 +33,4 @@ Created 2013-03-16 Sunny Bains this must be > MLOG_BUF_MARGIN + 30! */ #define DYN_ARRAY_DATA_SIZE 512 -/** Flag for dyn_block_t::used that indicates a full block */ -#define DYN_BLOCK_FULL_FLAG 0x1000000UL - #endif /* dyn0types_h */ From 2250b42f522ef6a0ca676620ef56ae80af061efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 21 Mar 2024 16:01:29 +0200 Subject: [PATCH 015/159] Fix heap-use-after-free in fts_free() This fixes up 83a87da430dc545a5ed33f7b9252cac283b385e6 --- storage/innobase/fts/fts0fts.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index bc143da449d..39698cc5e1e 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -5421,8 +5421,8 @@ fts_free( { fts_t* fts = table->fts; table->fts = NULL; - mem_heap_free(fts->fts_heap); fts->~fts_t(); + mem_heap_free(fts->fts_heap); } /*********************************************************************//** From ef9cdacf51320fbb2935c03d406b22a3688bf295 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 21 Mar 2024 17:17:53 +1100 Subject: [PATCH 016/159] MDEV-33220 Fix -wmaybe-uninitialized warnings for g++-13 --- sql/item_strfunc.cc | 4 +-- sql/mysqld.cc | 2 +- storage/spider/ha_spider.cc | 23 +++++++++++---- storage/spider/hs_client/config.cpp | 31 ++++++++++---------- storage/spider/spd_copy_tables.cc | 43 +++++---------------------- storage/spider/spd_db_mysql.cc | 45 +++++++++++++++-------------- storage/spider/spd_table.cc | 12 ++++---- 7 files changed, 72 insertions(+), 88 deletions(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 697d4fdf2ea..f7a2b1aa176 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1383,7 +1383,7 @@ String *Item_func_regexp_replace::val_str_internal(String *str, char buff2[MAX_FIELD_WIDTH]; String tmp0(buff0,sizeof(buff0),&my_charset_bin); String tmp2(buff2,sizeof(buff2),&my_charset_bin); - String *source, *replace; + String *source, *replace= 0; LEX_CSTRING src, rpl; int startoffset= 0; @@ -1584,7 +1584,7 @@ String *Item_str_conv::val_str(String *str) { DBUG_ASSERT(fixed == 1); String *res; - size_t alloced_length, len; + size_t alloced_length= 0, len; if ((null_value= (!(res= args[0]->val_str(&tmp_value)) || str->alloc((alloced_length= res->length() * multiply))))) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 4d0a891faf9..879159c68fd 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -6390,7 +6390,7 @@ void create_new_thread(CONNECT *connect) void handle_accepted_socket(MYSQL_SOCKET new_sock, MYSQL_SOCKET sock) { CONNECT *connect; - bool is_unix_sock; + bool is_unix_sock= false; #ifdef FD_CLOEXEC (void) fcntl(mysql_socket_getfd(new_sock), F_SETFD, FD_CLOEXEC); diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 89d86a9ca75..90dd37b78aa 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -509,12 +509,23 @@ int ha_spider::open( result_list.last = NULL; result_list.current = NULL; result_list.record_num = 0; - if ( - !(result_list.sqls = new spider_string[share->link_count]) || - !(result_list.insert_sqls = new spider_string[share->link_count]) || - !(result_list.update_sqls = new spider_string[share->link_count]) || - !(result_list.tmp_sqls = new spider_string[share->link_count]) - ) { + if (!(result_list.sqls = new spider_string[share->link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_result_list; + } + if (!(result_list.insert_sqls = new spider_string[share->link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_result_list; + } + if (!(result_list.update_sqls = new spider_string[share->link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_result_list; + } + if (!(result_list.tmp_sqls = new spider_string[share->link_count])) + { error_num = HA_ERR_OUT_OF_MEM; goto error_init_result_list; } diff --git a/storage/spider/hs_client/config.cpp b/storage/spider/hs_client/config.cpp index 97d479220e0..d2759e37d8f 100644 --- a/storage/spider/hs_client/config.cpp +++ b/storage/spider/hs_client/config.cpp @@ -228,23 +228,22 @@ config::operator =(const config& x) conf_param *param, *new_param; for(ulong i = 0; i < x.conf_hash.records; i++) { - if ( - (param = (conf_param *) my_hash_element((HASH *) &x.conf_hash, i)) && - (new_param = new conf_param()) - ) { - if ( - !new_param->key.copy(param->key) && - !new_param->val.copy(param->val) - ) { - new_param->key.c_ptr_safe(); - new_param->val.c_ptr_safe(); - DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", - new_param->key.ptr(), new_param->val.ptr())); - if (my_hash_insert(&conf_hash, (uchar*) new_param)) + if ((param = (conf_param *) my_hash_element((HASH *) &x.conf_hash, i))) + if ((new_param = new conf_param())) + { + if ( + !new_param->key.copy(param->key) && + !new_param->val.copy(param->val) + ) { + new_param->key.c_ptr_safe(); + new_param->val.c_ptr_safe(); + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", + new_param->key.ptr(), new_param->val.ptr())); + if (my_hash_insert(&conf_hash, (uchar*) new_param)) + delete new_param; + } else delete new_param; - } else - delete new_param; - } + } } } DENA_VERBOSE(10, fprintf(stderr, "config operator = end %p", this)); diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index 6e9d1f2bcc6..34e3cb66712 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -1002,7 +1002,12 @@ long long spider_copy_tables_body( all_link_cnt = copy_tables->link_idx_count[0] + copy_tables->link_idx_count[1]; if ( - !(tmp_sql = new spider_string[all_link_cnt]) || + !(tmp_sql = new spider_string[all_link_cnt]) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + if ( !(spider = new ha_spider[all_link_cnt]) ) { my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); @@ -1029,13 +1034,6 @@ long long spider_copy_tables_body( } tmp_spider->share = table_conn->share; tmp_spider->trx = copy_tables->trx; -/* - if (spider_db_append_set_names(table_conn->share)) - { - my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); - goto error_append_set_names; - } -*/ tmp_spider->conns = &table_conn->conn; tmp_sql[roop_count].init_calc_mem(SPD_MID_COPY_TABLES_BODY_3); tmp_sql[roop_count].set_charset(copy_tables->access_charset); @@ -1073,13 +1071,6 @@ long long spider_copy_tables_body( } tmp_spider->share = table_conn->share; tmp_spider->trx = copy_tables->trx; -/* - if (spider_db_append_set_names(table_conn->share)) - { - my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); - goto error_append_set_names; - } -*/ tmp_spider->conns = &table_conn->conn; tmp_sql[roop_count].init_calc_mem(SPD_MID_COPY_TABLES_BODY_5); tmp_sql[roop_count].set_charset(copy_tables->access_charset); @@ -1106,14 +1097,6 @@ long long spider_copy_tables_body( bulk_insert_rows))) goto error_db_udf_copy_tables; -/* - for (table_conn = copy_tables->table_conn[0]; - table_conn; table_conn = table_conn->next) - spider_db_free_set_names(table_conn->share); - for (table_conn = copy_tables->table_conn[1]; - table_conn; table_conn = table_conn->next) - spider_db_free_set_names(table_conn->share); -*/ if (table_list->table) { #if MYSQL_VERSION_ID < 50500 @@ -1138,8 +1121,7 @@ long long spider_copy_tables_body( } delete [] spider; } - if (tmp_sql) - delete [] tmp_sql; + delete [] tmp_sql; spider_udf_free_copy_tables_alloc(copy_tables); DBUG_RETURN(1); @@ -1147,17 +1129,6 @@ long long spider_copy_tables_body( error_db_udf_copy_tables: error_create_dbton_handler: error_init_dbton_handler: -/* -error_append_set_names: -*/ -/* - for (table_conn = copy_tables->table_conn[0]; - table_conn; table_conn = table_conn->next) - spider_db_free_set_names(table_conn->share); - for (table_conn = copy_tables->table_conn[1]; - table_conn; table_conn = table_conn->next) - spider_db_free_set_names(table_conn->share); -*/ error: if (spider) { diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index fe83c652260..a7bf14b7fed 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -7218,11 +7218,9 @@ int spider_mbase_share::init() DBUG_RETURN(HA_ERR_OUT_OF_MEM); } - if (keys > 0 && - !(key_hint = new spider_string[keys]) - ) { - DBUG_RETURN(HA_ERR_OUT_OF_MEM); - } + if (keys > 0) + if (!(key_hint = new spider_string[keys])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); for (roop_count = 0; roop_count < keys; roop_count++) { key_hint[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_INIT_2); @@ -7230,12 +7228,12 @@ int spider_mbase_share::init() } DBUG_PRINT("info",("spider key_hint=%p", key_hint)); - if ( - !(table_select = new spider_string[1]) || - (keys > 0 && - !(key_select = new spider_string[keys]) - ) || - (error_num = create_table_names_str()) || + if (!(table_select = new spider_string[1])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (keys > 0) + if (!(key_select = new spider_string[keys])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if ((error_num = create_table_names_str()) || (table_share && ( (error_num = create_column_name_str()) || @@ -7386,11 +7384,18 @@ int spider_mbase_share::create_table_names_str() table_names_str = NULL; db_names_str = NULL; db_table_str = NULL; - if ( - !(table_names_str = new spider_string[spider_share->all_link_count]) || - !(db_names_str = new spider_string[spider_share->all_link_count]) || - !(db_table_str = new spider_string[spider_share->all_link_count]) - ) { + if (!(table_names_str = new spider_string[spider_share->all_link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (!(db_names_str = new spider_string[spider_share->all_link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (!(db_table_str = new spider_string[spider_share->all_link_count])) + { error_num = HA_ERR_OUT_OF_MEM; goto error; } @@ -7541,11 +7546,9 @@ int spider_mbase_share::create_column_name_str() Field **field; TABLE_SHARE *table_share = spider_share->table_share; DBUG_ENTER("spider_mbase_share::create_column_name_str"); - if ( - table_share->fields && - !(column_name_str = new spider_string[table_share->fields]) - ) - DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (table_share->fields) + if (!(column_name_str = new spider_string[table_share->fields])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); for (field = table_share->field, str = column_name_str; *field; field++, str++) { diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index e47b8eff7a2..fae239c57db 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -4217,12 +4217,12 @@ SPIDER_SHARE *spider_create_share( share->table.read_set = &table_share->all_set; #endif - if (table_share->keys > 0 && - !(share->key_hint = new spider_string[table_share->keys]) - ) { - *error_num = HA_ERR_OUT_OF_MEM; - goto error_init_hint_string; - } + if (table_share->keys > 0) + if (!(share->key_hint = new spider_string[table_share->keys])) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_hint_string; + } for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++) share->key_hint[roop_count].init_calc_mem(SPD_MID_CREATE_SHARE_2); DBUG_PRINT("info",("spider share->key_hint=%p", share->key_hint)); From e0c8165487ecfbee1d25625422a91a6352d7e522 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Thu, 21 Mar 2024 14:03:19 +0100 Subject: [PATCH 017/159] MDEV-33509 Failed to apply write set with flags=(rollback|pa_unsafe) Fix function `remove_fragment()` in wsrep_schema so that no error is raised if the fragment to be removed is not found in the wsrep_streaming_log table. This is necessary to handle the case where streaming transaction in idle state is BF aborted. This may result in the case where the rollbacker thread successfully removes the transaction's fragments, followed by the applier's attempt to remove the same fragments. Causing the node to leave the cluster after reporting a "Failed to apply write set" error. Signed-off-by: Julius Goryavsky --- .../r/galera_sr_bf_abort_idle.result | 33 +++++++++ .../galera_sr/t/galera_sr_bf_abort_idle.test | 68 +++++++++++++++++++ sql/wsrep_schema.cc | 5 +- 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/galera_sr/r/galera_sr_bf_abort_idle.result create mode 100644 mysql-test/suite/galera_sr/t/galera_sr_bf_abort_idle.test diff --git a/mysql-test/suite/galera_sr/r/galera_sr_bf_abort_idle.result b/mysql-test/suite/galera_sr/r/galera_sr_bf_abort_idle.result new file mode 100644 index 00000000000..a1495f1c138 --- /dev/null +++ b/mysql-test/suite/galera_sr/r/galera_sr_bf_abort_idle.result @@ -0,0 +1,33 @@ +connection node_2; +connection node_1; +connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connection node_1; +CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 INTEGER); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1); +SET SESSION wsrep_trx_fragment_size=10; +SET SESSION wsrep_trx_fragment_unit='rows'; +START TRANSACTION; +UPDATE t1 SET f2 = f2 + 10; +connection node_2; +INSERT INTO t1 VALUES (10,2); +connection node_1a; +connection node_1; +INSERT INTO t1 VALUES (9,1); +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ROLLBACK; +DROP TABLE t1; +connection node_1; +CREATE TABLE t1(f1 INTEGER PRIMARY KEY, f2 INTEGER); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1); +SET SESSION wsrep_trx_fragment_size=5; +SET SESSION wsrep_trx_fragment_unit='rows'; +START TRANSACTION; +UPDATE t1 SET f2 = f2 + 10; +connection node_2; +INSERT INTO t1 VALUES (10,2); +connection node_1a; +connection node_1; +INSERT INTO t1 VALUES (9,1); +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ROLLBACK; +DROP TABLE t1; diff --git a/mysql-test/suite/galera_sr/t/galera_sr_bf_abort_idle.test b/mysql-test/suite/galera_sr/t/galera_sr_bf_abort_idle.test new file mode 100644 index 00000000000..66259b790cc --- /dev/null +++ b/mysql-test/suite/galera_sr/t/galera_sr_bf_abort_idle.test @@ -0,0 +1,68 @@ +# +# Test BF abort for idle SR transactions +# + +--source include/galera_cluster.inc + +--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 + +# +# Case 1: BF abort idle SR transaction that has not yet replicated any fragments +# +--connection node_1 +CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 INTEGER); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1); + +--let $bf_count = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.global_status WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts'` + +SET SESSION wsrep_trx_fragment_size=10; +SET SESSION wsrep_trx_fragment_unit='rows'; +START TRANSACTION; +UPDATE t1 SET f2 = f2 + 10; + +--connection node_2 +INSERT INTO t1 VALUES (10,2); + +# Wait for SR transaction to be BF aborted +--connection node_1a +--let $wait_condition = SELECT VARIABLE_VALUE = $bf_count + 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts' +--source include/wait_condition.inc + + +--connection node_1 +--error ER_LOCK_DEADLOCK +INSERT INTO t1 VALUES (9,1); +ROLLBACK; + +DROP TABLE t1; + + +# +# Case 2: BF abort idle SR transaction that has already replicated a fragment +# +--connection node_1 +CREATE TABLE t1(f1 INTEGER PRIMARY KEY, f2 INTEGER); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1); + +--let $bf_count = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.global_status WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts'` + + +SET SESSION wsrep_trx_fragment_size=5; +SET SESSION wsrep_trx_fragment_unit='rows'; +START TRANSACTION; +UPDATE t1 SET f2 = f2 + 10; + +--connection node_2 +INSERT INTO t1 VALUES (10,2); + +# Wait for SR transaction to be BF aborted +--connection node_1a +--let $wait_condition = SELECT VARIABLE_VALUE = $bf_count + 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts' +--source include/wait_condition.inc + +--connection node_1 +--error ER_LOCK_DEADLOCK +INSERT INTO t1 VALUES (9,1); +ROLLBACK; + +DROP TABLE t1; diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc index a59d13dd839..1c4f827ae97 100644 --- a/sql/wsrep_schema.cc +++ b/sql/wsrep_schema.cc @@ -1117,7 +1117,10 @@ static int remove_fragment(THD* thd, seqno.get(), error); } - ret= error; + else + { + ret= error; + } } else if (Wsrep_schema_impl::delete_row(frag_table)) { From 9b7c2c6b0050967733de0d084bfb179f96973f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 26 Mar 2024 10:47:43 +0200 Subject: [PATCH 018/159] MDEV-33220 fixup: Remove some initialization --- sql/item_strfunc.cc | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index f7a2b1aa176..427c39a6812 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1383,19 +1383,20 @@ String *Item_func_regexp_replace::val_str_internal(String *str, char buff2[MAX_FIELD_WIDTH]; String tmp0(buff0,sizeof(buff0),&my_charset_bin); String tmp2(buff2,sizeof(buff2),&my_charset_bin); - String *source, *replace= 0; + String *source, *replace; LEX_CSTRING src, rpl; int startoffset= 0; - if ((null_value= - (!(source= args[0]->val_str(&tmp0)) || - !(replace= args[2]->val_str_null_to_empty(&tmp2, null_to_empty)) || - re.recompile(args[1])))) - return (String *) 0; - + source= args[0]->val_str(&tmp0); + if (!source) + goto err; + replace= args[2]->val_str_null_to_empty(&tmp2, null_to_empty); + if (!replace || re.recompile(args[1])) + goto err; if (!(source= re.convert_if_needed(source, &re.subject_converter)) || !(replace= re.convert_if_needed(replace, &re.replace_converter))) goto err; + null_value= false; src= source->lex_cstring(); rpl= replace->lex_cstring(); @@ -1439,7 +1440,7 @@ String *Item_func_regexp_replace::val_str_internal(String *str, err: null_value= true; - return (String *) 0; + return nullptr; } @@ -1583,13 +1584,21 @@ bool Item_func_insert::fix_length_and_dec() String *Item_str_conv::val_str(String *str) { DBUG_ASSERT(fixed == 1); - String *res; - size_t alloced_length= 0, len; + String *res= args[0]->val_str(&tmp_value); - if ((null_value= (!(res= args[0]->val_str(&tmp_value)) || - str->alloc((alloced_length= res->length() * multiply))))) - return 0; + if (!res) + { + err: + null_value= true; + return nullptr; + } + size_t alloced_length= res->length() * multiply, len; + + if (str->alloc((alloced_length))) + goto err; + + null_value= false; len= converter(collation.collation, (char*) res->ptr(), res->length(), (char*) str->ptr(), alloced_length); DBUG_ASSERT(len <= alloced_length); From 17573166c4980c86907176064ad61d36da5d753f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 26 Mar 2024 10:47:50 +0200 Subject: [PATCH 019/159] MDEV-22742 fixup: Remove a suppression --- mysql-test/mysql-test-run.pl | 2 -- 1 file changed, 2 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index cdd8f0bf6cd..4313cfa6a89 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -4472,8 +4472,6 @@ sub extract_warning_lines ($$) { qr/Dump thread [0-9]+ last sent to server [0-9]+ binlog file:pos .+/, qr/Detected table cache mutex contention at instance .* waits. Additional table cache instance cannot be activated: consider raising table_open_cache_instances. Number of active instances/, - # for UBSAN - qr/decimal\.c.*: runtime error: signed integer overflow/, # Disable test for UBSAN on dynamically loaded objects qr/runtime error: member call.*object.*'Handler_share'/, qr/sql_type\.cc.* runtime error: member call.*object.* 'Type_collection'/, From ed027d65f145621bdf0b34586522356bf7766dc5 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 22 Mar 2024 14:04:46 +0300 Subject: [PATCH 020/159] MDEV-33747: Optimization of (SELECT) IN (SELECT ...) executes subquery at prepare stage Make IN->EXISTS rewrite not to compute constant left expression if it has a subquery in it. --- mysql-test/main/subselect4.result | 29 +++++++++++++++++++++++++++++ mysql-test/main/subselect4.test | 15 +++++++++++++++ sql/item_cmpfunc.cc | 8 +++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result index 4edcffa0ee5..d609fe4ce96 100644 --- a/mysql-test/main/subselect4.result +++ b/mysql-test/main/subselect4.result @@ -3292,4 +3292,33 @@ a 2 DEALLOCATE PREPARE stmt; DROP TABLE t1,t2,t3; +# +# MDEV-33747: Optimization of (SELECT) IN (SELECT ...) executes subquery at prepare stage +# +create table t1 (a int, b int); +insert into t1 select seq, seq from seq_1_to_200; +create table t2 as select * from t1; +create table t3 as select * from t1; +analyze table t1,t2,t3; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +test.t2 analyze status Engine-independent statistics collected +test.t2 analyze status OK +test.t3 analyze status Engine-independent statistics collected +test.t3 analyze status OK +select @@expensive_subquery_limit < 200 as DEFAULTS_ARE_SUITABLE; +DEFAULTS_ARE_SUITABLE +1 +flush status; +explain select * from t1 where a<3 or (select max(a) from t2) in (select b from t3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 200 Using where +3 SUBQUERY t3 ALL NULL NULL NULL NULL 200 Using where +2 SUBQUERY t2 ALL NULL NULL NULL NULL 200 +# Must show 0. If this shows 200, this means subquery was executed and you have a bug: +show status like 'Handler_read_rnd_next%'; +Variable_name Value +Handler_read_rnd_next 0 +drop table t1,t2,t3; # End of 10.4 tests diff --git a/mysql-test/main/subselect4.test b/mysql-test/main/subselect4.test index d5871f1202c..8ab6fa3afd6 100644 --- a/mysql-test/main/subselect4.test +++ b/mysql-test/main/subselect4.test @@ -2666,4 +2666,19 @@ DEALLOCATE PREPARE stmt; DROP TABLE t1,t2,t3; +--echo # +--echo # MDEV-33747: Optimization of (SELECT) IN (SELECT ...) executes subquery at prepare stage +--echo # +create table t1 (a int, b int); +insert into t1 select seq, seq from seq_1_to_200; +create table t2 as select * from t1; +create table t3 as select * from t1; +analyze table t1,t2,t3; +select @@expensive_subquery_limit < 200 as DEFAULTS_ARE_SUITABLE; +flush status; +explain select * from t1 where a<3 or (select max(a) from t2) in (select b from t3); +--echo # Must show 0. If this shows 200, this means subquery was executed and you have a bug: +show status like 'Handler_read_rnd_next%'; +drop table t1,t2,t3; + --echo # End of 10.4 tests diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index cffd2e8add8..1dc555dad3a 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1363,7 +1363,13 @@ bool Item_in_optimizer::fix_left(THD *thd) copy_with_sum_func(args[0]); with_param= args[0]->with_param || args[1]->with_param; with_field= args[0]->with_field; - if ((const_item_cache= args[0]->const_item())) + + /* + If left expression is a constant, cache its value. + But don't do that if that involves computing a subquery, as we are in a + prepare-phase rewrite. + */ + if ((const_item_cache= args[0]->const_item()) && !args[0]->with_subquery()) { cache->store(args[0]); cache->cache_value(); From d695e2de5447727be029dc9ef0e2f1a54a8a9844 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 26 Mar 2024 13:10:16 +0100 Subject: [PATCH 021/159] MDEV-33506 Show original IP in the "aborted" message. Add "real ip:" part to the aborted message Only for proxy-protocoled connection, so it does not not to cause confusion to normal users. --- include/mysql_com.h | 1 + mysql-test/main/mysql_client_test.result | 1 + mysql-test/main/mysql_client_test.test | 6 +++++ sql/net_serv.cc | 3 +++ sql/share/errmsg-utf8.txt | 32 ++++++++++++------------ sql/sql_class.h | 20 ++++++++++++++- sql/sql_connect.cc | 2 +- tests/mysql_client_test.c | 6 ++++- 8 files changed, 52 insertions(+), 19 deletions(-) diff --git a/include/mysql_com.h b/include/mysql_com.h index 2e51f67b662..3d760ef28d4 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -456,6 +456,7 @@ typedef struct st_net { my_bool thread_specific_malloc; unsigned char compress; my_bool unused3; /* Please remove with the next incompatible ABI change. */ + my_bool using_proxy_protocol; /* Pointer to query object in query cache, do not equal NULL (0) for queries in cache that have not stored its results yet diff --git a/mysql-test/main/mysql_client_test.result b/mysql-test/main/mysql_client_test.result index dbc1feaa23b..dbd5aaeaae5 100644 --- a/mysql-test/main/mysql_client_test.result +++ b/mysql-test/main/mysql_client_test.result @@ -261,3 +261,4 @@ SET @@global.character_set_server= @save_character_set_server; SET @@global.collation_server= @save_collation_server; SET @@global.character_set_client= @save_character_set_client; SET @@global.collation_connection= @save_collation_connection; +FOUND 1 /Aborted connection.*'u' host: '192.0.2.1' real ip: '(localhost|::1)'/ in mysqld.1.err diff --git a/mysql-test/main/mysql_client_test.test b/mysql-test/main/mysql_client_test.test index 9fb7bcd81c9..09efc99796d 100644 --- a/mysql-test/main/mysql_client_test.test +++ b/mysql-test/main/mysql_client_test.test @@ -59,3 +59,9 @@ SET @@global.character_set_server= @save_character_set_server; SET @@global.collation_server= @save_collation_server; SET @@global.character_set_client= @save_character_set_client; SET @@global.collation_connection= @save_collation_connection; + +# Search for "real ip" in Aborted message +# This is indicator for abort of the proxied connections. +let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err; +let SEARCH_PATTERN= Aborted connection.*'u' host: '192.0.2.1' real ip: '(localhost|::1)'; +source include/search_pattern_in_file.inc; diff --git a/sql/net_serv.cc b/sql/net_serv.cc index c52083f8c2a..ecba6af0c86 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -151,6 +151,7 @@ my_bool my_net_init(NET *net, Vio *vio, void *thd, uint my_flags) net->where_b = net->remain_in_buf=0; net->net_skip_rest_factor= 0; net->last_errno=0; + net->using_proxy_protocol= 0; net->thread_specific_malloc= MY_TEST(my_flags & MY_THREAD_SPECIFIC); net->thd= 0; #ifdef MYSQL_SERVER @@ -192,6 +193,7 @@ void net_end(NET *net) DBUG_ENTER("net_end"); my_free(net->buff); net->buff=0; + net->using_proxy_protocol= 0; DBUG_VOID_RETURN; } @@ -908,6 +910,7 @@ static handle_proxy_header_result handle_proxy_header(NET *net) return RETRY; /* Change peer address in THD and ACL structures.*/ uint host_errors; + net->using_proxy_protocol= 1; return (handle_proxy_header_result)thd_set_peer_addr(thd, &(peer_info.peer_addr), NULL, peer_info.port, false, &host_errors); diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index eda61fbe218..c80f35ce341 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -4252,22 +4252,22 @@ ER_ERROR_DURING_CHECKPOINT swe "Fick fel %M vid CHECKPOINT" ukr "Отримано помилку %M під час CHECKPOINT" ER_NEW_ABORTING_CONNECTION 08S01 - chi "终止的连接 %lld 到数据库: '%-.192s' 用户: '%-.48s' 主机: '%-.64s' (%-.64s)" - cze "Spojení %lld do databáze: '%-.192s' uživatel: '%-.48s' stroj: '%-.64s' (%-.64s) bylo přerušeno" - dan "Afbrød forbindelsen %lld til databasen '%-.192s' bruger: '%-.48s' vært: '%-.64s' (%-.64s)" - eng "Aborted connection %lld to db: '%-.192s' user: '%-.48s' host: '%-.64s' (%-.64s)" - est "Ühendus katkestatud %lld andmebaas: '%-.192s' kasutaja: '%-.48s' masin: '%-.64s' (%-.64s)" - fre "Connection %lld avortée vers la bd: '%-.192s' utilisateur: '%-.48s' hôte: '%-.64s' (%-.64s)" - ger "Abbruch der Verbindung %lld zur Datenbank '%-.192s'. Benutzer: '%-.48s', Host: '%-.64s' (%-.64s)" - ita "Interrotta la connessione %lld al db: ''%-.192s' utente: '%-.48s' host: '%-.64s' (%-.64s)" - jpn "接続 %lld が中断されました。データベース: '%-.192s' ユーザー: '%-.48s' ホスト: '%-.64s' (%-.64s)" - nla "Afgebroken verbinding %lld naar db: '%-.192s' gebruiker: '%-.48s' host: '%-.64s' (%-.64s)" - por "Conexão %lld abortada para banco de dados '%-.192s' - usuário '%-.48s' - 'host' '%-.64s' ('%-.64s')" - rus "Прервано соединение %lld к базе данных '%-.192s' пользователя '%-.48s' с хоста '%-.64s' (%-.64s)" - serbian "Prekinuta konekcija broj %lld ka bazi: '%-.192s' korisnik je bio: '%-.48s' a host: '%-.64s' (%-.64s)" - spa "Abortada conexión %lld para db: '%-.192s' usuario: '%-.48s' servidor: '%-.64s' (%-.64s)" - swe "Avbröt länken för tråd %lld till db '%-.192s', användare '%-.48s', host '%-.64s' (%-.64s)" - ukr "Перервано з'єднання %lld до бази данних: '%-.192s' користувач: '%-.48s' хост: '%-.64s' (%-.64s)" + chi "终止的连接 %lld 到数据库: '%-.192s' 用户: '%-.48s' 主机: '%-.64s'%-.64s (%-.64s)" + cze "Spojení %lld do databáze: '%-.192s' uživatel: '%-.48s' stroj: '%-.64s'%-.64s (%-.64s) bylo přerušeno" + dan "Afbrød forbindelsen %lld til databasen '%-.192s' bruger: '%-.48s' vært: '%-.64s'%-.64s (%-.64s)" + eng "Aborted connection %lld to db: '%-.192s' user: '%-.48s' host: '%-.64s'%-.64s (%-.64s)" + est "Ühendus katkestatud %lld andmebaas: '%-.192s' kasutaja: '%-.48s' masin: '%-.64s'%-.64s (%-.64s)" + fre "Connection %lld avortée vers la bd: '%-.192s' utilisateur: '%-.48s' hôte: '%-.64s'%-.64s (%-.64s)" + ger "Abbruch der Verbindung %lld zur Datenbank '%-.192s'. Benutzer: '%-.48s', Host: '%-.64s'%-.64s (%-.64s)" + ita "Interrotta la connessione %lld al db: ''%-.192s' utente: '%-.48s' host: '%-.64s'%-.64s (%-.64s)" + jpn "接続 %lld が中断されました。データベース: '%-.192s' ユーザー: '%-.48s' ホスト: '%-.64s'%-.64s (%-.64s)" + nla "Afgebroken verbinding %lld naar db: '%-.192s' gebruiker: '%-.48s' host: '%-.64s'%-.64s (%-.64s)" + por "Conexão %lld abortada para banco de dados '%-.192s' - usuário '%-.48s' - 'host' '%-.64s'%-.64s ('%-.64s')" + rus "Прервано соединение %lld к базе данных '%-.192s' пользователя '%-.48s' с хоста '%-.64s'%-.64s (%-.64s)" + serbian "Prekinuta konekcija broj %lld ka bazi: '%-.192s' korisnik je bio: '%-.48s' a host: '%-.64s'%-.64s (%-.64s)" + spa "Abortada conexión %lld a la base de datos: '%-.192s' usuario: '%-.48s' equipo: '%-.64s'%-.64s (%-.64s)" + swe "Avbröt länken för tråd %lld till db '%-.192s', användare '%-.48s', host '%-.64s'%-.64s (%-.64s)" + ukr "Перервано з'єднання %lld до бази данних: '%-.192s' користувач: '%-.48s' хост: '%-.64s'%-.64s (%-.64s)" ER_UNUSED_10 eng "You should never see it" ER_FLUSH_MASTER_BINLOG_CLOSED diff --git a/sql/sql_class.h b/sql/sql_class.h index a6c56a6e023..e71f802b8c1 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4773,11 +4773,29 @@ public: { if (global_system_variables.log_warnings > threshold) { + char real_ip_str[64]; + real_ip_str[0]= 0; + + /* For proxied connections, add the real IP to the warning message */ + if (net.using_proxy_protocol && net.vio) + { + if(net.vio->localhost) + snprintf(real_ip_str, sizeof(real_ip_str), " real ip: 'localhost'"); + else + { + char buf[INET6_ADDRSTRLEN]; + if (!vio_getnameinfo((sockaddr *)&(net.vio->remote), buf, + sizeof(buf),NULL, 0, NI_NUMERICHOST)) + { + snprintf(real_ip_str, sizeof(real_ip_str), " real ip: '%s'",buf); + } + } + } Security_context *sctx= &main_security_ctx; sql_print_warning(ER_THD(this, ER_NEW_ABORTING_CONNECTION), thread_id, (db.str ? db.str : "unconnected"), sctx->user ? sctx->user : "unauthenticated", - sctx->host_or_ip, reason); + sctx->host_or_ip, real_ip_str, reason); } } diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index eae30ce76aa..a633064bae2 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -1282,7 +1282,7 @@ void prepare_new_connection_state(THD* thd) thd->thread_id, thd->db.str ? thd->db.str : "unconnected", sctx->user ? sctx->user : "unauthenticated", - sctx->host_or_ip, "init_connect command failed"); + sctx->host_or_ip, "", "init_connect command failed"); thd->server_status&= ~SERVER_STATUS_CLEAR_SET; thd->protocol->end_statement(); thd->killed = KILL_CONNECTION; diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index da04b078e76..cf6e8155533 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -20546,7 +20546,6 @@ typedef struct { #ifndef EMBEDDED_LIBRARY static void test_proxy_header_tcp(const char *ipaddr, int port) { - int rc; MYSQL_RES *result; int family = (strchr(ipaddr,':') == NULL)?AF_INET:AF_INET6; @@ -20621,6 +20620,11 @@ static void test_proxy_header_tcp(const char *ipaddr, int port) DIE_UNLESS(strncmp(row[0], normalized_addr, addrlen) == 0); DIE_UNLESS(atoi(row[0] + addrlen+1) == port); mysql_free_result(result); + if (i == 0 && !strcmp(ipaddr,"192.0.2.1")) + { + /* do "dirty" close, to get aborted message in error log.*/ + mariadb_cancel(m); + } mysql_close(m); } sprintf(query,"DROP USER 'u'@'%s'",normalized_addr); From bf49e7cfc78999aaaaf549bc44ba8548cc98bab8 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Tue, 26 Mar 2024 15:29:33 +0530 Subject: [PATCH 022/159] MDEV-33770 Alter operation hangs when encryption thread works on the same tablespace - Background encryption threads wait for stop flag to exit early from the tablespace. Alter operation fails to set the stop flag before waiting for the encryption thread to stop using the tablespace. --- storage/innobase/fil/fil0crypt.cc | 2 +- storage/innobase/fil/fil0fil.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index 49cb8ee6024..ad02f1c3393 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -2755,7 +2755,7 @@ fil_space_crypt_close_tablespace( << " seconds to drop space: " << space->name << " (" << space->id << ") active threads " - << cnt << "flushing=" + << cnt << " flushing=" << flushing << "."; last = now; } diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 45f8c341ee2..44e061b9400 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -2288,13 +2288,13 @@ fil_check_pending_operations( fil_space_t* sp = fil_space_get_by_id(id); if (sp) { + sp->set_stopping(true); if (sp->crypt_data && sp->acquire()) { mutex_exit(&fil_system.mutex); fil_space_crypt_close_tablespace(sp); mutex_enter(&fil_system.mutex); sp->release(); } - sp->set_stopping(true); } /* Check for pending operations. */ From 9d34939c6e9f8fe138717e66633809d0f2370f49 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 20 Feb 2024 11:20:21 +1100 Subject: [PATCH 023/159] MDEV-33494 fix spider init with no_zero_date global sql mode Like the fix for MDEV-32753 and MDEV-33242, spider init queries creates new connections that use the global sql_mode of the existing connection. --- .../mysql-test/spider/bugfix/r/mdev_33494.result | 4 ++++ .../spider/mysql-test/spider/bugfix/t/mdev_33494.test | 11 +++++++++++ storage/spider/spd_init_query.h | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result new file mode 100644 index 00000000000..3db28c0f08e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result @@ -0,0 +1,4 @@ +set @old_sql_mode=@@global.sql_mode; +set global sql_mode=(SELECT CONCAT (@@sql_mode,',no_zero_date')); +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test new file mode 100644 index 00000000000..30beca77f35 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test @@ -0,0 +1,11 @@ +# This test tests spider init with global no_zero_date sql mode +set @old_sql_mode=@@global.sql_mode; +set global sql_mode=(SELECT CONCAT (@@sql_mode,',no_zero_date')); +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; + +--disable_query_log +--disable_result_log +--source ../../include/clean_up_spider.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h index b8d1751a21b..c83bf56c4dd 100644 --- a/storage/spider/spd_init_query.h +++ b/storage/spider/spd_init_query.h @@ -21,7 +21,7 @@ static LEX_STRING spider_init_queries[] = { {C_STRING_WITH_LEN( - "SET @@SQL_MODE = REPLACE(@@SQL_MODE, 'ORACLE', '');" + "SET @@SQL_MODE = REGEXP_REPLACE(@@SQL_MODE, '(ORACLE|NO_ZERO_DATE)', '');" )}, {C_STRING_WITH_LEN( "create table if not exists mysql.spider_xa(" From db0b9ec37ba16bb17fc41a39522a7a1898df6902 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 27 Mar 2024 11:40:41 +1100 Subject: [PATCH 024/159] MDEV-33584 Use the default SQL_MODE for spider init queries This should fix all future problems caused by a non-default global sql_mode from the server where spider is to be installed. --- .../mysql-test/spider/bugfix/r/mdev_33584.result | 4 ++++ .../spider/mysql-test/spider/bugfix/t/mdev_33584.test | 11 +++++++++++ storage/spider/spd_init_query.h | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result new file mode 100644 index 00000000000..796c75cc560 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result @@ -0,0 +1,4 @@ +set @old_sql_mode=@@global.sql_mode; +set global sql_mode='traditional'; +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test new file mode 100644 index 00000000000..886449716eb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test @@ -0,0 +1,11 @@ +# This test tests spider init with global no_zero_date sql mode +set @old_sql_mode=@@global.sql_mode; +set global sql_mode='traditional'; +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; + +--disable_query_log +--disable_result_log +--source ../../include/clean_up_spider.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h index c83bf56c4dd..1311384c7ce 100644 --- a/storage/spider/spd_init_query.h +++ b/storage/spider/spd_init_query.h @@ -20,8 +20,10 @@ */ static LEX_STRING spider_init_queries[] = { + /* Use the default SQL_MODE for this connection. */ {C_STRING_WITH_LEN( - "SET @@SQL_MODE = REGEXP_REPLACE(@@SQL_MODE, '(ORACLE|NO_ZERO_DATE)', '');" + "SET @@SQL_MODE = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO," + "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';" )}, {C_STRING_WITH_LEN( "create table if not exists mysql.spider_xa(" From c71dc395292f41685530c0fa92c5ce4d78eabfa0 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Thu, 24 Nov 2022 14:47:18 +0100 Subject: [PATCH 025/159] MDEV-26499 Fix error "mysql_shutdown failed" during MTR tests - Fix to avoid mysqltest client getting killed abruptly during mysql_shutdown(). When Galera replication is shutdown, wait for THDs with `thd->stmt_da()->is_eof()` to disconnect (these are about to disconnect anyway). - Extract duplicate code from `wsrep_stop_replication()` and `wsrep_shutdown_replication()` in a new function. - No need to use a custom `shutdown_mysqld.inc` in galera suite. Delete it, so that the one in `mysql-test/include/` is used. Signed-off-by: Julius Goryavsky --- .../suite/galera/include/shutdown_mysqld.inc | 18 ----- mysql-test/suite/galera/r/MDEV-26499.result | 6 ++ mysql-test/suite/galera/t/MDEV-26499.test | 20 ++++++ sql/sql_parse.cc | 1 + sql/wsrep_mysqld.cc | 70 ++++++++++--------- 5 files changed, 64 insertions(+), 51 deletions(-) delete mode 100644 mysql-test/suite/galera/include/shutdown_mysqld.inc create mode 100644 mysql-test/suite/galera/r/MDEV-26499.result create mode 100644 mysql-test/suite/galera/t/MDEV-26499.test diff --git a/mysql-test/suite/galera/include/shutdown_mysqld.inc b/mysql-test/suite/galera/include/shutdown_mysqld.inc deleted file mode 100644 index 793be8d76ac..00000000000 --- a/mysql-test/suite/galera/include/shutdown_mysqld.inc +++ /dev/null @@ -1,18 +0,0 @@ -# This is the first half of include/restart_mysqld.inc. -if ($rpl_inited) -{ - if (!$allow_rpl_inited) - { - --die ERROR IN TEST: When using the replication test framework (master-slave.inc, rpl_init.inc etc), use rpl_restart_server.inc instead of restart_mysqld.inc. If you know what you are doing and you really have to use restart_mysqld.inc, set allow_rpl_inited=1 before you source restart_mysqld.inc - } -} - -# Write file to make mysql-test-run.pl expect the "crash", but don't start it ---let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name - -# Send shutdown to the connected server ---shutdown_server ---source include/wait_until_disconnected.inc - diff --git a/mysql-test/suite/galera/r/MDEV-26499.result b/mysql-test/suite/galera/r/MDEV-26499.result new file mode 100644 index 00000000000..15d372470a4 --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-26499.result @@ -0,0 +1,6 @@ +connection node_2; +connection node_1; +connection node_1; +connection node_2; +connection node_2; +SET GLOBAL debug_dbug="+d,simulate_slow_client_at_shutdown"; diff --git a/mysql-test/suite/galera/t/MDEV-26499.test b/mysql-test/suite/galera/t/MDEV-26499.test new file mode 100644 index 00000000000..824b28c14f3 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-26499.test @@ -0,0 +1,20 @@ +# +# MDEV-26499 +# +# This test reproduces some failure on mysql_shutdown() call +# which manifests sporadically in some galera MTR tests during +# restart of a node. +# + +--source include/galera_cluster.inc +--source include/have_debug_sync.inc + +--let $node_1=node_1 +--let $node_2=node_2 +--source include/auto_increment_offset_save.inc + +--connection node_2 +SET GLOBAL debug_dbug="+d,simulate_slow_client_at_shutdown"; +--source include/restart_mysqld.inc + +--source include/auto_increment_offset_restore.inc diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 4d52e515710..0fa793cea1a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2208,6 +2208,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, my_eof(thd); kill_mysql(thd); error=TRUE; + DBUG_EXECUTE_IF("simulate_slow_client_at_shutdown", my_sleep(2000000);); break; } #endif diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 5ec96478e4a..2e5bf3f426e 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1014,10 +1014,8 @@ void wsrep_recover() WSREP_INFO("Recovered position: %s", oss.str().c_str()); } - -void wsrep_stop_replication(THD *thd) +static void wsrep_stop_replication_common(THD *thd) { - WSREP_INFO("Stop replication by %llu", (thd) ? thd->thread_id : 0); if (Wsrep_server_state::instance().state() != Wsrep_server_state::s_disconnected) { @@ -1030,40 +1028,30 @@ void wsrep_stop_replication(THD *thd) } } - /* my connection, should not terminate with wsrep_close_client_connection(), - make transaction to rollback - */ - if (thd && !thd->wsrep_applier) trans_rollback(thd); + /* my connection, should not terminate with + wsrep_close_client_connections(), make transaction to rollback */ + if (thd && !thd->wsrep_applier) + trans_rollback(thd); wsrep_close_client_connections(TRUE, thd); - + /* wait until appliers have stopped */ wsrep_wait_appliers_close(thd); node_uuid= WSREP_UUID_UNDEFINED; } +void wsrep_stop_replication(THD *thd) +{ + WSREP_INFO("Stop replication by %llu", (thd) ? thd->thread_id : 0); + wsrep_stop_replication_common(thd); +} + void wsrep_shutdown_replication() { WSREP_INFO("Shutdown replication"); - if (Wsrep_server_state::instance().state() != wsrep::server_state::s_disconnected) - { - WSREP_DEBUG("Disconnect provider"); - Wsrep_server_state::instance().disconnect(); - if (Wsrep_server_state::instance().wait_until_state( - Wsrep_server_state::s_disconnected)) - { - WSREP_WARN("Wsrep interrupted while waiting for disconnected state"); - } - } - - wsrep_close_client_connections(TRUE); - - /* wait until appliers have stopped */ - wsrep_wait_appliers_close(NULL); - node_uuid= WSREP_UUID_UNDEFINED; - + wsrep_stop_replication_common(nullptr); /* Undocking the thread specific data. */ - my_pthread_setspecific_ptr(THR_THD, NULL); + my_pthread_setspecific_ptr(THR_THD, nullptr); } bool wsrep_start_replication(const char *wsrep_cluster_address) @@ -2644,14 +2632,19 @@ static my_bool have_client_connections(THD *thd, void*) { DBUG_PRINT("quit",("Informing thread %lld that it's time to die", (longlong) thd->thread_id)); - if (is_client_connection(thd) && thd->killed == KILL_CONNECTION) + if (is_client_connection(thd)) { - WSREP_DEBUG("Informing thread %lld that it's time to die", - thd->thread_id); - (void)abort_replicated(thd); - return true; + if (thd->killed == KILL_CONNECTION) + { + (void)abort_replicated(thd); + return true; + } + if (thd->get_stmt_da()->is_eof()) + { + return true; + } } - return 0; + return false; } static void wsrep_close_thread(THD *thd) @@ -2691,14 +2684,24 @@ static my_bool kill_all_threads(THD *thd, THD *caller_thd) /* We skip slave threads & scheduler on this first loop through. */ if (is_client_connection(thd) && thd != caller_thd) { + if (thd->get_stmt_da()->is_eof()) + { + return 0; + } + if (is_replaying_connection(thd)) + { thd->set_killed(KILL_CONNECTION); - else if (!abort_replicated(thd)) + return 0; + } + + if (!abort_replicated(thd)) { /* replicated transactions must be skipped */ WSREP_DEBUG("closing connection %lld", (longlong) thd->thread_id); /* instead of wsrep_close_thread() we do now soft kill by THD::awake */ thd->awake(KILL_CONNECTION); + return 0; } } return 0; @@ -2710,6 +2713,7 @@ static my_bool kill_remaining_threads(THD *thd, THD *caller_thd) if (is_client_connection(thd) && !abort_replicated(thd) && !is_replaying_connection(thd) && + !thd->get_stmt_da()->is_eof() && thd_is_connection_alive(thd) && thd != caller_thd) { From fa1ae367f174e6b9c9d6c0274d61a56c8dba13b3 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Wed, 27 Mar 2024 01:23:42 +0100 Subject: [PATCH 026/159] galera: wsrep-lib submodule update --- wsrep-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsrep-lib b/wsrep-lib index a5d95f0175f..dfc4bdb8a5d 160000 --- a/wsrep-lib +++ b/wsrep-lib @@ -1 +1 @@ -Subproject commit a5d95f0175f10b6127ea039c542725f6c4aa5cb9 +Subproject commit dfc4bdb8a5dcbd6fbea007ad3beff899a6b5b7bd From c77680768c154778068f68b4cb08b5720ef42ec7 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 14:20:12 +0100 Subject: [PATCH 027/159] MDEV-33460 use the correct sql_mode and fix for --view --- mysql-test/main/empty_string_literal.result | 5 +++-- mysql-test/main/empty_string_literal.test | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/empty_string_literal.result b/mysql-test/main/empty_string_literal.result index 569b9d5e9ca..a0d05fd6e6b 100644 --- a/mysql-test/main/empty_string_literal.result +++ b/mysql-test/main/empty_string_literal.result @@ -208,12 +208,13 @@ t1 CREATE TABLE `t1` ( KEY `a` (`a`,`b`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci drop table t1; +set sql_mode= default; # # MDEV-33460 select '123' 'x'; unexpected result # SELECT ''; -NULL -NULL + + SELECT '' 'b' 'c'; bc bc diff --git a/mysql-test/main/empty_string_literal.test b/mysql-test/main/empty_string_literal.test index 3320841fb42..e3ae009445b 100644 --- a/mysql-test/main/empty_string_literal.test +++ b/mysql-test/main/empty_string_literal.test @@ -25,12 +25,15 @@ flush tables; update t1 set a = 2; show create table t1; drop table t1; +set sql_mode= default; --echo # --echo # MDEV-33460 select '123' 'x'; unexpected result --echo # +--disable_view_protocol SELECT ''; +--enable_view_protocol SELECT '' 'b' 'c'; SELECT '' '' 'c'; SELECT 'a' '' 'c'; From c84d67a302bc8b197b2da1ddb02d5e29abc3e23e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 25 Mar 2024 12:20:16 +0100 Subject: [PATCH 028/159] reenable main.mysqldump-system test --- mysql-test/main/mysqldump-system.test | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mysql-test/main/mysqldump-system.test b/mysql-test/main/mysqldump-system.test index c1965410167..9aaa5fff6f9 100644 --- a/mysql-test/main/mysqldump-system.test +++ b/mysql-test/main/mysqldump-system.test @@ -3,10 +3,6 @@ --source include/have_udf.inc --source include/platform.inc -if (!$AUTH_SOCKET_SO) { - --skip Need auth socket plugin -} - --echo # --echo # MDEV-23630: mysqldump to logically dump system tables --echo # From 353f904ea91af919016633ed057e52aedfa9f235 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 25 Mar 2024 14:44:31 +0100 Subject: [PATCH 029/159] MDEV-31379 Undefined behavior in the reference Ed25519 implementation apply the fix from MXS-4686 --- plugin/auth_ed25519/ref10/fe_mul.c | 21 +++++---- plugin/auth_ed25519/ref10/fe_sq.c | 21 +++++---- plugin/auth_ed25519/ref10/fe_sq2.c | 21 +++++---- plugin/auth_ed25519/ref10/fe_tobytes.c | 37 +++++++-------- .../auth_ed25519/ref10/ge_scalarmult_base.c | 2 +- plugin/auth_ed25519/ref10/sc_muladd.c | 46 +++++++++---------- plugin/auth_ed25519/ref10/sc_reduce.c | 34 +++++++------- 7 files changed, 93 insertions(+), 89 deletions(-) diff --git a/plugin/auth_ed25519/ref10/fe_mul.c b/plugin/auth_ed25519/ref10/fe_mul.c index 26ca8b3682d..8ccad3c30d8 100644 --- a/plugin/auth_ed25519/ref10/fe_mul.c +++ b/plugin/auth_ed25519/ref10/fe_mul.c @@ -1,5 +1,6 @@ #include "fe.h" #include "crypto_int64.h" +#include "crypto_uint64.h" /* h = f * g @@ -179,16 +180,16 @@ void fe_mul(fe h,const fe f,const fe g) crypto_int64 h7 = f0g7+f1g6 +f2g5 +f3g4 +f4g3 +f5g2 +f6g1 +f7g0 +f8g9_19+f9g8_19; crypto_int64 h8 = f0g8+f1g7_2 +f2g6 +f3g5_2 +f4g4 +f5g3_2 +f6g2 +f7g1_2 +f8g0 +f9g9_38; crypto_int64 h9 = f0g9+f1g8 +f2g7 +f3g6 +f4g5 +f5g4 +f6g3 +f7g2 +f8g1 +f9g0 ; - crypto_int64 carry0; - crypto_int64 carry1; - crypto_int64 carry2; - crypto_int64 carry3; - crypto_int64 carry4; - crypto_int64 carry5; - crypto_int64 carry6; - crypto_int64 carry7; - crypto_int64 carry8; - crypto_int64 carry9; + crypto_uint64 carry0; + crypto_uint64 carry1; + crypto_uint64 carry2; + crypto_uint64 carry3; + crypto_uint64 carry4; + crypto_uint64 carry5; + crypto_uint64 carry6; + crypto_uint64 carry7; + crypto_uint64 carry8; + crypto_uint64 carry9; /* |h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38)) diff --git a/plugin/auth_ed25519/ref10/fe_sq.c b/plugin/auth_ed25519/ref10/fe_sq.c index 8dd119841c6..3c718033a0a 100644 --- a/plugin/auth_ed25519/ref10/fe_sq.c +++ b/plugin/auth_ed25519/ref10/fe_sq.c @@ -1,5 +1,6 @@ #include "fe.h" #include "crypto_int64.h" +#include "crypto_uint64.h" /* h = f * f @@ -106,16 +107,16 @@ void fe_sq(fe h,const fe f) crypto_int64 h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38; crypto_int64 h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38; crypto_int64 h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2; - crypto_int64 carry0; - crypto_int64 carry1; - crypto_int64 carry2; - crypto_int64 carry3; - crypto_int64 carry4; - crypto_int64 carry5; - crypto_int64 carry6; - crypto_int64 carry7; - crypto_int64 carry8; - crypto_int64 carry9; + crypto_uint64 carry0; + crypto_uint64 carry1; + crypto_uint64 carry2; + crypto_uint64 carry3; + crypto_uint64 carry4; + crypto_uint64 carry5; + crypto_uint64 carry6; + crypto_uint64 carry7; + crypto_uint64 carry8; + crypto_uint64 carry9; carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; diff --git a/plugin/auth_ed25519/ref10/fe_sq2.c b/plugin/auth_ed25519/ref10/fe_sq2.c index 026ed3aacf5..97c03cf4899 100644 --- a/plugin/auth_ed25519/ref10/fe_sq2.c +++ b/plugin/auth_ed25519/ref10/fe_sq2.c @@ -1,5 +1,6 @@ #include "fe.h" #include "crypto_int64.h" +#include "crypto_uint64.h" /* h = 2 * f * f @@ -106,16 +107,16 @@ void fe_sq2(fe h,const fe f) crypto_int64 h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38; crypto_int64 h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38; crypto_int64 h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2; - crypto_int64 carry0; - crypto_int64 carry1; - crypto_int64 carry2; - crypto_int64 carry3; - crypto_int64 carry4; - crypto_int64 carry5; - crypto_int64 carry6; - crypto_int64 carry7; - crypto_int64 carry8; - crypto_int64 carry9; + crypto_uint64 carry0; + crypto_uint64 carry1; + crypto_uint64 carry2; + crypto_uint64 carry3; + crypto_uint64 carry4; + crypto_uint64 carry5; + crypto_uint64 carry6; + crypto_uint64 carry7; + crypto_uint64 carry8; + crypto_uint64 carry9; h0 += h0; h1 += h1; diff --git a/plugin/auth_ed25519/ref10/fe_tobytes.c b/plugin/auth_ed25519/ref10/fe_tobytes.c index 0a63baf9c17..a4dff2c1574 100644 --- a/plugin/auth_ed25519/ref10/fe_tobytes.c +++ b/plugin/auth_ed25519/ref10/fe_tobytes.c @@ -1,4 +1,5 @@ #include "fe.h" +#include "crypto_uint32.h" /* Preconditions: @@ -38,16 +39,16 @@ void fe_tobytes(unsigned char *s,const fe h) crypto_int32 h8 = h[8]; crypto_int32 h9 = h[9]; crypto_int32 q; - crypto_int32 carry0; - crypto_int32 carry1; - crypto_int32 carry2; - crypto_int32 carry3; - crypto_int32 carry4; - crypto_int32 carry5; - crypto_int32 carry6; - crypto_int32 carry7; - crypto_int32 carry8; - crypto_int32 carry9; + crypto_uint32 carry0; + crypto_uint32 carry1; + crypto_uint32 carry2; + crypto_uint32 carry3; + crypto_uint32 carry4; + crypto_uint32 carry5; + crypto_uint32 carry6; + crypto_uint32 carry7; + crypto_uint32 carry8; + crypto_uint32 carry9; q = (19 * h9 + (((crypto_int32) 1) << 24)) >> 25; q = (h0 + q) >> 26; @@ -87,32 +88,32 @@ void fe_tobytes(unsigned char *s,const fe h) s[0] = h0 >> 0; s[1] = h0 >> 8; s[2] = h0 >> 16; - s[3] = (h0 >> 24) | (h1 << 2); + s[3] = (h0 >> 24) | ((crypto_uint32)h1 << 2); s[4] = h1 >> 6; s[5] = h1 >> 14; - s[6] = (h1 >> 22) | (h2 << 3); + s[6] = (h1 >> 22) | ((crypto_uint32)h2 << 3); s[7] = h2 >> 5; s[8] = h2 >> 13; - s[9] = (h2 >> 21) | (h3 << 5); + s[9] = (h2 >> 21) | ((crypto_uint32)h3 << 5); s[10] = h3 >> 3; s[11] = h3 >> 11; - s[12] = (h3 >> 19) | (h4 << 6); + s[12] = (h3 >> 19) | ((crypto_uint32)h4 << 6); s[13] = h4 >> 2; s[14] = h4 >> 10; s[15] = h4 >> 18; s[16] = h5 >> 0; s[17] = h5 >> 8; s[18] = h5 >> 16; - s[19] = (h5 >> 24) | (h6 << 1); + s[19] = (h5 >> 24) | ((crypto_uint32)h6 << 1); s[20] = h6 >> 7; s[21] = h6 >> 15; - s[22] = (h6 >> 23) | (h7 << 3); + s[22] = (h6 >> 23) | ((crypto_uint32)h7 << 3); s[23] = h7 >> 5; s[24] = h7 >> 13; - s[25] = (h7 >> 21) | (h8 << 4); + s[25] = (h7 >> 21) | ((crypto_uint32)h8 << 4); s[26] = h8 >> 4; s[27] = h8 >> 12; - s[28] = (h8 >> 20) | (h9 << 6); + s[28] = (h8 >> 20) | ((crypto_uint32)h9 << 6); s[29] = h9 >> 2; s[30] = h9 >> 10; s[31] = h9 >> 18; diff --git a/plugin/auth_ed25519/ref10/ge_scalarmult_base.c b/plugin/auth_ed25519/ref10/ge_scalarmult_base.c index 421e4fa0fba..9a4ced2182f 100644 --- a/plugin/auth_ed25519/ref10/ge_scalarmult_base.c +++ b/plugin/auth_ed25519/ref10/ge_scalarmult_base.c @@ -35,7 +35,7 @@ static void select(ge_precomp *t,int pos,signed char b) { ge_precomp minust; unsigned char bnegative = negative(b); - unsigned char babs = b - (((-bnegative) & b) << 1); + unsigned char babs = b - ((unsigned char)((-bnegative) & b) << 1); ge_precomp_0(t); cmov(t,&base[pos][0],equal(babs,1)); diff --git a/plugin/auth_ed25519/ref10/sc_muladd.c b/plugin/auth_ed25519/ref10/sc_muladd.c index 6f1e9d02d60..7bf222be815 100644 --- a/plugin/auth_ed25519/ref10/sc_muladd.c +++ b/plugin/auth_ed25519/ref10/sc_muladd.c @@ -95,29 +95,29 @@ void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,co crypto_int64 s21; crypto_int64 s22; crypto_int64 s23; - crypto_int64 carry0; - crypto_int64 carry1; - crypto_int64 carry2; - crypto_int64 carry3; - crypto_int64 carry4; - crypto_int64 carry5; - crypto_int64 carry6; - crypto_int64 carry7; - crypto_int64 carry8; - crypto_int64 carry9; - crypto_int64 carry10; - crypto_int64 carry11; - crypto_int64 carry12; - crypto_int64 carry13; - crypto_int64 carry14; - crypto_int64 carry15; - crypto_int64 carry16; - crypto_int64 carry17; - crypto_int64 carry18; - crypto_int64 carry19; - crypto_int64 carry20; - crypto_int64 carry21; - crypto_int64 carry22; + crypto_uint64 carry0; + crypto_uint64 carry1; + crypto_uint64 carry2; + crypto_uint64 carry3; + crypto_uint64 carry4; + crypto_uint64 carry5; + crypto_uint64 carry6; + crypto_uint64 carry7; + crypto_uint64 carry8; + crypto_uint64 carry9; + crypto_uint64 carry10; + crypto_uint64 carry11; + crypto_uint64 carry12; + crypto_uint64 carry13; + crypto_uint64 carry14; + crypto_uint64 carry15; + crypto_uint64 carry16; + crypto_uint64 carry17; + crypto_uint64 carry18; + crypto_uint64 carry19; + crypto_uint64 carry20; + crypto_uint64 carry21; + crypto_uint64 carry22; s0 = c0 + a0*b0; s1 = c1 + a0*b1 + a1*b0; diff --git a/plugin/auth_ed25519/ref10/sc_reduce.c b/plugin/auth_ed25519/ref10/sc_reduce.c index d01f5a5737e..422d94b6faf 100644 --- a/plugin/auth_ed25519/ref10/sc_reduce.c +++ b/plugin/auth_ed25519/ref10/sc_reduce.c @@ -58,23 +58,23 @@ void sc_reduce(unsigned char *s) crypto_int64 s21 = 2097151 & (load_3(s + 55) >> 1); crypto_int64 s22 = 2097151 & (load_4(s + 57) >> 6); crypto_int64 s23 = (load_4(s + 60) >> 3); - crypto_int64 carry0; - crypto_int64 carry1; - crypto_int64 carry2; - crypto_int64 carry3; - crypto_int64 carry4; - crypto_int64 carry5; - crypto_int64 carry6; - crypto_int64 carry7; - crypto_int64 carry8; - crypto_int64 carry9; - crypto_int64 carry10; - crypto_int64 carry11; - crypto_int64 carry12; - crypto_int64 carry13; - crypto_int64 carry14; - crypto_int64 carry15; - crypto_int64 carry16; + crypto_uint64 carry0; + crypto_uint64 carry1; + crypto_uint64 carry2; + crypto_uint64 carry3; + crypto_uint64 carry4; + crypto_uint64 carry5; + crypto_uint64 carry6; + crypto_uint64 carry7; + crypto_uint64 carry8; + crypto_uint64 carry9; + crypto_uint64 carry10; + crypto_uint64 carry11; + crypto_uint64 carry12; + crypto_uint64 carry13; + crypto_uint64 carry14; + crypto_uint64 carry15; + crypto_uint64 carry16; s11 += s23 * 666643; s12 += s23 * 470296; From 89fd381be854c244fd412d56da02b829ce15bce8 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 25 Mar 2024 19:34:41 +0100 Subject: [PATCH 030/159] MDEV-25252 main.type_float fails in new buildbot disable approximate math in icx. and disable ansi aliasing too (aria loghandler unit tests fail) --- configure.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/configure.cmake b/configure.cmake index fcfce85edb9..1ac875cde35 100644 --- a/configure.cmake +++ b/configure.cmake @@ -991,3 +991,8 @@ IF(have_C__Werror) ) SET(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS}) ENDIF() + +IF(CMAKE_C_COMPILER_ID MATCHES "Intel") + MY_CHECK_AND_SET_COMPILER_FLAG("-no-ansi-alias") + MY_CHECK_AND_SET_COMPILER_FLAG("-fp-model precise") +ENDIF() From 8bb8820df2bd5340c80416c83c87561120915c90 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 26 Mar 2024 20:59:42 +0100 Subject: [PATCH 031/159] MDEV-22949 perfschema.memory_aggregate_no_a_no_u fails sporadically in buildbot with wrong result perfschema aggregation, like SHOW STATUS, is only statistically correct. It doesn't use atomics for performance reasons and might miss individual increments, particularly when two connections are disconnecting at the same time. To have stable results tests should avoid doing it. --- mysql-test/suite/perfschema/include/memory_aggregate_load.inc | 3 ++- mysql-test/suite/perfschema/r/memory_aggregate.result | 2 +- mysql-test/suite/perfschema/r/memory_aggregate_no_a.result | 2 +- .../suite/perfschema/r/memory_aggregate_no_a_no_h.result | 2 +- .../suite/perfschema/r/memory_aggregate_no_a_no_u.result | 2 +- .../suite/perfschema/r/memory_aggregate_no_a_no_u_no_h.result | 2 +- mysql-test/suite/perfschema/r/memory_aggregate_no_h.result | 2 +- mysql-test/suite/perfschema/r/memory_aggregate_no_u.result | 2 +- .../suite/perfschema/r/memory_aggregate_no_u_no_h.result | 2 +- 9 files changed, 10 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/perfschema/include/memory_aggregate_load.inc b/mysql-test/suite/perfschema/include/memory_aggregate_load.inc index 7a54d25216e..c6e58d094d6 100644 --- a/mysql-test/suite/perfschema/include/memory_aggregate_load.inc +++ b/mysql-test/suite/perfschema/include/memory_aggregate_load.inc @@ -274,7 +274,6 @@ execute dump_users; execute dump_hosts; --disconnect con1 ---disconnect con5 --connection default @@ -283,6 +282,8 @@ let $wait_condition= select count(*) = 0 from performance_schema.threads where `TYPE`='FOREGROUND' and PROCESSLIST_USER= 'user1'; --source include/wait_condition.inc + +--disconnect con5 let $wait_condition= select count(*) = 1 from performance_schema.threads where `TYPE`='FOREGROUND' and PROCESSLIST_USER= 'user4'; diff --git a/mysql-test/suite/perfschema/r/memory_aggregate.result b/mysql-test/suite/perfschema/r/memory_aggregate.result index 69eb033e74b..1d963dd8caa 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate.result @@ -2507,8 +2507,8 @@ execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS localhost 6 6 disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); diff --git a/mysql-test/suite/perfschema/r/memory_aggregate_no_a.result b/mysql-test/suite/perfschema/r/memory_aggregate_no_a.result index b5c8e1cd3c7..abac503b965 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate_no_a.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate_no_a.result @@ -1903,8 +1903,8 @@ execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS localhost 6 6 disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); diff --git a/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_h.result b/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_h.result index cc0e0c03dcf..f63e6f1d002 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_h.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_h.result @@ -1653,8 +1653,8 @@ user4 2 2 execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); diff --git a/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_u.result b/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_u.result index 8b24b5b565b..32785952fe7 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_u.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_u.result @@ -1343,8 +1343,8 @@ execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS localhost 6 6 disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); diff --git a/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_u_no_h.result b/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_u_no_h.result index 45cbaf88372..e68f0e1baf6 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_u_no_h.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate_no_a_no_u_no_h.result @@ -1093,8 +1093,8 @@ USER CURRENT_CONNECTIONS TOTAL_CONNECTIONS execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); diff --git a/mysql-test/suite/perfschema/r/memory_aggregate_no_h.result b/mysql-test/suite/perfschema/r/memory_aggregate_no_h.result index 35d528bf63c..e3b7cd0f998 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate_no_h.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate_no_h.result @@ -2257,8 +2257,8 @@ user4 2 2 execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); diff --git a/mysql-test/suite/perfschema/r/memory_aggregate_no_u.result b/mysql-test/suite/perfschema/r/memory_aggregate_no_u.result index 1f800ce4ba6..fd9f2c69a42 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate_no_u.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate_no_u.result @@ -1947,8 +1947,8 @@ execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS localhost 6 6 disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); diff --git a/mysql-test/suite/perfschema/r/memory_aggregate_no_u_no_h.result b/mysql-test/suite/perfschema/r/memory_aggregate_no_u_no_h.result index b1ac5f24ec9..fdbd2d75d56 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate_no_u_no_h.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate_no_u_no_h.result @@ -1697,8 +1697,8 @@ USER CURRENT_CONNECTIONS TOTAL_CONNECTIONS execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); From 49f2e9f700c2a3e3972fc1872eecac444b030a50 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 00:05:00 +0100 Subject: [PATCH 032/159] update bison version dependency need at least 2.4 because we use per-type %destructor that was added after 2.3 in 2.3a --- sql/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index c33e6454e20..bb86d5cac66 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -65,7 +65,7 @@ ADD_CUSTOM_COMMAND( DEPENDS gen_lex_token ) -FIND_PACKAGE(BISON 2.0) +FIND_PACKAGE(BISON 2.4) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yy_mariadb.yy From dc681953cf57da17cf566f4ef14e15589507955f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 09:51:28 +0100 Subject: [PATCH 033/159] events in perfschema tests: use ON COMPLETION NOT PRESERVE when the execution is very slow, under valgrind, the event might manage to fire more than once, making the test to fail --- mysql-test/suite/perfschema/include/program_execution.inc | 2 +- .../r/statement_program_nesting_event_check.result | 4 ++-- .../suite/perfschema/r/statement_program_non_nested.result | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/perfschema/include/program_execution.inc b/mysql-test/suite/perfschema/include/program_execution.inc index 8c0bc691898..f774a4d7b50 100644 --- a/mysql-test/suite/perfschema/include/program_execution.inc +++ b/mysql-test/suite/perfschema/include/program_execution.inc @@ -32,7 +32,7 @@ SET GLOBAL event_scheduler=ON; CREATE TABLE table_t(a INT); DELIMITER |; -CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO +CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND ON COMPLETION NOT PRESERVE DO BEGIN INSERT INTO table_t VALUES(1); END| diff --git a/mysql-test/suite/perfschema/r/statement_program_nesting_event_check.result b/mysql-test/suite/perfschema/r/statement_program_nesting_event_check.result index 5e376a12a18..1a973c9448b 100644 --- a/mysql-test/suite/perfschema/r/statement_program_nesting_event_check.result +++ b/mysql-test/suite/perfschema/r/statement_program_nesting_event_check.result @@ -145,7 +145,7 @@ Bollywood # Event SET GLOBAL event_scheduler=ON; CREATE TABLE table_t(a INT); -CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO +CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND ON COMPLETION NOT PRESERVE DO BEGIN INSERT INTO table_t VALUES(1); END| @@ -165,7 +165,7 @@ statement/sql/call_procedure CALL SampleProc1(30,40,50) NULL NULL 0 statement/sql/call_procedure CALL SampleProc2("Jwalamukhi",34) NULL NULL 0 statement/sql/call_procedure CALL SampleProc3() NULL NULL 0 statement/sql/call_procedure CALL SampleProc4() NULL NULL 0 -statement/sql/create_event CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO +statement/sql/create_event CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND ON COMPLETION NOT PRESERVE DO BEGIN INSERT INTO table_t VALUES(1); END NULL NULL 0 diff --git a/mysql-test/suite/perfschema/r/statement_program_non_nested.result b/mysql-test/suite/perfschema/r/statement_program_non_nested.result index af9807cbc97..1c75dac11ac 100644 --- a/mysql-test/suite/perfschema/r/statement_program_non_nested.result +++ b/mysql-test/suite/perfschema/r/statement_program_non_nested.result @@ -145,7 +145,7 @@ Bollywood # Event SET GLOBAL event_scheduler=ON; CREATE TABLE table_t(a INT); -CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO +CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND ON COMPLETION NOT PRESERVE DO BEGIN INSERT INTO table_t VALUES(1); END| @@ -182,7 +182,7 @@ statement/sql/call_procedure CALL SampleProc1(30,40,50) stored_programs NULL NUL statement/sql/call_procedure CALL SampleProc2("Jwalamukhi",34) stored_programs NULL NULL NULL NULL 0 statement/sql/call_procedure CALL SampleProc3() stored_programs NULL NULL NULL NULL 0 statement/sql/call_procedure CALL SampleProc4() stored_programs NULL NULL NULL NULL 0 -statement/sql/create_event CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO +statement/sql/create_event CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND ON COMPLETION NOT PRESERVE DO BEGIN INSERT INTO table_t VALUES(1); END stored_programs NULL NULL NULL NULL 0 @@ -553,7 +553,7 @@ Bollywood # Event SET GLOBAL event_scheduler=ON; CREATE TABLE table_t(a INT); -CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND DO +CREATE EVENT e1 ON SCHEDULE EVERY 2 SECOND ON COMPLETION NOT PRESERVE DO BEGIN INSERT INTO table_t VALUES(1); END| From f50694c52be8de72adca27e1f9623aa90ed26a48 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 09:53:56 +0100 Subject: [PATCH 034/159] remove pointless test --- .../r/innodb_purge_threads_basic.result | 41 -------------- .../t/innodb_purge_threads_basic.test | 53 ------------------- 2 files changed, 94 deletions(-) delete mode 100644 mysql-test/suite/sys_vars/r/innodb_purge_threads_basic.result delete mode 100644 mysql-test/suite/sys_vars/t/innodb_purge_threads_basic.test diff --git a/mysql-test/suite/sys_vars/r/innodb_purge_threads_basic.result b/mysql-test/suite/sys_vars/r/innodb_purge_threads_basic.result deleted file mode 100644 index 2cb697acb6d..00000000000 --- a/mysql-test/suite/sys_vars/r/innodb_purge_threads_basic.result +++ /dev/null @@ -1,41 +0,0 @@ -SELECT COUNT(@@GLOBAL.innodb_purge_threads); -COUNT(@@GLOBAL.innodb_purge_threads) -1 -1 Expected -SELECT COUNT(@@innodb_purge_threads); -COUNT(@@innodb_purge_threads) -1 -1 Expected -SET @@GLOBAL.innodb_purge_threads=1; -ERROR HY000: Variable 'innodb_purge_threads' is a read only variable -Expected error 'Read-only variable' -SELECT innodb_purge_threads = @@SESSION.innodb_purge_threads; -ERROR 42S22: Unknown column 'innodb_purge_threads' in 'field list' -Expected error 'Read-only variable' -SELECT @@GLOBAL.innodb_purge_threads = VARIABLE_VALUE -FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES -WHERE VARIABLE_NAME='innodb_purge_threads'; -@@GLOBAL.innodb_purge_threads = VARIABLE_VALUE -1 -1 Expected -SELECT COUNT(VARIABLE_VALUE) -FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES -WHERE VARIABLE_NAME='innodb_purge_threads'; -COUNT(VARIABLE_VALUE) -1 -1 Expected -SELECT @@innodb_purge_threads = @@GLOBAL.innodb_purge_threads; -@@innodb_purge_threads = @@GLOBAL.innodb_purge_threads -1 -1 Expected -SELECT COUNT(@@local.innodb_purge_threads); -ERROR HY000: Variable 'innodb_purge_threads' is a GLOBAL variable -Expected error 'Variable is a GLOBAL variable' -SELECT COUNT(@@SESSION.innodb_purge_threads); -ERROR HY000: Variable 'innodb_purge_threads' is a GLOBAL variable -Expected error 'Variable is a GLOBAL variable' -SELECT VARIABLE_NAME, VARIABLE_VALUE -FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES -WHERE VARIABLE_NAME = 'innodb_purge_threads'; -VARIABLE_NAME VARIABLE_VALUE -INNODB_PURGE_THREADS 4 diff --git a/mysql-test/suite/sys_vars/t/innodb_purge_threads_basic.test b/mysql-test/suite/sys_vars/t/innodb_purge_threads_basic.test deleted file mode 100644 index 4d039601e40..00000000000 --- a/mysql-test/suite/sys_vars/t/innodb_purge_threads_basic.test +++ /dev/null @@ -1,53 +0,0 @@ -# Variable name: innodb_purge_threads -# Scope: Global -# Access type: Static -# Data type: numeric - ---source include/have_innodb.inc - -SELECT COUNT(@@GLOBAL.innodb_purge_threads); ---echo 1 Expected - -SELECT COUNT(@@innodb_purge_threads); ---echo 1 Expected - ---error ER_INCORRECT_GLOBAL_LOCAL_VAR -SET @@GLOBAL.innodb_purge_threads=1; ---echo Expected error 'Read-only variable' - ---Error ER_BAD_FIELD_ERROR -SELECT innodb_purge_threads = @@SESSION.innodb_purge_threads; ---echo Expected error 'Read-only variable' - ---disable_warnings -SELECT @@GLOBAL.innodb_purge_threads = VARIABLE_VALUE -FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES -WHERE VARIABLE_NAME='innodb_purge_threads'; ---enable_warnings ---echo 1 Expected - ---disable_warnings -SELECT COUNT(VARIABLE_VALUE) -FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES -WHERE VARIABLE_NAME='innodb_purge_threads'; ---enable_warnings ---echo 1 Expected - -SELECT @@innodb_purge_threads = @@GLOBAL.innodb_purge_threads; ---echo 1 Expected - ---Error ER_INCORRECT_GLOBAL_LOCAL_VAR -SELECT COUNT(@@local.innodb_purge_threads); ---echo Expected error 'Variable is a GLOBAL variable' - ---Error ER_INCORRECT_GLOBAL_LOCAL_VAR -SELECT COUNT(@@SESSION.innodb_purge_threads); ---echo Expected error 'Variable is a GLOBAL variable' - -# Check the default value ---disable_warnings -SELECT VARIABLE_NAME, VARIABLE_VALUE -FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES -WHERE VARIABLE_NAME = 'innodb_purge_threads'; ---enable_warnings - From 721a6a5e6be2c76f3806de36f80e4c6e09795daf Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 11:38:36 +0100 Subject: [PATCH 035/159] plugins.test_sql_service --valgrind plugin var check function must store the new variable value in *save --- plugin/test_sql_service/test_sql_service.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin/test_sql_service/test_sql_service.c b/plugin/test_sql_service/test_sql_service.c index 4ea6533af84..94031e36231 100644 --- a/plugin/test_sql_service/test_sql_service.c +++ b/plugin/test_sql_service/test_sql_service.c @@ -129,6 +129,7 @@ void auditing(MYSQL_THD thd, unsigned int event_class, const void *ev) static int run_test(MYSQL_THD thd, struct st_mysql_sys_var *var, void *save, struct st_mysql_value *value) { + *(my_bool*)save= 1; // must initialize the return value return (test_passed= (do_tests() == 0)) == 0; } @@ -139,6 +140,7 @@ static int run_sql(MYSQL *mysql, void *save, struct st_mysql_value *value) int len= 0; MYSQL_RES *res; + *(my_bool*)save= 1; // must initialize the return value str= value->val_str(value, NULL, &len); if (mysql_real_query(mysql, str, len)) From 58c7f63176fa63c4df25e01f48ac4edd4acb76db Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 15:01:28 +0100 Subject: [PATCH 036/159] mysqltest: better error reporting when "shutdown" fails as a side effect --replace and --error now work for shutdown command --- client/mysqltest.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 7a36f460799..f1ddea7c083 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5199,7 +5199,11 @@ void do_shutdown_server(struct st_command *command) */ if (timeout && mysql_shutdown(mysql, SHUTDOWN_DEFAULT)) - die("mysql_shutdown failed"); + { + handle_error(command, mysql_errno(mysql), mysql_error(mysql), + mysql_sqlstate(mysql), &ds_res); + DBUG_VOID_RETURN; + } if (!timeout || wait_until_dead(pid, timeout)) { @@ -8191,7 +8195,7 @@ static int match_expected_error(struct st_command *command, SYNOPSIS handle_error() - q - query context + command - command err_errno - error number err_error - error message err_sqlstate - sql state From 3226787bba5d8e825e7d32e864e3a522b9ded65f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 15:14:31 +0100 Subject: [PATCH 037/159] Revert "Fixed random failure in main.kill_processlist-6619" This reverts commit 8b3f470c0bdf183b26cb2b06a9ae416aa7f16b04. because it doesn't work, the test still fails, and even more than before --- mysql-test/main/kill_processlist-6619.result | 6 ------ mysql-test/main/kill_processlist-6619.test | 9 --------- 2 files changed, 15 deletions(-) diff --git a/mysql-test/main/kill_processlist-6619.result b/mysql-test/main/kill_processlist-6619.result index 25831a1f63b..7dd42790cc7 100644 --- a/mysql-test/main/kill_processlist-6619.result +++ b/mysql-test/main/kill_processlist-6619.result @@ -1,8 +1,4 @@ -SET DEBUG_SYNC='dispatch_command_end SIGNAL ready WAIT_FOR go'; -select 1; connect con1,localhost,root,,; -SET DEBUG_SYNC='now wait_for ready'; -SET DEBUG_SYNC='now signal go'; SHOW PROCESSLIST; Id User Host db Command Time State Info Progress # root # test Sleep # # NULL 0.000 @@ -10,8 +6,6 @@ Id User Host db Command Time State Info Progress SET DEBUG_SYNC='before_execute_sql_command SIGNAL ready WAIT_FOR go'; SHOW PROCESSLIST; connection default; -1 -1 SET DEBUG_SYNC='now WAIT_FOR ready'; KILL QUERY con_id; SET DEBUG_SYNC='now SIGNAL go'; diff --git a/mysql-test/main/kill_processlist-6619.test b/mysql-test/main/kill_processlist-6619.test index 7330c79acd8..c272e68a877 100644 --- a/mysql-test/main/kill_processlist-6619.test +++ b/mysql-test/main/kill_processlist-6619.test @@ -4,14 +4,7 @@ --source include/not_embedded.inc --source include/have_debug_sync.inc -# This is to ensure that the following SHOW PROCESSLIST does not show the query -SET DEBUG_SYNC='dispatch_command_end SIGNAL ready WAIT_FOR go'; ---send select 1 - --connect (con1,localhost,root,,) -SET DEBUG_SYNC='now wait_for ready'; -SET DEBUG_SYNC='now signal go'; - --let $con_id = `SELECT CONNECTION_ID()` --replace_result Execute Query --replace_column 1 # 3 # 6 # 7 # @@ -19,8 +12,6 @@ SHOW PROCESSLIST; SET DEBUG_SYNC='before_execute_sql_command SIGNAL ready WAIT_FOR go'; send SHOW PROCESSLIST; --connection default ---reap - # We must wait for the SHOW PROCESSLIST query to have started before sending # the kill. Otherwise, the KILL may be lost since it is reset at the start of # query execution. From 81f75ca83ae618bcdd5893fa690aaded35cba0e9 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 15:21:49 +0100 Subject: [PATCH 038/159] Fixed random failure in main.kill_processlist-6619 wait for all previous connections to disconnect and for all previous queries to finish running --- mysql-test/main/kill_processlist-6619.test | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mysql-test/main/kill_processlist-6619.test b/mysql-test/main/kill_processlist-6619.test index c272e68a877..09c41f28a8f 100644 --- a/mysql-test/main/kill_processlist-6619.test +++ b/mysql-test/main/kill_processlist-6619.test @@ -4,8 +4,15 @@ --source include/not_embedded.inc --source include/have_debug_sync.inc +let $wait_condition=select count(*) = 1 from information_schema.processlist; +source include/wait_condition.inc; + --connect (con1,localhost,root,,) --let $con_id = `SELECT CONNECTION_ID()` + +let $wait_condition=select info is NULL from information_schema.processlist where id != $con_id; +source include/wait_condition.inc; + --replace_result Execute Query --replace_column 1 # 3 # 6 # 7 # SHOW PROCESSLIST; From 0b627377a95d01c3f1dd1bfff52523bb48d5d5e7 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 13 Mar 2024 13:10:47 +1100 Subject: [PATCH 039/159] MDEV-33661 MENT-1591 Documenting spider_mon_table_cache and friends. Partial documentation due to time constraints. Will improve over time. Also removed a redundant parameter link_idx from spider_get_sys_tables_connect_info(). And deleted some commented out code. --- storage/spider/spd_copy_tables.cc | 2 +- storage/spider/spd_include.h | 1 + storage/spider/spd_ping_table.cc | 128 ++++++++++++++++++++---------- storage/spider/spd_sys_table.cc | 71 ++++++++++------- storage/spider/spd_sys_table.h | 3 +- storage/spider/spd_table.cc | 48 ++++------- 6 files changed, 150 insertions(+), 103 deletions(-) diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index 34e3cb66712..d205cd244ca 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -307,7 +307,7 @@ int spider_udf_get_copy_tgt_tables( if ( (error_num = spider_get_sys_tables_connect_info( - table_tables, tmp_share, 0, mem_root)) || + table_tables, tmp_share, mem_root)) || (error_num = spider_get_sys_tables_link_status( table_tables, tmp_share, 0, mem_root)) || (error_num = spider_get_sys_tables_link_idx( diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 0e72ce26696..51fac2a4cea 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -1606,6 +1606,7 @@ typedef struct st_spider_table_mon st_spider_table_mon *next; } SPIDER_TABLE_MON; +/* List of `SPIDER_TABLE_MON's */ typedef struct st_spider_table_mon_list { char *key; diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index 34d643d3555..92f5ff9e69f 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -54,6 +54,8 @@ extern PSI_mutex_key spd_key_mutex_mon_list_update_status; extern PSI_mutex_key spd_key_mutex_mon_table_cache; #endif +/* Array (of size `spider_udf_table_mon_mutex_count') of hashes of +`SPIDER_TABLE_MON_LIST'. */ HASH *spider_udf_table_mon_list_hash; uint spider_udf_table_mon_list_hash_id; const char *spider_udf_table_mon_list_hash_func_name; @@ -63,23 +65,43 @@ pthread_mutex_t *spider_udf_table_mon_mutexes; pthread_cond_t *spider_udf_table_mon_conds; pthread_mutex_t spider_mon_table_cache_mutex; +/* A cache to store distinct SPIDER_MON_KEYs with db name, table name +and link id read from mysql.spider_link_mon_servers table. Initialised +and populated in spider_init_ping_table_mon_cache(), and used in +spider_ping_table_cache_compare(). The udf +spider_flush_table_mon_cache is used to flag a initialisation. */ DYNAMIC_ARRAY spider_mon_table_cache; uint spider_mon_table_cache_id; const char *spider_mon_table_cache_func_name; const char *spider_mon_table_cache_file_name; ulong spider_mon_table_cache_line_no; +/* The mon table cache version, initialised at 0, and always no +greater than spider_mon_table_cache_version_req. When the inequality +is strict, an initialisation of spider_mon_table_cache will be +triggered. */ volatile ulonglong spider_mon_table_cache_version = 0; +/* The required mon table cache version, incremented by one by the +udf spider_flush_table_mon_cache */ volatile ulonglong spider_mon_table_cache_version_req = 1; + /* Get or create a `SPIDER_TABLE_MON_LIST' for a key `str' */ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( SPIDER_TRX *trx, THD *thd, - spider_string *str, + spider_string *str, /* The key to search in + `spider_udf_table_mon_list_hash', + usually in the format of + "./$db_name/$table_name000000000$link_idx" */ uint conv_name_length, int link_idx, char *static_link_id, uint static_link_id_length, - uint32 server_id, + uint32 server_id, /* The server id of the monitor + server, used for creating a new + table mon list having a + `SPIDER_TABLE_MON' corresponding to + the server id as the `current' + field */ bool need_lock, int *error_num ) { @@ -91,6 +113,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( my_hash_value_type hash_value; #endif DBUG_ENTER("spider_get_ping_table_mon_list"); + /* Reset the cache if the version does not match the requirement */ if (spider_mon_table_cache_version != spider_mon_table_cache_version_req) { SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); @@ -103,6 +126,9 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( free_root(&mem_root, MYF(0)); } + /* Search for the table mon list in the hash, if one is not found or + if it is found but has the wrong cache version, create and + initialise a new one. */ mutex_hash = spider_udf_calc_hash(str->c_ptr(), spider_param_udf_table_mon_mutex_count()); DBUG_PRINT("info",("spider hash key=%s", str->c_ptr())); @@ -129,12 +155,15 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( ) #endif { + /* If table_mon_list is found but the cache version does not + match, remove it from the hash and free it. */ if ( table_mon_list && table_mon_list->mon_table_cache_version != mon_table_cache_version ) spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list); - + /* create and initialise `table_mon_list' and insert it into the + hash */ if (!(table_mon_list = spider_get_ping_table_tgt(thd, str->c_ptr(), conv_name_length, link_idx, static_link_id, static_link_id_length, server_id, str, need_lock, error_num))) @@ -277,6 +306,14 @@ int spider_release_ping_table_mon_list( DBUG_RETURN(0); } +/* + Look for a `SPIDER_MON_KEY` in `spider_mon_table_cache' whose db and + table name and link_idx matching `name' and `link_idx' with wild + card matching. If a match is found, create `SPIDER_TABLE_MON's from + all rows in mysql.spider_link_mon_servers that match the info in the + `SPIDER_MON_KEY' and populate the `table_mon_list' with these + `SPIDER_TABLE_MON's. +*/ int spider_get_ping_table_mon( THD *thd, SPIDER_TABLE_MON_LIST *table_mon_list, @@ -357,6 +394,8 @@ int spider_get_ping_table_mon( goto error; create_table_mon: + /* Find the first row in mysql.spider_link_mon_servers matching the + db name, table name and link_idx */ if ((error_num = spider_get_sys_table_by_idx(table_link_mon, table_key, table_link_mon->s->primary_key, 3))) { @@ -364,6 +403,9 @@ create_table_mon: goto error; } + /* create one `SPIDER_TABLE_MON' per row in + mysql.spider_link_mon_servers with matching db name, table name and + link_idx, and add it to `table_mon_list'. */ do { if (!(table_mon = (SPIDER_TABLE_MON *) spider_bulk_malloc(spider_current_trx, SPD_MID_GET_PING_TABLE_MON_1, MYF(MY_WME | MY_ZEROFILL), @@ -394,7 +436,7 @@ create_table_mon: (error_num = spider_get_sys_link_mon_server_id( table_link_mon, &table_mon->server_id, mem_root)) || (error_num = spider_get_sys_link_mon_connect_info( - table_link_mon, tmp_share, 0, mem_root)) + table_link_mon, tmp_share, mem_root)) ) { table_link_mon->file->print_error(error_num, MYF(0)); spider_sys_index_end(table_link_mon); @@ -458,15 +500,21 @@ error: DBUG_RETURN(error_num); } +/* + creates and return table_mon_list associated with table with `name' + and `link_idx'th link. +*/ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( THD *thd, - char *name, + char *name, /* The table name, usually fully qualified */ uint name_length, int link_idx, char *static_link_id, uint static_link_id_length, - uint32 server_id, - spider_string *str, + uint32 server_id, /* The server_id will determine the + `current' field of the returned + `SPIDER_TABLE_MON_LIST'. */ + spider_string *str, /* str->c_ptr() == name */ bool need_lock, int *error_num ) { @@ -511,6 +559,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( memcpy(key_str, str->ptr(), table_mon_list->key_length); tmp_share->access_charset = thd->variables.character_set_client; + /* Open mysql.spider_tables */ if ( !(table_tables = spider_open_sys_table( thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, @@ -520,6 +569,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( my_error(*error_num, MYF(0)); goto error; } + /* store db and table names and link idx in mysql.spider_tables for + reading */ spider_store_tables_name(table_tables, name, name_length); if (static_link_id) { @@ -543,9 +594,10 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( goto error; } } + /* Populate tmp_share with info read from mysql.spider_tables */ if ( (*error_num = spider_get_sys_tables_connect_info( - table_tables, tmp_share, 0, &mem_root)) || + table_tables, tmp_share, &mem_root)) || (*error_num = spider_get_sys_tables_link_status( table_tables, tmp_share, 0, &mem_root)) ) { @@ -569,9 +621,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( tmp_share, name, name_length )) || (*error_num = spider_create_conn_keys(tmp_share)) || -/* - (*error_num = spider_db_create_table_names_str(tmp_share)) || -*/ + /* Pinally, populate `table_mon_list' with newly created + `SPIDER_TABLE_MON's */ (*error_num = spider_get_ping_table_mon( thd, table_mon_list, name, name_length, link_idx, server_id, &mem_root, need_lock)) @@ -836,6 +887,11 @@ error_open_table_tables: DBUG_RETURN(error_num); } +/* + Initialise `spider_mon_table_cache' by scanning the + mysql.spider_link_mon_servers table, creating distinct + `SPIDER_MON_KEY's with the info and inserting them into the cache. +*/ int spider_init_ping_table_mon_cache( THD *thd, MEM_ROOT *mem_root, @@ -867,6 +923,7 @@ int spider_init_ping_table_mon_cache( /* reset */ spider_mon_table_cache.elements = 0; + /* start at the first row */ if ((error_num = spider_sys_index_first(table_link_mon, table_link_mon->s->primary_key))) { @@ -883,10 +940,16 @@ int spider_init_ping_table_mon_cache( mon_key.table_name_length = SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1; mon_key.link_id_length = SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1; do { + /* update content of `mon_key' */ if ((error_num = spider_get_sys_link_mon_key(table_link_mon, &mon_key, mem_root, &same))) goto error_get_sys_link_mon_key; + /* `mon_key' has changed content. since + mysql.spider_link_mon_servers is indexed by db_name, + table_name, link_idx, and server_id, it is possible that + different server_ids share the same mon_key which only has + db_name, table_name, link_idx */ if (!same) { mon_key.sort = spider_calc_for_sort(3, mon_key.db_name, @@ -941,6 +1004,13 @@ error_open_sys_table: DBUG_RETURN(error_num); } +/* + Read from msyql.spider_link_mon_servers table fields the db name, + table name and link_id and search for them with wild card matching + in `spider_mon_table_cache'. store the db name, table name, and + link_id of the matching `SPIDER_MON_KEY' back to the table field on + success. +*/ int spider_ping_table_cache_compare( TABLE *table, MEM_ROOT *mem_root @@ -1239,9 +1309,6 @@ long long spider_ping_table_body( DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 2")); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1256,9 +1323,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1312,9 +1376,6 @@ long long spider_ping_table_body( DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 3")); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1329,9 +1390,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1375,9 +1433,6 @@ long long spider_ping_table_body( mon_table_result->result_status == SPIDER_LINK_MON_NG && table_mon_list->mon_status != SPIDER_LINK_MON_NG ) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1392,9 +1447,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1565,9 +1617,9 @@ int spider_ping_table_mon_from_table( SPIDER_SHARE *share, int base_link_idx, uint32 server_id, - char *conv_name, + char *conv_name, /* Usually fully qualified table name */ uint conv_name_length, - int link_idx, + int link_idx, /* The link id to ping */ char *where_clause, uint where_clause_length, long monitoring_kind, @@ -1577,9 +1629,6 @@ int spider_ping_table_mon_from_table( ) { int error_num = 0, current_mon_count, flags; uint32 first_sid; -/* - THD *thd = trx->thd; -*/ SPIDER_TABLE_MON_LIST *table_mon_list; SPIDER_TABLE_MON *table_mon; SPIDER_MON_TABLE_RESULT mon_table_result; @@ -1648,6 +1697,7 @@ int spider_ping_table_mon_from_table( if (monitoring_flag & 1) flags |= SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES; + /* Get or create `table_mon_list' for `conv_name_str'. */ if (!(table_mon_list = spider_get_ping_table_mon_list(trx, thd, &conv_name_str, conv_name_length, link_idx, share->static_link_ids[link_idx], @@ -1679,6 +1729,8 @@ int spider_ping_table_mon_from_table( table_mon = table_mon_list->current; first_sid = table_mon->server_id; current_mon_count = 1; + /* Call spider_ping_table on each table_mon of `table_mon_list', + until one succeeds */ while (TRUE) { DBUG_PRINT("info",("spider thd->killed=%s", @@ -1723,16 +1775,13 @@ int spider_ping_table_mon_from_table( if (!spider_db_udf_ping_table_mon_next( thd, table_mon, mon_conn, &mon_table_result, conv_name, conv_name_length, link_idx, - where_clause, where_clause_length, -1, table_mon_list->list_size, + where_clause, where_clause_length, /*first_sid=*/-1, table_mon_list->list_size, 0, 0, 0, flags, monitoring_limit)) { if ( mon_table_result.result_status == SPIDER_LINK_MON_NG && table_mon_list->mon_status != SPIDER_LINK_MON_NG ) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1747,9 +1796,6 @@ int spider_ping_table_mon_from_table( spider_sys_log_tables_link_failed(thd, conv_name, conv_name_length, link_idx, need_lock); } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); } table_mon_list->last_caller_result = mon_table_result.result_status; diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc index f33a5373168..10f9fdedd5b 100644 --- a/storage/spider/spd_sys_table.cc +++ b/storage/spider/spd_sys_table.cc @@ -570,6 +570,11 @@ int spider_check_sys_table_for_update_all_columns( #endif } +/* + Creates a key (`table_key') consisting of `col_count' key parts of + `idx'th index of the table, then positions an index cursor to that + key. +*/ int spider_get_sys_table_by_idx( TABLE *table, char *table_key, @@ -602,17 +607,6 @@ int spider_get_sys_table_by_idx( key_length); if ( -/* -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 - (error_num = table->file->ha_index_read_idx_map( - table->record[0], idx, (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#else - (error_num = table->file->index_read_idx_map( - table->record[0], idx, (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#endif -*/ #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_read_map( table->record[0], (uchar *) table_key, @@ -649,7 +643,7 @@ int spider_sys_index_next_same( int spider_sys_index_first( TABLE *table, - const int idx + const int idx /* which index to use */ ) { int error_num; DBUG_ENTER("spider_sys_index_first"); @@ -870,6 +864,10 @@ void spider_store_xa_member_info( DBUG_VOID_RETURN; } +/* + Store db and table names from `name' to `table's corresponding + fields +*/ void spider_store_tables_name( TABLE *table, const char *name, @@ -2064,14 +2062,16 @@ int spider_get_sys_tables( DBUG_RETURN(0); } +/* Read table info from mysql.spider_tables into a `SPIDER_SHARE' */ int spider_get_sys_tables_connect_info( - TABLE *table, - SPIDER_SHARE *share, - int link_idx, + TABLE *table, /* The mysql.spider_tables table */ + SPIDER_SHARE *share, /* The `SPIDER_SHARE' to + update info */ MEM_ROOT *mem_root ) { char *ptr; int error_num = 0; + const int link_idx= 0; DBUG_ENTER("spider_get_sys_tables_connect_info"); if ((ptr = get_field(mem_root, table->field[3]))) { @@ -2297,9 +2297,14 @@ int spider_get_sys_tables_monitoring_binlog_pos_at_failing( DBUG_RETURN(error_num); } +/* + Read the link status from mysql.spider_tables into a `SPIDER_SHARE' + with default value 1 (`SPIDER_LINK_STATUS_OK') +*/ int spider_get_sys_tables_link_status( - TABLE *table, - SPIDER_SHARE *share, + TABLE *table, /* The mysql.spider_tables table */ + SPIDER_SHARE *share, /* The share to read link + status into */ int link_idx, MEM_ROOT *mem_root ) { @@ -2484,11 +2489,17 @@ error: DBUG_RETURN(error_num); } +/* Populate `mon_key' from the current row in `table' */ int spider_get_sys_link_mon_key( - TABLE *table, - SPIDER_MON_KEY *mon_key, + TABLE *table, /* the mysql.spider_link_mon_servers + table */ + SPIDER_MON_KEY *mon_key, /* output, to be populated in this + function */ MEM_ROOT *mem_root, - int *same + int *same /* output, true if the data from the + current row in the table agrees with + existing data in `mon_key' and false + otherwise */ ) { char *db_name, *table_name, *link_id; uint db_name_length, table_name_length, link_id_length; @@ -2504,6 +2515,7 @@ int spider_get_sys_link_mon_key( DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM); } + /* get data for `mon_key' from the table record */ if (!(db_name = get_field(mem_root, table->field[0]))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); if (!(table_name = get_field(mem_root, table->field[1]))) @@ -2549,9 +2561,12 @@ int spider_get_sys_link_mon_key( DBUG_RETURN(0); } +/* Get the server id from the spider_link_mon_servers table field */ int spider_get_sys_link_mon_server_id( - TABLE *table, - uint32 *server_id, + TABLE *table, /* the + mysql.spider_link_mon_servers + table */ + uint32 *server_id, /* output to server_id */ MEM_ROOT *mem_root ) { char *ptr; @@ -2564,14 +2579,17 @@ int spider_get_sys_link_mon_server_id( DBUG_RETURN(error_num); } +/* Get connect info from the spider_link_mon_servers table fields */ int spider_get_sys_link_mon_connect_info( - TABLE *table, - SPIDER_SHARE *share, - int link_idx, + TABLE *table, /* The + mysql.spider_link_mon_servers + table */ + SPIDER_SHARE *share, /* The output spider_share */ MEM_ROOT *mem_root ) { char *ptr; int error_num = 0; + const int link_idx= 0; DBUG_ENTER("spider_get_sys_link_mon_connect_info"); if ( !table->field[4]->is_null() && @@ -2753,9 +2771,6 @@ int spider_get_link_statuses( if ( (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) ) { -/* - table->file->print_error(error_num, MYF(0)); -*/ DBUG_RETURN(error_num); } } else if ((error_num = diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h index 53ef3b82465..fca38c67683 100644 --- a/storage/spider/spd_sys_table.h +++ b/storage/spider/spd_sys_table.h @@ -56,6 +56,7 @@ #define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64 #define SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE 64 +/* For insertion into `spider_mon_table_cache'. */ class SPIDER_MON_KEY: public SPIDER_SORT { public: @@ -425,7 +426,6 @@ int spider_get_sys_tables( int spider_get_sys_tables_connect_info( TABLE *table, SPIDER_SHARE *share, - int link_idx, MEM_ROOT *mem_root ); @@ -502,7 +502,6 @@ int spider_get_sys_link_mon_server_id( int spider_get_sys_link_mon_connect_info( TABLE *table, SPIDER_SHARE *share, - int link_idx, MEM_ROOT *mem_root ); diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index fae239c57db..610fbeda1f3 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -3421,13 +3421,15 @@ error_alloc_conn_string: DBUG_RETURN(error_num); } +/* Set default connect info of a SPIDER_SHARE if needed */ int spider_set_connect_info_default( - SPIDER_SHARE *share, + SPIDER_SHARE *share, /* The `SPIDER_SHARE' to set + default connect info */ #ifdef WITH_PARTITION_STORAGE_ENGINE - partition_element *part_elem, - partition_element *sub_elem, + partition_element *part_elem, /* partition info used as input */ + partition_element *sub_elem, /* subpartition info used as input */ #endif - TABLE_SHARE *table_share + TABLE_SHARE *table_share /* table share info used as input */ ) { int error_num, roop_count; DBUG_ENTER("spider_set_connect_info_default"); @@ -3558,22 +3560,6 @@ int spider_set_connect_info_default( } } -/* - if (!share->static_link_ids[roop_count]) - { - DBUG_PRINT("info",("spider create default static_link_ids")); - share->static_link_ids_lengths[roop_count] = - SPIDER_DB_STATIC_LINK_ID_LEN; - if ( - !(share->static_link_ids[roop_count] = spider_create_string( - SPIDER_DB_STATIC_LINK_ID_STR, - share->static_link_ids_lengths[roop_count])) - ) { - DBUG_RETURN(HA_ERR_OUT_OF_MEM); - } - } -*/ - if (share->tgt_ports[roop_count] == -1) { share->tgt_ports[roop_count] = MYSQL_PORT; @@ -3705,6 +3691,11 @@ int spider_set_connect_info_default( DBUG_RETURN(0); } +/* + This function is a no-op if all share->tgt_dbs and + share->tgt_table_names are non-null, otherwise it may assign them + with db_name and table_name +*/ int spider_set_connect_info_default_db_table( SPIDER_SHARE *share, const char *db_name, @@ -3748,6 +3739,11 @@ int spider_set_connect_info_default_db_table( DBUG_RETURN(0); } +/* + Parse `dbtable_name' into db name and table name, and call + spider_set_connect_info_default_db_table() to set the db/table name + values of `share' if needed +*/ int spider_set_connect_info_default_dbtable( SPIDER_SHARE *share, const char *dbtable_name, @@ -6062,7 +6058,7 @@ int spider_open_all_tables( (error_num = spider_get_sys_tables( table_tables, &db_name, &table_name, &mem_root)) || (error_num = spider_get_sys_tables_connect_info( - table_tables, &tmp_share, 0, &mem_root)) || + table_tables, &tmp_share, &mem_root)) || (error_num = spider_set_connect_info_default( &tmp_share, #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -6676,16 +6672,6 @@ int spider_db_init( #ifdef HTON_CAN_READ_CONNECT_STRING_IN_PARTITION spider_hton->flags |= HTON_CAN_READ_CONNECT_STRING_IN_PARTITION; #endif - /* spider_hton->db_type = DB_TYPE_SPIDER; */ - /* - spider_hton->savepoint_offset; - spider_hton->savepoint_set = spider_savepoint_set; - spider_hton->savepoint_rollback = spider_savepoint_rollback; - spider_hton->savepoint_release = spider_savepoint_release; - spider_hton->create_cursor_read_view = spider_create_cursor_read_view; - spider_hton->set_cursor_read_view = spider_set_cursor_read_view; - spider_hton->close_cursor_read_view = spider_close_cursor_read_view; - */ spider_hton->panic = spider_panic; spider_hton->close_connection = spider_close_connection; spider_hton->start_consistent_snapshot = spider_start_consistent_snapshot; From e6d12bb45947fd9358e0925c9a513ca66c705686 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 13 Mar 2024 13:11:07 +1100 Subject: [PATCH 040/159] MDEV-33661 MENT-1591 Fix spider/bugfix.mdev_28856 because of MDEV-29718. The failure should be table not found, rather than no spider same server link --- storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result | 3 +++ storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result index 7e4fd3cd084..5fd412b69ea 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result @@ -5,6 +5,8 @@ for master_1 for child2 for child3 set spider_same_server_link=1; +set @old_spider_same_server_link=@@global.spider_same_server_link; +set global spider_same_server_link=1; CREATE SERVER srv FOREIGN DATA WRAPPER mysql OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); # testing monitoring_* @@ -173,6 +175,7 @@ max(d) 93 drop table t1, t2; drop server srv; +set global spider_same_server_link=@old_spider_same_server_link; for master_1 for child2 for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test index a1642f7a9cd..9ccfc3784ef 100644 --- a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test @@ -10,6 +10,9 @@ # This test covers some table params under consideration for inclusion # in the engine-defined options to be implemented in MDEV-28856. set spider_same_server_link=1; +set @old_spider_same_server_link=@@global.spider_same_server_link; +set global spider_same_server_link=1; + evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); @@ -153,6 +156,7 @@ select max(d) from t1; drop table t1, t2; drop server srv; +set global spider_same_server_link=@old_spider_same_server_link; --disable_query_log --disable_result_log From 7890388d9145ab5000e945b7a518caffd1fc197e Mon Sep 17 00:00:00 2001 From: Anson Chung Date: Mon, 18 Mar 2024 20:45:45 +0000 Subject: [PATCH 041/159] MDEV-33044 Loading time zones does not work with alter_algorithm INPLACE $MYSQL_TZINFO_TO_SQL works by truncating tables. Truncation is an operation that cannot be done in-place and therefore is fundamentally incompatible with alter_algorithm='INPLACE'. As a result, we override the default alter_algorithm setting in tztime.cc to alter_algorithm='COPY' so that timezones can be loaded regardless of the previously set alter_algorithm. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- ...ezones_with_alter_algorithm_inplace.result | 18 +++++++++ ...imezones_with_alter_algorithm_inplace.test | 38 +++++++++++++++++++ .../main/mysql_tzinfo_to_sql_symlink.result | 18 +++++++++ sql/tztime.cc | 5 +++ 4 files changed, 79 insertions(+) create mode 100644 mysql-test/main/load_timezones_with_alter_algorithm_inplace.result create mode 100644 mysql-test/main/load_timezones_with_alter_algorithm_inplace.test diff --git a/mysql-test/main/load_timezones_with_alter_algorithm_inplace.result b/mysql-test/main/load_timezones_with_alter_algorithm_inplace.result new file mode 100644 index 00000000000..4992e7ed93b --- /dev/null +++ b/mysql-test/main/load_timezones_with_alter_algorithm_inplace.result @@ -0,0 +1,18 @@ +set global alter_algorithm=INPLACE; +RENAME TABLE mysql.time_zone TO mysql.time_zone_BACKUP; +RENAME TABLE mysql.time_zone_name TO mysql.time_zone_name_BACKUP; +RENAME TABLE mysql.time_zone_transition TO mysql.time_zone_transition_BACKUP; +RENAME TABLE mysql.time_zone_transition_type TO mysql.time_zone_transition_type_BACKUP; +CREATE TABLE mysql.time_zone LIKE mysql.time_zone_BACKUP; +CREATE TABLE mysql.time_zone_name LIKE mysql.time_zone_name_BACKUP; +CREATE TABLE mysql.time_zone_transition LIKE mysql.time_zone_transition_BACKUP; +CREATE TABLE mysql.time_zone_transition_type LIKE mysql.time_zone_transition_type_BACKUP; +DROP TABLE mysql.time_zone; +DROP TABLE mysql.time_zone_name; +DROP TABLE mysql.time_zone_transition; +DROP TABLE mysql.time_zone_transition_type; +RENAME TABLE mysql.time_zone_BACKUP TO mysql.time_zone; +RENAME TABLE mysql.time_zone_name_BACKUP TO mysql.time_zone_name; +RENAME TABLE mysql.time_zone_transition_BACKUP TO mysql.time_zone_transition; +RENAME TABLE mysql.time_zone_transition_type_BACKUP TO mysql.time_zone_transition_type; +set global alter_algorithm=DEFAULT; diff --git a/mysql-test/main/load_timezones_with_alter_algorithm_inplace.test b/mysql-test/main/load_timezones_with_alter_algorithm_inplace.test new file mode 100644 index 00000000000..e840ae94a74 --- /dev/null +++ b/mysql-test/main/load_timezones_with_alter_algorithm_inplace.test @@ -0,0 +1,38 @@ +# MDEV-33044 Loading time zones does not work with alter_algorithm INPLACE + +set global alter_algorithm=INPLACE; + +# Because loading timezones alters the mysql tables, +# this test will leave mysql in a different state than when it started. +# Furthermore, checksums on the various mysql.timezone_x tables will fail. + +# Therefore we: +# 1. Make "backups" of the existing tables by renaming them +# 2. Make dummy clones of the tables we just backed up +# 3. Load timezones with alterations made to the dummy clone tables +# 4. Drop the newly made tables with changes made to them +# 5. Restore the backed up tables so the checksums will pass + +RENAME TABLE mysql.time_zone TO mysql.time_zone_BACKUP; +RENAME TABLE mysql.time_zone_name TO mysql.time_zone_name_BACKUP; +RENAME TABLE mysql.time_zone_transition TO mysql.time_zone_transition_BACKUP; +RENAME TABLE mysql.time_zone_transition_type TO mysql.time_zone_transition_type_BACKUP; + +CREATE TABLE mysql.time_zone LIKE mysql.time_zone_BACKUP; +CREATE TABLE mysql.time_zone_name LIKE mysql.time_zone_name_BACKUP; +CREATE TABLE mysql.time_zone_transition LIKE mysql.time_zone_transition_BACKUP; +CREATE TABLE mysql.time_zone_transition_type LIKE mysql.time_zone_transition_type_BACKUP; + +--exec $MYSQL_TZINFO_TO_SQL std_data/zoneinfo | $MYSQL mysql + +DROP TABLE mysql.time_zone; +DROP TABLE mysql.time_zone_name; +DROP TABLE mysql.time_zone_transition; +DROP TABLE mysql.time_zone_transition_type; + +RENAME TABLE mysql.time_zone_BACKUP TO mysql.time_zone; +RENAME TABLE mysql.time_zone_name_BACKUP TO mysql.time_zone_name; +RENAME TABLE mysql.time_zone_transition_BACKUP TO mysql.time_zone_transition; +RENAME TABLE mysql.time_zone_transition_type_BACKUP TO mysql.time_zone_transition_type; + +set global alter_algorithm=DEFAULT; \ No newline at end of file diff --git a/mysql-test/main/mysql_tzinfo_to_sql_symlink.result b/mysql-test/main/mysql_tzinfo_to_sql_symlink.result index a9ada2d6fdb..ea1a09f66d6 100644 --- a/mysql-test/main/mysql_tzinfo_to_sql_symlink.result +++ b/mysql-test/main/mysql_tzinfo_to_sql_symlink.result @@ -20,12 +20,16 @@ ALTER TABLE time_zone ENGINE=InnoDB; ALTER TABLE time_zone_name ENGINE=InnoDB; ALTER TABLE time_zone_transition ENGINE=InnoDB; ALTER TABLE time_zone_transition_type ENGINE=InnoDB; +SET @old_alter_alg=@@SESSION.alter_algorithm; +SET session alter_algorithm='COPY'; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; TRUNCATE TABLE time_zone_transition_type; START TRANSACTION; ELSE +SET @old_alter_alg=@@SESSION.alter_algorithm; +SET session alter_algorithm='COPY'; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; @@ -62,6 +66,7 @@ ALTER TABLE time_zone_transition ENGINE=Aria, ORDER BY Time_zone_id, Transition_ ALTER TABLE time_zone_transition_type ENGINE=Aria, ORDER BY Time_zone_id, Transition_type_id; END IF| \d ; +SET session alter_algorithm=@old_alter_alg; SELECT COUNT(*) FROM time_zone; COUNT(*) 0 @@ -85,12 +90,16 @@ ALTER TABLE time_zone ENGINE=InnoDB; ALTER TABLE time_zone_name ENGINE=InnoDB; ALTER TABLE time_zone_transition ENGINE=InnoDB; ALTER TABLE time_zone_transition_type ENGINE=InnoDB; +SET @old_alter_alg=@@SESSION.alter_algorithm; +SET session alter_algorithm='COPY'; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; TRUNCATE TABLE time_zone_transition_type; START TRANSACTION; ELSE +SET @old_alter_alg=@@SESSION.alter_algorithm; +SET session alter_algorithm='COPY'; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; @@ -124,6 +133,7 @@ ALTER TABLE time_zone_transition ENGINE=Aria, ORDER BY Time_zone_id, Transition_ ALTER TABLE time_zone_transition_type ENGINE=Aria, ORDER BY Time_zone_id, Transition_type_id; END IF| \d ; +SET session alter_algorithm=@old_alter_alg; SELECT COUNT(*) FROM time_zone; COUNT(*) 2 @@ -145,6 +155,8 @@ COUNT(*) set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on' and variable_value='ON'), 'SET SESSION WSREP_ON=OFF', 'do 0'); SET SESSION SQL_LOG_BIN=0; execute immediate @prep1; +SET @old_alter_alg=@@SESSION.alter_algorithm; +SET session alter_algorithm='COPY'; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; @@ -172,6 +184,7 @@ UNLOCK TABLES; COMMIT; ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time; ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id; +SET session alter_algorithm=@old_alter_alg; SELECT COUNT(*) FROM time_zone; COUNT(*) 2 @@ -432,12 +445,16 @@ ALTER TABLE time_zone ENGINE=InnoDB; ALTER TABLE time_zone_name ENGINE=InnoDB; ALTER TABLE time_zone_transition ENGINE=InnoDB; ALTER TABLE time_zone_transition_type ENGINE=InnoDB; +SET @old_alter_alg=@@SESSION.alter_algorithm; +SET session alter_algorithm='COPY'; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; TRUNCATE TABLE time_zone_transition_type; START TRANSACTION; ELSE +SET @old_alter_alg=@@SESSION.alter_algorithm; +SET session alter_algorithm='COPY'; TRUNCATE TABLE time_zone; TRUNCATE TABLE time_zone_name; TRUNCATE TABLE time_zone_transition; @@ -457,6 +474,7 @@ ALTER TABLE time_zone_transition ENGINE=Aria, ORDER BY Time_zone_id, Transition_ ALTER TABLE time_zone_transition_type ENGINE=Aria, ORDER BY Time_zone_id, Transition_type_id; END IF| \d ; +SET session alter_algorithm=@old_alter_alg; DROP TABLE time_zone; DROP TABLE time_zone_name; DROP TABLE time_zone_transition; diff --git a/sql/tztime.cc b/sql/tztime.cc index 45a11942966..1480de96333 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -2718,6 +2718,8 @@ static const char *lock_tables= " time_zone_transition WRITE,\n" " time_zone_transition_type WRITE;\n"; static const char *trunc_tables_const= + "SET @old_alter_alg=@@SESSION.alter_algorithm;\n" + "SET session alter_algorithm='COPY';\n" "TRUNCATE TABLE time_zone;\n" "TRUNCATE TABLE time_zone_name;\n" "TRUNCATE TABLE time_zone_transition;\n" @@ -2833,6 +2835,9 @@ main(int argc, char **argv) "END IF|\n" "\\d ;\n"); + if (argc == 1 && !opt_leap) + printf("SET session alter_algorithm=@old_alter_alg;\n"); + free_allocated_data(); my_end(0); return 0; From 9f1019ba3ddec192ca0c1822710d654b0c42e4dd Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 28 Mar 2024 13:53:52 +1100 Subject: [PATCH 042/159] MDEV-33044 Loading time zones does not work with alter_algorithm INPLACE (postfix) Test case doesn't work on embedded builds. --- .../main/load_timezones_with_alter_algorithm_inplace.test | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/load_timezones_with_alter_algorithm_inplace.test b/mysql-test/main/load_timezones_with_alter_algorithm_inplace.test index e840ae94a74..809f147fe04 100644 --- a/mysql-test/main/load_timezones_with_alter_algorithm_inplace.test +++ b/mysql-test/main/load_timezones_with_alter_algorithm_inplace.test @@ -1,3 +1,5 @@ +--source include/not_embedded.inc + # MDEV-33044 Loading time zones does not work with alter_algorithm INPLACE set global alter_algorithm=INPLACE; @@ -35,4 +37,4 @@ RENAME TABLE mysql.time_zone_name_BACKUP TO mysql.time_zone_name; RENAME TABLE mysql.time_zone_transition_BACKUP TO mysql.time_zone_transition; RENAME TABLE mysql.time_zone_transition_type_BACKUP TO mysql.time_zone_transition_type; -set global alter_algorithm=DEFAULT; \ No newline at end of file +set global alter_algorithm=DEFAULT; From c81139357a4bb5bb1c774fa6d813166ef32e3735 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Thu, 28 Mar 2024 11:48:32 +0700 Subject: [PATCH 043/159] MDEV-14959: the follow-up patch to turn on the option -DWITH_PROTECT_STATEMENT_MEMROOT by default --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9605d786c93..6f668139b50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,9 +197,10 @@ OPTION(NOT_FOR_DISTRIBUTION "Allow linking with GPLv2-incompatible system librar # Enable protection of statement's memory root after first SP/PS execution. # Can be switched on only for debug build. # -OPTION(WITH_PROTECT_STATEMENT_MEMROOT "Enable protection of statement's memory root after first SP/PS execution. Turned into account only for debug build" OFF) -IF (CMAKE_BUILD_TYPE MATCHES "Debug" AND WITH_PROTECT_STATEMENT_MEMROOT) - ADD_DEFINITIONS(-DPROTECT_STATEMENT_MEMROOT) +OPTION(WITH_PROTECT_STATEMENT_MEMROOT "Enable protection of statement's memory root after first SP/PS execution. Turned into account only for debug build" ON) +IF (WITH_PROTECT_STATEMENT_MEMROOT) + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DPROTECT_STATEMENT_MEMROOT") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DPROTECT_STATEMENT_MEMROOT") ENDIF() INCLUDE(check_compiler_flag) From f44e41db38c44b1d6f6238aa1e1b0936814c43fb Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Wed, 27 Mar 2024 22:55:15 +0700 Subject: [PATCH 044/159] MDEV-33767: Memory leaks found in some tests run with --ps-protocol against a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT Found memory leaks were introduced by the commit a896bebfa6d00b0bb7685956196a7977d9273652 MDEV-18844 Implement EXCEPT ALL and INTERSECT ALL operations and caused by using a statement arena instead a runtime arena for allocation of objects having temporary life span by their nature. Aforementioned memory leaks were produced by running queries that typically use select with intersect, union or table values constructors. To fix these memory leaks use the runtime arena for allocation of Item_field objects used by set operations. Additionally, OOM handling added on allocation of aforementioned Item_field objects. --- sql/sql_union.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 96929a128ac..c3c4198439a 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1263,26 +1263,21 @@ bool st_select_lex_unit::join_union_item_types(THD *thd_arg, } -bool init_item_int(THD* thd, Item_int* &item) +static bool init_item_int(THD* thd, Item_int* &item) { if (!item) { - Query_arena *arena, backup_arena; - arena= thd->activate_stmt_arena_if_needed(&backup_arena); - item= new (thd->mem_root) Item_int(thd, 0); - if (arena) - thd->restore_active_arena(arena, &backup_arena); - if (!item) - return false; + return true; } else { item->value= 0; } - return true; + + return false; } @@ -1762,8 +1757,12 @@ cont: for(uint i= 0; i< hidden; i++) { - init_item_int(thd, addon_fields[i]); - types.push_front(addon_fields[i]); + if (init_item_int(thd, addon_fields[i]) || + types.push_front(addon_fields[i])) + { + types.empty(); + goto err; + } addon_fields[i]->name.str= i ? "__CNT_1" : "__CNT_2"; addon_fields[i]->name.length= 7; } From e1876e7f78f6011a5759e4a2a549c057f21efcc9 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Wed, 27 Mar 2024 20:44:05 +0700 Subject: [PATCH 045/159] MDEV-33768: Memory leak found in the test main.constraints run with --ps-protocol against a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT The discovered memory leak was introduced by the commit 762bf7a03b6214f091a66ca8683df341112d7d4a (MDEV-22602 Disable UPDATE CASCADE for SQL constraints) The reason why a memory leaked on running the test main.constraints is that a statement arena was used for allocation a memory for storing a constraint name. A constraint name is an entity having temporary nature by its design so runtime arena should be used for its allocation. --- mysql-test/main/constraints.result | 13 +++++++++++++ mysql-test/main/constraints.test | 15 +++++++++++++++ sql/sql_table.cc | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/constraints.result b/mysql-test/main/constraints.result index 105ea7cf1f4..77a25f5ad46 100644 --- a/mysql-test/main/constraints.result +++ b/mysql-test/main/constraints.result @@ -235,3 +235,16 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci drop procedure sp; drop table t1; +# +# MDEV-33768: Memory leak found in the test main.constraints run with --ps-protocol against a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT +# This test case was added by reviewer's request. +# +PREPARE stmt FROM 'CREATE TABLE t1 (a INT)'; +EXECUTE stmt; +DROP TABLE t1; +EXECUTE stmt; +EXECUTE stmt; +ERROR 42S01: Table 't1' already exists +# Clean up +DROP TABLE t1; +DEALLOCATE PREPARE stmt; diff --git a/mysql-test/main/constraints.test b/mysql-test/main/constraints.test index 5c673f9be81..83f3394d6f6 100644 --- a/mysql-test/main/constraints.test +++ b/mysql-test/main/constraints.test @@ -189,3 +189,18 @@ call sp; show create table t1; drop procedure sp; drop table t1; + +--echo # +--echo # MDEV-33768: Memory leak found in the test main.constraints run with --ps-protocol against a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT +--echo # This test case was added by reviewer's request. +--echo # +PREPARE stmt FROM 'CREATE TABLE t1 (a INT)'; +EXECUTE stmt; +DROP TABLE t1; +EXECUTE stmt; +--error ER_TABLE_EXISTS_ERROR +EXECUTE stmt; + +--echo # Clean up +DROP TABLE t1; +DEALLOCATE PREPARE stmt; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 839438dfc30..dc1a7060643 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5861,7 +5861,8 @@ static bool make_unique_constraint_name(THD *thd, LEX_CSTRING *name, if (!check) // Found unique name { name->length= (size_t) (real_end - buff); - name->str= strmake_root(thd->stmt_arena->mem_root, buff, name->length); + name->str= thd->strmake(buff, name->length); + return (name->str == NULL); } } From a618ff2b1c3980d20d258d7da0afb1e7b7ec1516 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Wed, 10 Jan 2024 14:34:12 +0100 Subject: [PATCH 046/159] MDEV-33216 stack-use-after-return in Wsrep_schema_impl::open_table() Fix a case of stack-use-after-return reported by ASAN in Wsrep_schema_impl::open_table(). This function has a stack allocated TABLE_LIST object and return TABLE_LIST::table to the caller. Changed the function to take a TABLE_LIST pointer as argument. Signed-off-by: Julius Goryavsky --- sql/wsrep_schema.cc | 143 +++++++++++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 54 deletions(-) diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc index 1c4f827ae97..6d435a3a1b5 100644 --- a/sql/wsrep_schema.cc +++ b/sql/wsrep_schema.cc @@ -245,58 +245,51 @@ static void finish_stmt(THD* thd) { close_thread_tables(thd); } -static int open_table(THD* thd, - const LEX_CSTRING *schema_name, - const LEX_CSTRING *table_name, - enum thr_lock_type const lock_type, - TABLE** table) { - assert(table); - *table= NULL; - +static int open_table(THD *thd, const LEX_CSTRING *schema_name, + const LEX_CSTRING *table_name, + enum thr_lock_type const lock_type, + TABLE_LIST *table_list) +{ + assert(table_list); DBUG_ENTER("Wsrep_schema::open_table()"); - - TABLE_LIST tables; - uint flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | - MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | - MYSQL_OPEN_IGNORE_FLUSH | - MYSQL_LOCK_IGNORE_TIMEOUT); - - tables.init_one_table(schema_name, - table_name, - NULL, lock_type); + const uint flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | + MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | + MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT); + table_list->init_one_table(schema_name, table_name, NULL, lock_type); thd->lex->query_tables_own_last= 0; - - if (!open_n_lock_single_table(thd, &tables, tables.lock_type, flags)) { + if (!open_n_lock_single_table(thd, table_list, table_list->lock_type, flags)) + { close_thread_tables(thd); DBUG_RETURN(1); } - *table= tables.table; - (*table)->use_all_columns(); + table_list->table->use_all_columns(); DBUG_RETURN(0); } - -static int open_for_write(THD* thd, const char* table_name, TABLE** table) { +static int open_for_write(THD* thd, const char* table_name, TABLE_LIST* table_list) +{ LEX_CSTRING schema_str= { wsrep_schema_str.c_str(), wsrep_schema_str.length() }; LEX_CSTRING table_str= { table_name, strlen(table_name) }; if (Wsrep_schema_impl::open_table(thd, &schema_str, &table_str, TL_WRITE, - table)) { + table_list)) + { // No need to log an error if the query was bf aborted, // thd client will get ER_LOCK_DEADLOCK in the end. const bool interrupted= thd->killed || (thd->is_error() && (thd->get_stmt_da()->sql_errno() == ER_QUERY_INTERRUPTED)); - if (!interrupted) { + if (!interrupted) + { WSREP_ERROR("Failed to open table %s.%s for writing", schema_str.str, table_name); } return 1; } - empty_record(*table); - (*table)->use_all_columns(); - restore_record(*table, s->default_values); + empty_record(table_list->table); + table_list->table->use_all_columns(); + restore_record(table_list->table, s->default_values); return 0; } @@ -438,19 +431,21 @@ static int delete_row(TABLE* table) { return 0; } -static int open_for_read(THD* thd, const char* table_name, TABLE** table) { - +static int open_for_read(THD *thd, const char *table_name, + TABLE_LIST *table_list) +{ LEX_CSTRING schema_str= { wsrep_schema_str.c_str(), wsrep_schema_str.length() }; LEX_CSTRING table_str= { table_name, strlen(table_name) }; if (Wsrep_schema_impl::open_table(thd, &schema_str, &table_str, TL_READ, - table)) { + table_list)) + { WSREP_ERROR("Failed to open table %s.%s for reading", schema_str.str, table_name); return 1; } - empty_record(*table); - (*table)->use_all_columns(); - restore_record(*table, s->default_values); + empty_record(table_list->table); + table_list->table->use_all_columns(); + restore_record(table_list->table, s->default_values); return 0; } @@ -706,8 +701,10 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) assert(view.status() == Wsrep_view::primary); int ret= 1; int error; + TABLE_LIST cluster_table_l; TABLE* cluster_table= 0; - TABLE* members_table= 0; + TABLE_LIST members_table_l; + TABLE* members_table = 0; #ifdef WSREP_SCHEMA_MEMBERS_HISTORY TABLE* members_history_table= 0; #endif /* WSREP_SCHEMA_MEMBERS_HISTORY */ @@ -732,11 +729,13 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) Store cluster view info */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_write(thd, cluster_table_str.c_str(), &cluster_table)) + if (Wsrep_schema_impl::open_for_write(thd, cluster_table_str.c_str(), &cluster_table_l)) { goto out; } + cluster_table= cluster_table_l.table; + Wsrep_schema_impl::store(cluster_table, 0, view.state_id().id()); Wsrep_schema_impl::store(cluster_table, 1, view.view_seqno().get()); Wsrep_schema_impl::store(cluster_table, 2, view.state_id().seqno().get()); @@ -756,12 +755,14 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) */ Wsrep_schema_impl::init_stmt(thd); if (Wsrep_schema_impl::open_for_write(thd, members_table_str.c_str(), - &members_table)) + &members_table_l)) { WSREP_ERROR("failed to open wsrep.members table"); goto out; } + members_table= members_table_l.table; + for (size_t i= 0; i < view.members().size(); ++i) { Wsrep_schema_impl::store(members_table, 0, view.members()[i].id()); @@ -815,8 +816,10 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { int ret= 1; int error; + TABLE_LIST cluster_table_l; TABLE* cluster_table= 0; bool end_cluster_scan= false; + TABLE_LIST members_table_l; TABLE* members_table= 0; bool end_members_scan= false; @@ -842,8 +845,12 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { Read cluster info from cluster table */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_read(thd, cluster_table_str.c_str(), &cluster_table) || - Wsrep_schema_impl::init_for_scan(cluster_table)) { + if (Wsrep_schema_impl::open_for_read(thd, cluster_table_str.c_str(), &cluster_table_l)) { + goto out; + } + cluster_table = cluster_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(cluster_table)) { goto out; } @@ -867,8 +874,14 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { Read members from members table */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_read(thd, members_table_str.c_str(), &members_table) || - Wsrep_schema_impl::init_for_scan(members_table)) { + if (Wsrep_schema_impl::open_for_read(thd, members_table_str.c_str(), + &members_table_l)) + { + goto out; + } + + members_table= members_table_l.table; + if (Wsrep_schema_impl::init_for_scan(members_table)) { goto out; } end_members_scan= true; @@ -972,14 +985,15 @@ int Wsrep_schema::append_fragment(THD* thd, Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd); Wsrep_schema_impl::init_stmt(thd); - TABLE* frag_table= 0; - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + TABLE_LIST frag_table_l; + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { trans_rollback_stmt(thd); thd->lex->restore_backup_query_tables_list(&query_tables_list_backup); DBUG_RETURN(1); } + TABLE* frag_table= frag_table_l.table; Wsrep_schema_impl::store(frag_table, 0, server_id); Wsrep_schema_impl::store(frag_table, 1, transaction_id.get()); Wsrep_schema_impl::store(frag_table, 2, seqno.get()); @@ -1023,13 +1037,15 @@ int Wsrep_schema::update_fragment_meta(THD* thd, uchar *key=NULL; key_part_map key_map= 0; TABLE* frag_table= 0; + TABLE_LIST frag_table_l; Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { thd->lex->restore_backup_query_tables_list(&query_tables_list_backup); DBUG_RETURN(1); } + frag_table= frag_table_l.table; /* Find record with the given uuid, trx id, and seqno -1 */ Wsrep_schema_impl::store(frag_table, 0, ws_meta.server_id()); @@ -1152,12 +1168,14 @@ int Wsrep_schema::remove_fragments(THD* thd, thd->reset_n_backup_open_tables_state(&open_tables_backup); TABLE* frag_table= 0; - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + TABLE_LIST frag_table_l; + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { ret= 1; } else { + frag_table= frag_table_l.table; for (std::vector::const_iterator i= fragments.begin(); i != fragments.end(); ++i) { @@ -1218,6 +1236,7 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, int ret= 1; int error; TABLE* frag_table= 0; + TABLE_LIST frag_table_l; uchar *key=NULL; key_part_map key_map= 0; @@ -1225,12 +1244,13 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, i != fragments.end(); ++i) { Wsrep_schema_impl::init_stmt(&thd); - if ((error= Wsrep_schema_impl::open_for_read(&thd, sr_table_str.c_str(), &frag_table))) + if ((error= Wsrep_schema_impl::open_for_read(&thd, sr_table_str.c_str(), &frag_table_l))) { WSREP_WARN("Could not open SR table for read: %d", error); Wsrep_schema_impl::finish_stmt(&thd); DBUG_RETURN(1); } + frag_table= frag_table_l.table; Wsrep_schema_impl::store(frag_table, 0, ws_meta.server_id()); Wsrep_schema_impl::store(frag_table, 1, ws_meta.transaction_id().get()); @@ -1276,12 +1296,13 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, if ((error= Wsrep_schema_impl::open_for_write(&thd, sr_table_str.c_str(), - &frag_table))) + &frag_table_l))) { WSREP_WARN("Could not open SR table for write: %d", error); Wsrep_schema_impl::finish_stmt(&thd); DBUG_RETURN(1); } + frag_table= frag_table_l.table; error= Wsrep_schema_impl::init_for_index_scan(frag_table, key, @@ -1323,7 +1344,9 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) (char*) &storage_thd); wsrep_assign_from_threadvars(&storage_thd); TABLE* frag_table= 0; + TABLE_LIST frag_table_l; TABLE* cluster_table= 0; + TABLE_LIST cluster_table_l; Wsrep_storage_service storage_service(&storage_thd); Wsrep_schema_impl::binlog_off binlog_off(&storage_thd); Wsrep_schema_impl::wsrep_off wsrep_off(&storage_thd); @@ -1338,10 +1361,15 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) Wsrep_schema_impl::init_stmt(&storage_thd); storage_thd.wsrep_skip_locking= FALSE; - if (Wsrep_schema_impl::open_for_read(&storage_thd, - cluster_table_str.c_str(), - &cluster_table) || - Wsrep_schema_impl::init_for_scan(cluster_table)) + if (Wsrep_schema_impl::open_for_read(&storage_thd, cluster_table_str.c_str(), + &cluster_table_l)) + { + Wsrep_schema_impl::finish_stmt(&storage_thd); + DBUG_RETURN(1); + } + cluster_table= cluster_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(cluster_table)) { Wsrep_schema_impl::finish_stmt(&storage_thd); DBUG_RETURN(1); @@ -1379,12 +1407,19 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) Open the table for reading and writing so that fragments without valid seqno can be deleted. */ - if (Wsrep_schema_impl::open_for_write(&storage_thd, sr_table_str.c_str(), &frag_table) || - Wsrep_schema_impl::init_for_scan(frag_table)) + if (Wsrep_schema_impl::open_for_write(&storage_thd, sr_table_str.c_str(), + &frag_table_l)) { WSREP_ERROR("Failed to open SR table for write"); goto out; } + frag_table= frag_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(frag_table)) + { + WSREP_ERROR("Failed to init for index scan"); + goto out; + } while (true) { From 29bb321f0497b4a30d4a2b1b19d7a6a924d22c3a Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 28 Mar 2024 14:01:43 +0400 Subject: [PATCH 047/159] MDEV-33788 HEX(COLUMN_CREATE(.. AS CHAR ...)) fails with --view-protocol Item_func_dyncol_create::print_arguments() printed only CHARSET clause without COLLATE. Therefore, HEX(column_create(1,'1212' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin)) inside a VIEW changed to just: HEX(column_create(1,'1212' AS CHAR CHARACTER SET utf8mb3)) which changed the collation ID seen in the HEX output. Note, the collation ID inside column_create() is not really much important. (It's only important what the character set is). And for COLLATE, the more important thing is what's later written in the AS clause of COLUMN_GET: SELECT COLUMN_GET( column_create(1,'1212' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin) column_nr AS type -- this type is more important ); Still, let's add the COLLATE clause into the COLUMN_CREATE() print output, although it's not important for now for anything else than just the HEX output. At least to make VIEW work in a more predictable way with HEX(COLUMN_CREATE()). Also, in the future we can start using somehow the collation ID written inside COLUMN_CREATE(), for example by making the `AS type` clause optional in COLUMN_GET(): COLUMN_GET(dyncol_blob, column_nr [AS type]); instead of: COLUMN_GET(dyncol_blob, column_nr AS type); SQL Server compatibility layer may need this for the SQL_Variant data type support. --- mysql-test/main/create.result | 2 +- mysql-test/main/dyncol.result | 28 ++++++++++++++++++++++++---- mysql-test/main/dyncol.test | 21 +++++++++++++++++++++ sql/item_strfunc.cc | 5 +++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/mysql-test/main/create.result b/mysql-test/main/create.result index cec7452affd..fc508108a97 100644 --- a/mysql-test/main/create.result +++ b/mysql-test/main/create.result @@ -1806,7 +1806,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `color` char(32) GENERATED ALWAYS AS (column_get(`dynamic_cols`,1 as char charset latin1)) STORED, - `cl` char(32) GENERATED ALWAYS AS (column_get(column_add(column_create(1,'blue' AS char charset latin1 ),2,'ttt'),`i` as char charset latin1)) STORED, + `cl` char(32) GENERATED ALWAYS AS (column_get(column_add(column_create(1,'blue' AS char charset latin1 collate latin1_swedish_ci ),2,'ttt'),`i` as char charset latin1)) STORED, `item_name` varchar(32) NOT NULL, `i` int(11) DEFAULT NULL, `dynamic_cols` blob DEFAULT NULL, diff --git a/mysql-test/main/dyncol.result b/mysql-test/main/dyncol.result index 6135be649b2..eb1e0464570 100644 --- a/mysql-test/main/dyncol.result +++ b/mysql-test/main/dyncol.result @@ -150,7 +150,7 @@ select hex(COLUMN_CREATE(1, "afaf" AS char character set utf8, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select hex(column_create(1,'afaf' AS char charset utf8 ,2,1212 AS unsigned int,3,1212 AS int,4,12.12 AS double,4 + 1,12.12 AS decimal,6,'2011-04-05' AS date,7,'- 0:45:49.000001' AS time,8,'2011-04-05 0:45:49.000001' AS datetime)) AS `ex` +Note 1003 select hex(column_create(1,'afaf' AS char charset utf8 collate utf8_general_ci ,2,1212 AS unsigned int,3,1212 AS int,4,12.12 AS double,4 + 1,12.12 AS decimal,6,'2011-04-05' AS date,7,'- 0:45:49.000001' AS time,8,'2011-04-05 0:45:49.000001' AS datetime)) AS `ex` select hex(column_create(1, 0.0 AS decimal)); hex(column_create(1, 0.0 AS decimal)) 000100010004 @@ -354,7 +354,7 @@ select column_get(column_create(1, "1212" AS char charset utf8), 1 as char chars id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select column_get(column_create(1,'1212' AS char charset utf8 ),1 as char charset utf8) AS `ex` +Note 1003 select column_get(column_create(1,'1212' AS char charset utf8 collate utf8_general_ci ),1 as char charset utf8) AS `ex` select column_get(column_create(1, 1212 AS unsigned int), 1 as char charset utf8) as ex; ex 1212 @@ -414,7 +414,7 @@ select column_get(column_create(1, "1212" AS char charset utf8), 1 as char chars id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select column_get(column_create(1,'1212' AS char charset utf8 ),1 as char charset binary) AS `ex` +Note 1003 select column_get(column_create(1,'1212' AS char charset utf8 collate utf8_general_ci ),1 as char charset binary) AS `ex` # # column get real # @@ -1882,7 +1882,7 @@ drop table t1; create view v1 as select column_get(column_add(column_create(1 , 'blue' as char), 2, 'ttt'), 1 as char); show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select column_get(column_add(column_create(1,'blue' AS char charset utf8 ),2,'ttt'),1 as char charset utf8) AS `Name_exp_1` utf8 utf8_general_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select column_get(column_add(column_create(1,'blue' AS char charset utf8 collate utf8_general_ci ),2,'ttt'),1 as char charset utf8) AS `Name_exp_1` utf8 utf8_general_ci select * from v1; Name_exp_1 blue @@ -1949,3 +1949,23 @@ ex # # End of 10.4 tests # +# +# Start of 10.5 tests +# +# +# Start of 10.5 tests +# +# +# MDEV-33788 HEX(COLUMN_CREATE(.. AS CHAR ...)) fails with --view-protocol +# +SELECT hex(column_create(1,'a' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin)) AS ex; +ex +0001000100035361 +SELECT hex(column_add(column_create( +1, 'a' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin), +2, 'b' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci)) AS ex; +ex +00020001000302001353612162 +# +# Start of 10.5 tests +# diff --git a/mysql-test/main/dyncol.test b/mysql-test/main/dyncol.test index 630ed122347..16cf8a2306d 100644 --- a/mysql-test/main/dyncol.test +++ b/mysql-test/main/dyncol.test @@ -1000,3 +1000,24 @@ SELECT HEX(COLUMN_ADD(COLUMN_CREATE(1,10),2,NULL,1,NULL)) as ex; --echo # --echo # End of 10.4 tests --echo # + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-33788 HEX(COLUMN_CREATE(.. AS CHAR ...)) fails with --view-protocol +--echo # + +SELECT hex(column_create(1,'a' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin)) AS ex; +SELECT hex(column_add(column_create( + 1, 'a' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin), + 2, 'b' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci)) AS ex; + +--echo # +--echo # Start of 10.5 tests +--echo # diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 4f4b0a20b29..1317d8fdfa9 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -4670,6 +4670,11 @@ void Item_func_dyncol_create::print_arguments(String *str, { str->append(STRING_WITH_LEN(" charset ")); str->append(defs[i].cs->csname); + if (Charset(defs[i].cs).can_have_collate_clause()) + { + str->append(STRING_WITH_LEN(" collate ")); + str->append(defs[i].cs->name); + } str->append(' '); } break; From 4987b5e3b125db2ea52525afefeae97976e2e828 Mon Sep 17 00:00:00 2001 From: joshhn Date: Tue, 2 Apr 2024 00:07:12 -0500 Subject: [PATCH 048/159] MDEV-33803 Error 4162 "Operator does not exists" is incorrectly-worded "Operator does not exists" should rather read "Operator does not exist". --- mysql-test/main/gis.result | 32 ++++++++++----------- mysql-test/suite/compat/oracle/r/gis.result | 32 ++++++++++----------- sql/share/errmsg-utf8.txt | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/mysql-test/main/gis.result b/mysql-test/main/gis.result index 258d0c2f050..e8c5e5c8e73 100644 --- a/mysql-test/main/gis.result +++ b/mysql-test/main/gis.result @@ -5072,37 +5072,37 @@ ERROR 42000: Incorrect parameter count in the call to native function 'WITHIN(PO # MDEV-20009 Add CAST(expr AS pluggable_type) # SELECT CAST(1 AS GEOMETRY); -ERROR HY000: Operator does not exists: 'CAST(expr AS geometry)' +ERROR HY000: Operator does not exist: 'CAST(expr AS geometry)' SELECT CAST(1 AS GEOMETRYCOLLECTION); -ERROR HY000: Operator does not exists: 'CAST(expr AS geometrycollection)' +ERROR HY000: Operator does not exist: 'CAST(expr AS geometrycollection)' SELECT CAST(1 AS POINT); -ERROR HY000: Operator does not exists: 'CAST(expr AS point)' +ERROR HY000: Operator does not exist: 'CAST(expr AS point)' SELECT CAST(1 AS LINESTRING); -ERROR HY000: Operator does not exists: 'CAST(expr AS linestring)' +ERROR HY000: Operator does not exist: 'CAST(expr AS linestring)' SELECT CAST(1 AS POLYGON); -ERROR HY000: Operator does not exists: 'CAST(expr AS polygon)' +ERROR HY000: Operator does not exist: 'CAST(expr AS polygon)' SELECT CAST(1 AS MULTIPOINT); -ERROR HY000: Operator does not exists: 'CAST(expr AS multipoint)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multipoint)' SELECT CAST(1 AS MULTILINESTRING); -ERROR HY000: Operator does not exists: 'CAST(expr AS multilinestring)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multilinestring)' SELECT CAST(1 AS MULTIPOLYGON); -ERROR HY000: Operator does not exists: 'CAST(expr AS multipolygon)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multipolygon)' SELECT CONVERT(1, GEOMETRY); -ERROR HY000: Operator does not exists: 'CAST(expr AS geometry)' +ERROR HY000: Operator does not exist: 'CAST(expr AS geometry)' SELECT CONVERT(1, GEOMETRYCOLLECTION); -ERROR HY000: Operator does not exists: 'CAST(expr AS geometrycollection)' +ERROR HY000: Operator does not exist: 'CAST(expr AS geometrycollection)' SELECT CONVERT(1, POINT); -ERROR HY000: Operator does not exists: 'CAST(expr AS point)' +ERROR HY000: Operator does not exist: 'CAST(expr AS point)' SELECT CONVERT(1, LINESTRING); -ERROR HY000: Operator does not exists: 'CAST(expr AS linestring)' +ERROR HY000: Operator does not exist: 'CAST(expr AS linestring)' SELECT CONVERT(1, POLYGON); -ERROR HY000: Operator does not exists: 'CAST(expr AS polygon)' +ERROR HY000: Operator does not exist: 'CAST(expr AS polygon)' SELECT CONVERT(1, MULTIPOINT); -ERROR HY000: Operator does not exists: 'CAST(expr AS multipoint)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multipoint)' SELECT CONVERT(1, MULTILINESTRING); -ERROR HY000: Operator does not exists: 'CAST(expr AS multilinestring)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multilinestring)' SELECT CONVERT(1, MULTIPOLYGON); -ERROR HY000: Operator does not exists: 'CAST(expr AS multipolygon)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multipolygon)' # # MDEV-17832 Protocol: extensions for Pluggable types and JSON, GEOMETRY # diff --git a/mysql-test/suite/compat/oracle/r/gis.result b/mysql-test/suite/compat/oracle/r/gis.result index 113cb0ea402..8145b97d695 100644 --- a/mysql-test/suite/compat/oracle/r/gis.result +++ b/mysql-test/suite/compat/oracle/r/gis.result @@ -33,37 +33,37 @@ ERROR 42000: Incorrect parameter count in the call to native function 'WITHIN(PO # MDEV-20009 Add CAST(expr AS pluggable_type) # SELECT CAST(1 AS GEOMETRY); -ERROR HY000: Operator does not exists: 'CAST(expr AS geometry)' +ERROR HY000: Operator does not exist: 'CAST(expr AS geometry)' SELECT CAST(1 AS GEOMETRYCOLLECTION); -ERROR HY000: Operator does not exists: 'CAST(expr AS geometrycollection)' +ERROR HY000: Operator does not exist: 'CAST(expr AS geometrycollection)' SELECT CAST(1 AS POINT); -ERROR HY000: Operator does not exists: 'CAST(expr AS point)' +ERROR HY000: Operator does not exist: 'CAST(expr AS point)' SELECT CAST(1 AS LINESTRING); -ERROR HY000: Operator does not exists: 'CAST(expr AS linestring)' +ERROR HY000: Operator does not exist: 'CAST(expr AS linestring)' SELECT CAST(1 AS POLYGON); -ERROR HY000: Operator does not exists: 'CAST(expr AS polygon)' +ERROR HY000: Operator does not exist: 'CAST(expr AS polygon)' SELECT CAST(1 AS MULTIPOINT); -ERROR HY000: Operator does not exists: 'CAST(expr AS multipoint)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multipoint)' SELECT CAST(1 AS MULTILINESTRING); -ERROR HY000: Operator does not exists: 'CAST(expr AS multilinestring)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multilinestring)' SELECT CAST(1 AS MULTIPOLYGON); -ERROR HY000: Operator does not exists: 'CAST(expr AS multipolygon)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multipolygon)' SELECT CONVERT(1, GEOMETRY); -ERROR HY000: Operator does not exists: 'CAST(expr AS geometry)' +ERROR HY000: Operator does not exist: 'CAST(expr AS geometry)' SELECT CONVERT(1, GEOMETRYCOLLECTION); -ERROR HY000: Operator does not exists: 'CAST(expr AS geometrycollection)' +ERROR HY000: Operator does not exist: 'CAST(expr AS geometrycollection)' SELECT CONVERT(1, POINT); -ERROR HY000: Operator does not exists: 'CAST(expr AS point)' +ERROR HY000: Operator does not exist: 'CAST(expr AS point)' SELECT CONVERT(1, LINESTRING); -ERROR HY000: Operator does not exists: 'CAST(expr AS linestring)' +ERROR HY000: Operator does not exist: 'CAST(expr AS linestring)' SELECT CONVERT(1, POLYGON); -ERROR HY000: Operator does not exists: 'CAST(expr AS polygon)' +ERROR HY000: Operator does not exist: 'CAST(expr AS polygon)' SELECT CONVERT(1, MULTIPOINT); -ERROR HY000: Operator does not exists: 'CAST(expr AS multipoint)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multipoint)' SELECT CONVERT(1, MULTILINESTRING); -ERROR HY000: Operator does not exists: 'CAST(expr AS multilinestring)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multilinestring)' SELECT CONVERT(1, MULTIPOLYGON); -ERROR HY000: Operator does not exists: 'CAST(expr AS multipolygon)' +ERROR HY000: Operator does not exist: 'CAST(expr AS multipolygon)' # # End of 10.5 tests # diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 1d9a88c51fc..33c66f75a20 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -9082,7 +9082,7 @@ ER_TOO_LONG_DATABASE_COMMENT ER_UNKNOWN_DATA_TYPE eng "Unknown data type: '%-.64s'" ER_UNKNOWN_OPERATOR - eng "Operator does not exists: '%-.128s'" + eng "Operator does not exist: '%-.128s'" ER_WARN_HISTORY_ROW_START_TIME eng "Table `%s.%s` history row start '%s' is later than row end '%s'" ER_PART_STARTS_BEYOND_INTERVAL From 722df777caca6d4823e867362aff4da79ae8b2c3 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Sat, 23 Mar 2024 21:37:55 +0300 Subject: [PATCH 049/159] MDEV-33757 Get rid of TrxUndoRsegs code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TrxUndoRsegs is wrapper for vector of trx_rseg_t*. It has two constructors, both initialize the vector with only one element. And they are used to push transactions rseg(the singular) to purge queue. There is no function to add elements to the vector. The default constructor is used only for declaration of NullElement. The TrxUndoRsegs was introduced in WL#6915 in MySQL 5.7 and. MySQL 5.7 would unnecessarily let the purge of history parse the temporary undo records, and then look up the table (via a global hash table), and only at the point of processing the parsed undo log record determine that the table is a temporary table and the undo record must be thrown away. In MariaDB 10.2 we have two disjoint sets of rollback segments (128 for persistent, 128 for temporary), and purge does not even see the temporary tables. The only reason why temporary tables are visible to other threads is a SQL layer bug (MDEV-17805). purge_sys_t::choose_next_log(): merge the relevant part of TrxUndoRsegsIterator::set_next() to the start of purge_sys_t::choose_next_log(). purge_sys_t::rseg_get_next_history_log(): add a tail call of purge_sys_t::choose_next_log() and adjust the callers, to simplify the control flow further. purge_sys.pq_mutex and purge_sys.purge_queue: make it private by adding some simple accessor function. trx_purge_cleanse_purge_queue(): make it a member of purge_sys_t to have have access to private purge_sys.pq_mutex and purge_sys.purge_queue, simplify the code with using simple array copy and clearing purge queue instead of poping each purge queue element. rseg_t::last_commit_and_offset: exchange trx_no and offset bits to avoid bitwise operations during pushing to/popping from purge queue. Thanks Marko Mäkelä for historical overview of TrxUndoRsegs development. Reviewed by: Marko Mäkelä --- storage/innobase/include/trx0purge.h | 177 +++++++++++++++------------ storage/innobase/include/trx0rseg.h | 10 +- storage/innobase/trx/trx0purge.cc | 176 ++++++++------------------ storage/innobase/trx/trx0rseg.cc | 17 ++- storage/innobase/trx/trx0trx.cc | 16 ++- 5 files changed, 177 insertions(+), 219 deletions(-) diff --git a/storage/innobase/include/trx0purge.h b/storage/innobase/include/trx0purge.h index a836c134c02..53f66d4930d 100644 --- a/storage/innobase/include/trx0purge.h +++ b/storage/innobase/include/trx0purge.h @@ -55,80 +55,79 @@ Run a purge batch. @return number of undo log pages handled in the batch */ ulint trx_purge(ulint n_tasks, ulint history_size); -/** Rollback segements from a given transaction with trx-no -scheduled for purge. */ -class TrxUndoRsegs { -private: - typedef std::vector > - trx_rsegs_t; -public: - typedef trx_rsegs_t::iterator iterator; - typedef trx_rsegs_t::const_iterator const_iterator; - - TrxUndoRsegs() = default; - - /** Constructor */ - TrxUndoRsegs(trx_rseg_t& rseg) - : trx_no(rseg.last_trx_no()), m_rsegs(1, &rseg) {} - /** Constructor */ - TrxUndoRsegs(trx_id_t trx_no, trx_rseg_t& rseg) - : trx_no(trx_no), m_rsegs(1, &rseg) {} - - bool operator!=(const TrxUndoRsegs& other) const - { return trx_no != other.trx_no; } - bool empty() const { return m_rsegs.empty(); } - void erase(iterator& it) { m_rsegs.erase(it); } - iterator begin() { return(m_rsegs.begin()); } - iterator end() { return(m_rsegs.end()); } - const_iterator begin() const { return m_rsegs.begin(); } - const_iterator end() const { return m_rsegs.end(); } - - /** Compare two TrxUndoRsegs based on trx_no. - @param elem1 first element to compare - @param elem2 second element to compare - @return true if elem1 > elem2 else false.*/ - bool operator()(const TrxUndoRsegs& lhs, const TrxUndoRsegs& rhs) - { - return(lhs.trx_no > rhs.trx_no); - } - - /** Copy of trx_rseg_t::last_trx_no() */ - trx_id_t trx_no= 0; -private: - /** Rollback segments of a transaction, scheduled for purge. */ - trx_rsegs_t m_rsegs{}; -}; - -typedef std::priority_queue< - TrxUndoRsegs, - std::vector >, - TrxUndoRsegs> purge_pq_t; - -/** Chooses the rollback segment with the oldest committed transaction */ -struct TrxUndoRsegsIterator { - /** Constructor */ - TrxUndoRsegsIterator(); - /** Sets the next rseg to purge in purge_sys. - Executed in the purge coordinator thread. - @retval false when nothing is to be purged - @retval true when purge_sys.rseg->latch was locked */ - inline bool set_next(); - -private: - // Disable copying - TrxUndoRsegsIterator(const TrxUndoRsegsIterator&); - TrxUndoRsegsIterator& operator=(const TrxUndoRsegsIterator&); - - /** The current element to process */ - TrxUndoRsegs m_rsegs; - /** Track the current element in m_rsegs */ - TrxUndoRsegs::const_iterator m_iter; -}; - /** The control structure used in the purge operation */ class purge_sys_t { - friend TrxUndoRsegsIterator; + /** Min-heap based priority queue over fixed size array */ + class purge_queue + { + /** Array of indexes in trx_sys.rseg_array. */ + alignas(CPU_LEVEL1_DCACHE_LINESIZE) byte m_array[TRX_SYS_N_RSEGS]; + /** Pointer to the end of m_array. */ + byte *m_end= m_array; + + public: + struct trx_rseg_cmp + { + /** Compare two trx_rseg_t* based on trx_no. + @param lhs first index in trx_sys.rseg_array to compare + @param rhs second index in trx_sys.rseg_array to compare + @return whether lhs>rhs */ + bool operator()(const byte lhs, const byte rhs) + { + ut_ad(lhs < TRX_SYS_N_RSEGS); + ut_ad(rhs < TRX_SYS_N_RSEGS); + /* We can compare without trx_rseg_t::latch, because rseg last + commit is always set before pushing rseg to purge queue. */ + return trx_sys.rseg_array[lhs].last_commit_and_offset > + trx_sys.rseg_array[rhs].last_commit_and_offset; + } + }; + byte *begin() { return m_array; } + byte *end() { return m_end; } + const byte *c_begin() const { return m_array; } + const byte *c_end() const { return m_end; } + size_t size() const + { + size_t s= c_end() - c_begin(); + ut_ad(s <= TRX_SYS_N_RSEGS); + return s; + } + bool empty() const { return !size(); } + void clear() { m_end= m_array; } + + /** Push index of trx_sys.rseg_array into min-heap. + @param i index to push */ + void push_rseg_index(byte i) + { + ut_ad(i < TRX_SYS_N_RSEGS); + ut_ad(size() + 1 <= TRX_SYS_N_RSEGS); + *m_end++= i; + std::push_heap(begin(), end(), trx_rseg_cmp()); + } + + /** Push rseg to priority queue. + @param rseg trx_rseg_t pointer to push */ + void push(const trx_rseg_t *rseg) + { + ut_ad(rseg >= trx_sys.rseg_array); + ut_ad(rseg < trx_sys.rseg_array + TRX_SYS_N_RSEGS); + byte i= byte(rseg - trx_sys.rseg_array); + push_rseg_index(i); + } + + /** Pop rseg from priority queue. + @return pointer to popped trx_rseg_t object */ + trx_rseg_t *pop() + { + ut_ad(!empty()); + std::pop_heap(begin(), end(), trx_rseg_cmp()); + byte i= *--m_end; + ut_ad(i < TRX_SYS_N_RSEGS); + return &trx_sys.rseg_array[i]; + } + }; + public: /** latch protecting view, m_enabled */ alignas(CPU_LEVEL1_DCACHE_LINESIZE) mutable srw_spin_lock latch; @@ -244,15 +243,27 @@ private: record */ uint16_t hdr_offset; /*!< Header byte offset on the page */ + /** Binary min-heap of indexes in trx_sys.rseg_array, ordered on + rseg_t::last_trx_no(). It is protected by the pq_mutex */ + purge_queue purge_queue; + + /** Mutex protecting purge_queue */ + mysql_mutex_t pq_mutex; - TrxUndoRsegsIterator - rseg_iter; /*!< Iterator to get the next rseg - to process */ public: - purge_pq_t purge_queue; /*!< Binary min-heap, ordered on - TrxUndoRsegs::trx_no. It is protected - by the pq_mutex */ - mysql_mutex_t pq_mutex; /*!< Mutex protecting purge_queue */ + /** Push to purge queue without acquiring pq_mutex. + @param rseg rseg to push */ + void enqueue(trx_rseg_t &rseg) + { + mysql_mutex_assert_owner(&pq_mutex); + purge_queue.push(&rseg); + } + + /** Acquare purge_queue_mutex */ + void queue_lock() { mysql_mutex_lock(&pq_mutex); } + + /** Release purge queue mutex */ + void queue_unlock() { mysql_mutex_unlock(&pq_mutex); } /** innodb_undo_log_truncate=ON state; only modified by purge_coordinator_callback() */ @@ -332,8 +343,9 @@ private: /** Update the last not yet purged history log info in rseg when we have purged a whole undo log. Advances also purge_trx_no - past the purged log. */ - void rseg_get_next_history_log(); + past the purged log. + @return whether anything is to be purged */ + bool rseg_get_next_history_log(); public: /** @@ -438,6 +450,11 @@ public: @param already_stopped True indicates purge threads were already stopped */ void stop_FTS(const dict_table_t &table, bool already_stopped=false); + + /** Cleanse purge queue to remove the rseg that reside in undo-tablespace + marked for truncate. + @param space undo tablespace being truncated */ + void cleanse_purge_queue(const fil_space_t &space); }; /** The global data structure coordinating a purge */ diff --git a/storage/innobase/include/trx0rseg.h b/storage/innobase/include/trx0rseg.h index 7211d9cba1a..e3d7a63efbb 100644 --- a/storage/innobase/include/trx0rseg.h +++ b/storage/innobase/include/trx0rseg.h @@ -170,19 +170,21 @@ public: /** Last not yet purged undo log header; FIL_NULL if all purged */ uint32_t last_page_no; - /** trx_t::no | last_offset << 48 */ + /** trx_t::no << 16 | last_offset */ uint64_t last_commit_and_offset; /** @return the commit ID of the last committed transaction */ trx_id_t last_trx_no() const - { return last_commit_and_offset & ((1ULL << 48) - 1); } + { return last_commit_and_offset >> 16; } /** @return header offset of the last committed transaction */ uint16_t last_offset() const - { return static_cast(last_commit_and_offset >> 48); } + { + return static_cast(last_commit_and_offset & ((1ULL << 16) - 1)); + } void set_last_commit(uint16_t last_offset, trx_id_t trx_no) { - last_commit_and_offset= static_cast(last_offset) << 48 | trx_no; + last_commit_and_offset= trx_no << 16 | static_cast(last_offset); } /** @return the page identifier */ diff --git a/storage/innobase/trx/trx0purge.cc b/storage/innobase/trx/trx0purge.cc index 5101879ddab..2fa202e8459 100644 --- a/storage/innobase/trx/trx0purge.cc +++ b/storage/innobase/trx/trx0purge.cc @@ -56,84 +56,6 @@ purge_sys_t purge_sys; my_bool srv_purge_view_update_only_debug; #endif /* UNIV_DEBUG */ -/** Sentinel value */ -static const TrxUndoRsegs NullElement; - -/** Default constructor */ -TrxUndoRsegsIterator::TrxUndoRsegsIterator() - : m_rsegs(NullElement), m_iter(m_rsegs.begin()) -{ -} - -/** Sets the next rseg to purge in purge_sys. -Executed in the purge coordinator thread. -@retval false when nothing is to be purged -@retval true when purge_sys.rseg->latch was locked */ -inline bool TrxUndoRsegsIterator::set_next() -{ - ut_ad(!purge_sys.next_stored); - mysql_mutex_lock(&purge_sys.pq_mutex); - - /* Only purge consumes events from the priority queue, user - threads only produce the events. */ - - /* Check if there are more rsegs to process in the - current element. */ - if (m_iter != m_rsegs.end()) { - /* We are still processing rollback segment from - the same transaction and so expected transaction - number shouldn't increase. Undo the increment of - expected commit done by caller assuming rollback - segments from given transaction are done. */ - purge_sys.tail.trx_no = (*m_iter)->last_trx_no(); - } else if (!purge_sys.purge_queue.empty()) { - m_rsegs = purge_sys.purge_queue.top(); - purge_sys.purge_queue.pop(); - ut_ad(purge_sys.purge_queue.empty() - || purge_sys.purge_queue.top() != m_rsegs); - m_iter = m_rsegs.begin(); - } else { - /* Queue is empty, reset iterator. */ - purge_sys.rseg = NULL; - mysql_mutex_unlock(&purge_sys.pq_mutex); - m_rsegs = NullElement; - m_iter = m_rsegs.begin(); - return false; - } - - purge_sys.rseg = *m_iter++; - mysql_mutex_unlock(&purge_sys.pq_mutex); - - /* We assume in purge of externally stored fields that space - id is in the range of UNDO tablespace space ids */ - ut_ad(purge_sys.rseg->space->id == TRX_SYS_SPACE - || srv_is_undo_tablespace(purge_sys.rseg->space->id)); - - purge_sys.rseg->latch.wr_lock(SRW_LOCK_CALL); - trx_id_t last_trx_no = purge_sys.rseg->last_trx_no(); - purge_sys.hdr_offset = purge_sys.rseg->last_offset(); - purge_sys.hdr_page_no = purge_sys.rseg->last_page_no; - - /* Only the purge_coordinator_task will access this object - purge_sys.rseg_iter, or any of purge_sys.hdr_page_no, - purge_sys.tail. - The field purge_sys.head and purge_sys.view are modified by - purge_sys_t::clone_end_view() - in the purge_coordinator_task - while holding exclusive purge_sys.latch. - The purge_sys.view may also be modified by - purge_sys_t::wake_if_not_active() while holding exclusive - purge_sys.latch. - The purge_sys.head may be read by - purge_truncation_callback(). */ - ut_ad(last_trx_no == m_rsegs.trx_no); - ut_a(purge_sys.hdr_page_no != FIL_NULL); - ut_a(purge_sys.tail.trx_no <= last_trx_no); - purge_sys.tail.trx_no = last_trx_no; - - return(true); -} - /** Build a purge 'query' graph. The actual purge is performed by executing this query graph. @return own: the query graph */ @@ -571,42 +493,17 @@ loop: goto loop; } -/** Cleanse purge queue to remove the rseg that reside in undo-tablespace -marked for truncate. -@param[in] space undo tablespace being truncated */ -static void trx_purge_cleanse_purge_queue(const fil_space_t& space) +void purge_sys_t::cleanse_purge_queue(const fil_space_t &space) { - typedef std::vector purge_elem_list_t; - purge_elem_list_t purge_elem_list; - - mysql_mutex_lock(&purge_sys.pq_mutex); - - /* Remove rseg instances that are in the purge queue before we start - truncate of corresponding UNDO truncate. */ - while (!purge_sys.purge_queue.empty()) { - purge_elem_list.push_back(purge_sys.purge_queue.top()); - purge_sys.purge_queue.pop(); - } - - for (purge_elem_list_t::iterator it = purge_elem_list.begin(); - it != purge_elem_list.end(); - ++it) { - - for (TrxUndoRsegs::iterator it2 = it->begin(); - it2 != it->end(); - ++it2) { - if ((*it2)->space == &space) { - it->erase(it2); - break; - } - } - - if (!it->empty()) { - purge_sys.purge_queue.push(*it); - } - } - - mysql_mutex_unlock(&purge_sys.pq_mutex); + byte purge_elem_list[TRX_SYS_N_RSEGS]; + mysql_mutex_lock(&pq_mutex); + std::copy(purge_queue.c_begin(), purge_queue.c_end(), purge_elem_list); + byte *purge_list_end = purge_elem_list + purge_queue.size(); + purge_queue.clear(); + for (byte *elem = purge_elem_list; elem < purge_list_end; ++elem) + if (trx_sys.rseg_array[*elem].space != &space) + purge_queue.push_rseg_index(*elem); + mysql_mutex_unlock(&pq_mutex); } dberr_t purge_sys_t::iterator::free_history() const @@ -750,7 +647,7 @@ not_free: const char *file_name= UT_LIST_GET_FIRST(space->chain)->name; sql_print_information("InnoDB: Truncating %s", file_name); - trx_purge_cleanse_purge_queue(*space); + purge_sys.cleanse_purge_queue(*space); /* Lock all modified pages of the tablespace. @@ -869,7 +766,7 @@ buf_block_t *purge_sys_t::get_page(page_id_t id) return nullptr; } -void purge_sys_t::rseg_get_next_history_log() +bool purge_sys_t::rseg_get_next_history_log() { fil_addr_t prev_log_addr; @@ -917,12 +814,13 @@ void purge_sys_t::rseg_get_next_history_log() can never produce events from an empty rollback segment. */ mysql_mutex_lock(&pq_mutex); - purge_queue.push(*rseg); + purge_queue.push(rseg); mysql_mutex_unlock(&pq_mutex); } } rseg->latch.wr_unlock(); + return choose_next_log(); } /** Position the purge sys "iterator" on the undo record to use for purging. @@ -930,11 +828,37 @@ void purge_sys_t::rseg_get_next_history_log() @retval true when purge_sys.rseg->latch was locked */ bool purge_sys_t::choose_next_log() { - if (!rseg_iter.set_next()) - return false; + ut_ad(!next_stored); - hdr_offset= rseg->last_offset(); - hdr_page_no= rseg->last_page_no; + mysql_mutex_lock(&pq_mutex); + if (purge_queue.empty()) { + rseg = nullptr; + mysql_mutex_unlock(&purge_sys.pq_mutex); + return false; + } + rseg= purge_queue.pop(); + mysql_mutex_unlock(&purge_sys.pq_mutex); + + /* We assume in purge of externally stored fields that space + id is in the range of UNDO tablespace space ids */ + ut_ad(rseg->space == fil_system.sys_space || + srv_is_undo_tablespace(rseg->space->id)); + + rseg->latch.wr_lock(SRW_LOCK_CALL); + trx_id_t last_trx_no = rseg->last_trx_no(); + hdr_offset = rseg->last_offset(); + hdr_page_no = rseg->last_page_no; + + /* Only the purge_coordinator_task will access this any of + purge_sys.hdr_page_no, purge_sys.tail. The field purge_sys.head and + purge_sys.view are modified by clone_end_view() in the + purge_coordinator_task while holding exclusive purge_sys.latch. The + purge_sys.view may also be modified by wake_if_not_active() while holding + exclusive purge_sys.latch. The purge_sys.head may be read by + purge_truncation_callback(). */ + ut_a(hdr_page_no != FIL_NULL); + ut_a(tail.trx_no <= last_trx_no); + tail.trx_no = last_trx_no; if (!rseg->needs_purge) { @@ -993,12 +917,9 @@ inline trx_purge_rec_t purge_sys_t::get_next_rec(roll_ptr_t roll_ptr) if (!offset) { - /* It is the dummy undo log record, which means that there is no - need to purge this undo log */ - rseg_get_next_history_log(); - - /* Look for the next undo log and record to purge */ - if (choose_next_log()) + /* It is the dummy undo log record, which means that there is no need to + purge this undo log. Look for the next undo log and record to purge */ + if (rseg_get_next_history_log()) rseg->latch.wr_unlock(); return {nullptr, 1}; } @@ -1046,9 +967,8 @@ inline trx_purge_rec_t purge_sys_t::get_next_rec(roll_ptr_t roll_ptr) else { got_no_rec: - rseg_get_next_history_log(); /* Look for the next undo log and record to purge */ - locked= choose_next_log(); + locked= rseg_get_next_history_log(); } if (locked) diff --git a/storage/innobase/trx/trx0rseg.cc b/storage/innobase/trx/trx0rseg.cc index 26d09f5fbbe..8732ae81005 100644 --- a/storage/innobase/trx/trx0rseg.cc +++ b/storage/innobase/trx/trx0rseg.cc @@ -544,7 +544,7 @@ static dberr_t trx_rseg_mem_restore(trx_rseg_t *rseg, mtr_t *mtr) if (rseg->last_page_no != FIL_NULL) /* There is no need to cover this operation by the purge mutex because we are still bootstrapping. */ - purge_sys.purge_queue.push(*rseg); + purge_sys.enqueue(*rseg); } return err; @@ -584,7 +584,17 @@ dberr_t trx_rseg_array_init() #endif mtr_t mtr; dberr_t err = DB_SUCCESS; - + /* mariabackup --prepare only deals with the redo log and the data + files, not with transactions or the data dictionary, that's why + trx_lists_init_at_db_start() does not invoke purge_sys.create() and + purge queue mutex stays uninitialized, and trx_rseg_mem_restore() quits + before initializing undo log lists. */ + if (srv_operation != SRV_OPERATION_RESTORE) + /* Acquiring purge queue mutex here should be fine from the + deadlock prevention point of view, because executing that + function is a prerequisite for starting the purge subsystem or + any transactions. */ + purge_sys.queue_lock(); for (ulint rseg_id = 0; rseg_id < TRX_SYS_N_RSEGS; rseg_id++) { mtr.start(); if (const buf_block_t* sys = trx_sysf_get(&mtr, false)) { @@ -640,7 +650,8 @@ dberr_t trx_rseg_array_init() mtr.commit(); } - + if (srv_operation != SRV_OPERATION_RESTORE) + purge_sys.queue_unlock(); if (err != DB_SUCCESS) { for (auto& rseg : trx_sys.rseg_array) { while (auto u = UT_LIST_GET_FIRST(rseg.undo_list)) { diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index 59685e21cfb..dbbdb8bace1 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -1138,15 +1138,23 @@ inline void trx_t::write_serialisation_history(mtr_t *mtr) } else if (rseg->last_page_no == FIL_NULL) { - mysql_mutex_lock(&purge_sys.pq_mutex); + /* trx_sys.assign_new_trx_no() and + purge_sys.enqueue() must be invoked in the same + critical section protected with purge queue mutex to avoid rseg with + greater last commit number to be pushed to purge queue prior to rseg with + lesser last commit number. In other words pushing to purge queue must be + serialized along with assigning trx_no. Otherwise purge coordinator + thread can also fetch redo log records from rseg with greater last commit + number before rseg with lesser one. */ + purge_sys.queue_lock(); trx_sys.assign_new_trx_no(this); const trx_id_t end{rw_trx_hash_element->no}; + rseg->last_page_no= undo->hdr_page_no; /* end cannot be less than anything in rseg. User threads only produce events when a rollback segment is empty. */ - purge_sys.purge_queue.push(TrxUndoRsegs{end, *rseg}); - mysql_mutex_unlock(&purge_sys.pq_mutex); - rseg->last_page_no= undo->hdr_page_no; rseg->set_last_commit(undo->hdr_offset, end); + purge_sys.enqueue(*rseg); + purge_sys.queue_unlock(); } else trx_sys.assign_new_trx_no(this); From 9a4991a089532ca0fe803e646a24c639c47c34b8 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Mon, 1 Apr 2024 09:46:50 -0600 Subject: [PATCH 050/159] MDEV-33799: mysql_manager_submit Segfault at Startup Still Possible During Recovery MDEV-26473 fixed a segmentation fault at startup between the handle manager thread and the binlog background thread, such that the binlog background thread could be started and submit a job to the handle manager, before it had initialized. Where MDEV-26473 made it so the handle manager would initialize before the main thread started the normal binary logs, it did not account for the recovery case. That is, there is still a possibility of a segmentation fault when a server is recovering using the binary logs such that it can open the binary logs, start the binlog background thread, and submit a job to the handle manager before it is initialized. This patch fixes this by moving the initialization of the mysql handler manager to happen prior to recovery. Reviewed By: ============ Andrei Elkin --- .../r/rpl_mysql_manager_race_condition.result | 31 +++++++++ .../t/rpl_mysql_manager_race_condition.test | 64 +++++++++++++++++++ sql/mysqld.cc | 7 +- 3 files changed, 99 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_mysql_manager_race_condition.result b/mysql-test/suite/rpl/r/rpl_mysql_manager_race_condition.result index 1172d8e39a9..740d1ddfcfa 100644 --- a/mysql-test/suite/rpl/r/rpl_mysql_manager_race_condition.result +++ b/mysql-test/suite/rpl/r/rpl_mysql_manager_race_condition.result @@ -17,6 +17,36 @@ include/sync_with_master_gtid.inc include/rpl_restart_server.inc [server_number=2 parameters: --debug_dbug="+d,delay_start_handle_manager"] include/start_slave.inc # +# MDEV-33799 +# Ensure that when the binary log is used for recovery (as tc log), that +# the recovery process cannot start the binlog background thread before +# the mysql handle manager has started. +connection slave; +# Add test suppresssions so crash recovery messages don't fail the test +set session sql_log_bin=0; +call mtr.add_suppression("mariadbd: Got error '145.*"); +call mtr.add_suppression("Checking table:.*"); +call mtr.add_suppression("mysql.gtid_slave_pos:.*hasn't closed the table properly"); +call mtr.add_suppression("Can't init tc log"); +call mtr.add_suppression("Aborting"); +set session sql_log_bin=1; +# Create slave-side only table +create table t2 (a int) engine=innodb; +# Crash mariadbd when binlogging transaction to corrupt database state +connection slave1; +set @@session.debug_dbug="+d,crash_before_writing_xid"; +insert into t2 values (1); +connection slave; +connection slave1; +Got one of the listed errors +# Restart mariadbd in recovery mode. Note --tc-heuristic-recover +# forces mysqld to exit with error, so we run mariadbd via CLI +# MYSQLD_LAST_CMD --debug_dbug="+d,delay_start_handle_manager" --tc-heuristic-recover=COMMIT +connection server_2; +connection slave1; +connection slave; +include/start_slave.inc +# # Cleanup # connection master; @@ -24,4 +54,5 @@ drop table t1; include/save_master_gtid.inc connection slave; include/sync_with_master_gtid.inc +drop table t2; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_mysql_manager_race_condition.test b/mysql-test/suite/rpl/t/rpl_mysql_manager_race_condition.test index 751da3158b7..dd4a0fbbc99 100644 --- a/mysql-test/suite/rpl/t/rpl_mysql_manager_race_condition.test +++ b/mysql-test/suite/rpl/t/rpl_mysql_manager_race_condition.test @@ -18,8 +18,14 @@ # associated with this test should enforce that the binlog background thread is # not created before the handle manager is initialized. # +# Addendum 1) This test is extended for MDEV-33799, as the original fix +# left out the possibility that the binlog background thread can be +# started during recovery if the binary log is used as the transaction +# coordinator. This resulted in similar segfaults as seen by MDEV-26473. +# # References: # MDEV-26473 mysqld got exception 0xc0000005 (rpl_slave_state/rpl_load_gtid_slave_state) +# MDEV-33799 mysql_manager_submit Segfault at Startup Still Possible During Recovery # --source include/have_debug.inc @@ -53,6 +59,63 @@ create table t1 (a int); --source include/start_slave.inc +--echo # +--echo # MDEV-33799 +--echo # Ensure that when the binary log is used for recovery (as tc log), that +--echo # the recovery process cannot start the binlog background thread before +--echo # the mysql handle manager has started. +--connection slave + +--echo # Add test suppresssions so crash recovery messages don't fail the test +set session sql_log_bin=0; +call mtr.add_suppression("mariadbd: Got error '145.*"); +call mtr.add_suppression("Checking table:.*"); +call mtr.add_suppression("mysql.gtid_slave_pos:.*hasn't closed the table properly"); +call mtr.add_suppression("Can't init tc log"); +call mtr.add_suppression("Aborting"); +set session sql_log_bin=1; + +--echo # Create slave-side only table +create table t2 (a int) engine=innodb; + +--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +wait +EOF + +--echo # Crash mariadbd when binlogging transaction to corrupt database state +--connection slave1 +set @@session.debug_dbug="+d,crash_before_writing_xid"; +--send insert into t2 values (1) + +--connection slave +--source include/wait_until_disconnected.inc + +--connection slave1 +--error 2013,ER_CONNECTION_KILLED +--reap + +--echo # Restart mariadbd in recovery mode. Note --tc-heuristic-recover +--echo # forces mysqld to exit with error, so we run mariadbd via CLI +--echo # MYSQLD_LAST_CMD --debug_dbug="+d,delay_start_handle_manager" --tc-heuristic-recover=COMMIT +--error 1 +--exec $MYSQLD_LAST_CMD --debug_dbug="+d,delay_start_handle_manager" --tc-heuristic-recover=COMMIT + +--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +restart +EOF + +--connection server_2 +--enable_reconnect +--source include/wait_until_connected_again.inc +--connection slave1 +--enable_reconnect +--source include/wait_until_connected_again.inc +--connection slave +--enable_reconnect +--source include/wait_until_connected_again.inc +--source include/start_slave.inc + + --echo # --echo # Cleanup --echo # @@ -63,5 +126,6 @@ drop table t1; --connection slave --source include/sync_with_master_gtid.inc +drop table t2; --source include/rpl_end.inc diff --git a/sql/mysqld.cc b/sql/mysqld.cc index c29bfc2ed50..d10c342a6dc 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5383,6 +5383,10 @@ static int init_server_components() if (ddl_log_initialize()) unireg_abort(1); +#ifndef EMBEDDED_LIBRARY + start_handle_manager(); +#endif + tc_log= get_tc_log_implementation(); if (tc_log->open(opt_bin_log ? opt_bin_logname : opt_tc_log_file)) @@ -5394,9 +5398,6 @@ static int init_server_components() if (ha_recover(0)) unireg_abort(1); -#ifndef EMBEDDED_LIBRARY - start_handle_manager(); -#endif if (opt_bin_log) { int error; From 8cc36fb7434114fce06725cc607c2f7c65ac3ac7 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Wed, 20 Mar 2024 13:09:12 +0300 Subject: [PATCH 051/159] MDEV-21102: Server crashes in JOIN_CACHE::write_record_data upon EXPLAIN with subqueries JOIN_CACHE has a light-weight initialization mode that's targeted at EXPLAINs. In that mode, JOIN_CACHE objects are not able to execute. Light-weight mode was used whenever the statement was an EXPLAIN. However the EXPLAIN can execute subqueries, provided they enumerate less than @@expensive_subquery_limit rows. Make sure we use light-weight initialization mode only when the select is more expensive @@expensive_subquery_limit. Also add an assert into JOIN_CACHE::put_record() which prevents its use if it was initialized for EXPLAIN only. --- mysql-test/main/join_cache.result | 22 ++++++++++++++++++++++ mysql-test/main/join_cache.test | 21 +++++++++++++++++++++ sql/item_subselect.cc | 2 ++ sql/sql_join_cache.cc | 1 + sql/sql_select.cc | 23 ++++++++++++++++++++++- 5 files changed, 68 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result index c07a8b1bf6b..49f3b0910fa 100644 --- a/mysql-test/main/join_cache.result +++ b/mysql-test/main/join_cache.result @@ -6396,5 +6396,27 @@ b b d c c 10 NULL NULL NULL NULL DROP TABLE t1,t2,t3,t4; # +# MDEV-21102: Server crashes in JOIN_CACHE::write_record_data upon EXPLAIN with subqueries and constant tables +# +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; +CREATE TABLE t2 (c int, d int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,10); +CREATE TABLE t3 (e int, key (e)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (2),(3); +# Must not crash, must use join buffer in subquery +EXPLAIN +SELECT * FROM t1 +WHERE a > b OR a IN ( +SELECT c FROM t2 WHERE EXISTS ( +SELECT * FROM t3 t3a JOIN t3 t3b WHERE t3a.e < d +) +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 +3 SUBQUERY t3a index e e 5 NULL 2 Using where; Using index +3 SUBQUERY t3b index NULL e 5 NULL 2 Using index; Using join buffer (flat, BNL join) +DROP TABLE t1,t2,t3; +# # End of 10.4 tests # diff --git a/mysql-test/main/join_cache.test b/mysql-test/main/join_cache.test index 868fc3f7e8a..8d341c9e0fc 100644 --- a/mysql-test/main/join_cache.test +++ b/mysql-test/main/join_cache.test @@ -4305,6 +4305,27 @@ eval $q2; DROP TABLE t1,t2,t3,t4; +--echo # +--echo # MDEV-21102: Server crashes in JOIN_CACHE::write_record_data upon EXPLAIN with subqueries and constant tables +--echo # +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; + +CREATE TABLE t2 (c int, d int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,10); + +CREATE TABLE t3 (e int, key (e)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (2),(3); + +--echo # Must not crash, must use join buffer in subquery +EXPLAIN +SELECT * FROM t1 +WHERE a > b OR a IN ( + SELECT c FROM t2 WHERE EXISTS ( + SELECT * FROM t3 t3a JOIN t3 t3b WHERE t3a.e < d + ) +); +DROP TABLE t1,t2,t3; + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index a8824adbdd8..d39c85e6f76 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -562,6 +562,8 @@ void Item_subselect::recalc_used_tables(st_select_lex *new_parent, This measure is used instead of JOIN::read_time, because it is considered to be much more reliable than the cost estimate. + Note: the logic in this function must agree with JOIN::init_join_caches(). + @return true if the subquery is expensive @return false otherwise */ diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 41d7dd89f55..c33c2f029cd 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -1589,6 +1589,7 @@ bool JOIN_CACHE::put_record() { bool is_full; uchar *link= 0; + DBUG_ASSERT(!for_explain_only); if (prev_cache) link= prev_cache->get_curr_rec_link(); write_record_data(link, &is_full); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9e8b8e4ebe0..efcd42be074 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1876,6 +1876,26 @@ JOIN::init_range_rowid_filters() int JOIN::init_join_caches() { + bool init_for_explain= false; + + /* + Can we use lightweight initalization mode just for EXPLAINs? We can if + we're certain that the optimizer will not execute the subquery. + The optimzier will not execute the subquery if it's too expensive. For + the exact criteria, see Item_subselect::is_expensive(). + Note that the subquery might be a UNION and we might not yet know if it is + expensive. + What we do know is that if this SELECT is too expensive, then the whole + subquery will be too expensive as well. + So, we can use lightweight initialization (init_for_explain=true) if this + SELECT examines more than @@expensive_subquery_limit rows. + */ + if ((select_options & SELECT_DESCRIBE) && + get_examined_rows() >= thd->variables.expensive_subquery_limit) + { + init_for_explain= true; + } + JOIN_TAB *tab; for (tab= first_linear_tab(this, WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES); @@ -1895,7 +1915,8 @@ int JOIN::init_join_caches() { table->prepare_for_keyread(tab->index, table->read_set); } - if (tab->cache && tab->cache->init(select_options & SELECT_DESCRIBE)) + + if (tab->cache && tab->cache->init(init_for_explain)) revise_cache_usage(tab); else tab->remove_redundant_bnl_scan_conds(); From 2fcf2ec229862fe24a97c54db4e62f1ae8f9ed63 Mon Sep 17 00:00:00 2001 From: sjaakola Date: Thu, 4 Apr 2024 17:12:09 +0300 Subject: [PATCH 052/159] MDEV-33749 hyphen in table name can cause galera certification failures Fix in this commit handles foreign key value appending into write set so that db and table names are converted from the filepath format to tablename format. This is compatible with key values appended from elsewhere in the code base There is a mtr test galera.galera_table_with_hyphen for regression testing Reviewer: monty@mariadb.com --- .../galera/r/galera_table_with_hyphen.result | 52 +++++++++++++++++++ .../galera/t/galera_table_with_hyphen.inc | 48 +++++++++++++++++ .../galera/t/galera_table_with_hyphen.test | 34 ++++++++++++ sql/handler.cc | 11 +++- storage/innobase/handler/ha_innodb.cc | 43 ++++++++++----- 5 files changed, 173 insertions(+), 15 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_table_with_hyphen.result create mode 100644 mysql-test/suite/galera/t/galera_table_with_hyphen.inc create mode 100644 mysql-test/suite/galera/t/galera_table_with_hyphen.test diff --git a/mysql-test/suite/galera/r/galera_table_with_hyphen.result b/mysql-test/suite/galera/r/galera_table_with_hyphen.result new file mode 100644 index 00000000000..c9993004b53 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_table_with_hyphen.result @@ -0,0 +1,52 @@ +connection node_2; +connection node_1; +connection node_1; +set wsrep_sync_wait=0; +connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; +SET SESSION wsrep_sync_wait = 0; +connection node_1; +SET GLOBAL wsrep_slave_threads=2; +CREATE TABLE `par-ent` ( id INT AUTO_INCREMENT PRIMARY KEY, j INT) ENGINE=InnoDB; +CREATE TABLE `child` (id INT AUTO_INCREMENT PRIMARY KEY, parent_id INT, j INT, FOREIGN KEY (parent_id) REFERENCES `par-ent`(id)) ENGINE=InnoDB; +INSERT INTO `par-ent` VALUES (23,0); +connection node_2; +connection node_1a; +SET GLOBAL DEBUG_DBUG='+d,wsrep_ha_write_row'; +connection node_2; +INSERT INTO `child` VALUES (21,23,0),(22,23,0),(23,23,0); +connection node_1a; +SET DEBUG_SYNC='now WAIT_FOR wsrep_ha_write_row_reached'; +connection node_2; +UPDATE `par-ent` SET j=2 WHERE id=23; +connection node_1a; +SET GLOBAL DEBUG_DBUG='-d,wsrep_ha_write_row'; +SET DEBUG_SYNC='now SIGNAL wsrep_ha_write_row_continue'; +SET GLOBAL DEBUG_DBUG="RESET"; +SET DEBUG_SYNC = 'RESET'; +SET GLOBAL wsrep_slave_threads=DEFAULT; +connection node_2; +drop table `child`; +drop table `par-ent`; +connection node_1; +SET GLOBAL wsrep_slave_threads=2; +CREATE TABLE `p-arent-` ( id INT AUTO_INCREMENT PRIMARY KEY, j INT) ENGINE=InnoDB; +CREATE TABLE `c-hild` (id INT AUTO_INCREMENT PRIMARY KEY, parent_id INT, j INT, FOREIGN KEY (parent_id) REFERENCES `p-arent-`(id)) ENGINE=InnoDB; +INSERT INTO `p-arent-` VALUES (23,0); +connection node_2; +connection node_1a; +SET GLOBAL DEBUG_DBUG='+d,wsrep_ha_write_row'; +connection node_2; +INSERT INTO `c-hild` VALUES (21,23,0),(22,23,0),(23,23,0); +connection node_1a; +SET DEBUG_SYNC='now WAIT_FOR wsrep_ha_write_row_reached'; +connection node_2; +UPDATE `p-arent-` SET j=2 WHERE id=23; +connection node_1a; +SET GLOBAL DEBUG_DBUG='-d,wsrep_ha_write_row'; +SET DEBUG_SYNC='now SIGNAL wsrep_ha_write_row_continue'; +SET GLOBAL DEBUG_DBUG="RESET"; +SET DEBUG_SYNC = 'RESET'; +SET GLOBAL wsrep_slave_threads=DEFAULT; +connection node_2; +drop table `c-hild`; +drop table `p-arent-`; diff --git a/mysql-test/suite/galera/t/galera_table_with_hyphen.inc b/mysql-test/suite/galera/t/galera_table_with_hyphen.inc new file mode 100644 index 00000000000..ac79d864e82 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_table_with_hyphen.inc @@ -0,0 +1,48 @@ +# +# parameters: +# $fk_child - child table name +# $fk_parent - parent table name +# +--connection node_1 +SET GLOBAL wsrep_slave_threads=2; + +--eval CREATE TABLE `$fk_parent` ( id INT AUTO_INCREMENT PRIMARY KEY, j INT) ENGINE=InnoDB + +--eval CREATE TABLE `$fk_child` (id INT AUTO_INCREMENT PRIMARY KEY, parent_id INT, j INT, FOREIGN KEY (parent_id) REFERENCES `$fk_parent`(id)) ENGINE=InnoDB + +--eval INSERT INTO `$fk_parent` VALUES (23,0) + +--connection node_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM `$fk_parent`; +--source include/wait_condition.inc + +--connection node_1a +SET GLOBAL DEBUG_DBUG='+d,wsrep_ha_write_row'; + +--connection node_2 +--eval INSERT INTO `$fk_child` VALUES (21,23,0),(22,23,0),(23,23,0) + +--connection node_1a +SET DEBUG_SYNC='now WAIT_FOR wsrep_ha_write_row_reached'; + +--let $wsrep_received_before = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_received'` + +--connection node_2 +--eval UPDATE `$fk_parent` SET j=2 WHERE id=23 + +--connection node_1a +--let $wait_condition = SELECT VARIABLE_VALUE = $wsrep_received_before + 1 FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_received' +--source include/wait_condition.inc + +SET GLOBAL DEBUG_DBUG='-d,wsrep_ha_write_row'; +SET DEBUG_SYNC='now SIGNAL wsrep_ha_write_row_continue'; + +SET GLOBAL DEBUG_DBUG="RESET"; +SET DEBUG_SYNC = 'RESET'; + +SET GLOBAL wsrep_slave_threads=DEFAULT; + +--connection node_2 +--eval drop table `$fk_child` +--eval drop table `$fk_parent` + diff --git a/mysql-test/suite/galera/t/galera_table_with_hyphen.test b/mysql-test/suite/galera/t/galera_table_with_hyphen.test new file mode 100644 index 00000000000..1b28bdeb3ca --- /dev/null +++ b/mysql-test/suite/galera/t/galera_table_with_hyphen.test @@ -0,0 +1,34 @@ +--source include/galera_cluster.inc +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc + +# +# Testing how tables and databases with special characters +# are treated in certification +# +# The test creates two tables having foreign key constraint +# reference and executes two transactions which modify +# same rows. The same test is executed with different names +# containin special characters to see if the certification +# can detect the conflicts +# +# Actual test is in include file galera_table_with_hyphen.inc +# It create the test tables from parameters $fk_child and +# $fk_parent +# +--connection node_1 +set wsrep_sync_wait=0; + +--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 +SET SESSION wsrep_sync_wait = 0; + +--let $fk_child = child +--let $fk_parent = par-ent + +--source galera_table_with_hyphen.inc + +--let $fk_child = c-hild +--let $fk_parent = p-arent- + +--source galera_table_with_hyphen.inc diff --git a/sql/handler.cc b/sql/handler.cc index 352076a9e21..24bc845c694 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -7270,7 +7270,16 @@ int handler::ha_write_row(const uchar *buf) m_lock_type == F_WRLCK); DBUG_ENTER("handler::ha_write_row"); DEBUG_SYNC_C("ha_write_row_start"); - +#ifdef WITH_WSREP + DBUG_EXECUTE_IF("wsrep_ha_write_row", + { + const char act[]= + "now " + "SIGNAL wsrep_ha_write_row_reached " + "WAIT_FOR wsrep_ha_write_row_continue"; + DBUG_ASSERT(!debug_sync_set_action(ha_thd(), STRING_WITH_LEN(act))); + }); +#endif /* WITH_WSREP */ if ((error= ha_check_overlaps(NULL, buf))) DBUG_RETURN(error); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 19cfa21c84e..01c881e1bb8 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -9786,7 +9786,8 @@ wsrep_append_foreign_key( } ulint rcode = DB_SUCCESS; - char cache_key[513] = {'\0'}; + char cache_key[MAX_FULL_NAME_LEN] = {'\0'}; + char db_name[MAX_DATABASE_NAME_LEN+1] = {'\0'}; size_t cache_key_len = 0; if ( !((referenced) ? @@ -9871,14 +9872,38 @@ wsrep_append_foreign_key( return DB_ERROR; } - strncpy(cache_key, + char * fk_table = (wsrep_protocol_version > 1) ? ((referenced) ? foreign->referenced_table->name.m_name : foreign->foreign_table->name.m_name) : - foreign->foreign_table->name.m_name, sizeof(cache_key) - 1); - cache_key_len = strlen(cache_key); + foreign->foreign_table->name.m_name; + /* convert db and table name parts separately to system charset */ + ulint db_name_len = dict_get_db_name_len(fk_table); + strmake(db_name, fk_table, db_name_len); + uint errors; + cache_key_len= innobase_convert_to_system_charset(cache_key, + db_name, sizeof(cache_key), &errors); + if (errors) { + WSREP_WARN("unexpected foreign key table %s %s", + foreign->referenced_table->name.m_name, + foreign->foreign_table->name.m_name); + return DB_ERROR; + } + + /* after db name adding 0 and then converted table name */ + cache_key[db_name_len]= '\0'; + cache_key_len++; + + cache_key_len+= innobase_convert_to_system_charset(cache_key+cache_key_len, + fk_table+db_name_len+1, sizeof(cache_key), &errors); + if (errors) { + WSREP_WARN("unexpected foreign key table %s %s", + foreign->referenced_table->name.m_name, + foreign->foreign_table->name.m_name); + return DB_ERROR; + } #ifdef WSREP_DEBUG_PRINT ulint j; fprintf(stderr, "FK parent key, table: %s %s len: %lu ", @@ -9888,16 +9913,6 @@ wsrep_append_foreign_key( } fprintf(stderr, "\n"); #endif - char *p = strchr(cache_key, '/'); - - if (p) { - *p = '\0'; - } else { - WSREP_WARN("unexpected foreign key table %s %s", - foreign->referenced_table->name.m_name, - foreign->foreign_table->name.m_name); - } - wsrep_buf_t wkey_part[3]; wsrep_key_t wkey = {wkey_part, 3}; From a202371f0b0b2d07cf24660efff648b17aeb6af5 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Thu, 4 Apr 2024 16:38:26 +0300 Subject: [PATCH 053/159] MDEV-33757 Get rid of TrxUndoRsegs code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Post-push fix: purge queue array can't be fixed size, because the elements of the array is the analogue of undo logs, which must be processed in the order of transaction commits, and the array can contain more elements, than trx_sys.rseg_array. Also it's necessary to maintain min-heap property by the trx_no of transaction, which produced the first non-purged undo log in all rsegs. That's why the element of purge queue aray must contain not only trx_sys.rseg_array index, but also trx_no of committed transacion, i.e. the pair (trx_no, trx_sys.rseg_array index), which is encoded as uint64_t((trx_no << 8) | (trx_sys.rseg_array index)). Reviewed by: Marko Mäkelä --- storage/innobase/include/trx0purge.h | 116 ++++++++++++++------------- storage/innobase/include/trx0rseg.h | 2 +- storage/innobase/trx/trx0purge.cc | 12 ++- storage/innobase/trx/trx0trx.cc | 2 +- 4 files changed, 67 insertions(+), 65 deletions(-) diff --git a/storage/innobase/include/trx0purge.h b/storage/innobase/include/trx0purge.h index 53f66d4930d..dc28c866c74 100644 --- a/storage/innobase/include/trx0purge.h +++ b/storage/innobase/include/trx0purge.h @@ -58,62 +58,47 @@ ulint trx_purge(ulint n_tasks, ulint history_size); /** The control structure used in the purge operation */ class purge_sys_t { - /** Min-heap based priority queue over fixed size array */ + /** Min-heap based priority queue of (trx_no, trx_sys.rseg_array index) + pairs, ordered on trx_no. The highest 64-TRX_NO_SHIFT bits of each element is + trx_no, the lowest 8 bits is rseg's index in trx_sys.rseg_array. */ class purge_queue { - /** Array of indexes in trx_sys.rseg_array. */ - alignas(CPU_LEVEL1_DCACHE_LINESIZE) byte m_array[TRX_SYS_N_RSEGS]; - /** Pointer to the end of m_array. */ - byte *m_end= m_array; - public: - struct trx_rseg_cmp - { - /** Compare two trx_rseg_t* based on trx_no. - @param lhs first index in trx_sys.rseg_array to compare - @param rhs second index in trx_sys.rseg_array to compare - @return whether lhs>rhs */ - bool operator()(const byte lhs, const byte rhs) - { - ut_ad(lhs < TRX_SYS_N_RSEGS); - ut_ad(rhs < TRX_SYS_N_RSEGS); - /* We can compare without trx_rseg_t::latch, because rseg last - commit is always set before pushing rseg to purge queue. */ - return trx_sys.rseg_array[lhs].last_commit_and_offset > - trx_sys.rseg_array[rhs].last_commit_and_offset; - } - }; - byte *begin() { return m_array; } - byte *end() { return m_end; } - const byte *c_begin() const { return m_array; } - const byte *c_end() const { return m_end; } - size_t size() const - { - size_t s= c_end() - c_begin(); - ut_ad(s <= TRX_SYS_N_RSEGS); - return s; - } - bool empty() const { return !size(); } - void clear() { m_end= m_array; } + typedef std::vector> container_type; + /** Number of bits reseved to shift trx_no in purge queue element */ + static constexpr unsigned TRX_NO_SHIFT= 8; - /** Push index of trx_sys.rseg_array into min-heap. - @param i index to push */ - void push_rseg_index(byte i) + bool empty() const { return m_array.empty(); } + void clear() { m_array.clear(); } + + /** Push (trx_no, trx_sys.rseg_array index) into min-heap. + @param trx_no_rseg (trx_no << TRX_NO_SHIFT | (trx_sys.rseg_array index)) */ + void push_trx_no_rseg(container_type::value_type trx_no_rseg) { - ut_ad(i < TRX_SYS_N_RSEGS); - ut_ad(size() + 1 <= TRX_SYS_N_RSEGS); - *m_end++= i; - std::push_heap(begin(), end(), trx_rseg_cmp()); + m_array.push_back(trx_no_rseg); + std::push_heap(m_array.begin(), m_array.end(), + std::greater()); } /** Push rseg to priority queue. - @param rseg trx_rseg_t pointer to push */ - void push(const trx_rseg_t *rseg) + @param trx_no trx_no of committed transaction + @param rseg rseg of committed transaction*/ + void push(trx_id_t trx_no, const trx_rseg_t &rseg) { - ut_ad(rseg >= trx_sys.rseg_array); - ut_ad(rseg < trx_sys.rseg_array + TRX_SYS_N_RSEGS); - byte i= byte(rseg - trx_sys.rseg_array); - push_rseg_index(i); + ut_ad(trx_no < 1ULL << (DATA_TRX_ID_LEN * CHAR_BIT)); + ut_ad(&rseg >= trx_sys.rseg_array); + ut_ad(&rseg < trx_sys.rseg_array + TRX_SYS_N_RSEGS); + push_trx_no_rseg(trx_no << TRX_NO_SHIFT | + byte(&rseg - trx_sys.rseg_array)); + } + + /** Extracts rseg from (trx_no, trx_sys.rseg_array index) pair. + @param trx_no_rseg (trx_no << TRX_NO_SHIFT | (trx_sys.rseg_array index) + @return pointer to rseg in trx_sys.rseg_array */ + static trx_rseg_t *rseg(container_type::value_type trx_no_rseg) { + byte i= static_cast(trx_no_rseg); + ut_ad(i < TRX_SYS_N_RSEGS); + return &trx_sys.rseg_array[i]; } /** Pop rseg from priority queue. @@ -121,13 +106,23 @@ class purge_sys_t trx_rseg_t *pop() { ut_ad(!empty()); - std::pop_heap(begin(), end(), trx_rseg_cmp()); - byte i= *--m_end; - ut_ad(i < TRX_SYS_N_RSEGS); - return &trx_sys.rseg_array[i]; + std::pop_heap(m_array.begin(), m_array.end(), + std::greater()); + trx_rseg_t *r = rseg(m_array.back()); + m_array.pop_back(); + return r; } + + /** Clone m_array. + @return m_array clone */ + container_type clone_container() const{ return m_array; } + + private: + /** Array of (trx_no, trx_sys.rseg_array index) pairs. */ + container_type m_array; }; + public: /** latch protecting view, m_enabled */ alignas(CPU_LEVEL1_DCACHE_LINESIZE) mutable srw_spin_lock latch; @@ -243,20 +238,29 @@ private: record */ uint16_t hdr_offset; /*!< Header byte offset on the page */ - /** Binary min-heap of indexes in trx_sys.rseg_array, ordered on - rseg_t::last_trx_no(). It is protected by the pq_mutex */ + /** Binary min-heap of (trx_no, trx_sys.rseg_array index) pairs, ordered on + trx_no. It is protected by the pq_mutex */ purge_queue purge_queue; /** Mutex protecting purge_queue */ mysql_mutex_t pq_mutex; public: + + void enqueue(trx_id_t trx_no, const trx_rseg_t &rseg) { + mysql_mutex_assert_owner(&pq_mutex); + purge_queue.push(trx_no, rseg); + } + /** Push to purge queue without acquiring pq_mutex. @param rseg rseg to push */ - void enqueue(trx_rseg_t &rseg) - { + void enqueue(const trx_rseg_t &rseg) { enqueue(rseg.last_trx_no(), rseg); } + + /** Clone purge queue container. + @return purge queue container clone */ + purge_queue::container_type clone_queue_container() const { mysql_mutex_assert_owner(&pq_mutex); - purge_queue.push(&rseg); + return purge_queue.clone_container(); } /** Acquare purge_queue_mutex */ diff --git a/storage/innobase/include/trx0rseg.h b/storage/innobase/include/trx0rseg.h index e3d7a63efbb..24ba845271d 100644 --- a/storage/innobase/include/trx0rseg.h +++ b/storage/innobase/include/trx0rseg.h @@ -179,7 +179,7 @@ public: /** @return header offset of the last committed transaction */ uint16_t last_offset() const { - return static_cast(last_commit_and_offset & ((1ULL << 16) - 1)); + return static_cast(last_commit_and_offset); } void set_last_commit(uint16_t last_offset, trx_id_t trx_no) diff --git a/storage/innobase/trx/trx0purge.cc b/storage/innobase/trx/trx0purge.cc index 2fa202e8459..2445b85939d 100644 --- a/storage/innobase/trx/trx0purge.cc +++ b/storage/innobase/trx/trx0purge.cc @@ -495,14 +495,12 @@ loop: void purge_sys_t::cleanse_purge_queue(const fil_space_t &space) { - byte purge_elem_list[TRX_SYS_N_RSEGS]; mysql_mutex_lock(&pq_mutex); - std::copy(purge_queue.c_begin(), purge_queue.c_end(), purge_elem_list); - byte *purge_list_end = purge_elem_list + purge_queue.size(); + auto purge_elem_list= clone_queue_container(); purge_queue.clear(); - for (byte *elem = purge_elem_list; elem < purge_list_end; ++elem) - if (trx_sys.rseg_array[*elem].space != &space) - purge_queue.push_rseg_index(*elem); + for (auto elem : purge_elem_list) + if (purge_queue::rseg(elem)->space != &space) + purge_queue.push_trx_no_rseg(elem); mysql_mutex_unlock(&pq_mutex); } @@ -814,7 +812,7 @@ bool purge_sys_t::rseg_get_next_history_log() can never produce events from an empty rollback segment. */ mysql_mutex_lock(&pq_mutex); - purge_queue.push(rseg); + enqueue(*rseg); mysql_mutex_unlock(&pq_mutex); } } diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index dbbdb8bace1..e6068f51e04 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -1153,7 +1153,7 @@ inline void trx_t::write_serialisation_history(mtr_t *mtr) /* end cannot be less than anything in rseg. User threads only produce events when a rollback segment is empty. */ rseg->set_last_commit(undo->hdr_offset, end); - purge_sys.enqueue(*rseg); + purge_sys.enqueue(end, *rseg); purge_sys.queue_unlock(); } else From faf686db9e9d7dd85f5f917d1d8c3fa0a5ab27cc Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 28 Mar 2024 18:23:11 +0100 Subject: [PATCH 054/159] MDEV-22955 innodb.innodb-alter fails in buildbot with extra warning add 10.5-specific global suppression. the extra warning is gone in 10.6 --- mysql-test/mysql-test-run.pl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 6834a499c6e..14a6293ac29 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -4518,6 +4518,9 @@ sub extract_warning_lines ($$) { qr/sql_type\.cc.* runtime error: member call.*object.* 'Type_collection'/, ); + push @antipatterns, qr/though there are still open handles to table/ + if $mysql_version_id < 100600; + my $matched_lines= []; LINE: foreach my $line ( @lines ) { From a58a570c071f4639492dc8b6b85f46c44c8be68e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 17:17:53 +0100 Subject: [PATCH 055/159] innodb.monitor test: wait for the correct value on a busy system it might take time for buffer_page_written_index_leaf to reach the correct value. Wait for it. also, tag identical statements to be different in the result file. --- mysql-test/suite/innodb/r/monitor.result | 12 ++++++------ mysql-test/suite/innodb/t/monitor.test | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/innodb/r/monitor.result b/mysql-test/suite/innodb/r/monitor.result index d55f1230ed7..aed1e3e99e3 100644 --- a/mysql-test/suite/innodb/r/monitor.result +++ b/mysql-test/suite/innodb/r/monitor.result @@ -627,7 +627,7 @@ set global innodb_monitor_reset_all = default; # MONITORS # CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*1*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; NAME COUNT > 0 buffer_page_written_index_leaf 0 @@ -635,13 +635,13 @@ SET GLOBAL innodb_monitor_enable='module_buffer_page'; INSERT INTO t1 VALUES (1), (2), (3), (4); FLUSH TABLES t1 FOR EXPORT; UNLOCK TABLES; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*2*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; NAME COUNT > 0 buffer_page_written_index_leaf 1 SET GLOBAL innodb_monitor_disable='module_buffer_page'; SET GLOBAL innodb_monitor_reset_all='module_buffer_page'; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*3*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; NAME COUNT > 0 buffer_page_written_index_leaf 0 @@ -651,13 +651,13 @@ ERROR 42000: Variable 'innodb_compression_algorithm' can't be set to the value o INSERT INTO t1 VALUES (5), (6), (7), (8); FLUSH TABLES t1 FOR EXPORT; UNLOCK TABLES; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*4*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; NAME COUNT > 0 buffer_page_written_index_leaf 1 SET GLOBAL innodb_monitor_disable='%'; SET GLOBAL innodb_monitor_reset_all='%'; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*5*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; NAME COUNT > 0 buffer_page_written_index_leaf 0 @@ -665,7 +665,7 @@ SET GLOBAL innodb_monitor_enable='ALL'; INSERT INTO t1 VALUES (9), (10), (11), (12); FLUSH TABLES t1 FOR EXPORT; UNLOCK TABLES; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*6*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; NAME COUNT > 0 buffer_page_written_index_leaf 1 diff --git a/mysql-test/suite/innodb/t/monitor.test b/mysql-test/suite/innodb/t/monitor.test index 584dd635dcf..3fff9a1e98f 100644 --- a/mysql-test/suite/innodb/t/monitor.test +++ b/mysql-test/suite/innodb/t/monitor.test @@ -418,18 +418,22 @@ CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; let $innodb_monitor_enable = `SELECT @@innodb_monitor_enable`; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*1*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; SET GLOBAL innodb_monitor_enable='module_buffer_page'; INSERT INTO t1 VALUES (1), (2), (3), (4); FLUSH TABLES t1 FOR EXPORT; UNLOCK TABLES; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME + +let $wait_condition= select count > 0 from information_schema.innodb_metrics where name like 'buffer_page_written_index_leaf'; +source include/wait_condition.inc; + +SELECT /*2*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; SET GLOBAL innodb_monitor_disable='module_buffer_page'; SET GLOBAL innodb_monitor_reset_all='module_buffer_page'; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*3*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; SET GLOBAL innodb_monitor_enable='%'; @@ -437,18 +441,22 @@ SET GLOBAL innodb_monitor_enable='%'; SET GLOBAL innodb_monitor_reset_all= '%', innodb_compression_algorithm= foo; INSERT INTO t1 VALUES (5), (6), (7), (8); FLUSH TABLES t1 FOR EXPORT; UNLOCK TABLES; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME + +let $wait_condition= select count > 0 from information_schema.innodb_metrics where name like 'buffer_page_written_index_leaf'; +source include/wait_condition.inc; + +SELECT /*4*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; SET GLOBAL innodb_monitor_disable='%'; SET GLOBAL innodb_monitor_reset_all='%'; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*5*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; SET GLOBAL innodb_monitor_enable='ALL'; INSERT INTO t1 VALUES (9), (10), (11), (12); FLUSH TABLES t1 FOR EXPORT; UNLOCK TABLES; -SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME +SELECT /*6*/ NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE 'buffer_page_written_index_leaf'; DROP TABLE t1; From b067df321363b759e5766cea8417c66469442d1d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 28 Mar 2024 16:09:15 +0100 Subject: [PATCH 056/159] innodb.innodb_defrag_stats wait for the correct value failed on amd64-centos-stream8 --- mysql-test/suite/innodb/t/innodb_defrag_stats.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/t/innodb_defrag_stats.test b/mysql-test/suite/innodb/t/innodb_defrag_stats.test index 799faa93ff0..189809b82e4 100644 --- a/mysql-test/suite/innodb/t/innodb_defrag_stats.test +++ b/mysql-test/suite/innodb/t/innodb_defrag_stats.test @@ -35,7 +35,7 @@ SELECT @@GLOBAL.innodb_force_recovery<2 "have background defragmentation"; # Wait for defrag_pool to be processed. let $wait_timeout=30; -let $wait_condition = SELECT COUNT(*)>0 FROM mysql.innodb_index_stats; +let $wait_condition = SELECT COUNT(*)>5 FROM mysql.innodb_index_stats; --source include/wait_condition.inc --sorted_result From bd0e7515494a57ca83e437bd7d6578847eb36e1d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 20:45:36 +0100 Subject: [PATCH 057/159] rpl.rpl_domain_id_filter_master_crash failed on msan builder it seems that the test can get IO thread running or not, there's a comment about it. Thus stop_slave_io.inc is told to ignore errors. Make stop_slave_io.inc also disable warnings in this case, in particular "1255 Slave already has been stopped" --- mysql-test/include/stop_slave_io.inc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mysql-test/include/stop_slave_io.inc b/mysql-test/include/stop_slave_io.inc index ddc83782311..a9d97f2f8a1 100644 --- a/mysql-test/include/stop_slave_io.inc +++ b/mysql-test/include/stop_slave_io.inc @@ -34,8 +34,17 @@ if (!$rpl_debug) --disable_query_log } - +let $_enable_warnings=0; +if ($rpl_allow_error) { + if ($ENABLED_WARNINGS) { + let $_enable_warnings=1; + disable_warnings; + } +} STOP SLAVE IO_THREAD; +if ($_enable_warnings) { + enable_warnings; +} --source include/wait_for_slave_io_to_stop.inc From fc6711c636a8407ab99d06763f731b6bea7ccb71 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Mar 2024 22:30:29 +0100 Subject: [PATCH 058/159] mtr: increase timeouts under ASAN/UBSAN/MSAN not only under valgrind --- mysql-test/include/shutdown_mysqld.inc | 7 ++----- mysql-test/include/slow_environ.inc | 9 +++++++++ mysql-test/include/sync_slave_sql_with_io.inc | 7 ++----- mysql-test/include/sync_with_master_gtid.inc | 7 ++----- mysql-test/include/wait_for_slave_param.inc | 7 ++----- 5 files changed, 17 insertions(+), 20 deletions(-) create mode 100644 mysql-test/include/slow_environ.inc diff --git a/mysql-test/include/shutdown_mysqld.inc b/mysql-test/include/shutdown_mysqld.inc index fc2972560c3..2db4624e4ac 100644 --- a/mysql-test/include/shutdown_mysqld.inc +++ b/mysql-test/include/shutdown_mysqld.inc @@ -31,11 +31,8 @@ if ($rpl_inited) set @@global.log_warnings=0; --enable_query_log ---let $server_shutdown_timeout= 60 -if ($VALGRIND_TEST) -{ - --let $server_shutdown_timeout= 300 -} +--source include/slow_environ.inc +--let $server_shutdown_timeout= 60$_timeout_adjustment if ($shutdown_timeout) { diff --git a/mysql-test/include/slow_environ.inc b/mysql-test/include/slow_environ.inc new file mode 100644 index 00000000000..761147fd288 --- /dev/null +++ b/mysql-test/include/slow_environ.inc @@ -0,0 +1,9 @@ +if (!$slow_environ_check) +{ + let $_timeout_adjustment=; + if (`select $VALGRIND_TEST + count(*) from information_schema.system_variables where variable_name='have_sanitizer' and global_value like '%SAN%'`) + { + let $_timeout_adjustment=0; + } + let $slow_environ_check=1; +} diff --git a/mysql-test/include/sync_slave_sql_with_io.inc b/mysql-test/include/sync_slave_sql_with_io.inc index 9efede9a61f..c16d28edbb9 100644 --- a/mysql-test/include/sync_slave_sql_with_io.inc +++ b/mysql-test/include/sync_slave_sql_with_io.inc @@ -25,11 +25,8 @@ let $_slave_timeout= $slave_timeout; if (!$_slave_timeout) { - let $_slave_timeout= 300; - if ($VALGRIND_TEST) - { - let $_slave_timeout= 1500; - } + source include/slow_environ.inc; + let $_slave_timeout= 300$_timeout_adjustment; } --let $_master_log_file= query_get_value(SHOW SLAVE STATUS, Master_Log_File, 1) diff --git a/mysql-test/include/sync_with_master_gtid.inc b/mysql-test/include/sync_with_master_gtid.inc index 777711b979c..0ca2c90784e 100644 --- a/mysql-test/include/sync_with_master_gtid.inc +++ b/mysql-test/include/sync_with_master_gtid.inc @@ -33,11 +33,8 @@ let $_slave_timeout= $slave_timeout; if (!$_slave_timeout) { - let $_slave_timeout= 120; - if ($VALGRIND_TEST) - { - let $_slave_timeout= 1200; - } + source include/slow_environ.inc; + let $_slave_timeout= 120$_timeout_adjustment; } --let $_result= `SELECT master_gtid_wait('$master_pos', $_slave_timeout)` diff --git a/mysql-test/include/wait_for_slave_param.inc b/mysql-test/include/wait_for_slave_param.inc index ed81c55963f..6802cd41203 100644 --- a/mysql-test/include/wait_for_slave_param.inc +++ b/mysql-test/include/wait_for_slave_param.inc @@ -49,11 +49,8 @@ let $_slave_timeout= $slave_timeout; if (!$_slave_timeout) { - let $_slave_timeout= 300; - if ($VALGRIND_TEST) - { - let $_slave_timeout= 1500; - } + source include/slow_environ.inc; + let $_slave_timeout= 300$_timeout_adjustment; } let $_slave_param_comparison= $slave_param_comparison; From 53af3d8c255c62278c6b312b67edabf486d3ccd0 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 29 Feb 2024 16:51:17 +0200 Subject: [PATCH 059/159] Fixed memory leaks in embedded server and mysqltest This commit fixes the following issues: - memory leak checking enabled for mysqltest. This cover all cases except calls to 'die()' that only happens in case of internal failures in mysqltest. die() is not called anymore in the result files differs. - One can now run mtr --embedded without failures (this crashed or hang before) - cleanup_and_exit() has a new parameter that indicates that it is called from die(), in which case we should not do memory leak checks. We now always call cleanup_and_exit() instead of exit() to be able to free up memory and discover memory leaks. - Lots of new assert to catch error conditions - More DBUG statements. - Fixed that all results are freed in mysqltest (Fixed a memory leak in mysqltest when using prepared statements). - Fixed race condition in do_stmt_close() that caused embedded server to not free memory. (Memory leak in mysqltest with embedded server). - Fixed two memory leaks in embedded server when using prepared statements. These memory leaks caused timeout hangs in mtr when server was compiled with safemalloc. This issue was not noticed (except as timeouts) as memory report checking was done but output of it was disabled. --- client/mysqltest.cc | 133 ++++++++++++++++++++++++++----------------- libmysqld/lib_sql.cc | 2 + 2 files changed, 82 insertions(+), 53 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index f1ddea7c083..7267cd6e036 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -616,7 +616,7 @@ void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds, const char *from); ATTRIBUTE_NORETURN -static void cleanup_and_exit(int exit_code); +static void cleanup_and_exit(int exit_code, bool called_from_die); ATTRIBUTE_NORETURN static void really_die(const char *msg); @@ -933,6 +933,7 @@ pthread_attr_t cn_thd_attrib; pthread_handler_t connection_thread(void *arg) { struct st_connection *cn= (struct st_connection*)arg; + DBUG_ENTER("connection_thread"); mysql_thread_init(); while (cn->command != EMB_END_CONNECTION) @@ -944,6 +945,7 @@ pthread_handler_t connection_thread(void *arg) pthread_cond_wait(&cn->query_cond, &cn->query_mutex); pthread_mutex_unlock(&cn->query_mutex); } + DBUG_PRINT("info", ("executing command: %d", cn->command)); switch (cn->command) { case EMB_END_CONNECTION: @@ -964,24 +966,26 @@ pthread_handler_t connection_thread(void *arg) break; case EMB_CLOSE_STMT: cn->result= mysql_stmt_close(cn->stmt); + cn->stmt= 0; break; default: DBUG_ASSERT(0); } - cn->command= 0; pthread_mutex_lock(&cn->result_mutex); cn->query_done= 1; + cn->command= 0; pthread_cond_signal(&cn->result_cond); pthread_mutex_unlock(&cn->result_mutex); } end_thread: - cn->query_done= 1; + DBUG_ASSERT(cn->stmt == 0); mysql_close(cn->mysql); cn->mysql= 0; + cn->query_done= 1; mysql_thread_end(); pthread_exit(0); - return 0; + DBUG_RETURN(0); } static void wait_query_thread_done(struct st_connection *con) @@ -999,12 +1003,16 @@ static void wait_query_thread_done(struct st_connection *con) static void signal_connection_thd(struct st_connection *cn, int command) { + DBUG_ENTER("signal_connection_thd"); + DBUG_PRINT("enter", ("command: %d", command)); + DBUG_ASSERT(cn->has_thread); cn->query_done= 0; - cn->command= command; pthread_mutex_lock(&cn->query_mutex); + cn->command= command; pthread_cond_signal(&cn->query_cond); pthread_mutex_unlock(&cn->query_mutex); + DBUG_VOID_RETURN; } @@ -1066,27 +1074,38 @@ static int do_stmt_execute(struct st_connection *cn) static int do_stmt_close(struct st_connection *cn) { - /* The cn->stmt is already set. */ + DBUG_ENTER("do_stmt_close"); if (!cn->has_thread) - return mysql_stmt_close(cn->stmt); + { + /* The cn->stmt is already set. */ + int res= mysql_stmt_close(cn->stmt); + cn->stmt= 0; + DBUG_RETURN(res); + } + wait_query_thread_done(cn); signal_connection_thd(cn, EMB_CLOSE_STMT); wait_query_thread_done(cn); - return cn->result; + DBUG_ASSERT(cn->stmt == 0); + DBUG_RETURN(cn->result); } static void emb_close_connection(struct st_connection *cn) { + DBUG_ENTER("emb_close_connection"); if (!cn->has_thread) - return; + DBUG_VOID_RETURN; wait_query_thread_done(cn); signal_connection_thd(cn, EMB_END_CONNECTION); pthread_join(cn->tid, NULL); cn->has_thread= FALSE; + DBUG_ASSERT(cn->mysql == 0); + DBUG_ASSERT(cn->stmt == 0); pthread_mutex_destroy(&cn->query_mutex); pthread_cond_destroy(&cn->query_cond); pthread_mutex_destroy(&cn->result_mutex); pthread_cond_destroy(&cn->result_cond); + DBUG_VOID_RETURN; } @@ -1110,7 +1129,13 @@ static void init_connection_thd(struct st_connection *cn) #define do_read_query_result(cn) mysql_read_query_result(cn->mysql) #define do_stmt_prepare(cn, q, q_len) mysql_stmt_prepare(cn->stmt, q, (ulong)q_len) #define do_stmt_execute(cn) mysql_stmt_execute(cn->stmt) -#define do_stmt_close(cn) mysql_stmt_close(cn->stmt) + +static int do_stmt_close(struct st_connection *cn) +{ + int res= mysql_stmt_close(cn->stmt); + cn->stmt= 0; + return res; +} #endif /*EMBEDDED_LIBRARY*/ @@ -1438,7 +1463,6 @@ void close_statements() { if (con->stmt) do_stmt_close(con); - con->stmt= 0; } DBUG_VOID_RETURN; } @@ -1505,7 +1529,8 @@ void free_used_memory() } -ATTRIBUTE_NORETURN static void cleanup_and_exit(int exit_code) +ATTRIBUTE_NORETURN static void cleanup_and_exit(int exit_code, + bool called_from_die) { free_used_memory(); @@ -1513,16 +1538,6 @@ ATTRIBUTE_NORETURN static void cleanup_and_exit(int exit_code) if (server_initialized) mysql_server_end(); - /* - mysqltest is fundamentally written in a way that makes impossible - to free all memory before exit (consider memory allocated - for frame local DYNAMIC_STRING's and die() invoked down the stack. - - We close stderr here to stop unavoidable safemalloc reports - from polluting the output. - */ - fclose(stderr); - my_end(my_end_arg); if (!silent) { @@ -1542,6 +1557,11 @@ ATTRIBUTE_NORETURN static void cleanup_and_exit(int exit_code) } } + /* + Report memory leaks, if not called from 'die()', as die() will not release + all memory. + */ + sf_leaking_memory= called_from_die; exit(exit_code); } @@ -1608,7 +1628,7 @@ static void really_die(const char *msg) second time, just exit */ if (dying) - cleanup_and_exit(1); + cleanup_and_exit(1, 1); dying= 1; log_file.show_tail(opt_tail_lines); @@ -1620,7 +1640,7 @@ static void really_die(const char *msg) if (cur_con && !cur_con->pending) show_warnings_before_error(cur_con->mysql); - cleanup_and_exit(1); + cleanup_and_exit(1, 1); } void report_or_die(const char *fmt, ...) @@ -1674,7 +1694,7 @@ void abort_not_supported_test(const char *fmt, ...) } va_end(args); - cleanup_and_exit(62); + cleanup_and_exit(62, 0); } @@ -2220,14 +2240,14 @@ int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) check_result RETURN VALUES - error - the function will not return - + 0 ok + 1 error */ -void check_result() +int check_result() { const char *mess= 0; - + int error= 1; DBUG_ENTER("check_result"); DBUG_ASSERT(result_file_name); DBUG_PRINT("enter", ("result_file_name: %s", result_file_name)); @@ -2235,7 +2255,10 @@ void check_result() switch (compare_files(log_file.file_name(), result_file_name)) { case RESULT_OK: if (!error_count) + { + error= 0; break; /* ok */ + } mess= "Got errors while running test"; /* Fallthrough */ case RESULT_LENGTH_MISMATCH: @@ -2274,14 +2297,13 @@ void check_result() log_file.file_name(), reject_file, errno); show_diff(NULL, result_file_name, reject_file); - die("%s", mess); + fprintf(stderr, "%s", mess); break; } default: /* impossible */ die("Unknown error code from dyn_string_cmp()"); } - - DBUG_VOID_RETURN; + DBUG_RETURN(error); } @@ -5631,7 +5653,6 @@ void do_close_connection(struct st_command *command) #endif /*!EMBEDDED_LIBRARY*/ if (con->stmt) do_stmt_close(con); - con->stmt= 0; #ifdef EMBEDDED_LIBRARY /* As query could be still executed in a separate thread @@ -7308,17 +7329,17 @@ get_one_option(const struct my_option *opt, const char *argument, const char *) break; case 'V': print_version(); - exit(0); + cleanup_and_exit(0,0); case OPT_MYSQL_PROTOCOL: #ifndef EMBEDDED_LIBRARY if ((opt_protocol= find_type_with_warning(argument, &sql_protocol_typelib, opt->name)) <= 0) - exit(1); + cleanup_and_exit(1,0); #endif break; case '?': usage(); - exit(0); + cleanup_and_exit(0,0); } return 0; } @@ -7330,12 +7351,12 @@ int parse_args(int argc, char **argv) default_argv= argv; if ((handle_options(&argc, &argv, my_long_options, get_one_option))) - exit(1); + cleanup_and_exit(1, 0); if (argc > 1) { usage(); - exit(1); + cleanup_and_exit(1, 0); } if (argc == 1) opt_db= *argv; @@ -8445,7 +8466,7 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command, my_bool ds_res_1st_execution_init = FALSE; my_bool compare_2nd_execution = TRUE; int query_match_ps2_re; - + MYSQL_RES *res; DBUG_ENTER("run_query_stmt"); DBUG_PRINT("query", ("'%-.60s'", query)); @@ -8631,10 +8652,13 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command, The --enable_prepare_warnings command can be used to change this so that warnings from both the prepare and execute phase are shown. */ - if ((mysql_stmt_result_metadata(stmt) != NULL) && - !disable_warnings && - !prepare_warnings_enabled) - dynstr_set(&ds_prepare_warnings, NULL); + if ((res= mysql_stmt_result_metadata(stmt))) + { + if (!disable_warnings && + !prepare_warnings_enabled) + dynstr_set(&ds_prepare_warnings, NULL); + mysql_free_result(res); + } /* Fetch info before fetching warnings, since it will be reset @@ -9729,6 +9753,7 @@ static sig_handler signal_handler(int sig) fflush(stderr); my_write_core(sig); #ifndef _WIN32 + sf_leaking_memory= 1; exit(1); // Shouldn't get here but just in case #endif } @@ -9802,12 +9827,10 @@ int main(int argc, char **argv) uint command_executed= 0, last_command_executed= 0; char save_file[FN_REFLEN]; bool empty_result= FALSE; + int error= 0; MY_INIT(argv[0]); DBUG_ENTER("main"); - /* mysqltest has no way to free all its memory correctly */ - sf_leaking_memory= 1; - save_file[0]= 0; TMPDIR[0]= 0; @@ -10486,7 +10509,7 @@ int main(int argc, char **argv) die("Test ended with parsing disabled"); /* - The whole test has been executed _successfully_. + The whole test has been executed successfully. Time to compare result or save it to record file. The entire output from test is in the log file */ @@ -10509,7 +10532,7 @@ int main(int argc, char **argv) else { /* Check that the output from test is equal to result file */ - check_result(); + error= check_result(); } } } @@ -10519,7 +10542,8 @@ int main(int argc, char **argv) if (! result_file_name || record || compare_files (log_file.file_name(), result_file_name)) { - die("The test didn't produce any output"); + fprintf(stderr, "mysqltest: The test didn't produce any output\n"); + error= 1; } else { @@ -10528,12 +10552,15 @@ int main(int argc, char **argv) } if (!command_executed && result_file_name && !empty_result) - die("No queries executed but non-empty result file found!"); + { + fprintf(stderr, "mysqltest: No queries executed but non-empty result file found!\n"); + error= 1; + } - verbose_msg("Test has succeeded!"); + if (!error) + verbose_msg("Test has succeeded!"); timer_output(); - /* Yes, if we got this far the test has succeeded! Sakila smiles */ - cleanup_and_exit(0); + cleanup_and_exit(error, 0); return 0; /* Keep compiler happy too */ } diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 41eee607d23..377d1d7a573 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -266,6 +266,7 @@ static my_bool emb_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt) mysql->server_status|= SERVER_STATUS_IN_TRANS; stmt->fields= mysql->fields; + free_root(&stmt->mem_root, MYF(0)); stmt->mem_root= res->alloc; mysql->fields= NULL; my_free(res); @@ -375,6 +376,7 @@ int emb_read_binary_rows(MYSQL_STMT *stmt) set_stmt_errmsg(stmt, &stmt->mysql->net); return 1; } + free_root(&stmt->result.alloc, MYF(0)); stmt->result= *data; my_free(data); set_stmt_errmsg(stmt, &stmt->mysql->net); From 190280205b83be33aeb2bc3b637ad5919896f611 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 28 Mar 2024 21:31:24 +0100 Subject: [PATCH 060/159] perfschema is disabled until it's enabled as it was thinking it was enabled even if initialize_performance_schema wasn't called at all --- storage/perfschema/pfs_instr_class.cc | 2 +- storage/perfschema/unittest/pfs_instr_class-t.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/perfschema/pfs_instr_class.cc b/storage/perfschema/pfs_instr_class.cc index 2b1a80d3e11..fa85d8610bf 100644 --- a/storage/perfschema/pfs_instr_class.cc +++ b/storage/perfschema/pfs_instr_class.cc @@ -55,7 +55,7 @@ Indicate if the performance schema is enabled. This flag is set at startup, and never changes. */ -my_bool pfs_enabled= TRUE; +my_bool pfs_enabled= FALSE; /** PFS_INSTRUMENT option settings array diff --git a/storage/perfschema/unittest/pfs_instr_class-t.cc b/storage/perfschema/unittest/pfs_instr_class-t.cc index 7651898d684..76e3668d378 100644 --- a/storage/perfschema/unittest/pfs_instr_class-t.cc +++ b/storage/perfschema/unittest/pfs_instr_class-t.cc @@ -743,6 +743,7 @@ void do_all_tests() int main(int argc, char **argv) { plan(209); + pfs_enabled= 1; MY_INIT(argv[0]); do_all_tests(); my_end(0); From cb41757f0254d715464bce55ce45e3dfe56fd685 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 29 Mar 2024 08:39:42 +0100 Subject: [PATCH 061/159] cleanup: perfschema.threads_history improve debuggability --- .../suite/perfschema/r/threads_history.result | 404 +++++++++++--- .../suite/perfschema/t/threads_history.test | 494 ++++++++---------- 2 files changed, 554 insertions(+), 344 deletions(-) diff --git a/mysql-test/suite/perfschema/r/threads_history.result b/mysql-test/suite/perfschema/r/threads_history.result index aaf2cd09e31..9d361ac24e2 100644 --- a/mysql-test/suite/perfschema/r/threads_history.result +++ b/mysql-test/suite/perfschema/r/threads_history.result @@ -24,27 +24,22 @@ events_waits_history_long YES global_instrumentation YES thread_instrumentation YES statements_digest YES -# Switch to (con1, localhost, user1, , ) connect con1, localhost, user1, , ; update performance_schema.threads set INSTRUMENTED='YES', HISTORY='YES' where PROCESSLIST_ID = connection_id(); -# Switch to (con2, localhost, user2, , ) connect con2, localhost, user2, , ; update performance_schema.threads set INSTRUMENTED='YES', HISTORY='NO' where PROCESSLIST_ID = connection_id(); -# Switch to (con3, localhost, user3, , ) connect con3, localhost, user3, , ; update performance_schema.threads set INSTRUMENTED='NO', HISTORY='YES' where PROCESSLIST_ID = connection_id(); -# Switch to (con4, localhost, user4, , ) connect con4, localhost, user4, , ; update performance_schema.threads set INSTRUMENTED='NO', HISTORY='NO' where PROCESSLIST_ID = connection_id(); -# Switch to connection default connection default; truncate table performance_schema.events_transactions_current; truncate table performance_schema.events_transactions_history; @@ -58,7 +53,6 @@ truncate table performance_schema.events_stages_history_long; truncate table performance_schema.events_waits_current; truncate table performance_schema.events_waits_history; truncate table performance_schema.events_waits_history_long; -# Switch to connection con1 connection con1; XA START 'XA_CON1', 'XA_BQUAL', 12; select "Hi from con1"; @@ -67,7 +61,6 @@ Hi from con1 XA END 'XA_CON1', 'XA_BQUAL', 12; XA PREPARE 'XA_CON1', 'XA_BQUAL', 12; XA COMMIT 'XA_CON1', 'XA_BQUAL', 12; -# Switch to connection con2 connection con2; XA START 'XA_CON2', 'XA_BQUAL', 12; select "Hi from con2"; @@ -76,7 +69,6 @@ Hi from con2 XA END 'XA_CON2', 'XA_BQUAL', 12; XA PREPARE 'XA_CON2', 'XA_BQUAL', 12; XA COMMIT 'XA_CON2', 'XA_BQUAL', 12; -# Switch to connection con3 connection con3; XA START 'XA_CON3', 'XA_BQUAL', 12; select "Hi from con3"; @@ -85,7 +77,6 @@ Hi from con3 XA END 'XA_CON3', 'XA_BQUAL', 12; XA PREPARE 'XA_CON3', 'XA_BQUAL', 12; XA COMMIT 'XA_CON3', 'XA_BQUAL', 12; -# Switch to connection con4 connection con4; XA START 'XA_CON4', 'XA_BQUAL', 12; select "Hi from con4"; @@ -95,72 +86,124 @@ XA END 'XA_CON4', 'XA_BQUAL', 12; XA PREPARE 'XA_CON4', 'XA_BQUAL', 12; XA COMMIT 'XA_CON4', 'XA_BQUAL', 12; connection default; -"=========================== Transactions user 1" +########################### Transactions user 1 - 1 +select /*1-1*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +where THREAD_ID = $con1_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON1 XA_BQUAL +select /*1-1*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history +where THREAD_ID = $con1_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON1 XA_BQUAL +select /*1-1*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history_long +where THREAD_ID = $con1_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON1 XA_BQUAL -"=========================== Transactions user 2" +########################### Transactions user 2 - 1 +select /*2-1*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +where THREAD_ID = $con2_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON2 XA_BQUAL +select /*2-1*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-1*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Transactions user 3" +########################### Transactions user 3 - 1 +select /*3-1*/ count(*) from performance_schema.events_transactions_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-1*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-1*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Transactions user 4" +########################### Transactions user 4 - 1 +select /*4-1*/ count(*) from performance_schema.events_transactions_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-1*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-1*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Statements user 1" +########################### Statements user 1 - 1 +select /*1-1*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_commit XA COMMIT 'XA_CON1', 'XA_BQUAL', 12 +select /*1-1*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_start XA START 'XA_CON1', 'XA_BQUAL', 12 statement/sql/select select "Hi from con1" statement/sql/xa_end XA END 'XA_CON1', 'XA_BQUAL', 12 statement/sql/xa_prepare XA PREPARE 'XA_CON1', 'XA_BQUAL', 12 statement/sql/xa_commit XA COMMIT 'XA_CON1', 'XA_BQUAL', 12 +select /*1-1*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history_long +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_start XA START 'XA_CON1', 'XA_BQUAL', 12 statement/sql/select select "Hi from con1" statement/sql/xa_end XA END 'XA_CON1', 'XA_BQUAL', 12 statement/sql/xa_prepare XA PREPARE 'XA_CON1', 'XA_BQUAL', 12 statement/sql/xa_commit XA COMMIT 'XA_CON1', 'XA_BQUAL', 12 -"=========================== Statements user 2" +########################### Statements user 2 - 1 +select /*2-1*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_commit XA COMMIT 'XA_CON2', 'XA_BQUAL', 12 +select /*2-1*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-1*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Statements user 3" +########################### Statements user 3 - 1 +select /*3-1*/ count(*) from performance_schema.events_statements_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-1*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-1*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Statements user 4" +########################### Statements user 4 - 1 +select /*4-1*/ count(*) from performance_schema.events_statements_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-1*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-1*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Stages user 1" +########################### Stages user 1 - 1 +select /*1-1*/ EVENT_NAME from performance_schema.events_stages_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME +select /*1-1*/ EVENT_NAME from performance_schema.events_stages_history +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME stage/sql/Starting cleanup stage/sql/Freeing items @@ -172,6 +215,8 @@ stage/sql/closing tables stage/sql/Starting cleanup stage/sql/Freeing items stage/sql/Reset for next command +select /*1-1*/ EVENT_NAME from performance_schema.events_stages_history_long +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME stage/sql/starting stage/sql/Query end @@ -215,55 +260,96 @@ stage/sql/closing tables stage/sql/Starting cleanup stage/sql/Freeing items stage/sql/Reset for next command -"=========================== Stages user 2" +########################### Stages user 2 - 1 +select /*2-1*/ EVENT_NAME from performance_schema.events_stages_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME +select /*2-1*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-1*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Stages user 3" +########################### Stages user 3 - 1 +select /*3-1*/ count(*) from performance_schema.events_stages_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-1*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-1*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Stages user 4" +########################### Stages user 4 - 1 +select /*4-1*/ count(*) from performance_schema.events_stages_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-1*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-1*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Waits user 1" +########################### Waits user 1 - 1 +select /*1-1*/ EVENT_NAME from performance_schema.events_waits_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME idle +select /*1-1*/ (count(*) > 5) as has_waits from performance_schema.events_waits_history +where THREAD_ID = $con1_thread_id; has_waits 1 +select /*1-1*/ (count(*) > 15) as has_waits from performance_schema.events_waits_history_long +where THREAD_ID = $con1_thread_id; has_waits 1 -"=========================== Waits user 2" +########################### Waits user 2 - 1 +select /*2-1*/ EVENT_NAME from performance_schema.events_waits_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME idle +select /*2-1*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-1*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Waits user 3" +########################### Waits user 3 - 1 +select /*3-1*/ count(*) from performance_schema.events_waits_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-1*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-1*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Waits user 4" +########################### Waits user 4 - 1 +select /*4-1*/ count(*) from performance_schema.events_waits_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-1*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-1*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -# Switch to connection default, disable consumers connection default; update performance_schema.setup_consumers set enabled='NO' where name like "%history%"; @@ -296,7 +382,6 @@ truncate table performance_schema.events_stages_history_long; truncate table performance_schema.events_waits_current; truncate table performance_schema.events_waits_history; truncate table performance_schema.events_waits_history_long; -# Switch to connection con1 connection con1; XA START 'XA_CON1', 'XA_BQUAL', 12; select "Hi from con1"; @@ -305,7 +390,6 @@ Hi from con1 XA END 'XA_CON1', 'XA_BQUAL', 12; XA PREPARE 'XA_CON1', 'XA_BQUAL', 12; XA COMMIT 'XA_CON1', 'XA_BQUAL', 12; -# Switch to connection con2 connection con2; XA START 'XA_CON2', 'XA_BQUAL', 12; select "Hi from con2"; @@ -314,7 +398,6 @@ Hi from con2 XA END 'XA_CON2', 'XA_BQUAL', 12; XA PREPARE 'XA_CON2', 'XA_BQUAL', 12; XA COMMIT 'XA_CON2', 'XA_BQUAL', 12; -# Switch to connection con3 connection con3; XA START 'XA_CON3', 'XA_BQUAL', 12; select "Hi from con3"; @@ -323,7 +406,6 @@ Hi from con3 XA END 'XA_CON3', 'XA_BQUAL', 12; XA PREPARE 'XA_CON3', 'XA_BQUAL', 12; XA COMMIT 'XA_CON3', 'XA_BQUAL', 12; -# Switch to connection con4 connection con4; XA START 'XA_CON4', 'XA_BQUAL', 12; select "Hi from con4"; @@ -333,117 +415,212 @@ XA END 'XA_CON4', 'XA_BQUAL', 12; XA PREPARE 'XA_CON4', 'XA_BQUAL', 12; XA COMMIT 'XA_CON4', 'XA_BQUAL', 12; connection default; -"=========================== Transactions user 1" +########################### Transactions user 1 - 2 +select /*1-2*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +where THREAD_ID = $con1_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON1 XA_BQUAL +select /*1-2*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con1_thread_id; count(*) 0 +select /*1-2*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con1_thread_id; count(*) 0 -"=========================== Transactions user 2" +########################### Transactions user 2 - 2 +select /*2-2*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +where THREAD_ID = $con2_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON2 XA_BQUAL +select /*2-2*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-2*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Transactions user 3" +########################### Transactions user 3 - 2 +select /*3-2*/ count(*) from performance_schema.events_transactions_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-2*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-2*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Transactions user 4" +########################### Transactions user 4 - 2 +select /*4-2*/ count(*) from performance_schema.events_transactions_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-2*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-2*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Statements user 1" +########################### Statements user 1 - 2 +select /*1-2*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_commit XA COMMIT 'XA_CON1', 'XA_BQUAL', 12 +select /*1-2*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con1_thread_id; count(*) 0 +select /*1-2*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con1_thread_id; count(*) 0 -"=========================== Statements user 2" +########################### Statements user 2 - 2 +select /*2-2*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_commit XA COMMIT 'XA_CON2', 'XA_BQUAL', 12 +select /*2-2*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-2*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Statements user 3" +########################### Statements user 3 - 2 +select /*3-2*/ count(*) from performance_schema.events_statements_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-2*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-2*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Statements user 4" +########################### Statements user 4 - 2 +select /*4-2*/ count(*) from performance_schema.events_statements_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-2*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-2*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Stages user 1" +########################### Stages user 1 - 2 +select /*1-2*/ EVENT_NAME from performance_schema.events_stages_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME +select /*1-2*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con1_thread_id; count(*) 0 +select /*1-2*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con1_thread_id; count(*) 0 -"=========================== Stages user 2" +########################### Stages user 2 - 2 +select /*2-2*/ EVENT_NAME from performance_schema.events_stages_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME +select /*2-2*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-2*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Stages user 3" +########################### Stages user 3 - 2 +select /*3-2*/ count(*) from performance_schema.events_stages_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-2*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-2*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Stages user 4" +########################### Stages user 4 - 2 +select /*4-2*/ count(*) from performance_schema.events_stages_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-2*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-2*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Waits user 1" +########################### Waits user 1 - 2 +select /*1-2*/ EVENT_NAME from performance_schema.events_waits_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME idle +select /*1-2*/ count(*) as has_waits from performance_schema.events_waits_history +where THREAD_ID = $con1_thread_id; has_waits 0 +select /*1-2*/ count(*) as has_waits from performance_schema.events_waits_history_long +where THREAD_ID = $con1_thread_id; has_waits 0 -"=========================== Waits user 2" +########################### Waits user 2 - 2 +select /*2-2*/ EVENT_NAME from performance_schema.events_waits_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME idle +select /*2-2*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-2*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Waits user 3" +########################### Waits user 3 - 2 +select /*3-2*/ count(*) from performance_schema.events_waits_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-2*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-2*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Waits user 4" +########################### Waits user 4 - 2 +select /*4-2*/ count(*) from performance_schema.events_waits_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-2*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-2*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -# Switch to connection default, enable consumers connection default; update performance_schema.setup_consumers set enabled='YES' where name like "%history%"; @@ -476,7 +653,6 @@ truncate table performance_schema.events_stages_history_long; truncate table performance_schema.events_waits_current; truncate table performance_schema.events_waits_history; truncate table performance_schema.events_waits_history_long; -# Switch to connection con1 connection con1; XA START 'XA_CON1', 'XA_BQUAL', 12; select "Hi from con1"; @@ -485,7 +661,6 @@ Hi from con1 XA END 'XA_CON1', 'XA_BQUAL', 12; XA PREPARE 'XA_CON1', 'XA_BQUAL', 12; XA COMMIT 'XA_CON1', 'XA_BQUAL', 12; -# Switch to connection con2 connection con2; XA START 'XA_CON2', 'XA_BQUAL', 12; select "Hi from con2"; @@ -494,7 +669,6 @@ Hi from con2 XA END 'XA_CON2', 'XA_BQUAL', 12; XA PREPARE 'XA_CON2', 'XA_BQUAL', 12; XA COMMIT 'XA_CON2', 'XA_BQUAL', 12; -# Switch to connection con3 connection con3; XA START 'XA_CON3', 'XA_BQUAL', 12; select "Hi from con3"; @@ -503,7 +677,6 @@ Hi from con3 XA END 'XA_CON3', 'XA_BQUAL', 12; XA PREPARE 'XA_CON3', 'XA_BQUAL', 12; XA COMMIT 'XA_CON3', 'XA_BQUAL', 12; -# Switch to connection con4 connection con4; XA START 'XA_CON4', 'XA_BQUAL', 12; select "Hi from con4"; @@ -513,72 +686,124 @@ XA END 'XA_CON4', 'XA_BQUAL', 12; XA PREPARE 'XA_CON4', 'XA_BQUAL', 12; XA COMMIT 'XA_CON4', 'XA_BQUAL', 12; connection default; -"=========================== Transactions user 1" +########################### Transactions user 1 - 3 +select /*1-3*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +where THREAD_ID = $con1_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON1 XA_BQUAL +select /*1-3*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history +where THREAD_ID = $con1_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON1 XA_BQUAL +select /*1-3*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history_long +where THREAD_ID = $con1_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON1 XA_BQUAL -"=========================== Transactions user 2" +########################### Transactions user 2 - 3 +select /*2-3*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +where THREAD_ID = $con2_thread_id; XID_FORMAT_ID XID_GTRID XID_BQUAL 12 XA_CON2 XA_BQUAL +select /*2-3*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-3*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Transactions user 3" +########################### Transactions user 3 - 3 +select /*3-3*/ count(*) from performance_schema.events_transactions_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-3*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-3*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Transactions user 4" +########################### Transactions user 4 - 3 +select /*4-3*/ count(*) from performance_schema.events_transactions_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-3*/ count(*) from performance_schema.events_transactions_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-3*/ count(*) from performance_schema.events_transactions_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Statements user 1" +########################### Statements user 1 - 3 +select /*1-3*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_commit XA COMMIT 'XA_CON1', 'XA_BQUAL', 12 +select /*1-3*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_start XA START 'XA_CON1', 'XA_BQUAL', 12 statement/sql/select select "Hi from con1" statement/sql/xa_end XA END 'XA_CON1', 'XA_BQUAL', 12 statement/sql/xa_prepare XA PREPARE 'XA_CON1', 'XA_BQUAL', 12 statement/sql/xa_commit XA COMMIT 'XA_CON1', 'XA_BQUAL', 12 +select /*1-3*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history_long +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_start XA START 'XA_CON1', 'XA_BQUAL', 12 statement/sql/select select "Hi from con1" statement/sql/xa_end XA END 'XA_CON1', 'XA_BQUAL', 12 statement/sql/xa_prepare XA PREPARE 'XA_CON1', 'XA_BQUAL', 12 statement/sql/xa_commit XA COMMIT 'XA_CON1', 'XA_BQUAL', 12 -"=========================== Statements user 2" +########################### Statements user 2 - 3 +select /*2-3*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME SQL_TEXT statement/sql/xa_commit XA COMMIT 'XA_CON2', 'XA_BQUAL', 12 +select /*2-3*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-3*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Statements user 3" +########################### Statements user 3 - 3 +select /*3-3*/ count(*) from performance_schema.events_statements_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-3*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-3*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Statements user 4" +########################### Statements user 4 - 3 +select /*4-3*/ count(*) from performance_schema.events_statements_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-3*/ count(*) from performance_schema.events_statements_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-3*/ count(*) from performance_schema.events_statements_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Stages user 1" +########################### Stages user 1 - 3 +select /*1-3*/ EVENT_NAME from performance_schema.events_stages_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME +select /*1-3*/ EVENT_NAME from performance_schema.events_stages_history +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME stage/sql/Starting cleanup stage/sql/Freeing items @@ -590,6 +815,8 @@ stage/sql/closing tables stage/sql/Starting cleanup stage/sql/Freeing items stage/sql/Reset for next command +select /*1-3*/ EVENT_NAME from performance_schema.events_stages_history_long +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME stage/sql/starting stage/sql/Query end @@ -633,55 +860,96 @@ stage/sql/closing tables stage/sql/Starting cleanup stage/sql/Freeing items stage/sql/Reset for next command -"=========================== Stages user 2" +########################### Stages user 2 - 3 +select /*2-3*/ EVENT_NAME from performance_schema.events_stages_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME +select /*2-3*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-3*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Stages user 3" +########################### Stages user 3 - 3 +select /*3-3*/ count(*) from performance_schema.events_stages_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-3*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-3*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Stages user 4" +########################### Stages user 4 - 3 +select /*4-3*/ count(*) from performance_schema.events_stages_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-3*/ count(*) from performance_schema.events_stages_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-3*/ count(*) from performance_schema.events_stages_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -"=========================== Waits user 1" +########################### Waits user 1 - 3 +select /*1-3*/ EVENT_NAME from performance_schema.events_waits_current +where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME idle +select /*1-3*/ (count(*) > 5) as has_waits from performance_schema.events_waits_history +where THREAD_ID = $con1_thread_id; has_waits 1 +select /*1-3*/ (count(*) > 15) as has_waits from performance_schema.events_waits_history_long +where THREAD_ID = $con1_thread_id; has_waits 1 -"=========================== Waits user 2" +########################### Waits user 2 - 3 +select /*2-3*/ EVENT_NAME from performance_schema.events_waits_current +where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; EVENT_NAME idle +select /*2-3*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con2_thread_id; count(*) 0 +select /*2-3*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con2_thread_id; count(*) 0 -"=========================== Waits user 3" +########################### Waits user 3 - 3 +select /*3-3*/ count(*) from performance_schema.events_waits_current +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-3*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con3_thread_id; count(*) 0 +select /*3-3*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con3_thread_id; count(*) 0 -"=========================== Waits user 4" +########################### Waits user 4 - 3 +select /*4-3*/ count(*) from performance_schema.events_waits_current +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-3*/ count(*) from performance_schema.events_waits_history +where THREAD_ID = $con4_thread_id; count(*) 0 +select /*4-3*/ count(*) from performance_schema.events_waits_history_long +where THREAD_ID = $con4_thread_id; count(*) 0 -# Switch to connection default connection default; revoke all privileges, grant option from user1@localhost; revoke all privileges, grant option from user2@localhost; diff --git a/mysql-test/suite/perfschema/t/threads_history.test b/mysql-test/suite/perfschema/t/threads_history.test index f42dd6d0ab4..aee983339d2 100644 --- a/mysql-test/suite/perfschema/t/threads_history.test +++ b/mysql-test/suite/perfschema/t/threads_history.test @@ -23,7 +23,6 @@ flush privileges; select * from performance_schema.setup_consumers; ---echo # Switch to (con1, localhost, user1, , ) connect (con1, localhost, user1, , ); update performance_schema.threads @@ -33,7 +32,6 @@ update performance_schema.threads let $con1_thread_id= `select THREAD_ID from performance_schema.threads where PROCESSLIST_ID = connection_id()`; ---echo # Switch to (con2, localhost, user2, , ) connect (con2, localhost, user2, , ); update performance_schema.threads @@ -43,7 +41,6 @@ update performance_schema.threads let $con2_thread_id= `select THREAD_ID from performance_schema.threads where PROCESSLIST_ID = connection_id()`; ---echo # Switch to (con3, localhost, user3, , ) connect (con3, localhost, user3, , ); update performance_schema.threads @@ -53,7 +50,6 @@ update performance_schema.threads let $con3_thread_id= `select THREAD_ID from performance_schema.threads where PROCESSLIST_ID = connection_id()`; ---echo # Switch to (con4, localhost, user4, , ) connect (con4, localhost, user4, , ); update performance_schema.threads @@ -63,7 +59,6 @@ update performance_schema.threads let $con4_thread_id= `select THREAD_ID from performance_schema.threads where PROCESSLIST_ID = connection_id()`; ---echo # Switch to connection default --connection default truncate table performance_schema.events_transactions_current; @@ -79,7 +74,6 @@ truncate table performance_schema.events_waits_current; truncate table performance_schema.events_waits_history; truncate table performance_schema.events_waits_history_long; ---echo # Switch to connection con1 --connection con1 XA START 'XA_CON1', 'XA_BQUAL', 12; @@ -88,7 +82,6 @@ XA END 'XA_CON1', 'XA_BQUAL', 12; XA PREPARE 'XA_CON1', 'XA_BQUAL', 12; XA COMMIT 'XA_CON1', 'XA_BQUAL', 12; ---echo # Switch to connection con2 --connection con2 XA START 'XA_CON2', 'XA_BQUAL', 12; @@ -97,7 +90,6 @@ XA END 'XA_CON2', 'XA_BQUAL', 12; XA PREPARE 'XA_CON2', 'XA_BQUAL', 12; XA COMMIT 'XA_CON2', 'XA_BQUAL', 12; ---echo # Switch to connection con3 --connection con3 XA START 'XA_CON3', 'XA_BQUAL', 12; @@ -106,7 +98,6 @@ XA END 'XA_CON3', 'XA_BQUAL', 12; XA PREPARE 'XA_CON3', 'XA_BQUAL', 12; XA COMMIT 'XA_CON3', 'XA_BQUAL', 12; ---echo # Switch to connection con4 --connection con4 XA START 'XA_CON4', 'XA_BQUAL', 12; @@ -117,165 +108,150 @@ XA COMMIT 'XA_CON4', 'XA_BQUAL', 12; --connection default ---disable_query_log +echo ########################### Transactions user 1 - 1; -echo "=========================== Transactions user 1"; - -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +evalp select /*1-1*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current where THREAD_ID = $con1_thread_id; -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history +evalp select /*1-1*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history where THREAD_ID = $con1_thread_id; -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history_long +evalp select /*1-1*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history_long where THREAD_ID = $con1_thread_id; -echo "=========================== Transactions user 2"; +echo ########################### Transactions user 2 - 1; -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +evalp select /*2-1*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*2-1*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*2-1*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Transactions user 3"; +echo ########################### Transactions user 3 - 1; -eval select count(*) from performance_schema.events_transactions_current +evalp select /*3-1*/ count(*) from performance_schema.events_transactions_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*3-1*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*3-1*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Transactions user 4"; +echo ########################### Transactions user 4 - 1; -eval select count(*) from performance_schema.events_transactions_current +evalp select /*4-1*/ count(*) from performance_schema.events_transactions_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*4-1*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*4-1*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Statements user 1"; +echo ########################### Statements user 1 - 1; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history_long - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; +evalp select /*1-1*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-1*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-1*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history_long + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; -echo "=========================== Statements user 2"; +echo ########################### Statements user 2 - 1; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_statements_history +evalp select /*2-1*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-1*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*2-1*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Statements user 3"; +echo ########################### Statements user 3 - 1; -eval select count(*) from performance_schema.events_statements_current +evalp select /*3-1*/ count(*) from performance_schema.events_statements_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_statements_history +evalp select /*3-1*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*3-1*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Statements user 4"; +echo ########################### Statements user 4 - 1; -eval select count(*) from performance_schema.events_statements_current +evalp select /*4-1*/ count(*) from performance_schema.events_statements_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_statements_history +evalp select /*4-1*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*4-1*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Stages user 1"; +echo ########################### Stages user 1 - 1; -eval select EVENT_NAME from performance_schema.events_stages_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select EVENT_NAME from performance_schema.events_stages_history - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select EVENT_NAME from performance_schema.events_stages_history_long - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; +evalp select /*1-1*/ EVENT_NAME from performance_schema.events_stages_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-1*/ EVENT_NAME from performance_schema.events_stages_history + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-1*/ EVENT_NAME from performance_schema.events_stages_history_long + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; -echo "=========================== Stages user 2"; +echo ########################### Stages user 2 - 1; -eval select EVENT_NAME from performance_schema.events_stages_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_stages_history +evalp select /*2-1*/ EVENT_NAME from performance_schema.events_stages_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-1*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*2-1*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Stages user 3"; +echo ########################### Stages user 3 - 1; -eval select count(*) from performance_schema.events_stages_current +evalp select /*3-1*/ count(*) from performance_schema.events_stages_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_stages_history +evalp select /*3-1*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*3-1*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Stages user 4"; +echo ########################### Stages user 4 - 1; -eval select count(*) from performance_schema.events_stages_current +evalp select /*4-1*/ count(*) from performance_schema.events_stages_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_stages_history +evalp select /*4-1*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*4-1*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Waits user 1"; +echo ########################### Waits user 1 - 1; -eval select EVENT_NAME from performance_schema.events_waits_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select (count(*) > 5) as has_waits from performance_schema.events_waits_history +evalp select /*1-1*/ EVENT_NAME from performance_schema.events_waits_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-1*/ (count(*) > 5) as has_waits from performance_schema.events_waits_history where THREAD_ID = $con1_thread_id; -eval select (count(*) > 15) as has_waits from performance_schema.events_waits_history_long +evalp select /*1-1*/ (count(*) > 15) as has_waits from performance_schema.events_waits_history_long where THREAD_ID = $con1_thread_id; -echo "=========================== Waits user 2"; +echo ########################### Waits user 2 - 1; -eval select EVENT_NAME from performance_schema.events_waits_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_waits_history +evalp select /*2-1*/ EVENT_NAME from performance_schema.events_waits_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-1*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*2-1*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Waits user 3"; +echo ########################### Waits user 3 - 1; -eval select count(*) from performance_schema.events_waits_current +evalp select /*3-1*/ count(*) from performance_schema.events_waits_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_waits_history +evalp select /*3-1*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*3-1*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Waits user 4"; +echo ########################### Waits user 4 - 1; -eval select count(*) from performance_schema.events_waits_current +evalp select /*4-1*/ count(*) from performance_schema.events_waits_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_waits_history +evalp select /*4-1*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*4-1*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con4_thread_id; ---enable_query_log - ---echo # Switch to connection default, disable consumers --connection default update performance_schema.setup_consumers @@ -296,7 +272,6 @@ truncate table performance_schema.events_waits_current; truncate table performance_schema.events_waits_history; truncate table performance_schema.events_waits_history_long; ---echo # Switch to connection con1 --connection con1 XA START 'XA_CON1', 'XA_BQUAL', 12; @@ -305,7 +280,6 @@ XA END 'XA_CON1', 'XA_BQUAL', 12; XA PREPARE 'XA_CON1', 'XA_BQUAL', 12; XA COMMIT 'XA_CON1', 'XA_BQUAL', 12; ---echo # Switch to connection con2 --connection con2 XA START 'XA_CON2', 'XA_BQUAL', 12; @@ -314,7 +288,6 @@ XA END 'XA_CON2', 'XA_BQUAL', 12; XA PREPARE 'XA_CON2', 'XA_BQUAL', 12; XA COMMIT 'XA_CON2', 'XA_BQUAL', 12; ---echo # Switch to connection con3 --connection con3 XA START 'XA_CON3', 'XA_BQUAL', 12; @@ -323,7 +296,6 @@ XA END 'XA_CON3', 'XA_BQUAL', 12; XA PREPARE 'XA_CON3', 'XA_BQUAL', 12; XA COMMIT 'XA_CON3', 'XA_BQUAL', 12; ---echo # Switch to connection con4 --connection con4 XA START 'XA_CON4', 'XA_BQUAL', 12; @@ -334,161 +306,150 @@ XA COMMIT 'XA_CON4', 'XA_BQUAL', 12; --connection default ---disable_query_log +echo ########################### Transactions user 1 - 2; -echo "=========================== Transactions user 1"; - -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +evalp select /*1-2*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current where THREAD_ID = $con1_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*1-2*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con1_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*1-2*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con1_thread_id; -echo "=========================== Transactions user 2"; +echo ########################### Transactions user 2 - 2; -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +evalp select /*2-2*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*2-2*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*2-2*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Transactions user 3"; +echo ########################### Transactions user 3 - 2; -eval select count(*) from performance_schema.events_transactions_current +evalp select /*3-2*/ count(*) from performance_schema.events_transactions_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*3-2*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*3-2*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Transactions user 4"; +echo ########################### Transactions user 4 - 2; -eval select count(*) from performance_schema.events_transactions_current +evalp select /*4-2*/ count(*) from performance_schema.events_transactions_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*4-2*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*4-2*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Statements user 1"; +echo ########################### Statements user 1 - 2; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_statements_history +evalp select /*1-2*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-2*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con1_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*1-2*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con1_thread_id; -echo "=========================== Statements user 2"; +echo ########################### Statements user 2 - 2; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_statements_history +evalp select /*2-2*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-2*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*2-2*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Statements user 3"; +echo ########################### Statements user 3 - 2; -eval select count(*) from performance_schema.events_statements_current +evalp select /*3-2*/ count(*) from performance_schema.events_statements_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_statements_history +evalp select /*3-2*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*3-2*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Statements user 4"; +echo ########################### Statements user 4 - 2; -eval select count(*) from performance_schema.events_statements_current +evalp select /*4-2*/ count(*) from performance_schema.events_statements_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_statements_history +evalp select /*4-2*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*4-2*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Stages user 1"; +echo ########################### Stages user 1 - 2; -eval select EVENT_NAME from performance_schema.events_stages_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_stages_history +evalp select /*1-2*/ EVENT_NAME from performance_schema.events_stages_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-2*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con1_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*1-2*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con1_thread_id; -echo "=========================== Stages user 2"; +echo ########################### Stages user 2 - 2; -eval select EVENT_NAME from performance_schema.events_stages_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_stages_history +evalp select /*2-2*/ EVENT_NAME from performance_schema.events_stages_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-2*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*2-2*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Stages user 3"; +echo ########################### Stages user 3 - 2; -eval select count(*) from performance_schema.events_stages_current +evalp select /*3-2*/ count(*) from performance_schema.events_stages_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_stages_history +evalp select /*3-2*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*3-2*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Stages user 4"; +echo ########################### Stages user 4 - 2; -eval select count(*) from performance_schema.events_stages_current +evalp select /*4-2*/ count(*) from performance_schema.events_stages_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_stages_history +evalp select /*4-2*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*4-2*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Waits user 1"; +echo ########################### Waits user 1 - 2; -eval select EVENT_NAME from performance_schema.events_waits_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) as has_waits from performance_schema.events_waits_history +evalp select /*1-2*/ EVENT_NAME from performance_schema.events_waits_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-2*/ count(*) as has_waits from performance_schema.events_waits_history where THREAD_ID = $con1_thread_id; -eval select count(*) as has_waits from performance_schema.events_waits_history_long +evalp select /*1-2*/ count(*) as has_waits from performance_schema.events_waits_history_long where THREAD_ID = $con1_thread_id; -echo "=========================== Waits user 2"; +echo ########################### Waits user 2 - 2; -eval select EVENT_NAME from performance_schema.events_waits_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_waits_history +evalp select /*2-2*/ EVENT_NAME from performance_schema.events_waits_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-2*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*2-2*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Waits user 3"; +echo ########################### Waits user 3 - 2; -eval select count(*) from performance_schema.events_waits_current +evalp select /*3-2*/ count(*) from performance_schema.events_waits_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_waits_history +evalp select /*3-2*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*3-2*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Waits user 4"; +echo ########################### Waits user 4 - 2; -eval select count(*) from performance_schema.events_waits_current +evalp select /*4-2*/ count(*) from performance_schema.events_waits_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_waits_history +evalp select /*4-2*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*4-2*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con4_thread_id; ---enable_query_log - ---echo # Switch to connection default, enable consumers --connection default update performance_schema.setup_consumers @@ -509,7 +470,6 @@ truncate table performance_schema.events_waits_current; truncate table performance_schema.events_waits_history; truncate table performance_schema.events_waits_history_long; ---echo # Switch to connection con1 --connection con1 XA START 'XA_CON1', 'XA_BQUAL', 12; @@ -518,7 +478,6 @@ XA END 'XA_CON1', 'XA_BQUAL', 12; XA PREPARE 'XA_CON1', 'XA_BQUAL', 12; XA COMMIT 'XA_CON1', 'XA_BQUAL', 12; ---echo # Switch to connection con2 --connection con2 XA START 'XA_CON2', 'XA_BQUAL', 12; @@ -527,7 +486,6 @@ XA END 'XA_CON2', 'XA_BQUAL', 12; XA PREPARE 'XA_CON2', 'XA_BQUAL', 12; XA COMMIT 'XA_CON2', 'XA_BQUAL', 12; ---echo # Switch to connection con3 --connection con3 XA START 'XA_CON3', 'XA_BQUAL', 12; @@ -536,7 +494,6 @@ XA END 'XA_CON3', 'XA_BQUAL', 12; XA PREPARE 'XA_CON3', 'XA_BQUAL', 12; XA COMMIT 'XA_CON3', 'XA_BQUAL', 12; ---echo # Switch to connection con4 --connection con4 XA START 'XA_CON4', 'XA_BQUAL', 12; @@ -547,165 +504,150 @@ XA COMMIT 'XA_CON4', 'XA_BQUAL', 12; --connection default ---disable_query_log +echo ########################### Transactions user 1 - 3; -echo "=========================== Transactions user 1"; - -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +evalp select /*1-3*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current where THREAD_ID = $con1_thread_id; -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history +evalp select /*1-3*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history where THREAD_ID = $con1_thread_id; -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history_long +evalp select /*1-3*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_history_long where THREAD_ID = $con1_thread_id; -echo "=========================== Transactions user 2"; +echo ########################### Transactions user 2 - 3; -eval select XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current +evalp select /*2-3*/ XID_FORMAT_ID, XID_GTRID, XID_BQUAL from performance_schema.events_transactions_current where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*2-3*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*2-3*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Transactions user 3"; +echo ########################### Transactions user 3 - 3; -eval select count(*) from performance_schema.events_transactions_current +evalp select /*3-3*/ count(*) from performance_schema.events_transactions_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*3-3*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*3-3*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Transactions user 4"; +echo ########################### Transactions user 4 - 3; -eval select count(*) from performance_schema.events_transactions_current +evalp select /*4-3*/ count(*) from performance_schema.events_transactions_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_transactions_history +evalp select /*4-3*/ count(*) from performance_schema.events_transactions_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_transactions_history_long +evalp select /*4-3*/ count(*) from performance_schema.events_transactions_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Statements user 1"; +echo ########################### Statements user 1 - 3; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history_long - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; +evalp select /*1-3*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-3*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-3*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_history_long + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; -echo "=========================== Statements user 2"; +echo ########################### Statements user 2 - 3; -eval select EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_statements_history +evalp select /*2-3*/ EVENT_NAME, SQL_TEXT from performance_schema.events_statements_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-3*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*2-3*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Statements user 3"; +echo ########################### Statements user 3 - 3; -eval select count(*) from performance_schema.events_statements_current +evalp select /*3-3*/ count(*) from performance_schema.events_statements_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_statements_history +evalp select /*3-3*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*3-3*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Statements user 4"; +echo ########################### Statements user 4 - 3; -eval select count(*) from performance_schema.events_statements_current +evalp select /*4-3*/ count(*) from performance_schema.events_statements_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_statements_history +evalp select /*4-3*/ count(*) from performance_schema.events_statements_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_statements_history_long +evalp select /*4-3*/ count(*) from performance_schema.events_statements_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Stages user 1"; +echo ########################### Stages user 1 - 3; -eval select EVENT_NAME from performance_schema.events_stages_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select EVENT_NAME from performance_schema.events_stages_history - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select EVENT_NAME from performance_schema.events_stages_history_long - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; +evalp select /*1-3*/ EVENT_NAME from performance_schema.events_stages_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-3*/ EVENT_NAME from performance_schema.events_stages_history + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-3*/ EVENT_NAME from performance_schema.events_stages_history_long + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; -echo "=========================== Stages user 2"; +echo ########################### Stages user 2 - 3; -eval select EVENT_NAME from performance_schema.events_stages_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_stages_history +evalp select /*2-3*/ EVENT_NAME from performance_schema.events_stages_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-3*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*2-3*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Stages user 3"; +echo ########################### Stages user 3 - 3; -eval select count(*) from performance_schema.events_stages_current +evalp select /*3-3*/ count(*) from performance_schema.events_stages_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_stages_history +evalp select /*3-3*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*3-3*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Stages user 4"; +echo ########################### Stages user 4 - 3; -eval select count(*) from performance_schema.events_stages_current +evalp select /*4-3*/ count(*) from performance_schema.events_stages_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_stages_history +evalp select /*4-3*/ count(*) from performance_schema.events_stages_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_stages_history_long +evalp select /*4-3*/ count(*) from performance_schema.events_stages_history_long where THREAD_ID = $con4_thread_id; -echo "=========================== Waits user 1"; +echo ########################### Waits user 1 - 3; -eval select EVENT_NAME from performance_schema.events_waits_current - where THREAD_ID = $con1_thread_id - order by THREAD_ID, EVENT_ID; -eval select (count(*) > 5) as has_waits from performance_schema.events_waits_history +evalp select /*1-3*/ EVENT_NAME from performance_schema.events_waits_current + where THREAD_ID = $con1_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*1-3*/ (count(*) > 5) as has_waits from performance_schema.events_waits_history where THREAD_ID = $con1_thread_id; -eval select (count(*) > 15) as has_waits from performance_schema.events_waits_history_long +evalp select /*1-3*/ (count(*) > 15) as has_waits from performance_schema.events_waits_history_long where THREAD_ID = $con1_thread_id; -echo "=========================== Waits user 2"; +echo ########################### Waits user 2 - 3; -eval select EVENT_NAME from performance_schema.events_waits_current - where THREAD_ID = $con2_thread_id - order by THREAD_ID, EVENT_ID; -eval select count(*) from performance_schema.events_waits_history +evalp select /*2-3*/ EVENT_NAME from performance_schema.events_waits_current + where THREAD_ID = $con2_thread_id order by THREAD_ID, EVENT_ID; +evalp select /*2-3*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con2_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*2-3*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con2_thread_id; -echo "=========================== Waits user 3"; +echo ########################### Waits user 3 - 3; -eval select count(*) from performance_schema.events_waits_current +evalp select /*3-3*/ count(*) from performance_schema.events_waits_current where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_waits_history +evalp select /*3-3*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con3_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*3-3*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con3_thread_id; -echo "=========================== Waits user 4"; +echo ########################### Waits user 4 - 3; -eval select count(*) from performance_schema.events_waits_current +evalp select /*4-3*/ count(*) from performance_schema.events_waits_current where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_waits_history +evalp select /*4-3*/ count(*) from performance_schema.events_waits_history where THREAD_ID = $con4_thread_id; -eval select count(*) from performance_schema.events_waits_history_long +evalp select /*4-3*/ count(*) from performance_schema.events_waits_history_long where THREAD_ID = $con4_thread_id; ---enable_query_log - ---echo # Switch to connection default --connection default revoke all privileges, grant option from user1@localhost; From 075dd73641bfa2c388a6aebf82dad0a7bb72974e Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 28 Mar 2024 13:10:12 +1100 Subject: [PATCH 062/159] MDEV-33290: Disable ColumnStore based on boost version (postfix) Its important to fail early and only contine with the include after the boost version check succeeds. Needs to succeed on ealier verisons too so can't just fail if too new. As such, do a version check. --- storage/columnstore/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/storage/columnstore/CMakeLists.txt b/storage/columnstore/CMakeLists.txt index 644f0ca8984..be46caee2a6 100644 --- a/storage/columnstore/CMakeLists.txt +++ b/storage/columnstore/CMakeLists.txt @@ -13,15 +13,17 @@ endmacro() IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64") - add_subdirectory(columnstore) + cmake_policy(SET CMP0093 NEW) # https://jira.mariadb.org/browse/MCOL-5611 - FIND_PACKAGE(Boost 1.80.0 COMPONENTS system filesystem thread regex date_time chrono atomic) - IF (Boost_FOUND) + FIND_PACKAGE(Boost COMPONENTS system filesystem thread regex date_time chrono atomic) + IF (Boost_VERSION VERSION_GREATER "1.79.0") MESSAGE_ONCE(CS_NO_BOOST "Boost Libraries >= 1.80.0 not supported!") return() ENDIF() + add_subdirectory(columnstore) + IF(TARGET columnstore) # Needed to bump the component changes up to the main scope APPEND_FOR_CPACK(CPACK_COMPONENTS_ALL) From b3e29da540caf96cc3c17b512b999a4cd2d34824 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 4 Apr 2024 18:23:52 +0200 Subject: [PATCH 063/159] MDEV-33290: Disable ColumnStore based on boost version (post-postfix) policy CMP0093 was added in cmake 3.15 let's support cmake from 2.8.12, that's what our CMAKE_MINIMUM_REQUIRED() says --- storage/columnstore/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/storage/columnstore/CMakeLists.txt b/storage/columnstore/CMakeLists.txt index be46caee2a6..1b3b739b706 100644 --- a/storage/columnstore/CMakeLists.txt +++ b/storage/columnstore/CMakeLists.txt @@ -13,11 +13,10 @@ endmacro() IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64") - cmake_policy(SET CMP0093 NEW) # https://jira.mariadb.org/browse/MCOL-5611 FIND_PACKAGE(Boost COMPONENTS system filesystem thread regex date_time chrono atomic) - IF (Boost_VERSION VERSION_GREATER "1.79.0") + IF (${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_GREATER "1.79") MESSAGE_ONCE(CS_NO_BOOST "Boost Libraries >= 1.80.0 not supported!") return() ENDIF() From 96533bae54bed2216039cd7cdee97d9e5a1042da Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 5 Apr 2024 10:41:01 +0200 Subject: [PATCH 064/159] suppress a transient galera warning these warnings are expected and are auto-resolved by galera --- mysql-test/suite/galera/suite.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/galera/suite.pm b/mysql-test/suite/galera/suite.pm index f6caecdc36a..d09cb89df5c 100644 --- a/mysql-test/suite/galera/suite.pm +++ b/mysql-test/suite/galera/suite.pm @@ -63,6 +63,7 @@ push @::global_suppressions, qr(WSREP: Failed to remove page file .*), qr(WSREP: wsrep_sst_method is set to 'mysqldump' yet mysqld bind_address is set to .*), qr|WSREP: Sending JOIN failed: -107 \(Transport endpoint is not connected\). Will retry in new primary component.|, + qr|WSREP: Send action {.* STATE_REQUEST} returned -107 \(Transport endpoint is not connected\)|, qr|WSREP: Trying to continue unpaused monitor|, qr|WSREP: Wait for gtid returned error 3 while waiting for prior transactions to commit before setting position|, qr|WSREP: Failed to report last committed|, From 429fdb5bd6d3e59a08cf1e0e90f8159df2c81afc Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 5 Apr 2024 15:47:03 +0200 Subject: [PATCH 065/159] MDEV-29171 disable failing galera test --- mysql-test/suite/galera_3nodes/disabled.def | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/galera_3nodes/disabled.def b/mysql-test/suite/galera_3nodes/disabled.def index 730f98667e6..e1b4c2d5d5f 100644 --- a/mysql-test/suite/galera_3nodes/disabled.def +++ b/mysql-test/suite/galera_3nodes/disabled.def @@ -16,3 +16,4 @@ galera_ssl_reload : MDEV-32778 galera_ssl_reload failed with warning message galera_ipv6_mariabackup : temporarily disabled at the request of Codership galera_pc_bootstrap : temporarily disabled at the request of Codership galera_ipv6_mariabackup_section : temporarily disabled at the request of Codership +MDEV-29171 : MDEV-33842 galera_3nodes.MDEV-29171 fails on shutdown_server From 9b5d711ac384e4f3ce397746aa1711cdf284b9ab Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 5 Apr 2024 16:09:56 +0530 Subject: [PATCH 066/159] MDEV-20094 InnoDB blob allocation allocates extra extents - InnoDB reserves the free extents unnecessarily during blob page allocation even though btr_page_alloc() can handle reserving the extent when the existing ran out of pages to be used. --- .../innodb/r/check_ibd_filesize,32k.rdiff | 6 +++--- .../innodb/r/check_ibd_filesize,4k.rdiff | 6 +++--- .../innodb/r/check_ibd_filesize,64k.rdiff | 6 +++--- .../innodb/r/check_ibd_filesize,8k.rdiff | 6 +++--- .../suite/innodb/r/check_ibd_filesize.result | 2 +- storage/innobase/btr/btr0cur.cc | 20 ++++++++----------- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff index 44446602b9f..ad1f3a447c2 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:29:25.129637040 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,12 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -14,7 +14,7 @@ -# bytes: 65536 +# bytes: 131072 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; --# bytes: 4194304 +-# bytes: 2097152 -DROP TABLE t1; -CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) -ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff index ef55ad971fe..1412df393ff 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:31:39.288769153 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,18 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -13,7 +13,7 @@ -# bytes: 65536 +# bytes: 16384 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; - # bytes: 4194304 + # bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff index bcdcea31160..156925597ab 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:30:28.957174270 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,12 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -14,7 +14,7 @@ -# bytes: 65536 +# bytes: 262144 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; --# bytes: 4194304 +-# bytes: 2097152 -DROP TABLE t1; -CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) -ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff index 7b699ef4cea..55cf59737d3 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:31:03.516962339 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,18 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -13,7 +13,7 @@ -# bytes: 65536 +# bytes: 32768 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; - # bytes: 4194304 + # bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize.result b/mysql-test/suite/innodb/r/check_ibd_filesize.result index 0d224d6ac5f..b0f376183ea 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize.result +++ b/mysql-test/suite/innodb/r/check_ibd_filesize.result @@ -10,7 +10,7 @@ DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; # bytes: 65536 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; -# bytes: 4194304 +# bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 38bbf2d1bc1..bd88582d4f4 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -7684,7 +7684,6 @@ btr_store_big_rec_extern_fields( buf_block_t* block; page_t* page; const ulint commit_freq = 4; - ulint r_extents; ut_ad(page_align(field_ref) == page_align(rec)); @@ -7723,20 +7722,17 @@ btr_store_big_rec_extern_fields( alloc_mtr = &mtr; } - if (!fsp_reserve_free_extents(&r_extents, - index->table->space, 1, - FSP_BLOB, alloc_mtr, - 1)) { - - alloc_mtr->commit(); - error = DB_OUT_OF_FILE_SPACE; - goto func_exit; - } - block = btr_page_alloc(index, hint_page_no, FSP_NO_DIR, 0, alloc_mtr, &mtr); - index->table->space->release_free_extents(r_extents); + if (!block) { + error = DB_OUT_OF_FILE_SPACE; + alloc_mtr->commit(); + if (op == BTR_STORE_INSERT_BULK) { + mtr.commit(); + } + goto func_exit; + } if (UNIV_UNLIKELY(op == BTR_STORE_INSERT_BULK)) { mtr_bulk.commit(); From 12d448fde9793551a1604f129ef2ca338eeb43b2 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 6 Apr 2024 00:31:08 +0200 Subject: [PATCH 067/159] mtr: increase more timeouts under debuggers in particular, debug_sync timeout and wait_for_pos timeout --- mysql-test/lib/My/Debugger.pm | 1 + mysql-test/mysql-test-run.pl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/mysql-test/lib/My/Debugger.pm b/mysql-test/lib/My/Debugger.pm index bfa27b8dd3a..c852c767055 100644 --- a/mysql-test/lib/My/Debugger.pm +++ b/mysql-test/lib/My/Debugger.pm @@ -256,6 +256,7 @@ sub pre_setup() { $::opt_suite_timeout= 7 * 24 * 60; # in minutes $::opt_shutdown_timeout= 24 * 60 *60; # in seconds $::opt_start_timeout= 24 * 60 * 60; # in seconds + $::opt_debug_sync_timeout= 3000; # in seconds } } diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 14a6293ac29..c418e5169c6 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -5662,6 +5662,8 @@ sub start_mysqltest ($) { mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'}); } + mtr_add_arg($args, "--wait-for-pos-timeout=%d", $opt_debug_sync_timeout); + client_debug_arg($args, "mysqltest"); if ( $opt_record ) From a7bf0a42d0c1a5540c0b32a8284c1462d7c8c9a8 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 6 Apr 2024 23:05:57 +0200 Subject: [PATCH 068/159] sporadic failures of main.mdl_sync main.mdl_sync 'innodb' w32 [ fail ] Test ended at 2024-04-06 14:11:15 CURRENT_TEST: main.mdl_sync --- main/mdl_sync.result +++ main/mdl_sync.reject @@ -2458,6 +2458,7 @@ SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info; LOCK_MODE LOCK_TYPE TABLE_SCHEMA TABLE_NAME MDL_BACKUP_FTWRL2 Backup lock +MDL_SHARED Table metadata lock test t2 unlock tables; connection default; # Reaping UPDATE --- mysql-test/main/mdl_sync.result | 4 ++++ mysql-test/main/mdl_sync.test | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/mysql-test/main/mdl_sync.result b/mysql-test/main/mdl_sync.result index ae36a65aab4..9abeb05b011 100644 --- a/mysql-test/main/mdl_sync.result +++ b/mysql-test/main/mdl_sync.result @@ -2433,6 +2433,9 @@ create table t1 (a int) engine=myisam; create table t2 (a int) stats_persistent=0, engine=innodb; insert into t1 values (1); insert into t2 values (1); +connect con1, localhost, root; +start transaction with consistent snapshot; +connection default; SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL table_opened WAIT_FOR grlwait execute 2'; update t1,t2 set t1.a=2,t2.a=3; connection con2; @@ -2464,6 +2467,7 @@ connection default; SET DEBUG_SYNC= 'RESET'; drop table t1,t2; disconnect con2; +disconnect con1; # # Bug#50786 Assertion `thd->mdl_context.trans_sentinel() == __null' # failed in open_ltable() diff --git a/mysql-test/main/mdl_sync.test b/mysql-test/main/mdl_sync.test index 8ce4d1eb2b5..40a1112a6d4 100644 --- a/mysql-test/main/mdl_sync.test +++ b/mysql-test/main/mdl_sync.test @@ -3117,6 +3117,12 @@ create table t2 (a int) stats_persistent=0, engine=innodb; insert into t1 values (1); insert into t2 values (1); +connect (con1, localhost, root); +# disable innodb purge thread, otherwise it might start purging t2, +# and will take an mdl, affecting metadata_lock_info output. +start transaction with consistent snapshot; +connection default; + SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL table_opened WAIT_FOR grlwait execute 2'; --send update t1,t2 set t1.a=2,t2.a=3 @@ -3162,6 +3168,7 @@ connection default; SET DEBUG_SYNC= 'RESET'; drop table t1,t2; disconnect con2; +disconnect con1; --echo # --echo # Bug#50786 Assertion `thd->mdl_context.trans_sentinel() == __null' From 54ad3b0e9eddee432f1422506fbbda5900a41da8 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 7 Apr 2024 12:01:24 +0200 Subject: [PATCH 069/159] MDEV-22949 perfschema.memory_aggregate_no_a_no_u fails sporadically in buildbot with wrong result 32-bit followup for 8bb8820df2b --- mysql-test/suite/perfschema/r/memory_aggregate_32bit.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/perfschema/r/memory_aggregate_32bit.result b/mysql-test/suite/perfschema/r/memory_aggregate_32bit.result index 2b8ee675650..387af11f91a 100644 --- a/mysql-test/suite/perfschema/r/memory_aggregate_32bit.result +++ b/mysql-test/suite/perfschema/r/memory_aggregate_32bit.result @@ -2507,8 +2507,8 @@ execute dump_hosts; HOST CURRENT_CONNECTIONS TOTAL_CONNECTIONS localhost 6 6 disconnect con1; -disconnect con5; connection default; +disconnect con5; "================== con1/con5 disconnected ==================" "================== Step 10 ==================" call dump_thread(); From e1825e39cae73f43f20ed7ae856f167b0ecf4598 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 7 Apr 2024 22:29:51 +0200 Subject: [PATCH 070/159] increase performance-schema-max-thread-instances the value of 200 isn't enough for some tests anymore, this causes some random threads to become not instrumented and any table operations there are not reflected in the perfschema. If, say, a DROP TABLE doesn't change perfschema state, perfschema tables might show ghost tables that no longer exist in the server --- mysql-test/include/default_mysqld.cnf | 2 +- mysql-test/suite/perfschema/r/max_program_zero.result | 2 +- mysql-test/suite/perfschema/r/misc.result | 2 +- mysql-test/suite/perfschema/r/ortho_iter.result | 2 +- mysql-test/suite/perfschema/r/privilege_table_io.result | 2 +- .../suite/perfschema/r/start_server_disable_idle.result | 2 +- .../suite/perfschema/r/start_server_disable_stages.result | 2 +- .../suite/perfschema/r/start_server_disable_statements.result | 2 +- .../perfschema/r/start_server_disable_transactions.result | 2 +- .../suite/perfschema/r/start_server_disable_waits.result | 2 +- mysql-test/suite/perfschema/r/start_server_innodb.result | 2 +- mysql-test/suite/perfschema/r/start_server_low_index.result | 2 +- .../suite/perfschema/r/start_server_low_table_lock.result | 2 +- mysql-test/suite/perfschema/r/start_server_no_account.result | 2 +- .../suite/perfschema/r/start_server_no_cond_class.result | 2 +- .../suite/perfschema/r/start_server_no_cond_inst.result | 2 +- .../suite/perfschema/r/start_server_no_file_class.result | 2 +- .../suite/perfschema/r/start_server_no_file_inst.result | 2 +- mysql-test/suite/perfschema/r/start_server_no_host.result | 2 +- mysql-test/suite/perfschema/r/start_server_no_index.result | 2 +- mysql-test/suite/perfschema/r/start_server_no_mdl.result | 2 +- .../suite/perfschema/r/start_server_no_memory_class.result | 2 +- .../suite/perfschema/r/start_server_no_mutex_class.result | 2 +- .../suite/perfschema/r/start_server_no_mutex_inst.result | 2 +- .../r/start_server_no_prepared_stmts_instances.result | 2 +- .../suite/perfschema/r/start_server_no_rwlock_class.result | 2 +- .../suite/perfschema/r/start_server_no_rwlock_inst.result | 2 +- .../suite/perfschema/r/start_server_no_setup_actors.result | 2 +- .../suite/perfschema/r/start_server_no_setup_objects.result | 2 +- .../suite/perfschema/r/start_server_no_socket_class.result | 2 +- .../suite/perfschema/r/start_server_no_socket_inst.result | 2 +- .../suite/perfschema/r/start_server_no_stage_class.result | 2 +- .../suite/perfschema/r/start_server_no_stages_history.result | 2 +- .../perfschema/r/start_server_no_stages_history_long.result | 2 +- .../suite/perfschema/r/start_server_no_statement_class.result | 2 +- .../perfschema/r/start_server_no_statements_history.result | 2 +- .../r/start_server_no_statements_history_long.result | 2 +- .../suite/perfschema/r/start_server_no_table_hdl.result | 2 +- .../suite/perfschema/r/start_server_no_table_inst.result | 2 +- .../suite/perfschema/r/start_server_no_table_lock.result | 2 +- .../suite/perfschema/r/start_server_no_thread_class.result | 2 +- .../perfschema/r/start_server_no_transactions_history.result | 2 +- .../r/start_server_no_transactions_history_long.result | 2 +- mysql-test/suite/perfschema/r/start_server_no_user.result | 2 +- .../suite/perfschema/r/start_server_no_waits_history.result | 2 +- .../perfschema/r/start_server_no_waits_history_long.result | 2 +- mysql-test/suite/perfschema/r/start_server_off.result | 2 +- mysql-test/suite/perfschema/r/start_server_on.result | 2 +- mysql-test/suite/perfschema/r/start_server_variables.result | 4 ++-- .../suite/perfschema/r/statement_program_lost_inst.result | 2 +- 50 files changed, 51 insertions(+), 51 deletions(-) diff --git a/mysql-test/include/default_mysqld.cnf b/mysql-test/include/default_mysqld.cnf index cccf72591cc..40bf19ac922 100644 --- a/mysql-test/include/default_mysqld.cnf +++ b/mysql-test/include/default_mysqld.cnf @@ -92,7 +92,7 @@ loose-performance-schema-events-statements-history-size=10 loose-performance-schema-events-statements-history-long-size=1000 loose-performance-schema-events-transactions-history-size=10 loose-performance-schema-events-transactions-history-long-size=1000 -loose-performance-schema-max-thread-instances=200 +loose-performance-schema-max-thread-instances=400 loose-performance-schema-session-connect-attrs-size=2048 loose-performance-schema-max-metadata-locks=10000 diff --git a/mysql-test/suite/perfschema/r/max_program_zero.result b/mysql-test/suite/perfschema/r/max_program_zero.result index 85b9f49501c..d2e4526d307 100644 --- a/mysql-test/suite/perfschema/r/max_program_zero.result +++ b/mysql-test/suite/perfschema/r/max_program_zero.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/misc.result b/mysql-test/suite/perfschema/r/misc.result index df9942a170f..7468eeddb4c 100644 --- a/mysql-test/suite/perfschema/r/misc.result +++ b/mysql-test/suite/perfschema/r/misc.result @@ -94,7 +94,7 @@ test t_60905 NULL 5 5 0 1 DROP TABLE t_60905; show global variables like "performance_schema_max_thread_instances"; Variable_name Value -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 explain select * from performance_schema.threads; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE threads ALL NULL NULL NULL NULL 256 diff --git a/mysql-test/suite/perfschema/r/ortho_iter.result b/mysql-test/suite/perfschema/r/ortho_iter.result index 9489c1049e5..2dacee0ac27 100644 --- a/mysql-test/suite/perfschema/r/ortho_iter.result +++ b/mysql-test/suite/perfschema/r/ortho_iter.result @@ -261,7 +261,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/privilege_table_io.result b/mysql-test/suite/perfschema/r/privilege_table_io.result index 1755c89137d..2b40cdec14b 100644 --- a/mysql-test/suite/perfschema/r/privilege_table_io.result +++ b/mysql-test/suite/perfschema/r/privilege_table_io.result @@ -63,7 +63,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_disable_idle.result b/mysql-test/suite/perfschema/r/start_server_disable_idle.result index 00baba09fb6..8b609de4534 100644 --- a/mysql-test/suite/perfschema/r/start_server_disable_idle.result +++ b/mysql-test/suite/perfschema/r/start_server_disable_idle.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_disable_stages.result b/mysql-test/suite/perfschema/r/start_server_disable_stages.result index 6fe051b3c42..b31430eada3 100644 --- a/mysql-test/suite/perfschema/r/start_server_disable_stages.result +++ b/mysql-test/suite/perfschema/r/start_server_disable_stages.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_disable_statements.result b/mysql-test/suite/perfschema/r/start_server_disable_statements.result index b582ca072c8..c37509c98ab 100644 --- a/mysql-test/suite/perfschema/r/start_server_disable_statements.result +++ b/mysql-test/suite/perfschema/r/start_server_disable_statements.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_disable_transactions.result b/mysql-test/suite/perfschema/r/start_server_disable_transactions.result index 1431f925ae2..7fa2125b20e 100644 --- a/mysql-test/suite/perfschema/r/start_server_disable_transactions.result +++ b/mysql-test/suite/perfschema/r/start_server_disable_transactions.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_disable_waits.result b/mysql-test/suite/perfschema/r/start_server_disable_waits.result index 1b9356b34a2..b6bb1a989ac 100644 --- a/mysql-test/suite/perfschema/r/start_server_disable_waits.result +++ b/mysql-test/suite/perfschema/r/start_server_disable_waits.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_innodb.result b/mysql-test/suite/perfschema/r/start_server_innodb.result index c64e4f8416d..8cad1f4d414 100644 --- a/mysql-test/suite/perfschema/r/start_server_innodb.result +++ b/mysql-test/suite/perfschema/r/start_server_innodb.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_low_index.result b/mysql-test/suite/perfschema/r/start_server_low_index.result index 9fd9a8a447c..54441252db2 100644 --- a/mysql-test/suite/perfschema/r/start_server_low_index.result +++ b/mysql-test/suite/perfschema/r/start_server_low_index.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_low_table_lock.result b/mysql-test/suite/perfschema/r/start_server_low_table_lock.result index 981fa297971..9164fe18775 100644 --- a/mysql-test/suite/perfschema/r/start_server_low_table_lock.result +++ b/mysql-test/suite/perfschema/r/start_server_low_table_lock.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 1 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_account.result b/mysql-test/suite/perfschema/r/start_server_no_account.result index 4333c6f74d2..9ec22e633d1 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_account.result +++ b/mysql-test/suite/perfschema/r/start_server_no_account.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_cond_class.result b/mysql-test/suite/perfschema/r/start_server_no_cond_class.result index 74c4bed9696..e554b1e9aa4 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_cond_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_cond_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_cond_inst.result b/mysql-test/suite/perfschema/r/start_server_no_cond_inst.result index 03a7f935317..be07f77b99b 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_cond_inst.result +++ b/mysql-test/suite/perfschema/r/start_server_no_cond_inst.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_file_class.result b/mysql-test/suite/perfschema/r/start_server_no_file_class.result index c962a74e0db..f5367f17973 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_file_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_file_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_file_inst.result b/mysql-test/suite/perfschema/r/start_server_no_file_inst.result index ef80d6e3a2d..e9db05a1364 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_file_inst.result +++ b/mysql-test/suite/perfschema/r/start_server_no_file_inst.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_host.result b/mysql-test/suite/perfschema/r/start_server_no_host.result index b58acf57362..8298ca3a828 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_host.result +++ b/mysql-test/suite/perfschema/r/start_server_no_host.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_index.result b/mysql-test/suite/perfschema/r/start_server_no_index.result index 9e7a2bf34a7..50c693e4489 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_index.result +++ b/mysql-test/suite/perfschema/r/start_server_no_index.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_mdl.result b/mysql-test/suite/perfschema/r/start_server_no_mdl.result index 886a1ee1633..a495471f994 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_mdl.result +++ b/mysql-test/suite/perfschema/r/start_server_no_mdl.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_memory_class.result b/mysql-test/suite/perfschema/r/start_server_no_memory_class.result index a6605cc5ffb..a598db77dc9 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_memory_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_memory_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_mutex_class.result b/mysql-test/suite/perfschema/r/start_server_no_mutex_class.result index ae30ac59bdb..cc72db98662 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_mutex_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_mutex_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_mutex_inst.result b/mysql-test/suite/perfschema/r/start_server_no_mutex_inst.result index 1f4086500a0..ee1507c8c59 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_mutex_inst.result +++ b/mysql-test/suite/perfschema/r/start_server_no_mutex_inst.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_prepared_stmts_instances.result b/mysql-test/suite/perfschema/r/start_server_no_prepared_stmts_instances.result index 32356175e82..4b779b919df 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_prepared_stmts_instances.result +++ b/mysql-test/suite/perfschema/r/start_server_no_prepared_stmts_instances.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_rwlock_class.result b/mysql-test/suite/perfschema/r/start_server_no_rwlock_class.result index 75ebff83745..4c480f75b3b 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_rwlock_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_rwlock_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_rwlock_inst.result b/mysql-test/suite/perfschema/r/start_server_no_rwlock_inst.result index d7ebfb33d5b..d0f76f6a8a3 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_rwlock_inst.result +++ b/mysql-test/suite/perfschema/r/start_server_no_rwlock_inst.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_setup_actors.result b/mysql-test/suite/perfschema/r/start_server_no_setup_actors.result index b4b79d02b32..43e98074842 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_setup_actors.result +++ b/mysql-test/suite/perfschema/r/start_server_no_setup_actors.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 0 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_setup_objects.result b/mysql-test/suite/perfschema/r/start_server_no_setup_objects.result index aef0eb7c14d..b8c5e26d6cc 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_setup_objects.result +++ b/mysql-test/suite/perfschema/r/start_server_no_setup_objects.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 0 diff --git a/mysql-test/suite/perfschema/r/start_server_no_socket_class.result b/mysql-test/suite/perfschema/r/start_server_no_socket_class.result index 4695c03dc34..de55a7ff938 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_socket_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_socket_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_socket_inst.result b/mysql-test/suite/perfschema/r/start_server_no_socket_inst.result index 45f668bd668..57f7a5a3647 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_socket_inst.result +++ b/mysql-test/suite/perfschema/r/start_server_no_socket_inst.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_stage_class.result b/mysql-test/suite/perfschema/r/start_server_no_stage_class.result index cccc88ea078..fdefd3ad1f7 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_stage_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_stage_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_stages_history.result b/mysql-test/suite/perfschema/r/start_server_no_stages_history.result index 3631b3e401f..ac0355c51c6 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_stages_history.result +++ b/mysql-test/suite/perfschema/r/start_server_no_stages_history.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_stages_history_long.result b/mysql-test/suite/perfschema/r/start_server_no_stages_history_long.result index bb17a80d853..dd8fc35984e 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_stages_history_long.result +++ b/mysql-test/suite/perfschema/r/start_server_no_stages_history_long.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_statement_class.result b/mysql-test/suite/perfschema/r/start_server_no_statement_class.result index 61cf11f2238..49fdd561ad9 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_statement_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_statement_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_statements_history.result b/mysql-test/suite/perfschema/r/start_server_no_statements_history.result index 94811c40c53..612b305f6e6 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_statements_history.result +++ b/mysql-test/suite/perfschema/r/start_server_no_statements_history.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_statements_history_long.result b/mysql-test/suite/perfschema/r/start_server_no_statements_history_long.result index 4d61bf58fca..92a654bdab4 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_statements_history_long.result +++ b/mysql-test/suite/perfschema/r/start_server_no_statements_history_long.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_table_hdl.result b/mysql-test/suite/perfschema/r/start_server_no_table_hdl.result index 49b59cbc48c..b7204361047 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_table_hdl.result +++ b/mysql-test/suite/perfschema/r/start_server_no_table_hdl.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 0 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_table_inst.result b/mysql-test/suite/perfschema/r/start_server_no_table_inst.result index 17a10cf715e..943e1e92dc2 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_table_inst.result +++ b/mysql-test/suite/perfschema/r/start_server_no_table_inst.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 0 performance_schema_max_table_lock_stat 0 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_table_lock.result b/mysql-test/suite/perfschema/r/start_server_no_table_lock.result index a93f900f650..4996016b4af 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_table_lock.result +++ b/mysql-test/suite/perfschema/r/start_server_no_table_lock.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 0 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_thread_class.result b/mysql-test/suite/perfschema/r/start_server_no_thread_class.result index 051c81dd12f..374d3bb400b 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_thread_class.result +++ b/mysql-test/suite/perfschema/r/start_server_no_thread_class.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 0 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_transactions_history.result b/mysql-test/suite/perfschema/r/start_server_no_transactions_history.result index 1d5597f554b..0ce961296bb 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_transactions_history.result +++ b/mysql-test/suite/perfschema/r/start_server_no_transactions_history.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_transactions_history_long.result b/mysql-test/suite/perfschema/r/start_server_no_transactions_history_long.result index 99e170c9bb1..4b92d21150d 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_transactions_history_long.result +++ b/mysql-test/suite/perfschema/r/start_server_no_transactions_history_long.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_user.result b/mysql-test/suite/perfschema/r/start_server_no_user.result index 46aaa06bf65..2ac41042d03 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_user.result +++ b/mysql-test/suite/perfschema/r/start_server_no_user.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_waits_history.result b/mysql-test/suite/perfschema/r/start_server_no_waits_history.result index 1b717b9f768..570900fca79 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_waits_history.result +++ b/mysql-test/suite/perfschema/r/start_server_no_waits_history.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_no_waits_history_long.result b/mysql-test/suite/perfschema/r/start_server_no_waits_history_long.result index 5691b0e7826..dbcd2100141 100644 --- a/mysql-test/suite/perfschema/r/start_server_no_waits_history_long.result +++ b/mysql-test/suite/perfschema/r/start_server_no_waits_history_long.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_off.result b/mysql-test/suite/perfschema/r/start_server_off.result index 06af389a857..f9de9146a13 100644 --- a/mysql-test/suite/perfschema/r/start_server_off.result +++ b/mysql-test/suite/perfschema/r/start_server_off.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_on.result b/mysql-test/suite/perfschema/r/start_server_on.result index c64e4f8416d..8cad1f4d414 100644 --- a/mysql-test/suite/perfschema/r/start_server_on.result +++ b/mysql-test/suite/perfschema/r/start_server_on.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/start_server_variables.result b/mysql-test/suite/perfschema/r/start_server_variables.result index 6ed93360d9b..f7f44904660 100644 --- a/mysql-test/suite/perfschema/r/start_server_variables.result +++ b/mysql-test/suite/perfschema/r/start_server_variables.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 @@ -187,7 +187,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 diff --git a/mysql-test/suite/perfschema/r/statement_program_lost_inst.result b/mysql-test/suite/perfschema/r/statement_program_lost_inst.result index 1723c35da2c..264be0ede45 100644 --- a/mysql-test/suite/perfschema/r/statement_program_lost_inst.result +++ b/mysql-test/suite/perfschema/r/statement_program_lost_inst.result @@ -140,7 +140,7 @@ performance_schema_max_table_handles 1000 performance_schema_max_table_instances 500 performance_schema_max_table_lock_stat 500 performance_schema_max_thread_classes 50 -performance_schema_max_thread_instances 200 +performance_schema_max_thread_instances 400 performance_schema_session_connect_attrs_size 2048 performance_schema_setup_actors_size 100 performance_schema_setup_objects_size 100 From 504925c416e50e78275ae75a7c8ffdb4255b1ab1 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 19 Feb 2024 15:12:16 +1100 Subject: [PATCH 071/159] MDEV-33434 spider direct sql: Check length before memcpy similar to MDEV-30981 --- .../spider/bugfix/r/mdev_33434.result | 12 ++ .../spider/bugfix/t/mdev_33434.test | 15 +++ storage/spider/spd_direct_sql.cc | 115 +++++++----------- 3 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result new file mode 100644 index 00000000000..2cbcff38752 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result @@ -0,0 +1,12 @@ +# +# MDEV-33434 MDEV-33434 UBSAN null pointer passed as argument 2, which is declared to never be null in spider_udf_direct_sql_create_conn +# +INSTALL SONAME 'ha_spider'; +SET character_set_connection=ucs2; +SELECT SPIDER_DIRECT_SQL('SELECT SLEEP(1)', '', 'srv "dummy", port "3307"'); +ERROR HY000: Unable to connect to foreign data source: localhost +Warnings: +Warning 1620 Plugin is busy and will be uninstalled on shutdown +# +# end of test mdev_33434 +# diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test new file mode 100644 index 00000000000..dd9f882f42e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test @@ -0,0 +1,15 @@ +--echo # +--echo # MDEV-33434 MDEV-33434 UBSAN null pointer passed as argument 2, which is declared to never be null in spider_udf_direct_sql_create_conn +--echo # + +INSTALL SONAME 'ha_spider'; +SET character_set_connection=ucs2; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +SELECT SPIDER_DIRECT_SQL('SELECT SLEEP(1)', '', 'srv "dummy", port "3307"'); +--disable_query_log +--source ../../include/clean_up_spider.inc +--enable_query_log + +--echo # +--echo # end of test mdev_33434 +--echo # diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc index 6639fcee79c..c0c37581865 100644 --- a/storage/spider/spd_direct_sql.cc +++ b/storage/spider/spd_direct_sql.cc @@ -387,6 +387,23 @@ int spider_udf_direct_sql_create_conn_key( DBUG_RETURN(0); } +static inline void spider_maybe_memcpy_string( + char **dest, + char *src, + char *tmp, + uint *dest_len, + uint src_len) +{ + *dest_len= src_len; + if (src_len) + { + *dest= tmp; + memcpy(*dest, src, src_len); + } else + *dest= NULL; +} + + SPIDER_CONN *spider_udf_direct_sql_create_conn( const SPIDER_DIRECT_SQL *direct_sql, int *error_num @@ -469,74 +486,36 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn( { #endif conn->tgt_port = direct_sql->tgt_port; - conn->tgt_socket_length = direct_sql->tgt_socket_length; - conn->tgt_socket = tmp_socket; - memcpy(conn->tgt_socket, direct_sql->tgt_socket, - direct_sql->tgt_socket_length); - conn->tgt_username_length = direct_sql->tgt_username_length; - conn->tgt_username = tmp_username; - memcpy(conn->tgt_username, direct_sql->tgt_username, - direct_sql->tgt_username_length); - conn->tgt_password_length = direct_sql->tgt_password_length; - conn->tgt_password = tmp_password; - memcpy(conn->tgt_password, direct_sql->tgt_password, - direct_sql->tgt_password_length); - conn->tgt_ssl_ca_length = direct_sql->tgt_ssl_ca_length; - if (conn->tgt_ssl_ca_length) - { - conn->tgt_ssl_ca = tmp_ssl_ca; - memcpy(conn->tgt_ssl_ca, direct_sql->tgt_ssl_ca, - direct_sql->tgt_ssl_ca_length); - } else - conn->tgt_ssl_ca = NULL; - conn->tgt_ssl_capath_length = direct_sql->tgt_ssl_capath_length; - if (conn->tgt_ssl_capath_length) - { - conn->tgt_ssl_capath = tmp_ssl_capath; - memcpy(conn->tgt_ssl_capath, direct_sql->tgt_ssl_capath, - direct_sql->tgt_ssl_capath_length); - } else - conn->tgt_ssl_capath = NULL; - conn->tgt_ssl_cert_length = direct_sql->tgt_ssl_cert_length; - if (conn->tgt_ssl_cert_length) - { - conn->tgt_ssl_cert = tmp_ssl_cert; - memcpy(conn->tgt_ssl_cert, direct_sql->tgt_ssl_cert, - direct_sql->tgt_ssl_cert_length); - } else - conn->tgt_ssl_cert = NULL; - conn->tgt_ssl_cipher_length = direct_sql->tgt_ssl_cipher_length; - if (conn->tgt_ssl_cipher_length) - { - conn->tgt_ssl_cipher = tmp_ssl_cipher; - memcpy(conn->tgt_ssl_cipher, direct_sql->tgt_ssl_cipher, - direct_sql->tgt_ssl_cipher_length); - } else - conn->tgt_ssl_cipher = NULL; - conn->tgt_ssl_key_length = direct_sql->tgt_ssl_key_length; - if (conn->tgt_ssl_key_length) - { - conn->tgt_ssl_key = tmp_ssl_key; - memcpy(conn->tgt_ssl_key, direct_sql->tgt_ssl_key, - direct_sql->tgt_ssl_key_length); - } else - conn->tgt_ssl_key = NULL; - conn->tgt_default_file_length = direct_sql->tgt_default_file_length; - if (conn->tgt_default_file_length) - { - conn->tgt_default_file = tmp_default_file; - memcpy(conn->tgt_default_file, direct_sql->tgt_default_file, - direct_sql->tgt_default_file_length); - } else - conn->tgt_default_file = NULL; - conn->tgt_default_group_length = direct_sql->tgt_default_group_length; - if (conn->tgt_default_group_length) - { - conn->tgt_default_group = tmp_default_group; - memcpy(conn->tgt_default_group, direct_sql->tgt_default_group, - direct_sql->tgt_default_group_length); - } else - conn->tgt_default_group = NULL; + spider_maybe_memcpy_string( + &conn->tgt_socket, direct_sql->tgt_socket, tmp_socket, + &conn->tgt_socket_length, direct_sql->tgt_socket_length); + spider_maybe_memcpy_string( + &conn->tgt_username, direct_sql->tgt_username, tmp_username, + &conn->tgt_username_length, direct_sql->tgt_username_length); + spider_maybe_memcpy_string( + &conn->tgt_password, direct_sql->tgt_password, tmp_password, + &conn->tgt_password_length, direct_sql->tgt_password_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_ca, direct_sql->tgt_ssl_ca, tmp_ssl_ca, + &conn->tgt_ssl_ca_length, direct_sql->tgt_ssl_ca_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_capath, direct_sql->tgt_ssl_capath, tmp_ssl_capath, + &conn->tgt_ssl_capath_length, direct_sql->tgt_ssl_capath_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_cert, direct_sql->tgt_ssl_cert, tmp_ssl_cert, + &conn->tgt_ssl_cert_length, direct_sql->tgt_ssl_cert_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_cipher, direct_sql->tgt_ssl_cipher, tmp_ssl_cipher, + &conn->tgt_ssl_cipher_length, direct_sql->tgt_ssl_cipher_length); + spider_maybe_memcpy_string( + &conn->tgt_ssl_key, direct_sql->tgt_ssl_key, tmp_ssl_key, + &conn->tgt_ssl_key_length, direct_sql->tgt_ssl_key_length); + spider_maybe_memcpy_string( + &conn->tgt_default_file, direct_sql->tgt_default_file, tmp_default_file, + &conn->tgt_default_file_length, direct_sql->tgt_default_file_length); + spider_maybe_memcpy_string( + &conn->tgt_default_group, direct_sql->tgt_default_group, tmp_default_group, + &conn->tgt_default_group_length, direct_sql->tgt_default_group_length); conn->tgt_ssl_vsc = direct_sql->tgt_ssl_vsc; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } else { From 11fe2ee0af6d27cae17a85fc3874b27550cef3b7 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 21 Feb 2024 14:17:34 +1100 Subject: [PATCH 072/159] MDEV-33493 Spider: Make a symlink result file a normal file --- .../r/udf_mysql_func_early_init_file.result | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) mode change 120000 => 100644 storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result diff --git a/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result b/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result deleted file mode 120000 index 045ddc4372c..00000000000 --- a/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result +++ /dev/null @@ -1 +0,0 @@ -udf_mysql_func_early.result \ No newline at end of file diff --git a/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result b/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result new file mode 100644 index 00000000000..b84f60a67fb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result @@ -0,0 +1,43 @@ +# +# Test that udf created by inserting into mysql_func works as expected +# +CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS ( +HOST 'localhost', +DATABASE 'auto_test_local', +USER 'root', +PASSWORD '', +SOCKET '$MASTER_1_MYSOCK' + ); +CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS ( +HOST 'localhost', +DATABASE 'auto_test_remote', +USER 'root', +PASSWORD '', +SOCKET '$CHILD2_1_MYSOCK' + ); +connect master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK; +connect child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK; +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +insert into tbl_a values (42); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +create temporary table results (a int); +SELECT SPIDER_DIRECT_SQL('select * from tbl_a', 'results', 'srv "s_2_1", database "auto_test_remote"'); +SPIDER_DIRECT_SQL('select * from tbl_a', 'results', 'srv "s_2_1", database "auto_test_remote"') +1 +select * from results; +a +42 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; From 44c88faecaa76ad2368101001f30bcb504ff2c7e Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 20 Mar 2024 10:36:25 +1100 Subject: [PATCH 073/159] MDEV-28992 Spider group by handler: Push down TIMESTAMPDIFF function Also removed ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC. Similar to pr#2225, with the testcase adapted from that patch: --8<---------------cut here---------------start------------->8--- From 884f7c6df16236748ca975339e0b1c267e195309 Mon Sep 17 00:00:00 2001 From: "Norio Akagi (norakagi)" Date: Wed, 3 Aug 2022 23:30:34 -0700 Subject: [PATCH] [MDEV-28992] Push down TIMESTAMP_DIFF in spider This changes so that TIMESTAMP_DIFF function in a query is pushed down and works natively in Spider. Instead of directly accessing item's member, now we can rely on a public accessor method to make it work. Unit tests are added under spider.pushdown_timestamp_diff. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --8<---------------cut here---------------end--------------->8--- --- .../feature/r/pushdown_timestamp_diff.result | 111 ++++++++++++++++++ .../feature/t/pushdown_timestamp_diff.test | 93 +++++++++++++++ storage/spider/spd_db_handlersocket.cc | 6 +- storage/spider/spd_db_mysql.cc | 34 +----- storage/spider/spd_db_oracle.cc | 6 +- 5 files changed, 208 insertions(+), 42 deletions(-) create mode 100644 storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result create mode 100644 storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test diff --git a/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result b/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result new file mode 100644 index 00000000000..3acd89127c0 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result @@ -0,0 +1,111 @@ +# +# MDEV-28992 Spider: Push down TIMESTAMPDIFF function +# +for master_1 +for child2 +for child3 +set spider_same_server_link= 1; +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +); +CREATE TABLE t1 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +INSERT INTO t1 (a, b, c) VALUES +(1, 'a', '2018-11-01 10:21:39'), +(2, 'b', '2015-06-30 23:59:59'), +(3, 'c', '2013-11-01 01:01:01'); +interval year +explain select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(year, '2000-01-01 00:00:00', c) +1 a 18 +2 b 15 +3 c 13 +interval quarter +explain select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(quarter, '2000-01-01 00:00:00', c) +1 a 75 +2 b 61 +3 c 55 +interval month +explain select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(month, '2000-01-01 00:00:00', c) +1 a 226 +2 b 185 +3 c 166 +interval week +explain select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(week, '2000-01-01 00:00:00', c) +1 a 982 +2 b 808 +3 c 721 +interval day +explain select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(day, '2000-01-01 00:00:00', c) +1 a 6879 +2 b 5659 +3 c 5053 +internal hour +explain select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(hour, '2000-01-01 00:00:00', c) +1 a 165106 +2 b 135839 +3 c 121273 +internal minute +explain select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(minute, '2000-01-01 00:00:00', c) +1 a 9906381 +2 b 8150399 +3 c 7276381 +internal second +explain select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(second, '2000-01-01 00:00:00', c) +1 a 594382899 +2 b 489023999 +3 c 436582861 +internal microsecond +explain select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(microsecond, '2000-01-01 00:00:00', c) +1 a 594382899000000 +2 b 489023999000000 +3 c 436582861000000 +drop table t1, t2; +drop server srv; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test b/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test new file mode 100644 index 00000000000..81251860f74 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test @@ -0,0 +1,93 @@ +--echo # +--echo # MDEV-28992 Spider: Push down TIMESTAMPDIFF function +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +set spider_same_server_link= 1; +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +create table t2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +); +CREATE TABLE t1 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; + +INSERT INTO t1 (a, b, c) VALUES + (1, 'a', '2018-11-01 10:21:39'), + (2, 'b', '2015-06-30 23:59:59'), + (3, 'c', '2013-11-01 01:01:01'); + +--echo interval year +let $query= +select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval quarter +let $query= +select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval month +let $query= +select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval week +let $query= +select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval day +let $query= +select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal hour +let $query= +select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal minute +let $query= +select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal second +let $query= +select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal microsecond +let $query= +select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +drop table t1, t2; +drop server srv; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc index 03d8b505bfe..137aa47e3d6 100644 --- a/storage/spider/spd_db_handlersocket.cc +++ b/storage/spider/spd_db_handlersocket.cc @@ -3178,14 +3178,13 @@ int spider_db_handlersocket_util::open_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; if (str) { const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -3257,9 +3256,6 @@ int spider_db_handlersocket_util::open_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index a7bf14b7fed..68f5821d47e 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -5533,14 +5533,6 @@ int spider_db_mbase_util::open_item_func( alias_length, use_fields, fields)); } -static bool item_func_is_timestampdiff( - const char *func_name, - int func_name_length -) { - return func_name_length == 13 && - !strncasecmp("timestampdiff", func_name, func_name_length); -} - static bool not_func_should_be_skipped( Item_func *item_func ){ @@ -5610,10 +5602,6 @@ int spider_db_mbase_util::check_item_func( Item_func::Functype func_type = item_func->functype(); DBUG_PRINT("info",("spider functype = %d", func_type)); - const char *func_name = (char*) item_func->func_name(); - int func_name_length = strlen(func_name); - DBUG_PRINT("info",("spider func_name = %s", func_name)); - /* The blacklist of the functions that cannot be pushed down */ switch (func_type) { @@ -5628,14 +5616,6 @@ int spider_db_mbase_util::check_item_func( break; case Item_func::FUNC_SP: case Item_func::UDF_FUNC: - /* Notes on merging regarding MDEV-29447: please refer to the - following commits for build error or merge conflicts: - 10.5: d7b564da2a634dcf86798d6b86bd127e7eef9286 - 10.6: 1ed20b993b0dd4e95450cab2e8347e5bf4617a69 - 10.9: dd316b6e20265cfd832bb5585cb4c96e716387c8 - 10.10-11: 3f67f110ba1b23a89c5ede0fbeeb203cf5e164f4 - 11.0-1: 17ba6748afa8834df5658361088e6c8e65aca16f - Please remove this comment after merging. */ use_pushdown_udf= spider_param_use_pushdown_udf( spider->trx->thd, spider->share->use_pushdown_udf); if (!use_pushdown_udf) @@ -5645,12 +5625,6 @@ int spider_db_mbase_util::check_item_func( if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); break; -#ifndef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC - case Item_func::UNKNOWN_FUNC: - if (item_func_is_timestampdiff(func_name, func_name_length)) - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); - break; -#endif default: break; } @@ -6015,12 +5989,11 @@ int spider_db_mbase_util::print_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -6071,7 +6044,7 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); str->q_append(interval_str, interval_len); str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); - + if ((error_num = spider_db_print_item_type(item_list[0], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); @@ -6092,9 +6065,6 @@ int spider_db_mbase_util::print_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 6d52f3827ea..769aab21c46 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -3424,14 +3424,13 @@ int spider_db_oracle_util::open_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; if (str) { const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -3503,9 +3502,6 @@ int spider_db_oracle_util::open_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { From 9c93d41ad7b6efcbad38fe19a994a76c1c4b5c32 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 20 Mar 2024 14:03:52 +1100 Subject: [PATCH 074/159] MDEV-33728 spider: remove use of MYSQL_VERSION_ID and MARIADB_BASE_VERSION change created by: unifdef -DMYSQL_VERSION_ID=100400 -DMARIADB_BASE_VERSION -m storage/spider/spd_* storage/spider/ha_spider.* storage/spider/hs_client/* basically MDEV-27637, MDEV-27641, MDEV-27655 --- storage/spider/ha_spider.cc | 162 --------------------- storage/spider/ha_spider.h | 37 ----- storage/spider/hs_client/config.cpp | 5 - storage/spider/hs_client/config.hpp | 5 - storage/spider/hs_client/fatal.cpp | 5 - storage/spider/hs_client/fatal.hpp | 5 - storage/spider/hs_client/hs_compat.h | 12 -- storage/spider/hs_client/hstcpcli.cpp | 5 - storage/spider/hs_client/hstcpcli.hpp | 5 - storage/spider/hs_client/socket.cpp | 7 - storage/spider/hs_client/socket.hpp | 5 - storage/spider/hs_client/string_util.cpp | 5 - storage/spider/spd_conn.cc | 102 ------------- storage/spider/spd_copy_tables.cc | 39 ----- storage/spider/spd_db_conn.cc | 70 --------- storage/spider/spd_db_handlersocket.cc | 21 --- storage/spider/spd_db_include.cc | 5 - storage/spider/spd_db_include.h | 24 --- storage/spider/spd_db_mysql.cc | 63 -------- storage/spider/spd_db_oracle.cc | 25 ---- storage/spider/spd_direct_sql.cc | 59 -------- storage/spider/spd_environ.h | 12 -- storage/spider/spd_group_by_handler.cc | 5 - storage/spider/spd_i_s.cc | 9 -- storage/spider/spd_include.h | 114 --------------- storage/spider/spd_malloc.cc | 5 - storage/spider/spd_param.cc | 130 ----------------- storage/spider/spd_param.h | 3 - storage/spider/spd_ping_table.cc | 61 -------- storage/spider/spd_sys_table.cc | 177 ----------------------- storage/spider/spd_sys_table.h | 19 --- storage/spider/spd_table.cc | 176 ---------------------- storage/spider/spd_trx.cc | 64 -------- 33 files changed, 1441 deletions(-) diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 90dd37b78aa..b0671cb6f1a 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -22,10 +22,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -33,7 +29,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "ha_partition.h" #include "spd_param.h" #include "spd_err.h" @@ -48,15 +43,9 @@ #include "spd_ping_table.h" #include "spd_malloc.h" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 #define SPIDER_CAN_BG_SEARCH (1LL << 37) #define SPIDER_CAN_BG_INSERT (1LL << 38) #define SPIDER_CAN_BG_UPDATE (1LL << 39) -#else -#define SPIDER_CAN_BG_SEARCH (LL(1) << 37) -#define SPIDER_CAN_BG_INSERT (LL(1) << 38) -#define SPIDER_CAN_BG_UPDATE (LL(1) << 39) -#endif extern handlerton *spider_hton_ptr; extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; @@ -1253,9 +1242,6 @@ int ha_spider::external_lock( DBUG_ENTER("ha_spider::external_lock"); DBUG_PRINT("info",("spider this=%p", this)); DBUG_PRINT("info",("spider lock_type=%x", lock_type)); -#if MYSQL_VERSION_ID < 50500 - DBUG_PRINT("info",("spider thd->options=%x", (int) thd->options)); -#endif #ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC info_auto_called = FALSE; #endif @@ -1943,14 +1929,11 @@ int ha_spider::extra( if (!(trx = spider_get_trx(ha_thd(), TRUE, &error_num))) DBUG_RETURN(error_num); break; -#if MYSQL_VERSION_ID < 50500 -#else case HA_EXTRA_ADD_CHILDREN_LIST: DBUG_PRINT("info",("spider HA_EXTRA_ADD_CHILDREN_LIST")); if (!(trx = spider_get_trx(ha_thd(), TRUE, &error_num))) DBUG_RETURN(error_num); break; -#endif #if defined(HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN) || defined(HA_EXTRA_HAS_HA_EXTRA_USE_CMP_REF) #ifdef HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN case HA_EXTRA_STARTING_ORDERED_INDEX_SCAN: @@ -4430,7 +4413,6 @@ bool ha_spider::check_no_where_cond() } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows ha_spider::multi_range_read_info_const( uint keyno, RANGE_SEQ_IF *seq, @@ -4440,17 +4422,6 @@ ha_rows ha_spider::multi_range_read_info_const( uint *flags, Cost_estimate *cost ) -#else -ha_rows ha_spider::multi_range_read_info_const( - uint keyno, - RANGE_SEQ_IF *seq, - void *seq_init_param, - uint n_ranges, - uint *bufsz, - uint *flags, - COST_VECT *cost -) -#endif { DBUG_ENTER("ha_spider::multi_range_read_info_const"); DBUG_PRINT("info",("spider this=%p", this)); @@ -4494,7 +4465,6 @@ ha_rows ha_spider::multi_range_read_info_const( DBUG_RETURN(rows); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows ha_spider::multi_range_read_info( uint keyno, uint n_ranges, @@ -4504,17 +4474,6 @@ ha_rows ha_spider::multi_range_read_info( uint *flags, Cost_estimate *cost ) -#else -ha_rows ha_spider::multi_range_read_info( - uint keyno, - uint n_ranges, - uint keys, - uint key_parts, - uint *bufsz, - uint *flags, - COST_VECT *cost -) -#endif { DBUG_ENTER("ha_spider::multi_range_read_info"); DBUG_PRINT("info",("spider this=%p", this)); @@ -4586,16 +4545,10 @@ int ha_spider::multi_range_read_init( #endif #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next_first( range_id_t *range_info ) #else -int ha_spider::multi_range_read_next_first( - char **range_info -) -#endif -#else int ha_spider::read_multi_range_first_internal( uchar *buf, KEY_MULTI_RANGE **found_range_p, @@ -5081,19 +5034,11 @@ int ha_spider::read_multi_range_first_internal( DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys)); spider_free(spider_current_trx, multi_range_keys, MYF(0)); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 if (!(multi_range_keys = (range_id_t *) spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_1, sizeof(range_id_t) * (multi_range_num < result_list.multi_split_read ? multi_range_num : result_list.multi_split_read), MYF(MY_WME))) ) -#else - if (!(multi_range_keys = (char **) - spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_2, sizeof(char *) * - (multi_range_num < result_list.multi_split_read ? - multi_range_num : result_list.multi_split_read), MYF(MY_WME))) - ) -#endif DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_PRINT("info",("spider alloc multi_range_keys=%p", multi_range_keys)); if (!mrr_key_buff) @@ -5311,11 +5256,7 @@ int ha_spider::read_multi_range_first_internal( } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if (bka_mode == 2) { @@ -5438,11 +5379,7 @@ int ha_spider::read_multi_range_first_internal( { #ifdef HA_MRR_USE_DEFAULT_IMPL DBUG_PRINT("info",("spider range_res7=%d", range_res)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if ((error_num = spider_db_append_select(this))) DBUG_RETURN(error_num); @@ -5986,15 +5923,9 @@ int ha_spider::pre_multi_range_read_next( DBUG_RETURN(0); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next( range_id_t *range_info ) -#else -int ha_spider::multi_range_read_next( - char **range_info -) -#endif { int error_num; DBUG_ENTER("ha_spider::multi_range_read_next"); @@ -6072,16 +6003,10 @@ int ha_spider::read_multi_range_first( #endif #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next_next( range_id_t *range_info ) #else -int ha_spider::multi_range_read_next_next( - char **range_info -) -#endif -#else int ha_spider::read_multi_range_next( KEY_MULTI_RANGE **found_range_p ) @@ -6797,11 +6722,7 @@ int ha_spider::read_multi_range_next( } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if (bka_mode == 2) { @@ -6922,11 +6843,7 @@ int ha_spider::read_multi_range_next( #endif { #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if ((error_num = spider_db_append_select(this))) DBUG_RETURN(error_num); @@ -9952,29 +9869,15 @@ int ha_spider::write_row( bulk_access_pre_called = FALSE; DBUG_RETURN(spider_db_bulk_bulk_insert(this)); } -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_write_row(buf); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif #ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT ha_statistic_increment(&SSV::ha_write_count); -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) - table->timestamp_field->set_time(); #endif if (!bulk_insert) store_last_insert_id = 0; @@ -10069,21 +9972,12 @@ int ha_spider::pre_write_row( THD *thd = trx->thd; DBUG_ENTER("ha_spider::pre_write_row"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_current->spider->ha_write_row(buf); bulk_access_link_current->spider->bulk_access_pre_called = TRUE; bulk_access_link_current->called = TRUE; -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -10206,20 +10100,11 @@ int ha_spider::update_row( bulk_access_link_exec_tgt->called ) { ulonglong option_backup = 0; -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_update_row( old_data, new_data); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -10228,11 +10113,6 @@ int ha_spider::update_row( #endif #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS do_direct_update = FALSE; -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) - table->timestamp_field->set_time(); #endif if ((error_num = spider_db_update(this, table, old_data))) DBUG_RETURN(check_error_mode(error_num)); @@ -10349,14 +10229,10 @@ int ha_spider::direct_update_rows_init( direct_update_fields ) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -10516,14 +10392,10 @@ int ha_spider::direct_update_rows_init() if (direct_update_fields) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -10843,19 +10715,10 @@ int ha_spider::delete_row( bulk_access_link_exec_tgt->called ) { ulonglong option_backup = 0; -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_delete_row(buf); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -10920,14 +10783,10 @@ int ha_spider::direct_delete_rows_init( if (!range_count) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -11020,14 +10879,10 @@ int ha_spider::direct_delete_rows_init() cond_check = FALSE; spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -11441,11 +11296,7 @@ int ha_spider::create( uint sql_command = thd_sql_command(thd), roop_count; SPIDER_TRX *trx; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool need_lock = FALSE; DBUG_ENTER("ha_spider::create"); DBUG_PRINT("info",("spider this=%p", this)); @@ -11686,11 +11537,7 @@ int ha_spider::rename_table( TABLE *table_tables = NULL; SPIDER_ALTER_TABLE *alter_table_from, *alter_table_to; SPIDER_LGTM_TBLHND_SHARE *from_lgtm_tblhnd_share, *to_lgtm_tblhnd_share; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool need_lock = FALSE; DBUG_ENTER("ha_spider::rename_table"); DBUG_PRINT("info",("spider this=%p", this)); @@ -11914,11 +11761,7 @@ int ha_spider::delete_table( TABLE *table_tables = NULL; uint sql_command = thd_sql_command(thd); SPIDER_ALTER_TABLE *alter_table; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool need_lock = FALSE; DBUG_ENTER("ha_spider::delete_table"); DBUG_PRINT("info",("spider this=%p", this)); @@ -15854,13 +15697,8 @@ int ha_spider::bulk_tmp_table_rnd_next() if (tmp_table[roop_count]) { if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 !(error_num = tmp_table[roop_count]->file->ha_rnd_next( tmp_table[roop_count]->record[0])) -#else - !(error_num = tmp_table[roop_count]->file->rnd_next( - tmp_table[roop_count]->record[0])) -#endif ) { DBUG_RETURN(error_num); } diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index 543b92629da..f5a597b88a7 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -147,11 +147,7 @@ public: bool have_second_range; KEY_MULTI_RANGE mrr_second_range; spider_string *mrr_key_buff; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 range_id_t *multi_range_keys; -#else - char **multi_range_keys; -#endif #else KEY_MULTI_RANGE *multi_range_ranges; #endif @@ -357,7 +353,6 @@ public: void reset_no_where_cond(); bool check_no_where_cond(); #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows multi_range_read_info_const( uint keyno, RANGE_SEQ_IF *seq, @@ -376,26 +371,6 @@ public: uint *flags, Cost_estimate *cost ); -#else - ha_rows multi_range_read_info_const( - uint keyno, - RANGE_SEQ_IF *seq, - void *seq_init_param, - uint n_ranges, - uint *bufsz, - uint *flags, - COST_VECT *cost - ); - ha_rows multi_range_read_info( - uint keyno, - uint n_ranges, - uint keys, - uint key_parts, - uint *bufsz, - uint *flags, - COST_VECT *cost - ); -#endif int multi_range_read_init( RANGE_SEQ_IF *seq, void *seq_init_param, @@ -403,7 +378,6 @@ public: uint mode, HANDLER_BUFFER *buf ); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int multi_range_read_next( range_id_t *range_info ); @@ -413,17 +387,6 @@ public: int multi_range_read_next_next( range_id_t *range_info ); -#else - int multi_range_read_next( - char **range_info - ); - int multi_range_read_next_first( - char **range_info - ); - int multi_range_read_next_next( - char **range_info - ); -#endif #else int read_multi_range_first( KEY_MULTI_RANGE **found_range_p, diff --git a/storage/spider/hs_client/config.cpp b/storage/spider/hs_client/config.cpp index d2759e37d8f..9c6f936b8a8 100644 --- a/storage/spider/hs_client/config.cpp +++ b/storage/spider/hs_client/config.cpp @@ -9,13 +9,8 @@ #include #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "config.hpp" diff --git a/storage/spider/hs_client/config.hpp b/storage/spider/hs_client/config.hpp index 2880f2f5a33..a3a986cc1fd 100644 --- a/storage/spider/hs_client/config.hpp +++ b/storage/spider/hs_client/config.hpp @@ -11,14 +11,9 @@ #define DENA_CONFIG_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #define DENA_VERBOSE(lv, x) if (dena::verbose_level >= (lv)) { (x); } diff --git a/storage/spider/hs_client/fatal.cpp b/storage/spider/hs_client/fatal.cpp index cfbc14df64a..1ed20189a93 100644 --- a/storage/spider/hs_client/fatal.cpp +++ b/storage/spider/hs_client/fatal.cpp @@ -9,13 +9,8 @@ #include #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "fatal.hpp" diff --git a/storage/spider/hs_client/fatal.hpp b/storage/spider/hs_client/fatal.hpp index 38fc149e98e..859b695baf3 100644 --- a/storage/spider/hs_client/fatal.hpp +++ b/storage/spider/hs_client/fatal.hpp @@ -11,14 +11,9 @@ #define DENA_FATAL_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif namespace dena { diff --git a/storage/spider/hs_client/hs_compat.h b/storage/spider/hs_client/hs_compat.h index 8505d7978b7..e466dee67a7 100644 --- a/storage/spider/hs_client/hs_compat.h +++ b/storage/spider/hs_client/hs_compat.h @@ -16,21 +16,9 @@ #ifndef HS_COMPAT_H #define HS_COMPAT_H -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100213 #define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ my_init_dynamic_array2(A, B, C, D, E, F) #define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ init_alloc_root(A, "spider", B, C, D) -#elif defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ - my_init_dynamic_array2(A, B, C, D, E, F) -#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ - init_alloc_root(A, B, C, D) -#else -#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ - my_init_dynamic_array2(A, B, C, D, E) -#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ - init_alloc_root(A, B, C) -#endif #endif diff --git a/storage/spider/hs_client/hstcpcli.cpp b/storage/spider/hs_client/hstcpcli.cpp index 4c93b5a3a49..791ee9a9e4c 100644 --- a/storage/spider/hs_client/hstcpcli.cpp +++ b/storage/spider/hs_client/hstcpcli.cpp @@ -10,14 +10,9 @@ #include #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #include "hstcpcli.hpp" #include "auto_file.hpp" diff --git a/storage/spider/hs_client/hstcpcli.hpp b/storage/spider/hs_client/hstcpcli.hpp index aac02ce7f46..06044f169a3 100644 --- a/storage/spider/hs_client/hstcpcli.hpp +++ b/storage/spider/hs_client/hstcpcli.hpp @@ -13,13 +13,8 @@ #define HANDLERSOCKET_MYSQL_UTIL 1 #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "config.hpp" #include "socket.hpp" diff --git a/storage/spider/hs_client/socket.cpp b/storage/spider/hs_client/socket.cpp index 45b8100e64c..469acb2725f 100644 --- a/storage/spider/hs_client/socket.cpp +++ b/storage/spider/hs_client/socket.cpp @@ -16,16 +16,9 @@ #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 #include -#endif #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "socket.hpp" #include "string_util.hpp" diff --git a/storage/spider/hs_client/socket.hpp b/storage/spider/hs_client/socket.hpp index a3e6527a46d..e4f7530aec9 100644 --- a/storage/spider/hs_client/socket.hpp +++ b/storage/spider/hs_client/socket.hpp @@ -11,13 +11,8 @@ #define DENA_SOCKET_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "auto_addrinfo.hpp" #include "auto_file.hpp" diff --git a/storage/spider/hs_client/string_util.cpp b/storage/spider/hs_client/string_util.cpp index 39934148cb8..647cf877805 100644 --- a/storage/spider/hs_client/string_util.cpp +++ b/storage/spider/hs_client/string_util.cpp @@ -10,13 +10,8 @@ #include #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "string_util.hpp" diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index ba8a579b1ac..be9b27d83ad 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -18,16 +18,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "tztime.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -733,12 +728,8 @@ SPIDER_CONN *spider_create_conn( else conn->need_mon = need_mon; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_mta_conn_mutex_init; @@ -1883,43 +1874,27 @@ int spider_create_conn_thread( DBUG_ENTER("spider_create_conn_thread"); if (conn && !conn->bg_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn_chain, &conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_chain_mutex_init; } conn->bg_conn_chain_mutex_ptr = NULL; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn_sync, &conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn, &conn->bg_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_job_stack_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_job_stack, &conn->bg_job_stack_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_job_stack_mutex_init; @@ -1936,36 +1911,22 @@ int spider_create_conn_thread( conn->bg_job_stack.max_element * conn->bg_job_stack.size_of_element); conn->bg_job_stack_cur_pos = 0; -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&conn->bg_conn_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_conn_sync, &conn->bg_conn_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&conn->bg_conn_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_conn, &conn->bg_conn_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } pthread_mutex_lock(&conn->bg_conn_mutex); -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&conn->bg_thread, &spider_pt_attr, - spider_bg_conn_action, (void *) conn) - ) -#else if (mysql_thread_create(spd_key_thd_bg, &conn->bg_thread, &spider_pt_attr, spider_bg_conn_action, (void *) conn) ) -#endif { pthread_mutex_unlock(&conn->bg_conn_mutex); error_num = HA_ERR_OUT_OF_MEM; @@ -2936,35 +2897,21 @@ int spider_create_sts_thread( DBUG_ENTER("spider_create_sts_thread"); if (!share->bg_sts_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_sts_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts, &share->bg_sts_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_sts_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts_sync, &share->bg_sts_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_sts_thread, &spider_pt_attr, - spider_bg_sts_action, (void *) share) - ) -#else if (mysql_thread_create(spd_key_thd_bg_sts, &share->bg_sts_thread, &spider_pt_attr, spider_bg_sts_action, (void *) share) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -3301,35 +3248,21 @@ int spider_create_crd_thread( DBUG_ENTER("spider_create_crd_thread"); if (!share->bg_crd_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_crd_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd, &share->bg_crd_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_crd_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd_sync, &share->bg_crd_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_crd_thread, &spider_pt_attr, - spider_bg_crd_action, (void *) share) - ) -#else if (mysql_thread_create(spd_key_thd_bg_crd, &share->bg_crd_thread, &spider_pt_attr, spider_bg_crd_action, (void *) share) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -3743,13 +3676,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_mutex_init(&share->bg_mon_mutexes[roop_count], - MY_MUTEX_INIT_FAST) -#else mysql_mutex_init(spd_key_mutex_bg_mon, &share->bg_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -3761,12 +3689,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_cond_init(&share->bg_mon_conds[roop_count], NULL) -#else mysql_cond_init(spd_key_cond_bg_mon, &share->bg_mon_conds[roop_count], NULL) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -3778,12 +3702,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_cond_init(&share->bg_mon_sleep_conds[roop_count], NULL) -#else mysql_cond_init(spd_key_cond_bg_mon_sleep, &share->bg_mon_sleep_conds[roop_count], NULL) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -3798,16 +3718,10 @@ int spider_create_mon_threads( { link_pack.link_idx = roop_count; pthread_mutex_lock(&share->bg_mon_mutexes[roop_count]); -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_mon_threads[roop_count], - &spider_pt_attr, spider_bg_mon_action, (void *) &link_pack) - ) -#else if (mysql_thread_create(spd_key_thd_bg_mon, &share->bg_mon_threads[roop_count], &spider_pt_attr, spider_bg_mon_action, (void *) &link_pack) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -4061,17 +3975,9 @@ int spider_conn_first_link_idx( my_afree(link_idxs); DBUG_RETURN(-1); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 DBUG_PRINT("info",("spider server_id=%lu", thd->variables.server_id)); -#else - DBUG_PRINT("info",("spider server_id=%u", thd->server_id)); -#endif DBUG_PRINT("info",("spider thread_id=%lu", thd_get_thread_id(thd))); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 rand_val = spider_rand(thd->variables.server_id + thd_get_thread_id(thd)); -#else - rand_val = spider_rand(thd->server_id + thd_get_thread_id(thd)); -#endif DBUG_PRINT("info",("spider rand_val=%f", rand_val)); balance_val = (longlong) (rand_val * balance_total); DBUG_PRINT("info",("spider balance_val=%lld", balance_val)); @@ -4597,21 +4503,13 @@ SPIDER_IP_PORT_CONN* spider_create_ipport_conn(SPIDER_CONN *conn) goto err_return_direct; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&ret->mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_conn_i, &ret->mutex, MY_MUTEX_INIT_FAST)) -#endif { //error goto err_malloc_key; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&ret->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_conn_i, &ret->cond, NULL)) -#endif { pthread_mutex_destroy(&ret->mutex); goto err_malloc_key; diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index d205cd244ca..a63d63ca430 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -17,17 +17,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_base.h" #include "sql_partition.h" #include "transaction.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -250,11 +245,7 @@ int spider_udf_get_copy_tgt_tables( ) { int error_num, roop_count; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif char table_key[MAX_KEY_LENGTH]; SPIDER_COPY_TABLE_CONN *table_conn = NULL, *src_table_conn_prev = NULL, *dst_table_conn_prev = NULL; @@ -744,13 +735,8 @@ long long spider_copy_tables_body( thd->handler_tables_hash.records != 0 || thd->derived_tables != 0 || thd->lock != 0 || -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables != 0 || - thd->prelocked_mode != NON_PRELOCKED -#else thd->locked_tables_list.locked_tables() || thd->locked_tables_mode != LTM_NONE -#endif ) { if (thd->open_tables != 0) { @@ -773,18 +759,6 @@ long long spider_copy_tables_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), "thd->lock", thd->lock); -#if MYSQL_VERSION_ID < 50500 - } else if (thd->locked_tables != 0) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), - "thd->locked_tables", thd->locked_tables); - } else if (thd->prelocked_mode != NON_PRELOCKED) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), - "thd->prelocked_mode", (longlong) thd->prelocked_mode); -#else } else if (thd->locked_tables_list.locked_tables()) { my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, @@ -796,7 +770,6 @@ long long spider_copy_tables_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), "thd->locked_tables_mode", (longlong) thd->locked_tables_mode); -#endif } goto error; } @@ -888,9 +861,6 @@ long long spider_copy_tables_body( copy_tables->trx->trx_start = TRUE; copy_tables->trx->updated_in_this_trx = FALSE; DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE")); -#if MYSQL_VERSION_ID < 50500 - if (open_and_lock_tables(thd, table_list)) -#else table_list->mdl_request.init( MDL_key::TABLE, SPIDER_TABLE_LIST_db_str(table_list), @@ -899,7 +869,6 @@ long long spider_copy_tables_body( MDL_TRANSACTION ); if (open_and_lock_tables(thd, table_list, FALSE, 0)) -#endif { thd->m_reprepare_observer = reprepare_observer_backup; copy_tables->trx->trx_start = FALSE; @@ -1099,11 +1068,7 @@ long long spider_copy_tables_body( if (table_list->table) { -#if MYSQL_VERSION_ID < 50500 - ha_autocommit_or_rollback(thd, 0); -#else (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); -#endif close_thread_tables(thd); } if (spider) @@ -1149,11 +1114,7 @@ error: } if (table_list && table_list->table) { -#if MYSQL_VERSION_ID < 50500 - ha_autocommit_or_rollback(thd, 0); -#else (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); -#endif close_thread_tables(thd); } if (spider) diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 52fde02ad0c..40dc15a2149 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -33,7 +29,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "sql_common.h" #include #include "spd_err.h" @@ -1930,10 +1925,8 @@ int spider_db_append_key_where_internal( DBUG_PRINT("info", ("spider start_key->flag=%d", start_key->flag)); switch (start_key->flag) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 case HA_READ_PREFIX_LAST: result_list->desc_flg = TRUE; -#endif /* fall through */ case HA_READ_KEY_EXACT: if (sql_kind == SPIDER_SQL_KIND_SQL) @@ -2169,12 +2162,6 @@ int spider_db_append_key_where_internal( } #endif break; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - case HA_READ_PREFIX_LAST: - result_list->limit_num = 1; - /* fall through */ -#endif case HA_READ_KEY_OR_PREV: case HA_READ_PREFIX_LAST_OR_PREV: result_list->desc_flg = TRUE; @@ -3016,13 +3003,8 @@ int spider_db_get_row_from_tmp_tbl( current->result_tmp_tbl_inited = 1; } if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = current->result_tmp_tbl->file->ha_rnd_next( current->result_tmp_tbl->record[0])) -#else - (error_num = current->result_tmp_tbl->file->rnd_next( - current->result_tmp_tbl->record[0])) -#endif ) { DBUG_RETURN(error_num); } @@ -3050,13 +3032,8 @@ int spider_db_get_row_from_tmp_tbl_pos( result->result_tmp_tbl_inited = 2; } if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = tmp_tbl->file->ha_rnd_pos(tmp_tbl->record[0], (uchar *) &pos->tmp_tbl_pos)) -#else - (error_num = tmp_tbl->file->rnd_pos(tmp_tbl->record[0], - (uchar *) &pos->tmp_tbl_pos)) -#endif ) { DBUG_RETURN(error_num); } @@ -6573,11 +6550,7 @@ int spider_db_update_auto_increment( if ( table->s->next_number_keypart == 0 && mysql_bin_log.is_open() && -#if MYSQL_VERSION_ID < 50500 - !thd->current_stmt_binlog_row_based -#else !thd->is_current_stmt_binlog_format_row() -#endif ) { if ( spider->check_partitioned() && @@ -6606,11 +6579,7 @@ int spider_db_update_auto_increment( if ( table->s->next_number_keypart == 0 && mysql_bin_log.is_open() && -#if MYSQL_VERSION_ID < 50500 - !thd->current_stmt_binlog_row_based -#else !thd->is_current_stmt_binlog_format_row() -#endif ) { for (roop_count = 0; roop_count < (int) affected_rows; roop_count++) push_warning_printf(thd, SPIDER_WARN_LEVEL_NOTE, @@ -6849,9 +6818,7 @@ int spider_db_update( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 conn->ignore_dup_key = spider->ignore_dup_key; -#endif pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_UPDATE_SQL, roop_count))) @@ -8980,11 +8947,7 @@ int spider_db_print_item_type_default( { if (spider->share->access_charset->cset == system_charset_info->cset) { -#if MYSQL_VERSION_ID < 50500 - item->print(str->get_str(), QT_IS); -#else item->print(str->get_str(), QT_TO_SYSTEM_CHARSET); -#endif } else { item->print(str->get_str(), QT_ORDINARY); } @@ -10155,13 +10118,8 @@ int spider_db_udf_direct_sql( spider_param_ping_interval_at_trx_start(thd); time_t tmp_time = (time_t) time((time_t*) 0); bool need_trx_end, need_all_commit, insert_start = FALSE; -#if MYSQL_VERSION_ID < 50500 -#else enum_sql_command sql_command_backup; -#endif DBUG_ENTER("spider_db_udf_direct_sql"); -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used) { if (spider_sys_open_tables(c_thd, &direct_sql->table_list_first, @@ -10180,7 +10138,6 @@ int spider_db_udf_direct_sql( direct_sql->open_tables_thd = c_thd; roop_count = 0; } -#endif if (c_thd != thd) { @@ -10188,21 +10145,15 @@ int spider_db_udf_direct_sql( need_trx_end = TRUE; } else { need_all_commit = FALSE; -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used) { need_trx_end = TRUE; } else { -#endif if (c_thd->transaction.stmt.ha_list) need_trx_end = FALSE; else need_trx_end = TRUE; -#if MYSQL_VERSION_ID < 50500 -#else } -#endif } if (!conn->disable_reconnect) @@ -10222,11 +10173,8 @@ int spider_db_udf_direct_sql( DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); } -#if MYSQL_VERSION_ID < 50500 -#else sql_command_backup = c_thd->lex->sql_command; c_thd->lex->sql_command = SQLCOM_INSERT; -#endif pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); @@ -10252,10 +10200,7 @@ int spider_db_udf_direct_sql( if ((error_num = conn->db_conn->append_sql( direct_sql->sql, direct_sql->sql_length, &request_key))) { -#if MYSQL_VERSION_ID < 50500 -#else c_thd->lex->sql_command = sql_command_backup; -#endif DBUG_RETURN(error_num); } } @@ -10329,9 +10274,6 @@ int spider_db_udf_direct_sql( for (; roop_count2 < set_off; roop_count2++) bitmap_clear_bit(table->write_set, (uint) roop_count2); -#if MYSQL_VERSION_ID < 50500 - if (table->file->has_transactions()) -#endif { THR_LOCK_DATA *to[2]; table->file->store_lock(table->in_use, to, @@ -10342,8 +10284,6 @@ int spider_db_udf_direct_sql( table->file->print_error(error_num, MYF(0)); break; } -#if MYSQL_VERSION_ID < 50500 -#else if ( table->s->tmp_table == NO_TMP_TABLE && table->pos_in_table_list @@ -10365,7 +10305,6 @@ int spider_db_udf_direct_sql( next_tables = next_tables->next_global; } } -#endif } if (direct_sql->iop) @@ -10427,13 +10366,8 @@ int spider_db_udf_direct_sql( else if (direct_sql->iop[roop_count] == 2) table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); } -#if MYSQL_VERSION_ID < 50500 - if (table->file->has_transactions()) -#endif { table->file->ha_external_lock(table->in_use, F_UNLCK); -#if MYSQL_VERSION_ID < 50500 -#else if ( table->s->tmp_table == NO_TMP_TABLE && table->pos_in_table_list @@ -10449,7 +10383,6 @@ int spider_db_udf_direct_sql( next_tables = next_tables->next_global; } } -#endif } table->file->ha_reset(); table->in_use = thd; @@ -10512,10 +10445,7 @@ int spider_db_udf_direct_sql( } } } -#if MYSQL_VERSION_ID < 50500 -#else c_thd->lex->sql_command = sql_command_backup; -#endif DBUG_RETURN(error_num); } diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc index 137aa47e3d6..5d04fa8084d 100644 --- a/storage/spider/spd_db_handlersocket.cc +++ b/storage/spider/spd_db_handlersocket.cc @@ -17,14 +17,9 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_analyse.h" -#endif #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #include "spd_err.h" @@ -3297,11 +3292,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3431,11 +3422,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3585,11 +3572,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3720,11 +3703,7 @@ int spider_db_handlersocket_util::open_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; -#ifdef MARIADB_BASE_VERSION case Item_func::XOR_FUNC: -#else - case Item_func::COND_XOR_FUNC: -#endif if (str) str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); DBUG_RETURN( diff --git a/storage/spider/spd_db_include.cc b/storage/spider/spd_db_include.cc index 7f600142187..7363564aa04 100644 --- a/storage/spider/spd_db_include.cc +++ b/storage/spider/spd_db_include.cc @@ -17,14 +17,9 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #include "sql_common.h" #include #include diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 5add9fac3e4..20bd82e48da 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -23,56 +23,32 @@ #define SPIDER_DB_WRAPPER_MYSQL "mysql" #define SPIDER_DB_WRAPPER_MARIADB "mariadb" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100204 #define PLUGIN_VAR_CAN_MEMALLOC /* #define ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC #define HASH_UPDATE_WITH_HASH_VALUE */ -#else -#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS -#define HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS -#endif -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 #define SPIDER_HAS_DISCOVER_TABLE_STRUCTURE #define SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE #define SPIDER_HAS_SHOW_SIMPLE_FUNC #define SPIDER_HAS_JT_HASH_INDEX_MERGE #define SPIDER_HAS_EXPR_CACHE_ITEM -#else -#define SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100007 #define SPIDER_ITEM_HAS_CMP_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define SPIDER_HAS_TIME_STATUS #define SPIDER_HAS_DECIMAL_OPERATION_RESULTS_VALUE_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100014 #define SPIDER_ITEM_STRING_WITHOUT_SET_STR_WITH_COPY -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_ITEM_STRING_WITHOUT_SET_STR_WITH_COPY_AND_THDPTR -#endif -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108 #define SPIDER_HAS_GROUP_BY_HANDLER -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 #define SPIDER_ORDER_HAS_ENUM_ORDER -#endif -#if defined(MARIADB_BASE_VERSION) #define SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR #define SPIDER_HANDLER_AUTO_REPAIR_HAS_ERROR -#endif class spider_db_conn; typedef spider_db_conn SPIDER_DB_CONN; diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 68f5821d47e..c239baf636d 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -17,10 +17,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -31,7 +27,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "sql_common.h" #include #include @@ -811,11 +806,7 @@ int spider_db_mbase_result::fetch_table_status( int error_num; MYSQL_ROW mysql_row; MYSQL_TIME mysql_time; -#ifdef MARIADB_BASE_VERSION uint not_used_uint; -#else - my_bool not_used_my_bool; -#endif #ifdef SPIDER_HAS_TIME_STATUS MYSQL_TIME_STATUS time_status; #else @@ -893,13 +884,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[11], strlen(mysql_row[11]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.create_time = (time_t) 0; #ifdef DBUG_TRACE @@ -918,13 +904,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[12], strlen(mysql_row[12]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.update_time = (time_t) 0; #ifndef DBUG_OFF @@ -943,13 +924,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[13], strlen(mysql_row[13]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.check_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1022,13 +998,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[6], strlen(mysql_row[6]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.create_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1047,13 +1018,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[7], strlen(mysql_row[7]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.update_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1072,13 +1038,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[8], strlen(mysql_row[8]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.check_time = (time_t) 0; #ifdef DBUG_TRACE @@ -2391,11 +2352,7 @@ int spider_db_mbase::next_result() strmov(db_conn->net.sqlstate, "00000"); db_conn->affected_rows = ~(my_ulonglong) 0; -#if MYSQL_VERSION_ID < 50500 - if (db_conn->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) -#else if (db_conn->server_status & SERVER_MORE_RESULTS_EXISTS) -#endif { if ((status = db_conn->methods->read_query_result(db_conn)) > 0) DBUG_RETURN(spider_db_errorno(conn)); @@ -2409,11 +2366,7 @@ uint spider_db_mbase::affected_rows() MYSQL *last_used_con; DBUG_ENTER("spider_db_mbase::affected_rows"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif DBUG_RETURN((uint) last_used_con->affected_rows); } @@ -2422,11 +2375,7 @@ uint spider_db_mbase::matched_rows() MYSQL *last_used_con; DBUG_ENTER("spider_db_mysql::matched_rows"); DBUG_PRINT("info", ("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif /* Rows matched: 65 Changed: 65 Warnings: 0 */ const char *info = last_used_con->info; if (!info) @@ -2451,11 +2400,7 @@ bool spider_db_mbase::inserted_info( { DBUG_RETURN(TRUE); } -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif /* Records: 10 Duplicates: 4 Warnings: 0 */ const char *info = last_used_con->info; if (!info) @@ -2497,11 +2442,7 @@ ulonglong spider_db_mbase::last_insert_id() MYSQL *last_used_con; DBUG_ENTER("spider_db_mbase::last_insert_id"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif DBUG_RETURN((uint) last_used_con->insert_id); } @@ -12891,11 +12832,7 @@ int spider_mbase_handler::bulk_tmp_table_rnd_next() int error_num; DBUG_ENTER("spider_mbase_handler::bulk_tmp_table_rnd_next"); DBUG_PRINT("info",("spider this=%p", this)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); -#else - error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); -#endif if (!error_num) { error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 769aab21c46..b15bda5e77d 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -17,10 +17,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_partition.h" @@ -28,7 +24,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #ifdef HAVE_ORACLE_OCI #if (defined(WIN32) || defined(_WIN32) || defined(WINDOWS) || defined(_WINDOWS)) @@ -3543,11 +3538,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3677,11 +3668,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3967,11 +3954,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -4102,11 +4085,7 @@ int spider_db_oracle_util::open_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; -#ifdef MARIADB_BASE_VERSION case Item_func::XOR_FUNC: -#else - case Item_func::COND_XOR_FUNC: -#endif if (str) str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); DBUG_RETURN( @@ -10446,11 +10425,7 @@ int spider_oracle_handler::bulk_tmp_table_rnd_next() int error_num; DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_next"); DBUG_PRINT("info",("spider this=%p", this)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); -#else - error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); -#endif if (!error_num) { error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc index c0c37581865..d23b7053840 100644 --- a/storage/spider/spd_direct_sql.cc +++ b/storage/spider/spd_direct_sql.cc @@ -17,10 +17,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -28,7 +24,6 @@ #include "sql_base.h" #include "sql_servers.h" #include "tztime.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -43,9 +38,7 @@ #include "spd_udf.h" #include "spd_malloc.h" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define SPIDER_NEED_INIT_ONE_TABLE_FOR_FIND_TEMPORARY_TABLE -#endif extern const char **spd_defaults_extra_file; extern const char **spd_defaults_file; @@ -114,21 +107,6 @@ int spider_udf_direct_sql_create_table_list( } else break; } -#if MYSQL_VERSION_ID < 50500 - if (!(direct_sql->db_names = (char**) - spider_bulk_malloc(spider_current_trx, SPD_MID_UDF_DIRECT_SQL_CREATE_TABLE_LIST_1, MYF(MY_WME | MY_ZEROFILL), - &direct_sql->db_names, sizeof(char*) * table_count, - &direct_sql->table_names, sizeof(char*) * table_count, - &direct_sql->tables, sizeof(TABLE*) * table_count, - &tmp_name_ptr, sizeof(char) * ( - table_name_list_length + - thd->db_length * table_count + - 2 * table_count - ), - &direct_sql->iop, sizeof(int) * table_count, - NullS)) - ) -#else if (!(direct_sql->db_names = (char**) spider_bulk_malloc(spider_current_trx, SPD_MID_UDF_DIRECT_SQL_CREATE_TABLE_LIST_2, MYF(MY_WME | MY_ZEROFILL), &direct_sql->db_names, sizeof(char*) * table_count, @@ -144,7 +122,6 @@ int spider_udf_direct_sql_create_table_list( &direct_sql->real_table_bitmap, sizeof(uchar) * ((table_count + 7) / 8), NullS)) ) -#endif DBUG_RETURN(HA_ERR_OUT_OF_MEM); tmp_ptr = table_name_list; @@ -561,12 +538,8 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn( } #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_mta_conn_mutex_init; @@ -1061,10 +1034,7 @@ static void spider_minus_1(SPIDER_DIRECT_SQL *direct_sql) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) direct_sql->access_mode = -1; #endif -#if MYSQL_VERSION_ID < 50500 -#else direct_sql->use_real_table = -1; -#endif direct_sql->error_rw_mode = -1; for (int i = 0; i < direct_sql->table_count; i++) direct_sql->iop[i] = -1; @@ -1132,10 +1102,7 @@ int spider_udf_parse_direct_sql_param( SPIDER_PARAM_STR("srv", server_name); SPIDER_PARAM_INT_WITH_MAX("svc", tgt_ssl_vsc, 0, 1); SPIDER_PARAM_INT_WITH_MAX("tlm", table_loop_mode, 0, 2); -#if MYSQL_VERSION_ID < 50500 -#else SPIDER_PARAM_INT_WITH_MAX("urt", use_real_table, 0, 1); -#endif SPIDER_PARAM_INT("wto", net_write_timeout, 0); error_num= parse.fail(true); goto error; @@ -1186,10 +1153,7 @@ int spider_udf_parse_direct_sql_param( error_num= parse.fail(true); goto error; case 14: -#if MYSQL_VERSION_ID < 50500 -#else SPIDER_PARAM_INT_WITH_MAX("use_real_table", use_real_table, 0, 1); -#endif error_num= parse.fail(true); goto error; case 15: @@ -1394,14 +1358,11 @@ void spider_udf_free_direct_sql_alloc( pthread_mutex_unlock(direct_sql->bg_mutex); } #endif -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used && direct_sql->open_tables_thd) { spider_sys_close_table(direct_sql->open_tables_thd, &direct_sql->open_tables_backup); } -#endif if (direct_sql->server_name) { spider_free(spider_current_trx, direct_sql->server_name, MYF(0)); @@ -1485,11 +1446,8 @@ long long spider_direct_sql_body( char *sql; TABLE_LIST table_list; SPIDER_BG_DIRECT_SQL *bg_direct_sql; -#if MYSQL_VERSION_ID < 50500 -#else TABLE_LIST *real_table_list_last = NULL; uint use_real_table = 0; -#endif DBUG_ENTER("spider_direct_sql_body"); SPIDER_BACKUP_DASTATUS; if (!(direct_sql = (SPIDER_DIRECT_SQL *) @@ -1580,11 +1538,8 @@ long long spider_direct_sql_body( #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } #endif -#if MYSQL_VERSION_ID < 50500 -#else use_real_table = spider_param_udf_ds_use_real_table(thd, direct_sql->use_real_table); -#endif for (roop_count = 0; roop_count < direct_sql->table_count; roop_count++) { #ifdef SPIDER_NEED_INIT_ONE_TABLE_FOR_FIND_TEMPORARY_TABLE @@ -1615,19 +1570,14 @@ long long spider_direct_sql_body( if (!(direct_sql->tables[roop_count] = spider_find_temporary_table(thd, &table_list))) { -#if MYSQL_VERSION_ID < 50500 -#else if (!use_real_table) { -#endif error_num = ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM; my_printf_error(ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM, ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_STR, MYF(0), SPIDER_TABLE_LIST_db_str(&table_list), SPIDER_TABLE_LIST_table_name_str(&table_list)); goto error; -#if MYSQL_VERSION_ID < 50500 -#else } TABLE_LIST *tables = &direct_sql->table_list[roop_count]; tables->mdl_request.init(MDL_key::TABLE, @@ -1643,7 +1593,6 @@ long long spider_direct_sql_body( real_table_list_last = tables; spider_set_bit(direct_sql->real_table_bitmap, roop_count); direct_sql->real_table_used = TRUE; -#endif } } if ((error_num = spider_udf_direct_sql_create_conn_key(direct_sql))) @@ -1760,22 +1709,14 @@ my_bool spider_direct_sql_init_body( strcpy(message, "spider_bg_direct_sql() out of memory"); goto error; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_direct_sql, &bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) -#endif { strcpy(message, "spider_bg_direct_sql() out of memory"); goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&bg_direct_sql->bg_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_direct_sql, &bg_direct_sql->bg_cond, NULL)) -#endif { strcpy(message, "spider_bg_direct_sql() out of memory"); goto error_cond_init; diff --git a/storage/spider/spd_environ.h b/storage/spider/spd_environ.h index 728cc7e1781..5a6b824fd30 100644 --- a/storage/spider/spd_environ.h +++ b/storage/spider/spd_environ.h @@ -19,16 +19,11 @@ #ifndef SPD_ENVIRON_INCLUDED -#if (defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000) #define SPIDER_HANDLER_START_BULK_INSERT_HAS_FLAGS -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE #define SPIDER_NET_HAS_THD -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100211 #define HANDLER_HAS_TOP_TABLE_FIELDS #define HANDLER_HAS_DIRECT_UPDATE_ROWS #define HANDLER_HAS_DIRECT_AGGREGATE @@ -37,20 +32,13 @@ #define HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN #define HANDLER_HAS_NEED_INFO_FOR_AUTO_INC #define HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100300 #define SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100309 #define SPIDER_MDEV_16246 -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 #define SPIDER_USE_CONST_ITEM_FOR_STRING_INT_REAL_DECIMAL_DATE_ITEM #define SPIDER_SQL_CACHE_IS_IN_LEX #define SPIDER_LIKE_FUNC_HAS_GET_NEGATED #define HA_HAS_CHECKSUM_EXTENDED -#endif #endif /* SPD_ENVIRON_INCLUDED */ diff --git a/storage/spider/spd_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index 2985c9f1302..167f8c3adff 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -17,17 +17,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_select.h" #include "ha_partition.h" -#endif #include "sql_common.h" #include #include "spd_err.h" diff --git a/storage/spider/spd_i_s.cc b/storage/spider/spd_i_s.cc index c43c666601f..c4d66f01fb6 100644 --- a/storage/spider/spd_i_s.cc +++ b/storage/spider/spd_i_s.cc @@ -17,16 +17,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_show.h" -#endif #include "spd_db_include.h" #include "spd_include.h" #include "spd_table.h" @@ -144,12 +139,9 @@ struct st_mysql_plugin spider_i_s_alloc_mem = NULL, NULL, NULL, -#if MYSQL_VERSION_ID >= 50600 0, -#endif }; -#ifdef MARIADB_BASE_VERSION struct st_maria_plugin spider_i_s_alloc_mem_maria = { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -166,4 +158,3 @@ struct st_maria_plugin spider_i_s_alloc_mem_maria = "1.0", MariaDB_PLUGIN_MATURITY_STABLE, }; -#endif diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 51fac2a4cea..76844b6b428 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -17,11 +17,6 @@ #define SPIDER_DETAIL_VERSION "3.3.15" #define SPIDER_HEX_VERSION 0x0303 -#if MYSQL_VERSION_ID < 50500 -#define spider_my_free(A,B) my_free(A,B) -#define pthread_mutex_assert_owner(A) -#define pthread_mutex_assert_not_owner(A) -#else #define spider_my_free(A,B) my_free(A) #ifdef pthread_mutex_t #undef pthread_mutex_t @@ -70,129 +65,50 @@ #endif #define pthread_cond_destroy mysql_cond_destroy #define my_sprintf(A,B) sprintf B -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define spider_stmt_da_message(A) thd_get_error_message(A) #define spider_stmt_da_sql_errno(A) thd_get_error_number(A) #define spider_user_defined_key_parts(A) (A)->user_defined_key_parts #define spider_join_table_count(A) (A)->table_count #define SPIDER_CAN_BG_UPDATE (1LL << 39) -#if MYSQL_VERSION_ID >= 100304 #define SPIDER_ALTER_PARTITION_ADD ALTER_PARTITION_ADD #define SPIDER_ALTER_PARTITION_DROP ALTER_PARTITION_DROP #define SPIDER_ALTER_PARTITION_COALESCE ALTER_PARTITION_COALESCE #define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_PARTITION_REORGANIZE #define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_PARTITION_TABLE_REORG #define SPIDER_ALTER_PARTITION_REBUILD ALTER_PARTITION_REBUILD -#else -#define SPIDER_ALTER_PARTITION_ADD Alter_info::ALTER_ADD_PARTITION -#define SPIDER_ALTER_PARTITION_DROP Alter_info::ALTER_DROP_PARTITION -#define SPIDER_ALTER_PARTITION_COALESCE Alter_info::ALTER_COALESCE_PARTITION -#define SPIDER_ALTER_PARTITION_REORGANIZE Alter_info::ALTER_REORGANIZE_PARTITION -#define SPIDER_ALTER_PARTITION_TABLE_REORG Alter_info::ALTER_TABLE_REORG -#define SPIDER_ALTER_PARTITION_REBUILD Alter_info::ALTER_REBUILD_PARTITION -#endif #define SPIDER_WARN_LEVEL_WARN Sql_condition::WARN_LEVEL_WARN #define SPIDER_WARN_LEVEL_NOTE Sql_condition::WARN_LEVEL_NOTE #define SPIDER_THD_KILL_CONNECTION KILL_CONNECTION -#else -#if MYSQL_VERSION_ID < 50500 -#define spider_stmt_da_message(A) (A)->main_da.message() -#define spider_stmt_da_sql_errno(A) (A)->main_da.sql_errno() -#else -#if MYSQL_VERSION_ID < 50600 -#define spider_stmt_da_message(A) (A)->stmt_da->message() -#define spider_stmt_da_sql_errno(A) (A)->stmt_da->sql_errno() -#else -#define spider_stmt_da_message(A) (A)->get_stmt_da()->message() -#define spider_stmt_da_sql_errno(A) (A)->get_stmt_da()->sql_errno() -#endif -#endif -#define spider_user_defined_key_parts(A) (A)->key_parts -#define spider_join_table_count(A) (A)->tables -#define SPIDER_ALTER_PARTITION_ADD ALTER_ADD_PARTITION -#define SPIDER_ALTER_PARTITION_DROP ALTER_DROP_PARTITION -#define SPIDER_ALTER_PARTITION_COALESCE ALTER_COALESCE_PARTITION -#define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_REORGANIZE_PARTITION -#define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_TABLE_REORG -#define SPIDER_ALTER_PARTITION_REBUILD ALTER_REBUILD_PARTITION -#define SPIDER_WARN_LEVEL_WARN MYSQL_ERROR::WARN_LEVEL_WARN -#define SPIDER_WARN_LEVEL_NOTE MYSQL_ERROR::WARN_LEVEL_NOTE -#define SPIDER_THD_KILL_CONNECTION THD::KILL_CONNECTION -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100005 #define SPIDER_HAS_EXPLAIN_QUERY -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100009 #define SPIDER_TEST(A) MY_TEST(A) -#else -#define SPIDER_TEST(A) test(A) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR #define SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #define SPIDER_XID_USES_xid_cache_iterate -#else -#define SPIDER_XID_STATE_HAS_in_thd -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108 #define SPIDER_Item_args_arg_count_IS_PROTECTED -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100112 #define SPIDER_Item_func_conv_charset_conv_charset collation.collation -#else -#define SPIDER_Item_func_conv_charset_conv_charset conv_charset -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 #define SPIDER_WITHOUT_HA_STATISTIC_INCREMENT #define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,E,F,G,H) #define SPIDER_HAS_NEXT_THREAD_ID #define SPIDER_new_THD(A) (new THD(A)) #define SPIDER_order_direction_is_asc(A) (A->direction == ORDER::ORDER_ASC) -#else -#define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,F,G,H) -#define SPIDER_new_THD(A) (new THD()) -#define SPIDER_order_direction_is_asc(A) (A->asc) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100201 #define SPIDER_HAS_MY_CHARLEN #define SPIDER_open_temporary_table -#endif -#if defined(MARIADB_BASE_VERSION) -#if MYSQL_VERSION_ID >= 100209 #define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,E,F,G) -#elif MYSQL_VERSION_ID >= 100200 -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,D,E,F,G,H) -#elif MYSQL_VERSION_ID >= 100007 -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G,H) -#else -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G) -#endif -#else -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100209 #define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,B,C,D,E,F) #define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,B,C,D,E,F) #define SPIDER_free_part_syntax(A,B) -#else -#define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,C,D,E,F) -#define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,C,D,E,F) -#define SPIDER_free_part_syntax(A,B) spider_my_free(A,B) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100306 #define SPIDER_read_record_read_record(A) read_record() #define SPIDER_has_Item_with_subquery #define SPIDER_use_LEX_CSTRING_for_KEY_Field_name @@ -211,36 +127,12 @@ #define SPIDER_item_name_str(A) (A)->name.str #define SPIDER_item_name_length(A) (A)->name.length const LEX_CSTRING SPIDER_empty_string = {"", 0}; -#else -#define SPIDER_read_record_read_record(A) read_record(A) -#define SPIDER_THD_db_str(A) (A)->db -#define SPIDER_THD_db_length(A) (A)->db_length -#define SPIDER_TABLE_LIST_db_str(A) (A)->db -#define SPIDER_TABLE_LIST_db_length(A) (A)->db_length -#define SPIDER_TABLE_LIST_table_name_str(A) (A)->table_name -#define SPIDER_TABLE_LIST_table_name_length(A) (A)->table_name_length -#define SPIDER_TABLE_LIST_alias_str(A) (A)->alias -#define SPIDER_TABLE_LIST_alias_length(A) strlen((A)->alias) -#define SPIDER_field_name_str(A) (A)->field_name -#define SPIDER_field_name_length(A) strlen((A)->field_name) -#define SPIDER_item_name_str(A) (A)->name -#define SPIDER_item_name_length(A) strlen((A)->name) -const char SPIDER_empty_string = ""; -#endif -#if MYSQL_VERSION_ID >= 50500 #define SPIDER_HAS_HASH_VALUE_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 #define SPIDER_date_mode_t(A) date_mode_t(A) #define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime_or_date(A,B,C,D,E) #define SPIDER_get_linkage(A) A->get_linkage() -#else -#define SPIDER_date_mode_t(A) A -#define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime(A,B,C,D,E) -#define SPIDER_get_linkage(A) A->linkage -#endif #define spider_bitmap_size(A) ((A + 7) / 8) #define spider_set_bit(BITMAP, BIT) \ @@ -1501,8 +1393,6 @@ typedef struct st_spider_direct_sql TABLE **tables; int *iop; -#if MYSQL_VERSION_ID < 50500 -#else /* for using real table */ bool real_table_used; TABLE_LIST *table_list_first; @@ -1510,7 +1400,6 @@ typedef struct st_spider_direct_sql uchar *real_table_bitmap; Open_tables_backup open_tables_backup; THD *open_tables_thd; -#endif char *sql; ulong sql_length; @@ -1530,10 +1419,7 @@ typedef struct st_spider_direct_sql #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) int access_mode; #endif -#if MYSQL_VERSION_ID < 50500 -#else int use_real_table; -#endif int error_rw_mode; char *server_name; diff --git a/storage/spider/spd_malloc.cc b/storage/spider/spd_malloc.cc index f43131d630d..a4aec9a3712 100644 --- a/storage/spider/spd_malloc.cc +++ b/storage/spider/spd_malloc.cc @@ -18,15 +18,10 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_analyse.h" -#endif #include "spd_db_include.h" #include "spd_include.h" #include "spd_malloc.h" diff --git a/storage/spider/spd_param.cc b/storage/spider/spd_param.cc index 5c86af68c0a..ce87afbdee7 100644 --- a/storage/spider/spd_param.cc +++ b/storage/spider/spd_param.cc @@ -38,15 +38,10 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" -#endif #include #include "spd_err.h" #include "spd_db_include.h" @@ -56,9 +51,7 @@ #include "spd_trx.h" extern struct st_mysql_plugin spider_i_s_alloc_mem; -#ifdef MARIADB_BASE_VERSION extern struct st_maria_plugin spider_i_s_alloc_mem_maria; -#endif extern volatile ulonglong spider_mon_table_cache_version; extern volatile ulonglong spider_mon_table_cache_version_req; @@ -231,13 +224,8 @@ struct st_mysql_show_var spider_status_variables[] = }; typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int); -#if MYSQL_VERSION_ID < 50500 -extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, - const char *name, long long val); -#else extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, bool is_unsignd, longlong v); -#endif static my_bool spider_support_xa; static MYSQL_SYSVAR_BOOL( @@ -700,14 +688,9 @@ static int spider_param_semi_table_lock_check( (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz; options.arg_type = REQUIRED_ARG; *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed); -#if MYSQL_VERSION_ID < 50500 - DBUG_RETURN(throw_bounds_warning(thd, fixed, FALSE, - ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, (long long) tmp)); -#else DBUG_RETURN(throw_bounds_warning(thd, ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, (longlong) tmp)); -#endif } /* @@ -758,14 +741,9 @@ static int spider_param_semi_table_lock_connection_check( (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz; options.arg_type = REQUIRED_ARG; *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed); -#if MYSQL_VERSION_ID < 50500 - DBUG_RETURN(throw_bounds_warning(thd, fixed, FALSE, - ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, (long long) tmp)); -#else DBUG_RETURN(throw_bounds_warning(thd, ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, (longlong) tmp)); -#endif } /* @@ -1738,7 +1716,6 @@ SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, udf_ds_table_loop_mode) static char *spider_remote_access_charset; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_access_charset, spider_remote_access_charset, @@ -1749,30 +1726,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_access_charset, - spider_remote_access_charset, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote access charset at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_access_charset, - spider_remote_access_charset, - PLUGIN_VAR_RQCMDARG, - "Set remote access charset at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char*, remote_access_charset) @@ -1800,7 +1753,6 @@ SPIDER_SYSVAR_VALUE_FUNC(int, remote_autocommit) static char *spider_remote_time_zone; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_time_zone, spider_remote_time_zone, @@ -1811,30 +1763,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_time_zone, - spider_remote_time_zone, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote time_zone at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_time_zone, - spider_remote_time_zone, - PLUGIN_VAR_RQCMDARG, - "Set remote time_zone at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char *, remote_time_zone) @@ -1885,7 +1813,6 @@ SPIDER_SYSVAR_VALUE_FUNC(int, remote_trx_isolation) static char *spider_remote_default_database; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_default_database, spider_remote_default_database, @@ -1896,30 +1823,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_default_database, - spider_remote_default_database, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote database at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_default_database, - spider_remote_default_database, - PLUGIN_VAR_RQCMDARG, - "Set remote database at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char *, remote_default_database) @@ -1973,7 +1876,6 @@ int spider_param_connect_retry_count( /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_THDVAR_STR( bka_engine, /* name */ PLUGIN_VAR_MEMALLOC | @@ -1983,28 +1885,6 @@ static MYSQL_THDVAR_STR( NULL, /* update */ NULL /* def */ ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_THDVAR_STR( - bka_engine, /* name */ - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Temporary table's engine for BKA", /* comment */ - NULL, /* check */ - NULL, /* update */ - NULL /* def */ -); -#else -static MYSQL_THDVAR_STR( - bka_engine, /* name */ - PLUGIN_VAR_RQCMDARG, - "Temporary table's engine for BKA", /* comment */ - NULL, /* check */ - NULL, /* update */ - NULL /* def */ -); -#endif -#endif char *spider_param_bka_engine( THD *thd, @@ -2365,8 +2245,6 @@ static MYSQL_SYSVAR_INT( SPIDER_SYSVAR_OVERRIDE_VALUE_FUN(int, bulk_access_free) #endif -#if MYSQL_VERSION_ID < 50500 -#else /* -1 :fallback to default 0 :can not use @@ -2385,7 +2263,6 @@ static MYSQL_THDVAR_INT( ); SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, udf_ds_use_real_table) -#endif static my_bool spider_general_log; static MYSQL_SYSVAR_BOOL( @@ -2950,10 +2827,7 @@ static struct st_mysql_sys_var* spider_system_variables[] = { #ifdef HA_CAN_BULK_ACCESS MYSQL_SYSVAR(bulk_access_free), #endif -#if MYSQL_VERSION_ID < 50500 -#else MYSQL_SYSVAR(udf_ds_use_real_table), -#endif MYSQL_SYSVAR(general_log), MYSQL_SYSVAR(index_hint_pushdown), MYSQL_SYSVAR(max_connections), @@ -2993,14 +2867,11 @@ mysql_declare_plugin(spider) spider_status_variables, spider_system_variables, NULL, -#if MYSQL_VERSION_ID >= 50600 0, -#endif }, spider_i_s_alloc_mem mysql_declare_plugin_end; -#ifdef MARIADB_BASE_VERSION maria_declare_plugin(spider) { MYSQL_STORAGE_ENGINE_PLUGIN, @@ -3019,4 +2890,3 @@ maria_declare_plugin(spider) }, spider_i_s_alloc_mem_maria maria_declare_plugin_end; -#endif diff --git a/storage/spider/spd_param.h b/storage/spider/spd_param.h index 9ffb9e8c278..e4f5fde1110 100644 --- a/storage/spider/spd_param.h +++ b/storage/spider/spd_param.h @@ -371,13 +371,10 @@ int spider_param_bulk_access_free( int bulk_access_free ); #endif -#if MYSQL_VERSION_ID < 50500 -#else int spider_param_udf_ds_use_real_table( THD *thd, int udf_ds_use_real_table ); -#endif my_bool spider_param_general_log(); my_bool spider_param_index_hint_pushdown( THD *thd diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index 92f5ff9e69f..4d2c826aa28 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -17,16 +17,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_acl.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -326,11 +321,7 @@ int spider_get_ping_table_mon( ) { int error_num; TABLE *table_link_mon = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif char table_key[MAX_KEY_LENGTH]; SPIDER_TABLE_MON *table_mon, *table_mon_prev = NULL; SPIDER_SHARE *tmp_share; @@ -519,11 +510,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( int *error_num ) { TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif char table_key[MAX_KEY_LENGTH]; SPIDER_TABLE_MON_LIST *table_mon_list = NULL; @@ -632,43 +619,26 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( if (tmp_share->link_statuses[0] == SPIDER_LINK_STATUS_NG) table_mon_list->mon_status = SPIDER_LINK_MON_NG; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_caller, &table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_caller_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_receptor, &table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_receptor_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_monitor, &table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_monitor_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->update_status_mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_update_status, &table_mon_list->update_status_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_update_status_mutex_init; @@ -741,13 +711,8 @@ int spider_get_ping_table_gtid_pos( int error_num, source_link_idx, need_mon; char table_key[MAX_KEY_LENGTH]; TABLE *table_tables, *table_gtid_pos; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup_tables; - Open_tables_state open_tables_backup_gtid_pos; -#else Open_tables_backup open_tables_backup_tables; Open_tables_backup open_tables_backup_gtid_pos; -#endif MEM_ROOT mem_root; long link_status; long monitoring_binlog_pos_at_failing; @@ -899,11 +864,7 @@ int spider_init_ping_table_mon_cache( ) { int error_num, same; TABLE *table_link_mon = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif SPIDER_MON_KEY mon_key; DBUG_ENTER("spider_init_ping_table_mon_cache"); @@ -1101,23 +1062,14 @@ long long spider_ping_table_body( conv_name.init_calc_mem(SPD_MID_PING_TABLE_BODY_1); tmp_str.init_calc_mem(SPD_MID_PING_TABLE_BODY_2); conv_name.length(0); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 server_id = global_system_variables.server_id; -#else - server_id = thd->server_id; -#endif if ( thd->open_tables != 0 || thd->handler_tables_hash.records != 0 || thd->derived_tables != 0 || thd->lock != 0 || -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables != 0 || - thd->prelocked_mode != NON_PRELOCKED -#else thd->locked_tables_list.locked_tables() || thd->locked_tables_mode != LTM_NONE -#endif ) { if (thd->open_tables != 0) { @@ -1140,18 +1092,6 @@ long long spider_ping_table_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), "thd->lock", thd->lock); -#if MYSQL_VERSION_ID < 50500 - } else if (thd->locked_tables != 0) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), - "thd->locked_tables", thd->locked_tables); - } else if (thd->prelocked_mode != NON_PRELOCKED) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), - "thd->prelocked_mode", (longlong) thd->prelocked_mode); -#else } else if (thd->locked_tables_list.locked_tables()) { my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, @@ -1163,7 +1103,6 @@ long long spider_ping_table_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), "thd->locked_tables_mode", (longlong) thd->locked_tables_mode); -#endif } goto error; } diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc index 10f9fdedd5b..a0440c294c2 100644 --- a/storage/spider/spd_sys_table.cc +++ b/storage/spider/spd_sys_table.cc @@ -17,17 +17,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "key.h" #include "sql_base.h" #include "tztime.h" -#endif #include "sql_select.h" #include "spd_err.h" #include "spd_param.h" @@ -121,17 +116,6 @@ inline int spider_delete_sys_table_row(TABLE *table, int record_number = 0, return error_num; } -#if MYSQL_VERSION_ID < 50500 -TABLE *spider_open_sys_table( - THD *thd, - const char *table_name, - int table_name_length, - bool write, - Open_tables_state *open_tables_backup, - bool need_lock, - int *error_num -) -#else TABLE *spider_open_sys_table( THD *thd, const char *table_name, @@ -141,26 +125,11 @@ TABLE *spider_open_sys_table( bool need_lock, int *error_num ) -#endif { TABLE *table; TABLE_LIST tables; -#if MYSQL_VERSION_ID < 50500 - TABLE_SHARE *table_share; - char table_key[MAX_DBKEY_LENGTH]; - uint table_key_length; -#endif DBUG_ENTER("spider_open_sys_table"); -#if MYSQL_VERSION_ID < 50500 - memset(&tables, 0, sizeof(TABLE_LIST)); - SPIDER_TABLE_LIST_db_str(&tables) = (char*)"mysql"; - SPIDER_TABLE_LIST_db_length(&tables) = sizeof("mysql") - 1; - SPIDER_TABLE_LIST_alias_str(&tables) = - SPIDER_TABLE_LIST_table_name_str(&tables) = (char *) table_name; - SPIDER_TABLE_LIST_table_name_length(&tables) = table_name_length; - tables.lock_type = (write ? TL_WRITE : TL_READ); -#else #ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias LEX_CSTRING db_name = { @@ -178,18 +147,8 @@ TABLE *spider_open_sys_table( "mysql", sizeof("mysql") - 1, table_name, table_name_length, table_name, (write ? TL_WRITE : TL_READ)); #endif -#endif -#if MYSQL_VERSION_ID < 50500 - if (need_lock) - { -#endif -#if MYSQL_VERSION_ID < 50500 - if (!(table = open_performance_schema_table(thd, &tables, - open_tables_backup))) -#else if (!(table = spider_sys_open_table(thd, &tables, open_tables_backup))) -#endif { my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM, ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0), @@ -197,38 +156,6 @@ TABLE *spider_open_sys_table( *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM; DBUG_RETURN(NULL); } -#if MYSQL_VERSION_ID < 50500 - } else { - thd->reset_n_backup_open_tables_state(open_tables_backup); - - if (!(table = (TABLE*) spider_malloc(spider_current_trx, SPD_MID_OPEN_SYS_TABLE_1, - sizeof(*table), MYF(MY_WME)))) - { - *error_num = HA_ERR_OUT_OF_MEM; - goto error_malloc; - } - - table_key_length = - create_table_def_key(thd, table_key, &tables, FALSE); - - if (!(table_share = get_table_share(thd, - &tables, table_key, table_key_length, 0, error_num))) - goto error; - if (open_table_from_share(thd, table_share, tables.alias, - (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX), - READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD, - (uint) HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_FROM_SQL_LAYER, - table, FALSE) - ) { - release_table_share(table_share, RELEASE_NORMAL); - my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM, - ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0), - "mysql", table_name); - *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM; - goto error; - } - } -#endif switch (table_name_length) { case 9: @@ -370,51 +297,22 @@ TABLE *spider_open_sys_table( } DBUG_RETURN(table); -#if MYSQL_VERSION_ID < 50500 -error: - spider_free(spider_current_trx, table, MYF(0)); -error_malloc: - thd->restore_backup_open_tables_state(open_tables_backup); -#endif error_col_num_chk: DBUG_RETURN(NULL); } -#if MYSQL_VERSION_ID < 50500 -void spider_close_sys_table( - THD *thd, - TABLE *table, - Open_tables_state *open_tables_backup, - bool need_lock -) -#else void spider_close_sys_table( THD *thd, TABLE *table, Open_tables_backup *open_tables_backup, bool need_lock ) -#endif { DBUG_ENTER("spider_close_sys_table"); -#if MYSQL_VERSION_ID < 50500 - if (need_lock) - { - close_performance_schema_table(thd, open_tables_backup); - } else { - table->file->ha_reset(); - closefrm(table, TRUE); - spider_free(spider_current_trx, table, MYF(0)); - thd->restore_backup_open_tables_state(open_tables_backup); - } -#else spider_sys_close_table(thd, open_tables_backup); -#endif DBUG_VOID_RETURN; } -#if MYSQL_VERSION_ID < 50500 -#else bool spider_sys_open_tables( THD *thd, TABLE_LIST **tables, @@ -467,7 +365,6 @@ void spider_sys_close_table( thd->restore_backup_open_tables_state(open_tables_backup); DBUG_VOID_RETURN; } -#endif int spider_sys_index_init( TABLE *table, @@ -512,15 +409,9 @@ int spider_check_sys_table( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[0], 0, (uchar *) table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[0], 0, (uchar *) table_key, - HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#endif } int spider_check_sys_table_with_find_flag( @@ -536,15 +427,9 @@ int spider_check_sys_table_with_find_flag( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[0], 0, (uchar *) table_key, HA_WHOLE_KEY, find_flag)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[0], 0, (uchar *) table_key, - HA_WHOLE_KEY, find_flag)); -#endif } int spider_check_sys_table_for_update_all_columns( @@ -559,15 +444,9 @@ int spider_check_sys_table_for_update_all_columns( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[1], 0, (uchar *) table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[1], 0, (uchar *) table_key, - HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#endif } /* @@ -607,15 +486,9 @@ int spider_get_sys_table_by_idx( key_length); if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_read_map( table->record[0], (uchar *) table_key, make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#else - (error_num = table->file->index_read_map( - table->record[0], (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -628,17 +501,10 @@ int spider_sys_index_next_same( char *table_key ) { DBUG_ENTER("spider_sys_index_next_same"); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_next_same( table->record[0], (const uchar*) table_key, table->key_info->key_length)); -#else - DBUG_RETURN(table->file->index_next_same( - table->record[0], - (const uchar*) table_key, - table->key_info->key_length)); -#endif } int spider_sys_index_first( @@ -651,11 +517,7 @@ int spider_sys_index_first( DBUG_RETURN(error_num); if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_first(table->record[0])) -#else - (error_num = table->file->index_first(table->record[0])) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -673,11 +535,7 @@ int spider_sys_index_last( DBUG_RETURN(error_num); if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_last(table->record[0])) -#else - (error_num = table->file->index_last(table->record[0])) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -689,11 +547,7 @@ int spider_sys_index_next( TABLE *table ) { DBUG_ENTER("spider_sys_index_next"); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_next(table->record[0])); -#else - DBUG_RETURN(table->file->index_next(table->record[0])); -#endif } void spider_store_xa_pk( @@ -1412,11 +1266,6 @@ int spider_log_tables_link_failed( table->use_all_columns(); spider_store_tables_name(table, name, name_length); spider_store_tables_link_idx(table, link_idx); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->field[3] == table->timestamp_field) - table->timestamp_field->set_time(); -#endif if ((error_num = spider_write_sys_table_row(table))) { DBUG_RETURN(error_num); @@ -1449,11 +1298,6 @@ int spider_log_xa_failed( (uint) strlen(status), system_charset_info); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->field[20] == table->timestamp_field) - table->timestamp_field->set_time(); -#endif if ((error_num = spider_write_sys_table_row(table))) { DBUG_RETURN(error_num); @@ -2385,11 +2229,7 @@ int spider_sys_update_tables_link_status( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_sys_update_tables_link_status"); if ( !(table_tables = spider_open_sys_table( @@ -2423,11 +2263,7 @@ int spider_sys_log_tables_link_failed( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_sys_log_tables_link_failed"); if ( !(table_tables = spider_open_sys_table( @@ -2462,11 +2298,7 @@ int spider_sys_log_xa_failed( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_sys_log_xa_failed"); if ( !(table_tables = spider_open_sys_table( @@ -2802,12 +2634,8 @@ int spider_sys_replace( if (table->file->ha_table_flags() & HA_DUPLICATE_POS) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = table->file->ha_rnd_pos(table->record[1], table->file->dup_ref); -#else - error_num = table->file->rnd_pos(table->record[1], table->file->dup_ref); -#endif if (error_num) { if (error_num == HA_ERR_RECORD_DELETED) @@ -2820,13 +2648,8 @@ int spider_sys_replace( key_copy((uchar*)table_key, table->record[0], table->key_info + key_num, 0); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = table->file->ha_index_read_idx_map(table->record[1], key_num, (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT); -#else - error_num = table->file->index_read_idx_map(table->record[1], key_num, - (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT); -#endif if (error_num) { if (error_num == HA_ERR_RECORD_DELETED) diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h index fca38c67683..f0d0d19439e 100644 --- a/storage/spider/spd_sys_table.h +++ b/storage/spider/spd_sys_table.h @@ -68,24 +68,6 @@ public: uint link_id_length; }; -#if MYSQL_VERSION_ID < 50500 -TABLE *spider_open_sys_table( - THD *thd, - const char *table_name, - int table_name_length, - bool write, - Open_tables_state *open_tables_backup, - bool need_lock, - int *error_num -); - -void spider_close_sys_table( - THD *thd, - TABLE *table, - Open_tables_state *open_tables_backup, - bool need_lock -); -#else TABLE *spider_open_sys_table( THD *thd, const char *table_name, @@ -119,7 +101,6 @@ void spider_sys_close_table( THD *thd, Open_tables_backup *open_tables_backup ); -#endif int spider_sys_index_init( TABLE *table, diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 610fbeda1f3..60e1ce6bad2 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "my_getopt.h" @@ -31,7 +27,6 @@ #include "sql_select.h" #include "tztime.h" #include "sql_parse.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -3612,11 +3607,7 @@ int spider_set_connect_info_default( if (share->monitoring_limit[roop_count] == -1) share->monitoring_limit[roop_count] = 1; if (share->monitoring_sid[roop_count] == -1) -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 share->monitoring_sid[roop_count] = global_system_variables.server_id; -#else - share->monitoring_sid[roop_count] = current_thd->server_id; -#endif #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (share->hs_read_ports[roop_count] == -1) @@ -4257,34 +4248,22 @@ SPIDER_SHARE *spider_create_share( if (share->table_count_mode & 2) share->additional_table_flags |= HA_HAS_RECORDS; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share, &share->mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->sts_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_sts, &share->sts_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_sts_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->crd_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_crd, &share->crd_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_crd_mutex; @@ -4411,11 +4390,7 @@ SPIDER_SHARE *spider_get_share( int semi_table_lock_conn; int search_link_idx; uint sql_command = thd_sql_command(thd); -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif MEM_ROOT mem_root; TABLE *table_tables = NULL; bool init_mem_root = FALSE; @@ -5714,13 +5689,8 @@ SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( lgtm_tblhnd_share->table_path_hash_value = hash_value; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&lgtm_tblhnd_share->auto_increment_mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_auto_increment, &lgtm_tblhnd_share->auto_increment_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_auto_increment_mutex; @@ -5830,35 +5800,22 @@ SPIDER_PARTITION_SHARE *spider_get_pt_share( partition_share->crd_get_time = partition_share->sts_get_time = share->crd_get_time; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&partition_share->sts_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_pt_share_sts, &partition_share->sts_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_sts_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&partition_share->crd_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_pt_share_crd, &partition_share->crd_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_crd_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&partition_share->pt_handler_mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_pt_handler, &partition_share->pt_handler_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_pt_handler_mutex; @@ -6012,11 +5969,7 @@ int spider_open_all_tables( long *long_info; longlong *longlong_info; MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_open_all_tables"); if ( !(table_tables = spider_open_sys_table( @@ -6722,13 +6675,8 @@ int spider_db_init( GetProcAddress(current_module, "?xid_cache@@3PAUst_hash@@A")); #else spd_db_att_LOCK_xid_cache = (pthread_mutex_t *) -#if MYSQL_VERSION_ID < 50500 - GetProcAddress(current_module, - "?LOCK_xid_cache@@3U_RTL_CRITICAL_SECTION@@A"); -#else GetProcAddress(current_module, "?LOCK_xid_cache@@3Ust_mysql_mutex@@A"); -#endif spd_db_att_xid_cache = (HASH *) GetProcAddress(current_module, "?xid_cache@@3Ust_hash@@A"); #endif @@ -6788,117 +6736,61 @@ int spider_db_init( */ #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_tbl_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_tbl, &spider_tbl_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_tbl_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_thread_id, &spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_thread_id_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_conn_id, &spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_conn_id_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_ipport_count, &spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_ipport_count_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_init_error_tbl, &spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_init_error_tbl_mutex_init; #ifdef WITH_PARTITION_STORAGE_ENGINE -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_pt_share_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_pt_share, &spider_pt_share_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_pt_share_mutex_init; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_lgtm_tblhnd_share, &spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_lgtm_tblhnd_share_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_conn, &spider_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_conn_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_open_conn, &spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_open_conn_mutex_init; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_hs_r_conn, &spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_hs_r_conn_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_hs_w_conn, &spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_hs_w_conn_mutex_init; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_allocated_thds, &spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_allocated_thds_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_table_cache, &spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_mon_table_cache_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mem_calc, &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_mem_calc_mutex_init; if (my_hash_init(&spider_open_tables, spd_charset_utf8_bin, 32, 0, 0, @@ -7011,25 +6903,16 @@ int spider_db_init( roop_count < (int) spider_param_udf_table_mon_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_udf_table_mon_mutexes[roop_count], - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_udf_table_mon, &spider_udf_table_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST)) -#endif goto error_init_udf_table_mon_mutex; } for (roop_count = 0; roop_count < (int) spider_param_udf_table_mon_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_udf_table_mon_conds[roop_count], NULL)) -#else if (mysql_cond_init(spd_key_cond_udf_table_mon, &spider_udf_table_mon_conds[roop_count], NULL)) -#endif goto error_init_udf_table_mon_cond; } for (roop_count = 0; @@ -8492,10 +8375,8 @@ bool spider_check_direct_order_limit( spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); bool first_check = TRUE; DBUG_PRINT("info",("spider select_lex=%p", select_lex)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 DBUG_PRINT("info",("spider leaf_tables.elements=%u", select_lex ? select_lex->leaf_tables.elements : 0)); -#endif if (select_lex && (select_lex->options & SELECT_DISTINCT)) { @@ -8508,22 +8389,16 @@ bool spider_check_direct_order_limit( DBUG_PRINT("info",("spider select_limit=%lld", select_limit)); DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit)); if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || #endif -#endif #ifdef SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT !spider->condition || #endif !select_lex || -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 select_lex->leaf_tables.elements != 1 || -#endif select_lex->table_list.elements != 1 ) { DBUG_PRINT("info",("spider first_check is FALSE")); @@ -8802,14 +8677,10 @@ int spider_set_direct_limit_offset( // contain where if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif spider->condition // conditions is null may be no where condition in rand_init ) @@ -8955,20 +8826,11 @@ ulong spider_calc_for_sort( double spider_rand( uint32 rand_source ) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 struct my_rnd_struct rand; -#else - struct rand_struct rand; -#endif DBUG_ENTER("spider_rand"); /* generate same as rand function for applications */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 my_rnd_init(&rand, (uint32) (rand_source * 65537L + 55555555L), (uint32) (rand_source * 268435457L)); -#else - randominit(&rand, (uint32) (rand_source * 65537L + 55555555L), - (uint32) (rand_source * 268435457L)); -#endif DBUG_RETURN(my_rnd(&rand)); } @@ -9499,46 +9361,27 @@ int spider_create_sts_threads( ) { int error_num; DBUG_ENTER("spider_create_sts_threads"); -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread->mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_stss, &spider_thread->mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_stss, &spider_thread->cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts_syncs, &spider_thread->sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&spider_thread->thread, &spider_pt_attr, - spider_table_bg_sts_action, (void *) spider_thread) - ) -#else if (mysql_thread_create(spd_key_thd_bg_stss, &spider_thread->thread, &spider_pt_attr, spider_table_bg_sts_action, (void *) spider_thread) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -9586,46 +9429,27 @@ int spider_create_crd_threads( ) { int error_num; DBUG_ENTER("spider_create_crd_threads"); -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread->mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_crds, &spider_thread->mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crds, &spider_thread->cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd_syncs, &spider_thread->sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&spider_thread->thread, &spider_pt_attr, - spider_table_bg_crd_action, (void *) spider_thread) - ) -#else if (mysql_thread_create(spd_key_thd_bg_crds, &spider_thread->thread, &spider_pt_attr, spider_table_bg_crd_action, (void *) spider_thread) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index 29b5497dd81..bdea13e7d3b 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.cc @@ -18,16 +18,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "records.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -1194,13 +1189,8 @@ SPIDER_TRX *spider_get_trx( roop_count < (int) spider_param_udf_table_lock_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&trx->udf_table_mutexes[roop_count], - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_udf_table, &trx->udf_table_mutexes[roop_count], MY_MUTEX_INIT_FAST)) -#endif goto error_init_udf_table_mutex; } @@ -1898,17 +1888,10 @@ int spider_internal_start_trx( (trx->xid.data, "%lx%016llx", thd_get_thread_id(thd), thd->query_id)); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 trx->xid.bqual_length = my_sprintf(trx->xid.data + trx->xid.gtrid_length, (trx->xid.data + trx->xid.gtrid_length, "%lx", thd->variables.server_id)); -#else - trx->xid.bqual_length - = my_sprintf(trx->xid.data + trx->xid.gtrid_length, - (trx->xid.data + trx->xid.gtrid_length, "%x", - thd->server_id)); -#endif #ifdef SPIDER_XID_STATE_HAS_in_thd trx->internal_xid_state.in_thd = 1; @@ -2018,11 +2001,7 @@ int spider_internal_xa_commit( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_commit"); @@ -2206,11 +2185,7 @@ int spider_internal_xa_rollback( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool server_lost = FALSE; bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; @@ -2448,11 +2423,7 @@ int spider_internal_xa_prepare( int error_num; SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_prepare"); @@ -2623,11 +2594,7 @@ int spider_internal_xa_recover( int cnt = 0; char xa_key[MAX_KEY_LENGTH]; MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif DBUG_ENTER("spider_internal_xa_recover"); /* select @@ -2685,21 +2652,13 @@ int spider_initinal_xa_recover( static THD *thd = NULL; static TABLE *table_xa = NULL; static READ_RECORD *read_record = NULL; -#if MYSQL_VERSION_ID < 50500 - static Open_tables_state *open_tables_backup = NULL; -#else static Open_tables_backup *open_tables_backup = NULL; -#endif int cnt = 0; MEM_ROOT mem_root; DBUG_ENTER("spider_initinal_xa_recover"); if (!open_tables_backup) { -#if MYSQL_VERSION_ID < 50500 - if (!(open_tables_backup = new Open_tables_state)) -#else if (!(open_tables_backup = new Open_tables_backup)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_create_state; @@ -2810,11 +2769,7 @@ int spider_internal_xa_commit_by_xid( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_commit_by_xid"); @@ -3045,11 +3000,7 @@ int spider_internal_xa_rollback_by_xid( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else Open_tables_backup open_tables_backup; -#endif bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_rollback_by_xid"); @@ -4109,19 +4060,8 @@ THD *spider_create_tmp_thd() DBUG_ENTER("spider_create_tmp_thd"); if (!(thd = SPIDER_new_THD((my_thread_id) 0))) DBUG_RETURN(NULL); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 thd->killed = NOT_KILLED; -#else - thd->killed = THD::NOT_KILLED; -#endif -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables = FALSE; -#endif thd->proc_info = ""; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 -#else - thd->thread_id = thd->variables.pseudo_thread_id = 0; -#endif thd->thread_stack = (char*) &thd; if (thd->store_globals()) DBUG_RETURN(NULL); @@ -4134,11 +4074,7 @@ void spider_free_tmp_thd( ) { DBUG_ENTER("spider_free_tmp_thd"); thd->cleanup(); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 thd->reset_globals(); -#else - thd->restore_globals(); -#endif delete thd; DBUG_VOID_RETURN; } From 860c1ca9ad90654f5064796e0989f29dd3ac1b59 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 18 Mar 2024 13:11:49 +1100 Subject: [PATCH 075/159] MDEV-33679 Spider group by handler: skip on multiple equalities The spider group by handler is created in JOIN::make_aggr_tables_info(), by which time calls to substitute_for_best_equal_field() should have already removed all the multiple equalities (i.e. Item_equal, with MULT_EQUAL_FUNC func_type). Therefore, if there is still such items, it is deemed as an optimizer bug and should be skipped. --- .../spider/bugfix/r/mdev_33679.result | 27 +++++++++++++++++ .../spider/bugfix/t/mdev_33679.test | 29 +++++++++++++++++++ storage/spider/spd_db_mysql.cc | 22 ++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result new file mode 100644 index 00000000000..0a11fe429cb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result @@ -0,0 +1,27 @@ +# +# MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to () +# +for master_1 +for child2 +for child3 +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM; +CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM; +SET spider_same_server_link= on; +CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER; +CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL +, PRIMARY KEY (`a`) USING BTREE +) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER; +INSERT INTO t1_spider VALUES(1,'oooo'); +INSERT INTO t2_spider VALUES(1,1); +SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1; +a c +1 1 +Warnings: +Warning 1815 Internal error: Spider group by handler: Encountered multiple equalities, likely an optimizer bug +drop table t1, t2, t1_spider, t2_spider; +drop server srv; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test new file mode 100644 index 00000000000..eee47a21163 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test @@ -0,0 +1,29 @@ +--echo # +--echo # MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to () +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM; +CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM; +SET spider_same_server_link= on; +CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER; +CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL +, PRIMARY KEY (`a`) USING BTREE +) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER; +INSERT INTO t1_spider VALUES(1,'oooo'); +INSERT INTO t2_spider VALUES(1,1); +SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1; + +drop table t1, t2, t1_spider, t2_spider; +drop server srv; +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index c239baf636d..a2262956d44 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -5566,6 +5566,17 @@ int spider_db_mbase_util::check_item_func( if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); break; + case Item_func::MULT_EQUAL_FUNC: + /* If there is still Item_equal by the time of + JOIN::make_aggr_tables_info() where the spider group by handler + is created, it indicates a bug in the optimizer, because there + shouldn't be any. */ + push_warning_printf( + spider->trx->thd, SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR, + ER_THD(spider->trx->thd, ER_INTERNAL_ERROR), + "Spider group by handler: Encountered multiple equalities, likely " + "an optimizer bug"); + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); default: break; } @@ -6492,6 +6503,17 @@ int spider_db_mbase_util::print_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; + case Item_func::MULT_EQUAL_FUNC: + /* If there is still Item_equal by the time of + JOIN::make_aggr_tables_info() where the spider group by handler + is created, it indicates a bug in the optimizer, because there + shouldn't be any. */ + push_warning_printf( + spider->trx->thd, SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR, + ER_THD(spider->trx->thd, ER_INTERNAL_ERROR), + "Spider group by handler: Encountered multiple equalities, likely " + "an optimizer bug"); + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); default: THD *thd = spider->trx->thd; SPIDER_SHARE *share = spider->share; From e865ef6a04db3d54acd43b748633376f85a6689e Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 25 Mar 2024 14:06:27 +1100 Subject: [PATCH 076/159] MDEV-33742 Remove macro PARTITION_HAS_GET_CHILD_HANDLERS Similar to MDEV-27658. Also fixing the positioning of #ifdef WITH_PARTITION_STORAGE_ENGINE blocks and add missing ones. --- storage/spider/spd_environ.h | 1 - storage/spider/spd_group_by_handler.cc | 30 ++++++-------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/storage/spider/spd_environ.h b/storage/spider/spd_environ.h index 5a6b824fd30..247b3bc525f 100644 --- a/storage/spider/spd_environ.h +++ b/storage/spider/spd_environ.h @@ -27,7 +27,6 @@ #define HANDLER_HAS_TOP_TABLE_FIELDS #define HANDLER_HAS_DIRECT_UPDATE_ROWS #define HANDLER_HAS_DIRECT_AGGREGATE -#define PARTITION_HAS_GET_CHILD_HANDLERS #define PARTITION_HAS_GET_PART_SPEC #define HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN #define HANDLER_HAS_NEED_INFO_FOR_AUTO_INC diff --git a/storage/spider/spd_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index 167f8c3adff..2f8f40eaa97 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -1433,38 +1433,32 @@ group_by_handler *spider_create_group_by_handler( break; } -#ifdef WITH_PARTITION_STORAGE_ENGINE from = query->from; do { DBUG_PRINT("info",("spider from=%p", from)); ++table_count; +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { DBUG_PRINT("info",("spider partition handler")); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) partition_info *part_info = from->table->part_info; uint bits = bitmap_bits_set(&part_info->read_partitions); DBUG_PRINT("info",("spider bits=%u", bits)); if (bits != 1) { DBUG_PRINT("info",("spider using multiple partitions is not supported by this feature yet")); -#else - DBUG_PRINT("info",("spider partition is not supported by this feature yet")); -#endif DBUG_RETURN(NULL); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } -#endif } - } while ((from = from->next_local)); #endif + } while ((from = from->next_local)); if (!(table_holder= spider_create_table_holder(table_count))) DBUG_RETURN(NULL); table_idx = 0; from = query->from; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1473,9 +1467,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1499,7 +1491,7 @@ group_by_handler *spider_create_group_by_handler( } while ((from = from->next_local)) { -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1508,9 +1500,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1541,7 +1531,7 @@ group_by_handler *spider_create_group_by_handler( from = query->from; do { -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1550,9 +1540,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1684,7 +1672,7 @@ group_by_handler *spider_create_group_by_handler( goto skip_free_table_holder; from = query->from; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1693,9 +1681,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1758,7 +1744,7 @@ group_by_handler *spider_create_group_by_handler( { fields->clear_conn_holder_from_conn(); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1767,9 +1753,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; From f9e0ebeca49b706fa6c8b39d29eb86b57dcf957d Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 8 Apr 2024 14:28:23 +1000 Subject: [PATCH 077/159] MDEV-33742 Do not create group by handler when all tables are constant --- sql/sql_select.cc | 2 +- storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result | 2 -- storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result | 2 -- .../r/partition_join_pushdown_for_single_partition.result | 2 -- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index efcd42be074..af51c3334a8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3367,7 +3367,7 @@ bool JOIN::make_aggr_tables_info() distinct in the engine, so we do this for all queries, not only GROUP BY queries. */ - if (tables_list && top_join_tab_count && !procedure) + if (tables_list && top_join_tab_count && !only_const_tables() && !procedure) { /* At the moment we only support push down for queries where diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result index edb45e4a62a..5d483481edd 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result @@ -72,7 +72,6 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; argument select `pkey`,`val` from `auto_test_remote`.`tbl_a` select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1 -select 1 from (select 1) t0 select `pkey`,`val` from `auto_test_remote`.`tbl_a` select `pkey`,`val` from `auto_test_remote`.`tbl_a` SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' @@ -86,7 +85,6 @@ argument select `pkey`,`val` from `auto_test_remote2`.`tbl_a` select `pkey`,`val` from `auto_test_remote2`.`tbl_a` select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 2 -select 1 from (select 1) t0 select `pkey`,`val` from `auto_test_remote2`.`tbl_a` SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' SELECT pkey, val FROM tbl_a ORDER BY pkey; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result index 0a11fe429cb..c021bc70e57 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result @@ -18,8 +18,6 @@ INSERT INTO t2_spider VALUES(1,1); SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1; a c 1 1 -Warnings: -Warning 1815 Internal error: Spider group by handler: Encountered multiple equalities, likely an optimizer bug drop table t1, t2, t1_spider, t2_spider; drop server srv; for master_1 diff --git a/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result index 5026025dfd0..899788ae1c1 100644 --- a/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result +++ b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result @@ -86,10 +86,8 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; argument select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5 select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5 -select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1 select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5 select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5 -select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1 SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' SELECT value FROM tbl_a ORDER BY value; value From a73c3f1077d3dd46f9a51e53a1666ab76b7d52e0 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 8 Apr 2024 16:35:21 +1000 Subject: [PATCH 078/159] MDEV-21007 Do not assert auto_increment_value unless all parts open Commit 6dce6aecebe6ef78a14cb5c5c5daa8a355551e40 breaks out of a loop in ha_partition::info when some partitions aren't opened, in which case auto_increment_value assertion will fail. This commit patches that hole. --- mysql-test/suite/parts/r/mdev_21007.result | 5 +++++ mysql-test/suite/parts/t/mdev_21007.test | 9 +++++++++ sql/ha_partition.cc | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/parts/r/mdev_21007.result create mode 100644 mysql-test/suite/parts/t/mdev_21007.test diff --git a/mysql-test/suite/parts/r/mdev_21007.result b/mysql-test/suite/parts/r/mdev_21007.result new file mode 100644 index 00000000000..fb2417ac3ae --- /dev/null +++ b/mysql-test/suite/parts/r/mdev_21007.result @@ -0,0 +1,5 @@ +CREATE TABLE t1 (a INT) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (1), PARTITION p1 VALUES LESS THAN (MAXVALUE)); +INSERT INTO t1 VALUES (1),(2); +ALTER TABLE t1 MODIFY a INT AUTO_INCREMENT PRIMARY KEY; +UPDATE t1 PARTITION (p1) SET a=9 ORDER BY a LIMIT 1; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/t/mdev_21007.test b/mysql-test/suite/parts/t/mdev_21007.test new file mode 100644 index 00000000000..ec6fbe4d108 --- /dev/null +++ b/mysql-test/suite/parts/t/mdev_21007.test @@ -0,0 +1,9 @@ +--source include/have_partition.inc + +CREATE TABLE t1 (a INT) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (1), PARTITION p1 VALUES LESS THAN (MAXVALUE)); +INSERT INTO t1 VALUES (1),(2); +ALTER TABLE t1 MODIFY a INT AUTO_INCREMENT PRIMARY KEY; +UPDATE t1 PARTITION (p1) SET a=9 ORDER BY a LIMIT 1; + +# Cleanup +DROP TABLE t1; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index f0421fa4026..f6acaa8c77e 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -8416,7 +8416,7 @@ int ha_partition::info(uint flag) file->stats.auto_increment_value); } while (*(++file_array)); - DBUG_ASSERT(auto_increment_value); + DBUG_ASSERT(!all_parts_opened || auto_increment_value); stats.auto_increment_value= auto_increment_value; if (all_parts_opened && auto_inc_is_first_in_idx) { From 73291de74e49a84700ce4e2aa2c7ec6769d884dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 8 Apr 2024 11:48:46 +0300 Subject: [PATCH 079/159] MDEV-33819 The purge of committed history is mis-parsing some log In commit aa719b5010c929132b4460b78113fbd07497d9c8 (part of MDEV-32050) a bug was introduced in the function purge_sys_t::choose_next_log(), which reimplements some logic that previously was part of trx_purge_read_undo_rec(). We must invoke trx_undo_get_first_rec() with the page number and offset of the undo log header, but we were incorrectly invoking it on the current undo page number, which caused us to parse undo records starting at an incorrect offset. purge_sys_t::choose_next_log(): Pass the correct parameter to trx_undo_page_get_first_rec(). trx_undo_page_get_next_rec(), trx_undo_page_get_first_rec(), trx_undo_page_get_last_rec(): Add debug assertions and make the code more robust by returning nullptr on corruption. Should we detect any corrupted undo logs during the purge of committed transaction history, the sanest thing to do is to pretend that the end of an undo log was reached. If any garbage is left in the tables, it will be ignored by anything else than CHECK TABLE ... EXTENDED, and it can be removed by OPTIMIZE TABLE. Thanks to Matthias Leich for providing an "rr replay" trace where this bug could be found. Reviewed by: Vladislav Lesin --- storage/innobase/include/trx0undo.inl | 3 ++- storage/innobase/trx/trx0purge.cc | 5 ++--- storage/innobase/trx/trx0undo.cc | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/storage/innobase/include/trx0undo.inl b/storage/innobase/include/trx0undo.inl index 9f05989f634..023e2b98fb2 100644 --- a/storage/innobase/include/trx0undo.inl +++ b/storage/innobase/include/trx0undo.inl @@ -125,5 +125,6 @@ trx_undo_page_get_next_rec(const buf_block_t *undo_page, uint16_t rec, { uint16_t end= trx_undo_page_get_end(undo_page, page_no, offset); uint16_t next= mach_read_from_2(undo_page->page.frame + rec); - return next == end ? nullptr : undo_page->page.frame + next; + ut_ad(next <= end); + return next >= end ? nullptr : undo_page->page.frame + next; } diff --git a/storage/innobase/trx/trx0purge.cc b/storage/innobase/trx/trx0purge.cc index 2445b85939d..0f5d59ffb2d 100644 --- a/storage/innobase/trx/trx0purge.cc +++ b/storage/innobase/trx/trx0purge.cc @@ -793,8 +793,7 @@ bool purge_sys_t::rseg_get_next_history_log() /* Read the previous log header. */ trx_id_t trx_no= 0; if (const buf_block_t* undo_page= - get_page(page_id_t(rseg->space->id, - prev_log_addr.page))) + get_page(page_id_t(rseg->space->id, prev_log_addr.page))) { const byte *log_hdr= undo_page->page.frame + prev_log_addr.boffset; trx_no= mach_read_from_8(log_hdr + TRX_UNDO_TRX_NO); @@ -887,7 +886,7 @@ bool purge_sys_t::choose_next_log() if (!b) goto purge_nothing; undo_rec= - trx_undo_page_get_first_rec(b, page_no, hdr_offset); + trx_undo_page_get_first_rec(b, hdr_page_no, hdr_offset); if (!undo_rec) goto purge_nothing; } diff --git a/storage/innobase/trx/trx0undo.cc b/storage/innobase/trx/trx0undo.cc index ccc68dfeef7..8f1ff53e9d8 100644 --- a/storage/innobase/trx/trx0undo.cc +++ b/storage/innobase/trx/trx0undo.cc @@ -134,8 +134,9 @@ trx_undo_page_get_first_rec(const buf_block_t *block, uint32_t page_no, uint16_t offset) { uint16_t start= trx_undo_page_get_start(block, page_no, offset); - return start == trx_undo_page_get_end(block, page_no, offset) - ? nullptr : block->page.frame + start; + uint16_t end= trx_undo_page_get_end(block, page_no, offset); + ut_ad(start <= end); + return start >= end ? nullptr : block->page.frame + start; } /** Get the last undo log record on a page. @@ -149,8 +150,10 @@ trx_undo_rec_t* trx_undo_page_get_last_rec(const buf_block_t *block, uint32_t page_no, uint16_t offset) { + uint16_t start= trx_undo_page_get_start(block, page_no, offset); uint16_t end= trx_undo_page_get_end(block, page_no, offset); - return trx_undo_page_get_start(block, page_no, offset) == end + ut_ad(start <= end); + return start >= end ? nullptr : block->page.frame + mach_read_from_2(block->page.frame + end - 2); } From 11986ec6541733477cb5dd312bac1dc64ed7e57c Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 8 Apr 2024 14:56:31 +0400 Subject: [PATCH 080/159] MDEV-31251 MDEV-30968 breaks running mariabackup on older mariadb (opendir(NULL)) The problem happened when running mariabackup agains a pre-MDEV-30971 server, i.e. not having yet the system variable @@aria_log_dir_path. As a result, backup_start() called the function backup_files_from_datadir() with a NULL value, which further caused a crash. Fix: Perform this call: backup_files_from_datadir(.., aria_log_dir_path, ..) only if aria_log_dir_path is not NULL. Otherwise, assume that Aria log files are in their default location, so they've just copied by the previous call: backup_files_from_datadir(.., fil_path_to_mysql_datadir, ..) Thanks to Walter Doekes for a patch proposal. --- extra/mariabackup/backup_copy.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc index 7b3336f67b7..90081ccb650 100644 --- a/extra/mariabackup/backup_copy.cc +++ b/extra/mariabackup/backup_copy.cc @@ -1439,9 +1439,10 @@ bool backup_start(ds_ctxt *ds_data, ds_ctxt *ds_meta, if (!backup_files_from_datadir(ds_data, fil_path_to_mysql_datadir, "aws-kms-key") || - !backup_files_from_datadir(ds_data, - aria_log_dir_path, - "aria_log")) { + (aria_log_dir_path && + !backup_files_from_datadir(ds_data, + aria_log_dir_path, + "aria_log"))) { return false; } From 3c40f8bafba8d525b2b9b2c3b1c3427b20848d01 Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Fri, 5 Apr 2024 18:08:53 +0530 Subject: [PATCH 081/159] MDEV-31402: SIGSEGV in json_get_path_next | Item_func_json_extract::read_json --- mysql-test/main/func_json.result | 7 +++++++ mysql-test/main/func_json.test | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index d6b25cfcb2a..e40951a0b1f 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -1690,5 +1690,12 @@ select json_arrayagg('ä'), json_objectagg(1, 'ä'); json_arrayagg('ä') json_objectagg(1, 'ä') ["ä"] {"1":"ä"} # +# MDEV-31402: SIGSEGV in json_get_path_next | Item_func_json_extract::read_json +# +CREATE TABLE t (id CHAR AS (JSON_COMPACT (JSON_EXTRACT(doc,"$._id"))) UNIQUE KEY,doc JSON,CONSTRAINT notnu CHECK (id IS NOT NULL)); +INSERT INTO t (doc) VALUES ('{ "_id" : { "$oid" : "0ca0b0f0" },"a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" :0} ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] }'); +ERROR 22001: Data too long for column 'id' at row 1 +DROP TABLE t; +# # End of 10.5 tests # diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index dd6e393501f..c881ede45ce 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -1115,6 +1115,16 @@ set names latin1; select json_arrayagg('ä'), json_objectagg(1, 'ä'); --enable_service_connection +--echo # +--echo # MDEV-31402: SIGSEGV in json_get_path_next | Item_func_json_extract::read_json +--echo # + +CREATE TABLE t (id CHAR AS (JSON_COMPACT (JSON_EXTRACT(doc,"$._id"))) UNIQUE KEY,doc JSON,CONSTRAINT notnu CHECK (id IS NOT NULL)); +--error ER_DATA_TOO_LONG +INSERT INTO t (doc) VALUES ('{ "_id" : { "$oid" : "0ca0b0f0" },"a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" :0} ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] }'); + +DROP TABLE t; + --echo # --echo # End of 10.5 tests --echo # From 89c907bd4f713b77e248f7c8e6247b5f3be18fb4 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Wed, 13 Mar 2024 14:42:28 -0600 Subject: [PATCH 082/159] MDEV-33672: Gtid_log_event Construction from File Should Ensure Event Length When Using Extra Flags A GTID event can have variable length, with contributing factors such as the variable length from the flags2 and optional extra flags fields. These fields are bitmaps, where each set bit indicates an additional value that should be appended to the event, e.g. multi-engine transactions append a number to indicate the number of additional engines a transaction uses. However, if a flags bit is set, and no additional fields are appended to the event, MDEV-33672 reports that the server can still try to read from memory as if it did exist. Note, however, in debug builds, this condition is asserted for FL_EXTRA_MULTI_ENGINE. This patch fixes this to check that the length of the event is aligned with the expectation set by the flags for FL_PREPARED_XA, FL_COMPLETED_XA, and FL_EXTRA_MULTI_ENGINE. Reviewed By ============ Kristian Nielsen --- .../suite/rpl/r/rpl_gtid_header_valid.result | 122 ++++++++++++ .../suite/rpl/t/rpl_gtid_header_valid.test | 181 ++++++++++++++++++ sql/log_event.cc | 17 +- sql/log_event.h | 11 +- sql/log_event_server.cc | 22 ++- 5 files changed, 349 insertions(+), 4 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_gtid_header_valid.result create mode 100644 mysql-test/suite/rpl/t/rpl_gtid_header_valid.test diff --git a/mysql-test/suite/rpl/r/rpl_gtid_header_valid.result b/mysql-test/suite/rpl/r/rpl_gtid_header_valid.result new file mode 100644 index 00000000000..fd440feb3c9 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_gtid_header_valid.result @@ -0,0 +1,122 @@ +include/master-slave.inc +[connection master] +# +# Initialize test data +connection master; +create table t1 (a int) engine=innodb; +include/save_master_gtid.inc +set @@SESSION.debug_dbug= "+d,binlog_force_commit_id"; +connection slave; +set SQL_LOG_BIN= 0; +call mtr.add_suppression('Found invalid event in binary log'); +call mtr.add_suppression('Slave SQL.*Relay log read failure: Could not parse relay log event entry.* 1594'); +set SQL_LOG_BIN= 1; +include/sync_with_master_gtid.inc +include/stop_slave.inc +include/start_slave.inc +# +# Test FL_PREPARED_XA +connection master; +set @@SESSION.debug_dbug= "+d,negate_xid_from_gtid"; +set @commit_id= 100; +XA START 'x1'; +insert into t1 values (1); +XA END 'x1'; +XA PREPARE 'x1'; +set @@SESSION.debug_dbug= "-d,negate_xid_from_gtid"; +XA COMMIT 'x1'; +include/save_master_gtid.inc +# Waiting for slave to find invalid event.. +connection slave; +include/wait_for_slave_sql_error.inc [errno=1594] +STOP SLAVE IO_THREAD; +# Reset master binlogs (as there is an invalid event) and slave state +connection master; +RESET MASTER; +connection slave; +RESET MASTER; +RESET SLAVE; +set @@global.gtid_slave_pos=""; +include/start_slave.inc +# +# Test FL_COMPLETED_XA +connection master; +set @commit_id= 101; +XA START 'x1'; +insert into t1 values (2); +XA END 'x1'; +XA PREPARE 'x1'; +set @@SESSION.debug_dbug= "+d,negate_xid_from_gtid"; +XA COMMIT 'x1'; +set @@SESSION.debug_dbug= "-d,negate_xid_from_gtid"; +include/save_master_gtid.inc +# Waiting for slave to find invalid event.. +connection slave; +include/wait_for_slave_sql_error.inc [errno=1594] +STOP SLAVE IO_THREAD; +# Cleanup hanging XA PREPARE on slave +set statement SQL_LOG_BIN=0 for XA COMMIT 'x1'; +# Reset master binlogs (as there is an invalid event) and slave state +connection master; +RESET MASTER; +connection slave; +RESET MASTER; +RESET SLAVE; +set @@global.gtid_slave_pos=""; +include/start_slave.inc +# +# Test Missing xid.data (but has format id and length description parts) +connection master; +set @commit_id= 101; +XA START 'x1'; +insert into t1 values (1); +XA END 'x1'; +XA PREPARE 'x1'; +set @@SESSION.debug_dbug= "+d,negate_xid_data_from_gtid"; +XA COMMIT 'x1'; +set @@SESSION.debug_dbug= "-d,negate_xid_data_from_gtid"; +include/save_master_gtid.inc +# Waiting for slave to find invalid event.. +connection slave; +include/wait_for_slave_sql_error.inc [errno=1594] +STOP SLAVE IO_THREAD; +# Cleanup hanging XA PREPARE on slave +set statement SQL_LOG_BIN=0 for XA COMMIT 'x1'; +# Reset master binlogs (as there is an invalid event) and slave state +connection master; +RESET MASTER; +connection slave; +RESET MASTER; +RESET SLAVE; +set @@global.gtid_slave_pos=""; +include/start_slave.inc +# +# Test FL_EXTRA_MULTI_ENGINE +connection master; +set @old_dbug= @@SESSION.debug_dbug; +set @@SESSION.debug_dbug= "+d,inject_fl_extra_multi_engine_into_gtid"; +set @commit_id= 102; +insert into t1 values (3); +include/save_master_gtid.inc +set @@SESSION.debug_dbug=@old_dbug; +connection slave; +# Waiting for slave to find invalid event.. +include/wait_for_slave_sql_error.inc [errno=1594] +STOP SLAVE IO_THREAD; +# Reset master binlogs (as there is an invalid event) and slave state +connection master; +RESET MASTER; +connection slave; +RESET SLAVE; +RESET MASTER; +set @@global.gtid_slave_pos=""; +include/start_slave.inc +# +# Cleanup +connection master; +drop table t1; +include/save_master_gtid.inc +connection slave; +include/sync_with_master_gtid.inc +include/rpl_end.inc +# End of rpl_gtid_header_valid.test diff --git a/mysql-test/suite/rpl/t/rpl_gtid_header_valid.test b/mysql-test/suite/rpl/t/rpl_gtid_header_valid.test new file mode 100644 index 00000000000..db546787914 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_gtid_header_valid.test @@ -0,0 +1,181 @@ +# +# This test ensures that, when a GTID event is constructed by reading its +# content from a binlog file, the reader (e.g. replica, in this test) cannot +# read beyond the length of the GTID event. That is, we ensure that the +# structure indicated by its flags and extra_flags are consistent with the +# actual content of the event. +# +# To spoof a broken GTID log event, we use the DEBUG_DBUG mechanism to inject +# the master to write invalid GTID events for each flag. The transaction is +# given a commit id to ensure the event is not shorter than GTID_HEADER_LEN, +# which would result in zero padding up to GTID_HEADER_LEN. +# +# +# References: +# MDEV-33672: Gtid_log_event Construction from File Should Ensure Event +# Length When Using Extra Flags +# + +--source include/have_debug.inc + +# GTID event extra_flags are format independent +--source include/have_binlog_format_row.inc +--source include/have_innodb.inc +--source include/master-slave.inc + +--echo # +--echo # Initialize test data +--connection master +create table t1 (a int) engine=innodb; +--source include/save_master_gtid.inc +set @@SESSION.debug_dbug= "+d,binlog_force_commit_id"; + +--connection slave +set SQL_LOG_BIN= 0; +call mtr.add_suppression('Found invalid event in binary log'); +call mtr.add_suppression('Slave SQL.*Relay log read failure: Could not parse relay log event entry.* 1594'); +set SQL_LOG_BIN= 1; +--source include/sync_with_master_gtid.inc +--source include/stop_slave.inc +--source include/start_slave.inc +--let $cid_ctr= 100 + + +--echo # +--echo # Test FL_PREPARED_XA +--connection master +set @@SESSION.debug_dbug= "+d,negate_xid_from_gtid"; +--eval set @commit_id= $cid_ctr + +XA START 'x1'; +insert into t1 values (1); +XA END 'x1'; +XA PREPARE 'x1'; +set @@SESSION.debug_dbug= "-d,negate_xid_from_gtid"; +XA COMMIT 'x1'; +--source include/save_master_gtid.inc + +--echo # Waiting for slave to find invalid event.. +--connection slave +let $slave_sql_errno= 1594; # ER_SLAVE_RELAY_LOG_READ_FAILURE +source include/wait_for_slave_sql_error.inc; +STOP SLAVE IO_THREAD; + +--echo # Reset master binlogs (as there is an invalid event) and slave state +--connection master +RESET MASTER; +--connection slave +RESET MASTER; +RESET SLAVE; +set @@global.gtid_slave_pos=""; +--source include/start_slave.inc + + +--echo # +--echo # Test FL_COMPLETED_XA +--connection master +--inc $cid_ctr +--eval set @commit_id= $cid_ctr +XA START 'x1'; +--let $next_val = `SELECT max(a)+1 FROM t1` +--eval insert into t1 values ($next_val) +XA END 'x1'; +XA PREPARE 'x1'; +set @@SESSION.debug_dbug= "+d,negate_xid_from_gtid"; +XA COMMIT 'x1'; +set @@SESSION.debug_dbug= "-d,negate_xid_from_gtid"; +--source include/save_master_gtid.inc + +--echo # Waiting for slave to find invalid event.. +--connection slave +let $slave_sql_errno= 1594; # ER_SLAVE_RELAY_LOG_READ_FAILURE +source include/wait_for_slave_sql_error.inc; +STOP SLAVE IO_THREAD; + +--echo # Cleanup hanging XA PREPARE on slave +set statement SQL_LOG_BIN=0 for XA COMMIT 'x1'; + +--echo # Reset master binlogs (as there is an invalid event) and slave state +--connection master +RESET MASTER; +--connection slave +RESET MASTER; +RESET SLAVE; +set @@global.gtid_slave_pos=""; +--source include/start_slave.inc + + +--echo # +--echo # Test Missing xid.data (but has format id and length description parts) + +--connection master +--eval set @commit_id= $cid_ctr + +XA START 'x1'; +insert into t1 values (1); +XA END 'x1'; +XA PREPARE 'x1'; +set @@SESSION.debug_dbug= "+d,negate_xid_data_from_gtid"; +XA COMMIT 'x1'; +set @@SESSION.debug_dbug= "-d,negate_xid_data_from_gtid"; +--source include/save_master_gtid.inc + +--echo # Waiting for slave to find invalid event.. +--connection slave +let $slave_sql_errno= 1594; # ER_SLAVE_RELAY_LOG_READ_FAILURE +source include/wait_for_slave_sql_error.inc; +STOP SLAVE IO_THREAD; + +--echo # Cleanup hanging XA PREPARE on slave +set statement SQL_LOG_BIN=0 for XA COMMIT 'x1'; + +--echo # Reset master binlogs (as there is an invalid event) and slave state +--connection master +RESET MASTER; +--connection slave +RESET MASTER; +RESET SLAVE; +set @@global.gtid_slave_pos=""; +--source include/start_slave.inc + + +--echo # +--echo # Test FL_EXTRA_MULTI_ENGINE +--connection master +set @old_dbug= @@SESSION.debug_dbug; +set @@SESSION.debug_dbug= "+d,inject_fl_extra_multi_engine_into_gtid"; +--inc $cid_ctr +--eval set @commit_id= $cid_ctr +--let $next_val = `SELECT max(a)+1 FROM t1` +--eval insert into t1 values ($next_val) +--source include/save_master_gtid.inc +set @@SESSION.debug_dbug=@old_dbug; + +--connection slave +--echo # Waiting for slave to find invalid event.. +let $slave_sql_errno= 1594; # ER_SLAVE_RELAY_LOG_READ_FAILURE +source include/wait_for_slave_sql_error.inc; +STOP SLAVE IO_THREAD; + +--echo # Reset master binlogs (as there is an invalid event) and slave state +--connection master +RESET MASTER; + +--connection slave +RESET SLAVE; +RESET MASTER; +set @@global.gtid_slave_pos=""; +--source include/start_slave.inc + +--echo # +--echo # Cleanup + +--connection master +drop table t1; +--source include/save_master_gtid.inc + +--connection slave +--source include/sync_with_master_gtid.inc + +--source include/rpl_end.inc +--echo # End of rpl_gtid_header_valid.test diff --git a/sql/log_event.cc b/sql/log_event.cc index 6779419e682..501dfffb774 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -2629,6 +2629,11 @@ Gtid_log_event::Gtid_log_event(const uchar *buf, uint event_len, } if (flags2 & (FL_PREPARED_XA | FL_COMPLETED_XA)) { + if (event_len < static_cast(buf - buf_0) + 6) + { + seq_no= 0; + return; + } xid.formatID= uint4korr(buf); buf+= 4; @@ -2637,6 +2642,11 @@ Gtid_log_event::Gtid_log_event(const uchar *buf, uint event_len, buf+= 2; long data_length= xid.bqual_length + xid.gtrid_length; + if (event_len < static_cast(buf - buf_0) + data_length) + { + seq_no= 0; + return; + } memcpy(xid.data, buf, data_length); buf+= data_length; } @@ -2651,8 +2661,11 @@ Gtid_log_event::Gtid_log_event(const uchar *buf, uint event_len, */ if (flags_extra & FL_EXTRA_MULTI_ENGINE) { - DBUG_ASSERT(static_cast(buf - buf_0) < event_len); - + if (event_len < static_cast(buf - buf_0) + 1) + { + seq_no= 0; + return; + } extra_engines= *buf++; DBUG_ASSERT(extra_engines > 0); diff --git a/sql/log_event.h b/sql/log_event.h index fca4015a15d..879a5a78270 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -3666,7 +3666,16 @@ public: { return GTID_HEADER_LEN + ((flags2 & FL_GROUP_COMMIT_ID) ? 2 : 0); } - bool is_valid() const { return seq_no != 0; } + + bool is_valid() const + { + /* + seq_no is set to 0 if the structure of a serialized GTID event does not + align with that as indicated by flags and extra_flags. + */ + return seq_no != 0; + } + #ifdef MYSQL_SERVER bool write(); static int make_compatible_event(String *packet, bool *need_dummy_event, diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 77856cde6f1..f4fddcd1f65 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -3411,21 +3411,41 @@ Gtid_log_event::write() write_len= GTID_HEADER_LEN + 2; } - if (flags2 & (FL_PREPARED_XA | FL_COMPLETED_XA)) + if (flags2 & (FL_PREPARED_XA | FL_COMPLETED_XA) +#ifndef DBUG_OFF + && DBUG_EVALUATE_IF("negate_xid_from_gtid", 0, 1) +#endif + ) { int4store(&buf[write_len], xid.formatID); buf[write_len +4]= (uchar) xid.gtrid_length; buf[write_len +4+1]= (uchar) xid.bqual_length; write_len+= 6; long data_length= xid.bqual_length + xid.gtrid_length; + +#ifndef DBUG_OFF + if (DBUG_EVALUATE_IF("negate_xid_data_from_gtid", 0, 1)) + { +#endif memcpy(buf+write_len, xid.data, data_length); write_len+= data_length; +#ifndef DBUG_OFF + } +#endif } + + DBUG_EXECUTE_IF("inject_fl_extra_multi_engine_into_gtid", { + flags_extra|= FL_EXTRA_MULTI_ENGINE; + }); if (flags_extra > 0) { buf[write_len]= flags_extra; write_len++; } + DBUG_EXECUTE_IF("inject_fl_extra_multi_engine_into_gtid", { + flags_extra&= ~FL_EXTRA_MULTI_ENGINE; + }); + if (flags_extra & FL_EXTRA_MULTI_ENGINE) { buf[write_len]= extra_engines; From d32b6f69b30803fdd2f223c0eb6ed2e173b1ab81 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 8 Apr 2024 17:22:06 +0200 Subject: [PATCH 083/159] update C/C fixes sporadic unit.conc_ps_bugs failures --- libmariadb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmariadb b/libmariadb index 9155b19b462..1d3fd5818a0 160000 --- a/libmariadb +++ b/libmariadb @@ -1 +1 @@ -Subproject commit 9155b19b462ac15fc69d0b58ae51370b7523ced5 +Subproject commit 1d3fd5818a0f97832b69bb60ee1a49d5c1faea4c From 50803bc456c14ff5b7e86d88bb90fcf063b1fb1c Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 8 Apr 2024 18:43:24 +0200 Subject: [PATCH 084/159] MDEV-25614 disable failing galera test --- mysql-test/suite/galera_3nodes/disabled.def | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/galera_3nodes/disabled.def b/mysql-test/suite/galera_3nodes/disabled.def index e1b4c2d5d5f..02479c1362e 100644 --- a/mysql-test/suite/galera_3nodes/disabled.def +++ b/mysql-test/suite/galera_3nodes/disabled.def @@ -17,3 +17,4 @@ galera_ipv6_mariabackup : temporarily disabled at the request of Codership galera_pc_bootstrap : temporarily disabled at the request of Codership galera_ipv6_mariabackup_section : temporarily disabled at the request of Codership MDEV-29171 : MDEV-33842 galera_3nodes.MDEV-29171 fails on shutdown_server +GCF-354 : MDEV-25614 Galera test failure on GCF-354 From 7e3090a8a0da030a6874da074c5dc909fcc22c87 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 8 Apr 2024 20:52:14 +0200 Subject: [PATCH 085/159] fix perfschema.misc when previous tests used lots of threads --- mysql-test/suite/perfschema/t/misc.test | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/perfschema/t/misc.test b/mysql-test/suite/perfschema/t/misc.test index 848be3beea1..b0a16fc5f99 100644 --- a/mysql-test/suite/perfschema/t/misc.test +++ b/mysql-test/suite/perfschema/t/misc.test @@ -175,6 +175,7 @@ DROP TABLE t_60905; # show global variables like "performance_schema_max_thread_instances"; +replace_result 512 256; explain select * from performance_schema.threads; # From b7b58a231099e21513f7a60835759260106b81a3 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 8 Apr 2024 16:24:46 +1000 Subject: [PATCH 086/159] MDEV-33731 Only iterate over m_locked_partitions in update_next_auto_inc_val() Only locked will participate in the query in this case. Chances are that not-locked partitions were not opened, which is the cause of the crash in the added test case spider/bugfix.mdev_33731 without this patch. --- sql/ha_partition.cc | 9 +++++---- .../mysql-test/spider/bugfix/r/mdev_33731.result | 10 ++++++++++ .../mysql-test/spider/bugfix/t/mdev_33731.test | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33731.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33731.test diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index c13b60f2cd8..952c6dd212f 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -10753,18 +10753,19 @@ int ha_partition::update_next_auto_inc_val() bool ha_partition::need_info_for_auto_inc() { - handler **file= m_file; DBUG_ENTER("ha_partition::need_info_for_auto_inc"); - do + for (uint i= bitmap_get_first_set(&m_locked_partitions); + i < m_tot_parts; + i= bitmap_get_next_set(&m_locked_partitions, i)) { - if ((*file)->need_info_for_auto_inc()) + if ((m_file[i])->need_info_for_auto_inc()) { /* We have to get new auto_increment values from handler */ part_share->auto_inc_initialized= FALSE; DBUG_RETURN(TRUE); } - } while (*(++file)); + } DBUG_RETURN(FALSE); } diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33731.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33731.result new file mode 100644 index 00000000000..a63830f194c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33731.result @@ -0,0 +1,10 @@ +for master_1 +for child2 +for child3 +CREATE TABLE t (a INT) ENGINE=Spider PARTITION BY LIST (a) PARTITIONS 2 (PARTITION p1 VALUES IN (0,1),PARTITION p2 VALUES IN (2,3)); +DELETE FROM t PARTITION (p2); +ERROR HY000: Unable to connect to foreign data source: localhost +drop table t; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33731.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33731.test new file mode 100644 index 00000000000..b98c9620414 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33731.test @@ -0,0 +1,16 @@ +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +CREATE TABLE t (a INT) ENGINE=Spider PARTITION BY LIST (a) PARTITIONS 2 (PARTITION p1 VALUES IN (0,1),PARTITION p2 VALUES IN (2,3)); +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +DELETE FROM t PARTITION (p2); +drop table t; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log From 09bae92c16f9c37c931ab3f7932664f55bb9a842 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 8 Apr 2024 16:34:38 +0200 Subject: [PATCH 087/159] MDEV-33840 tpool : switch off maintenance timer when not needed. Before patch, maintenance timer will tick every 0.4 seconds. After this patch, timer will tick every 0.4 seconds when necessary( there are delayed thread creation), switching off completely after 20 seconds of being idle. --- tpool/tpool_generic.cc | 70 ++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc index 8dbd7c94d30..0a2f9f8f5e1 100644 --- a/tpool/tpool_generic.cc +++ b/tpool/tpool_generic.cc @@ -270,10 +270,10 @@ class thread_pool_generic : public thread_pool OFF, ON }; timer_state_t m_timer_state= timer_state_t::OFF; - void switch_timer(timer_state_t state); + void switch_timer(timer_state_t state,std::unique_lock &lk); /* Updates idle_since, and maybe switches the timer off */ - void check_idle(std::chrono::system_clock::time_point now); + void check_idle(std::chrono::system_clock::time_point now, std::unique_lock &lk); /** time point when timer last ran, used as a coarse clock. */ std::chrono::system_clock::time_point m_timestamp; @@ -306,9 +306,9 @@ class thread_pool_generic : public thread_pool { ((thread_pool_generic *)arg)->maintenance(); } - bool add_thread(); + bool add_thread(std::unique_lock &lk); bool wake(worker_wake_reason reason, task *t = nullptr); - void maybe_wake_or_create_thread(); + void maybe_wake_or_create_thread(std::unique_lock &lk); bool too_many_active_threads(); bool get_task(worker_data *thread_var, task **t); bool wait_for_tasks(std::unique_lock &lk, @@ -616,11 +616,11 @@ void thread_pool_generic::worker_main(worker_data *thread_var) */ static const auto invalid_timestamp= std::chrono::system_clock::time_point::max(); -constexpr auto max_idle_time= std::chrono::minutes(1); +constexpr auto max_idle_time= std::chrono::seconds(20); /* Time since maintenance timer had nothing to do */ static std::chrono::system_clock::time_point idle_since= invalid_timestamp; -void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now) +void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now, std::unique_lock &lk) { DBUG_ASSERT(m_task_queue.empty()); @@ -647,7 +647,7 @@ void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now) if (now - idle_since > max_idle_time) { idle_since= invalid_timestamp; - switch_timer(timer_state_t::OFF); + switch_timer(timer_state_t::OFF,lk); } } @@ -681,7 +681,7 @@ void thread_pool_generic::maintenance() if (m_task_queue.empty()) { - check_idle(m_timestamp); + check_idle(m_timestamp, lk); m_last_activity = m_tasks_dequeued + m_wakeups; return; } @@ -701,7 +701,7 @@ void thread_pool_generic::maintenance() } } - maybe_wake_or_create_thread(); + maybe_wake_or_create_thread(lk); size_t thread_cnt = (int)thread_count(); if (m_last_activity == m_tasks_dequeued + m_wakeups && @@ -709,7 +709,7 @@ void thread_pool_generic::maintenance() { // no progress made since last iteration. create new // thread - add_thread(); + add_thread(lk); } m_last_activity = m_tasks_dequeued + m_wakeups; m_last_thread_count= thread_cnt; @@ -736,14 +736,14 @@ static int throttling_interval_ms(size_t n_threads,size_t concurrency) } /* Create a new worker.*/ -bool thread_pool_generic::add_thread() +bool thread_pool_generic::add_thread(std::unique_lock &lk) { size_t n_threads = thread_count(); if (n_threads >= m_max_threads) return false; - if (n_threads >= m_min_threads) + if (n_threads >= m_min_threads && m_min_threads != m_max_threads) { auto now = std::chrono::system_clock::now(); if (now - m_last_thread_creation < @@ -753,7 +753,7 @@ bool thread_pool_generic::add_thread() Throttle thread creation and wakeup deadlock detection timer, if is it off. */ - switch_timer(timer_state_t::ON); + switch_timer(timer_state_t::ON, lk); return false; } @@ -835,12 +835,10 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) : if (!m_concurrency) m_concurrency = 1; - // start the timer - m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); } -void thread_pool_generic::maybe_wake_or_create_thread() +void thread_pool_generic::maybe_wake_or_create_thread(std::unique_lock &lk) { if (m_task_queue.empty()) return; @@ -853,7 +851,7 @@ void thread_pool_generic::maybe_wake_or_create_thread() } else { - add_thread(); + add_thread(lk); } } @@ -872,7 +870,7 @@ void thread_pool_generic::submit_task(task* task) task->add_ref(); m_tasks_enqueued++; m_task_queue.push(task); - maybe_wake_or_create_thread(); + maybe_wake_or_create_thread(lk); } @@ -895,7 +893,7 @@ void thread_pool_generic::wait_begin() m_waiting_task_count++; /* Maintain concurrency */ - maybe_wake_or_create_thread(); + maybe_wake_or_create_thread(lk); } @@ -910,26 +908,30 @@ void thread_pool_generic::wait_end() } -void thread_pool_generic::switch_timer(timer_state_t state) +void thread_pool_generic::switch_timer(timer_state_t state, std::unique_lock &lk) { if (m_timer_state == state) return; - /* - We can't use timer::set_time, because mysys timers are deadlock - prone. + /* No maintenance timer for fixed threadpool size.*/ + DBUG_ASSERT(m_min_threads != m_max_threads); + DBUG_ASSERT(lk.owns_lock()); - Instead, to switch off we increase the timer period - and decrease period to switch on. - - This might introduce delays in thread creation when needed, - as period will only be changed when timer fires next time. - For this reason, we can't use very long periods for the "off" state. - */ m_timer_state= state; - long long period= (state == timer_state_t::OFF) ? - m_timer_interval.count()*10: m_timer_interval.count(); - - m_maintenance_timer.set_period((int)period); + if(state == timer_state_t::OFF) + { + m_maintenance_timer.set_period(0); + } + else + { + /* + It is necessary to unlock the thread_pool::m_mtx + to avoid the deadlock with thr_timer's LOCK_timer. + Otherwise, lock order would be violated. + */ + lk.unlock(); + m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); + lk.lock(); + } } From f9ecaa87cebb3043afec5da73fb665c24a30cc98 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Tue, 27 Feb 2024 12:19:18 +0100 Subject: [PATCH 088/159] MDEV-33668: Refactor parallel replication round-robin scheduling to use explicit FIFO This is a preparatory patch to facilitate the next commit to improve the scheduling of XA transactions in parallel replication. When choosing the scheduling bucket for the next event group in rpl_parallel_entry::choose_thread(), use an explicit FIFO for the round-robin selection instead of a simple cyclic counter i := (i+1) % N. This allows to schedule XA COMMIT/ROLLBACK dependencies explicitly without changing the round-robin scheduling of other event groups. Reviewed-by: Andrei Elkin Signed-off-by: Kristian Nielsen --- sql/rpl_parallel.cc | 54 +++++++++++++++++++++++++++------------------ sql/rpl_parallel.h | 13 ++++++++--- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index a63fa4a4b6b..68e42ecd03f 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -2357,33 +2357,38 @@ rpl_parallel_entry::choose_thread(rpl_group_info *rgi, bool *did_enter_cond, PSI_stage_info *old_stage, Gtid_log_event *gtid_ev) { - uint32 idx; + sched_bucket *cur_thr; Relay_log_info *rli= rgi->rli; rpl_parallel_thread *thr; - idx= rpl_thread_idx; if (gtid_ev) { + /* New event group; cycle the thread scheduling buckets round-robin. */ + thread_sched_fifo->push_back(thread_sched_fifo->get()); + if (gtid_ev->flags2 & (Gtid_log_event::FL_COMPLETED_XA | Gtid_log_event::FL_PREPARED_XA)) - idx= my_hash_sort(&my_charset_bin, gtid_ev->xid.key(), - gtid_ev->xid.key_length()) % rpl_thread_max; - else { - ++idx; - if (idx >= rpl_thread_max) - idx= 0; + /* + For XA COMMIT/ROLLBACK, choose the same bucket as the XA PREPARE, + overriding the round-robin scheduling. + */ + uint32 idx= my_hash_sort(&my_charset_bin, gtid_ev->xid.key(), + gtid_ev->xid.key_length()) % rpl_thread_max; + rpl_threads[idx].unlink(); + thread_sched_fifo->append(rpl_threads + idx); } - rpl_thread_idx= idx; } - thr= rpl_threads[idx]; + cur_thr= thread_sched_fifo->head(); + + thr= cur_thr->thr; if (thr) { *did_enter_cond= false; mysql_mutex_lock(&thr->LOCK_rpl_thread); for (;;) { - if (thr->current_owner != &rpl_threads[idx]) + if (thr->current_owner != &cur_thr->thr) { /* The worker thread became idle, and returned to the free list and @@ -2450,8 +2455,8 @@ rpl_parallel_entry::choose_thread(rpl_group_info *rgi, bool *did_enter_cond, } } if (!thr) - rpl_threads[idx]= thr= global_rpl_thread_pool.get_thread(&rpl_threads[idx], - this); + cur_thr->thr= thr= + global_rpl_thread_pool.get_thread(&cur_thr->thr, this); return thr; } @@ -2508,15 +2513,20 @@ rpl_parallel::find(uint32 domain_id) ulong count= opt_slave_domain_parallel_threads; if (count == 0 || count > opt_slave_parallel_threads) count= opt_slave_parallel_threads; - rpl_parallel_thread **p; + rpl_parallel_entry::sched_bucket *p; + I_List *fifo; if (!my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME|MY_ZEROFILL), &e, sizeof(*e), &p, count*sizeof(*p), + &fifo, sizeof(*fifo), NULL)) { my_error(ER_OUTOFMEMORY, MYF(0), (int)(sizeof(*e)+count*sizeof(*p))); return NULL; } + e->thread_sched_fifo = new (fifo) I_List; + for (ulong i= 0; i < count; ++i) + e->thread_sched_fifo->push_back(::new (p+i) rpl_parallel_entry::sched_bucket); e->rpl_threads= p; e->rpl_thread_max= count; e->domain_id= domain_id; @@ -2582,10 +2592,10 @@ rpl_parallel::wait_for_done(THD *thd, Relay_log_info *rli) mysql_mutex_unlock(&e->LOCK_parallel_entry); for (j= 0; j < e->rpl_thread_max; ++j) { - if ((rpt= e->rpl_threads[j])) + if ((rpt= e->rpl_threads[j].thr)) { mysql_mutex_lock(&rpt->LOCK_rpl_thread); - if (rpt->current_owner == &e->rpl_threads[j]) + if (rpt->current_owner == &e->rpl_threads[j].thr) mysql_cond_signal(&rpt->COND_rpl_thread); mysql_mutex_unlock(&rpt->LOCK_rpl_thread); } @@ -2605,10 +2615,10 @@ rpl_parallel::wait_for_done(THD *thd, Relay_log_info *rli) e= (struct rpl_parallel_entry *)my_hash_element(&domain_hash, i); for (j= 0; j < e->rpl_thread_max; ++j) { - if ((rpt= e->rpl_threads[j])) + if ((rpt= e->rpl_threads[j].thr)) { mysql_mutex_lock(&rpt->LOCK_rpl_thread); - while (rpt->current_owner == &e->rpl_threads[j]) + while (rpt->current_owner == &e->rpl_threads[j].thr) mysql_cond_wait(&rpt->COND_rpl_thread_stop, &rpt->LOCK_rpl_thread); mysql_mutex_unlock(&rpt->LOCK_rpl_thread); } @@ -2655,7 +2665,7 @@ int rpl_parallel_entry::queue_master_restart(rpl_group_info *rgi, Format_description_log_event *fdev) { - uint32 idx; + sched_bucket *cur_thr; rpl_parallel_thread *thr; rpl_parallel_thread::queued_event *qev; Relay_log_info *rli= rgi->rli; @@ -2670,12 +2680,12 @@ rpl_parallel_entry::queue_master_restart(rpl_group_info *rgi, Thus there is no need for the full complexity of choose_thread(). We only need to check if we have a current worker thread, and queue for it if so. */ - idx= rpl_thread_idx; - thr= rpl_threads[idx]; + cur_thr= thread_sched_fifo->head(); + thr= cur_thr->thr; if (!thr) return 0; mysql_mutex_lock(&thr->LOCK_rpl_thread); - if (thr->current_owner != &rpl_threads[idx]) + if (thr->current_owner != &cur_thr->thr) { /* No active worker thread, so no need to queue the master restart. */ mysql_mutex_unlock(&thr->LOCK_rpl_thread); diff --git a/sql/rpl_parallel.h b/sql/rpl_parallel.h index bcce54bc0ec..9ba86453d06 100644 --- a/sql/rpl_parallel.h +++ b/sql/rpl_parallel.h @@ -326,6 +326,11 @@ struct rpl_parallel_thread_pool { struct rpl_parallel_entry { + struct sched_bucket : public ilink { + sched_bucket() : thr(nullptr) { } + rpl_parallel_thread *thr; + }; + mysql_mutex_t LOCK_parallel_entry; mysql_cond_t COND_parallel_entry; uint32 domain_id; @@ -355,17 +360,19 @@ struct rpl_parallel_entry { uint64 stop_sub_id; /* - Cyclic array recording the last rpl_thread_max worker threads that we + Array recording the last rpl_thread_max worker threads that we queued event for. This is used to limit how many workers a single domain can occupy (--slave-domain-parallel-threads). + The array is structured as a FIFO using an I_List thread_sched_fifo. + Note that workers are never explicitly deleted from the array. Instead, we need to check (under LOCK_rpl_thread) that the thread still belongs to us before re-using (rpl_thread::current_owner). */ - rpl_parallel_thread **rpl_threads; + sched_bucket *rpl_threads; + I_List *thread_sched_fifo; uint32 rpl_thread_max; - uint32 rpl_thread_idx; /* The sub_id of the last transaction to commit within this domain_id. Must be accessed under LOCK_parallel_entry protection. From d90a2b44addef766cb59cb4e68c0b00d77aee160 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Tue, 27 Feb 2024 19:08:20 +0100 Subject: [PATCH 089/159] MDEV-33668: More precise dependency tracking of XA XID in parallel replication Keep track of each recently active XID, recording which worker it was queued on. If an XID might still be active, choose the same worker to queue event groups that refer to the same XID to avoid conflicts. Otherwise, schedule the XID freely in the next round-robin slot. This way, XA PREPARE can normally be scheduled without restrictions (unless duplicate XID transactions come close together). This improves scheduling and parallelism over the old method, where the worker thread to schedule XA PREPARE on was fixed based on a hash value of the XID. XA COMMIT will normally be scheduled on the same worker as XA PREPARE, but can be a different one if the XA PREPARE is far back in the event history. Testcase and code for trimming dynamic array due to Andrei. Reviewed-by: Andrei Elkin Signed-off-by: Kristian Nielsen --- .../rpl/r/rpl_parallel_multi_domain_xa.result | 55 ++++++ .../rpl/t/rpl_parallel_multi_domain_xa.test | 173 ++++++++++++++++++ sql/log_event_server.cc | 3 +- sql/rpl_parallel.cc | 131 +++++++++++-- sql/rpl_parallel.h | 41 +++++ 5 files changed, 391 insertions(+), 12 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_parallel_multi_domain_xa.result create mode 100644 mysql-test/suite/rpl/t/rpl_parallel_multi_domain_xa.test diff --git a/mysql-test/suite/rpl/r/rpl_parallel_multi_domain_xa.result b/mysql-test/suite/rpl/r/rpl_parallel_multi_domain_xa.result new file mode 100644 index 00000000000..defab6aef52 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_parallel_multi_domain_xa.result @@ -0,0 +1,55 @@ +include/master-slave.inc +[connection master] +call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); +call mtr.add_suppression("WSREP: handlerton rollback failed"); +connection master; +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +connection slave; +include/stop_slave.inc +SET @old_parallel_threads = @@GLOBAL.slave_parallel_threads; +SET @old_slave_domain_parallel_threads = @@GLOBAL.slave_domain_parallel_threads; +SET @@global.slave_parallel_threads = 5; +SET @@global.slave_domain_parallel_threads = 3; +SET @old_parallel_mode = @@GLOBAL.slave_parallel_mode; +CHANGE MASTER TO master_use_gtid=slave_pos; +connection master; +CREATE TABLE t1 (a int PRIMARY KEY, b INT) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 0); +include/save_master_gtid.inc +connection slave; +include/start_slave.inc +include/sync_with_master_gtid.inc +include/stop_slave.inc +SET @@global.slave_parallel_mode ='optimistic'; +connection master; +include/save_master_gtid.inc +connection slave; +include/start_slave.inc +include/sync_with_master_gtid.inc +include/stop_slave.inc +connection master; +include/save_master_gtid.inc +connection slave; +SET @@global.slave_parallel_mode ='conservative'; +include/start_slave.inc +include/sync_with_master_gtid.inc +include/stop_slave.inc +include/save_master_gtid.inc +connection slave; +SET @@global.slave_parallel_mode = 'optimistic'; +include/start_slave.inc +include/sync_with_master_gtid.inc +include/diff_tables.inc [master:t1, slave:t1] +connection slave; +include/stop_slave.inc +SET @@global.slave_parallel_mode = @old_parallel_mode; +SET @@global.slave_parallel_threads = @old_parallel_threads; +SET @@global.slave_domain_parallel_threads = @old_slave_domain_parallel_threads; +include/start_slave.inc +connection master; +DROP TABLE t1; +include/save_master_gtid.inc +connection slave; +include/sync_with_master_gtid.inc +connection master; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_parallel_multi_domain_xa.test b/mysql-test/suite/rpl/t/rpl_parallel_multi_domain_xa.test new file mode 100644 index 00000000000..da1aaea130f --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_parallel_multi_domain_xa.test @@ -0,0 +1,173 @@ +# Similar to rpl_parallel_optimistic_xa to verify XA +# parallel execution with multiple gtid domain. +# References: +# MDEV-33668 Adapt parallel slave's round-robin scheduling to XA events + +--source include/have_innodb.inc +--source include/have_perfschema.inc +--source include/master-slave.inc + +# Tests' global declarations +--let $trx = _trx_ + +call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); +call mtr.add_suppression("WSREP: handlerton rollback failed"); + +--connection master +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +--save_master_pos + +# Prepare to restart slave into optimistic parallel mode +--connection slave +--sync_with_master +--source include/stop_slave.inc +SET @old_parallel_threads = @@GLOBAL.slave_parallel_threads; +SET @old_slave_domain_parallel_threads = @@GLOBAL.slave_domain_parallel_threads; +SET @@global.slave_parallel_threads = 5; +SET @@global.slave_domain_parallel_threads = 3; +SET @old_parallel_mode = @@GLOBAL.slave_parallel_mode; + +CHANGE MASTER TO master_use_gtid=slave_pos; + +--connection master +CREATE TABLE t1 (a int PRIMARY KEY, b INT) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 0); +--source include/save_master_gtid.inc + +--connection slave +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc +--source include/stop_slave.inc + +--let $mode = 2 +# mode = 2 is optimistic +SET @@global.slave_parallel_mode ='optimistic'; +while ($mode) +{ + --connection master + # + # create XA events alternating gtid domains to run them in parallel on slave. + # + --let $domain_num = 3 + --let $trx_num = 777 + --let $i = $trx_num + --let $conn = master + --disable_query_log + while($i > 0) + { + --let $domain_id = `SELECT $i % $domain_num` + --eval set @@gtid_domain_id = $domain_id + # 'decision' to commit 0, or rollback 1 + --let $decision = `SELECT $i % 2` + --eval XA START '$conn$trx$i' + --eval UPDATE t1 SET b = 1 - 2 * $decision WHERE a = 1 + --eval XA END '$conn$trx$i' + --eval XA PREPARE '$conn$trx$i' + --let $term = COMMIT + if ($decision) + { + --let $term = ROLLBACK + } + --eval XA $term '$conn$trx$i' + + --dec $i + } + --enable_query_log + --source include/save_master_gtid.inc + + --connection slave + if (`select $mode = 1`) + { + SET @@global.slave_parallel_mode ='conservative'; + } + --source include/start_slave.inc + --source include/sync_with_master_gtid.inc + --source include/stop_slave.inc + + --dec $mode +} + + +# Generations test. +# Create few ranges of XAP groups length of greater than +# 3 * slave_parallel_threads + 1 +# terminated upon each range. +--let $iter = 3 +--let $generation_len = @@global.slave_parallel_threads +--let $domain_num = 3 +--disable_query_log +--connection master +while ($iter) +{ + --let $k = `select 3 * 3 * $generation_len` + --let $_k = $k + while ($k) + { + --source include/count_sessions.inc + --connect(con$k,localhost,root,,) + # + # create XA events alternating gtid domains to run them in parallel on slave. + # + --let $domain_id = `SELECT $k % $domain_num` + --eval set @@gtid_domain_id = $domain_id + --eval XA START '$trx$k' + --eval INSERT INTO t1 VALUES ($k + 1, $iter) + --eval XA END '$trx$k' + --eval XA PREPARE '$trx$k' + + --disconnect con$k + --connection master + --source include/wait_until_count_sessions.inc + + --dec $k + } + + --connection master + --let $k = $_k + while ($k) + { + --let $term = COMMIT + --let $decision = `SELECT $k % 2` + if ($decision) + { + --let $term = ROLLBACK + } + --eval XA $term '$trx$k' + } + --dec $iter +} +--enable_query_log +--source include/save_master_gtid.inc + +--connection slave +SET @@global.slave_parallel_mode = 'optimistic'; +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + + +# +# Overall consistency check +# +--let $diff_tables= master:t1, slave:t1 +--source include/diff_tables.inc + + +# +# Clean up. +# +--connection slave +--source include/stop_slave.inc +SET @@global.slave_parallel_mode = @old_parallel_mode; +SET @@global.slave_parallel_threads = @old_parallel_threads; +SET @@global.slave_domain_parallel_threads = @old_slave_domain_parallel_threads; +--source include/start_slave.inc + +--connection master +DROP TABLE t1; +--source include/save_master_gtid.inc + +--connection slave +--source include/sync_with_master_gtid.inc + +--connection master +--source include/rpl_end.inc diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index f4fddcd1f65..262c571c771 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -4199,7 +4199,8 @@ int XA_prepare_log_event::do_commit() thd->lex->xid= &xid; if (!one_phase) { - if ((res= thd->wait_for_prior_commit())) + if (thd->is_current_stmt_binlog_disabled() && + (res= thd->wait_for_prior_commit())) return res; thd->lex->sql_command= SQLCOM_XA_PREPARE; diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index 68e42ecd03f..fdc960a8fc6 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -2325,6 +2325,80 @@ rpl_parallel_thread_pool::copy_pool_for_pfs(Relay_log_info *rli) } } + +/* + Check when we have done a complete round of scheduling for workers + 0, 1, ..., (rpl_thread_max-1), in this order. + This often occurs every rpl_thread_max event group, but XA XID dependency + restrictions can cause insertion of extra out-of-order worker scheduling + in-between the normal round-robin scheduling. +*/ +void +rpl_parallel_entry::check_scheduling_generation(sched_bucket *cur) +{ + uint32 idx= static_cast(cur - rpl_threads); + DBUG_ASSERT(cur >= rpl_threads); + DBUG_ASSERT(cur < rpl_threads + rpl_thread_max); + if (idx == current_generation_idx) + { + ++idx; + if (idx >= rpl_thread_max) + { + /* A new generation; all workers have been scheduled at least once. */ + idx= 0; + ++current_generation; + } + current_generation_idx= idx; + } +} + + +rpl_parallel_entry::sched_bucket * +rpl_parallel_entry::check_xa_xid_dependency(xid_t *xid) +{ + uint64 cur_gen= current_generation; + my_off_t i= 0; + while (i < maybe_active_xid.elements) + { + /* + Purge no longer active XID from the list: + + - In generation N, XID might have been scheduled for worker W. + - Events in generation (N+1) might run freely in parallel with W. + - Events in generation (N+2) will have done wait_for_prior_commit for + the event group with XID (or a later one), but the XID might still be + active for a bit longer after wakeup_prior_commit(). + - Events in generation (N+3) will have done wait_for_prior_commit() for + an event in W _after_ the XID, so are sure not to see the XID active. + + Therefore, XID can be safely scheduled to a different worker in + generation (N+3) when last prior use was in generation N (or earlier). + */ + xid_active_generation *a= + dynamic_element(&maybe_active_xid, i, xid_active_generation *); + if (a->generation + 3 <= cur_gen) + { + *a= *((xid_active_generation *)pop_dynamic(&maybe_active_xid)); + continue; + } + if (xid->eq(&a->xid)) + { + /* Update the last used generation and return the match. */ + a->generation= cur_gen; + return a->thr; + } + ++i; + } + /* try to keep allocated memory in the range of [2,10] * initial_chunk_size */ + if (maybe_active_xid.elements <= 2 * active_xid_init_alloc() && + maybe_active_xid.max_element > 10 * active_xid_init_alloc()) + freeze_size(&maybe_active_xid); + + /* No matching XID conflicts. */ + return nullptr; +} + + /* Obtain a worker thread that we can queue an event to. @@ -2369,17 +2443,36 @@ rpl_parallel_entry::choose_thread(rpl_group_info *rgi, bool *did_enter_cond, if (gtid_ev->flags2 & (Gtid_log_event::FL_COMPLETED_XA | Gtid_log_event::FL_PREPARED_XA)) { - /* - For XA COMMIT/ROLLBACK, choose the same bucket as the XA PREPARE, - overriding the round-robin scheduling. - */ - uint32 idx= my_hash_sort(&my_charset_bin, gtid_ev->xid.key(), - gtid_ev->xid.key_length()) % rpl_thread_max; - rpl_threads[idx].unlink(); - thread_sched_fifo->append(rpl_threads + idx); + if ((cur_thr= check_xa_xid_dependency(>id_ev->xid))) + { + /* + A previously scheduled event group with the same XID might still be + active in a worker, so schedule this event group in the same worker + to avoid a conflict. + */ + cur_thr->unlink(); + thread_sched_fifo->append(cur_thr); + } + else + { + /* Record this XID now active. */ + xid_active_generation *a= + (xid_active_generation *)alloc_dynamic(&maybe_active_xid); + if (!a) + return NULL; + a->thr= cur_thr= thread_sched_fifo->head(); + a->generation= current_generation; + a->xid.set(>id_ev->xid); + } } + else + cur_thr= thread_sched_fifo->head(); + + check_scheduling_generation(cur_thr); } - cur_thr= thread_sched_fifo->head(); + else + cur_thr= thread_sched_fifo->head(); + thr= cur_thr->thr; if (thr) @@ -2471,6 +2564,7 @@ free_rpl_parallel_entry(void *element) dealloc_gco(e->current_gco); e->current_gco= prev_gco; } + delete_dynamic(&e->maybe_active_xid); mysql_cond_destroy(&e->COND_parallel_entry); mysql_mutex_destroy(&e->LOCK_parallel_entry); my_free(e); @@ -2524,11 +2618,26 @@ rpl_parallel::find(uint32 domain_id) my_error(ER_OUTOFMEMORY, MYF(0), (int)(sizeof(*e)+count*sizeof(*p))); return NULL; } + /* Initialize a FIFO of scheduled worker threads. */ e->thread_sched_fifo = new (fifo) I_List; - for (ulong i= 0; i < count; ++i) - e->thread_sched_fifo->push_back(::new (p+i) rpl_parallel_entry::sched_bucket); + /* + (We cycle the FIFO _before_ allocating next entry in + rpl_parallel_entry::choose_thread(). So initialize the FIFO with the + highest element at the front, just so that the first event group gets + scheduled on entry 0). + */ + e->thread_sched_fifo-> + push_back(::new (p+count-1) rpl_parallel_entry::sched_bucket); + for (ulong i= 0; i < count-1; ++i) + e->thread_sched_fifo-> + push_back(::new (p+i) rpl_parallel_entry::sched_bucket); e->rpl_threads= p; e->rpl_thread_max= count; + e->current_generation = 0; + e->current_generation_idx = 0; + init_dynamic_array2(PSI_INSTRUMENT_ME, &e->maybe_active_xid, + sizeof(rpl_parallel_entry::xid_active_generation), + 0, e->active_xid_init_alloc(), 0, MYF(0)); e->domain_id= domain_id; e->stop_on_error_sub_id= (uint64)ULONGLONG_MAX; e->pause_sub_id= (uint64)ULONGLONG_MAX; diff --git a/sql/rpl_parallel.h b/sql/rpl_parallel.h index 9ba86453d06..a605b977473 100644 --- a/sql/rpl_parallel.h +++ b/sql/rpl_parallel.h @@ -326,10 +326,26 @@ struct rpl_parallel_thread_pool { struct rpl_parallel_entry { + /* + A small struct to put worker threads references into a FIFO (using an + I_List) for round-robin scheduling. + */ struct sched_bucket : public ilink { sched_bucket() : thr(nullptr) { } rpl_parallel_thread *thr; }; + /* + A struct to keep track of into which "generation" an XA XID was last + scheduled. A "generation" means that we know that every worker thread + slot in the rpl_parallel_entry was scheduled at least once. When more + that two generations have passed, we can safely reuse the XID in a + different worker. + */ + struct xid_active_generation { + uint64 generation; + sched_bucket *thr; + xid_t xid; + }; mysql_mutex_t LOCK_parallel_entry; mysql_cond_t COND_parallel_entry; @@ -373,6 +389,23 @@ struct rpl_parallel_entry { sched_bucket *rpl_threads; I_List *thread_sched_fifo; uint32 rpl_thread_max; + /* + Keep track of all XA XIDs that may still be active in a worker thread. + The elements are of type xid_active_generation. + */ + DYNAMIC_ARRAY maybe_active_xid; + /* + Keeping track of the current scheduling generation. + + A new generation means that every worker thread in the rpl_threads array + have been scheduled at least one event group. + + When we have scheduled to slot current_generation_idx= 0, 1, ..., N-1 in this + order, we know that (at least) one generation has passed. + */ + uint64 current_generation; + uint32 current_generation_idx; + /* The sub_id of the last transaction to commit within this domain_id. Must be accessed under LOCK_parallel_entry protection. @@ -426,11 +459,19 @@ struct rpl_parallel_entry { /* The group_commit_orderer object for the events currently being queued. */ group_commit_orderer *current_gco; + void check_scheduling_generation(sched_bucket *cur); + sched_bucket *check_xa_xid_dependency(xid_t *xid); rpl_parallel_thread * choose_thread(rpl_group_info *rgi, bool *did_enter_cond, PSI_stage_info *old_stage, Gtid_log_event *gtid_ev); int queue_master_restart(rpl_group_info *rgi, Format_description_log_event *fdev); + /* + the initial size of maybe_ array corresponds to the case of + each worker receives perhaps unlikely XA-PREPARE and XA-COMMIT within + the same generation. + */ + inline uint active_xid_init_alloc() { return 3 * 2 * rpl_thread_max; } }; struct rpl_parallel { HASH domain_hash; From 6606abb6a46dac883552fc5096c4744781310215 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 9 Apr 2024 13:25:55 +0400 Subject: [PATCH 090/159] MDEV-18319 BIGINT UNSIGNED Performance issue The patch for MDEV-18319 BIGINT UNSIGNED Performance issue fixed this problem in 10.5.23. This patch adds only an MTR test to cover MDEV-18319. --- mysql-test/main/func_in.result | 24 ++++++++++++++++++++++++ mysql-test/main/func_in.test | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/mysql-test/main/func_in.result b/mysql-test/main/func_in.result index e81ececf752..21b11d74896 100644 --- a/mysql-test/main/func_in.result +++ b/mysql-test/main/func_in.result @@ -979,5 +979,29 @@ c1 9223372036854775808 drop table `a`; # +# MDEV-18319 BIGINT UNSIGNED Performance issue +# +CREATE OR REPLACE TABLE t1 ( +id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY +); +FOR i IN 0..255 +DO +INSERT INTO t1 VALUES (); +END FOR +$$ +SELECT MIN(id), MAX(id), COUNT(*) FROM t1; +MIN(id) MAX(id) COUNT(*) +1 256 256 +EXPLAIN SELECT id FROM t1 WHERE id IN (1,2); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL 2 Using where; Using index +EXPLAIN SELECT id FROM t1 WHERE id IN (9223372036854775806, 9223372036854775807); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL 2 Using where; Using index +EXPLAIN SELECT id FROM t1 WHERE id IN (9223372036854775807, 9223372036854775808); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL 2 Using where; Using index +DROP TABLE t1; +# # End of 10.5 tests # diff --git a/mysql-test/main/func_in.test b/mysql-test/main/func_in.test index 6cddf1dea5c..d24725dbca4 100644 --- a/mysql-test/main/func_in.test +++ b/mysql-test/main/func_in.test @@ -756,6 +756,27 @@ SELECT c1 FROM a WHERE c1 IN ( 1, 9223372036854775807 ); SELECT c1 FROM a WHERE c1 IN ( 1, 9223372036854775808 ); drop table `a`; +--echo # +--echo # MDEV-18319 BIGINT UNSIGNED Performance issue +--echo # + +CREATE OR REPLACE TABLE t1 ( + id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY +); +DELIMITER $$; +FOR i IN 0..255 +DO + INSERT INTO t1 VALUES (); +END FOR +$$ +DELIMITER ;$$ +SELECT MIN(id), MAX(id), COUNT(*) FROM t1; +EXPLAIN SELECT id FROM t1 WHERE id IN (1,2); +EXPLAIN SELECT id FROM t1 WHERE id IN (9223372036854775806, 9223372036854775807); +EXPLAIN SELECT id FROM t1 WHERE id IN (9223372036854775807, 9223372036854775808); +DROP TABLE t1; + + --echo # --echo # End of 10.5 tests --echo # From a4cda66e2df93f039ee536421095e05f52ddd17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 9 Apr 2024 12:48:01 +0300 Subject: [PATCH 091/159] MDEV-33588 buf::Block_hint is a performance hog In so-called optimistic buffer pool lookups, we must not dereference a block descriptor before we have made sure that it is accessible. While buf_pool_t::resize() is running, block descriptors could become invalid. The buf::Block_hint class was essentially duplicating a buf_pool.page_hash lookup that was executed in buf_page_optimistic_get() anyway. For better locality of reference, we had better execute that lookup only once. buf_page_optimistic_fix(): Prepare for buf_page_optimistic_get(). This basically is a simpler version of Buf::Block_hint. buf_page_optimistic_get(): Assume that buf_page_optimistic_fix() has been called and the page identifier verified. Should the block be evicted, the block->modify_clock will be invalidated; we do not need to check the block->page.id() again. It suffices to check the block->modify_clock after acquiring the page latch. btr_pcur_t::old_page_id: Store the expected page identifier for buf_page_optimistic_fix(). btr_pcur_t::block_when_stored: Remove. This was duplicating page_cur_t::block. btr_pcur_optimistic_latch_leaves(): Remove redundant parameters. First, invoke buf_page_optimistic_fix() on the requested page. If needed, acquire a latch on the left page. Finally, acquire a latch on the target page and recheck the block->modify_clock. If the page had been freed while we were not holding a page latch, fall back to the slow path. Validate the FIL_PAGE_PREV after acquiring a latch on the current page. The block->modify_clock is only being incremented when records are deleted or pages reorganized or evicted; it does not guard against concurrent page splits. Reviewed by: Debarun Banerjee --- storage/innobase/CMakeLists.txt | 1 - storage/innobase/btr/btr0btr.cc | 78 +++---- storage/innobase/btr/btr0bulk.cc | 2 +- storage/innobase/btr/btr0cur.cc | 90 +++++--- storage/innobase/btr/btr0pcur.cc | 192 +++++++---------- storage/innobase/buf/buf0block_hint.cc | 59 ------ storage/innobase/buf/buf0buf.cc | 245 +++++++++++----------- storage/innobase/gis/gis0sea.cc | 38 ++-- storage/innobase/include/btr0pcur.h | 5 +- storage/innobase/include/buf0block_hint.h | 76 ------- storage/innobase/include/buf0buf.h | 30 +-- storage/innobase/include/buf0buf.inl | 14 -- storage/innobase/mtr/mtr0mtr.cc | 2 +- 13 files changed, 342 insertions(+), 490 deletions(-) delete mode 100644 storage/innobase/buf/buf0block_hint.cc delete mode 100644 storage/innobase/include/buf0block_hint.h diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index 2f0ab232fc4..aaf0640cebd 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -143,7 +143,6 @@ SET(INNOBASE_SOURCES btr/btr0pcur.cc btr/btr0sea.cc btr/btr0defragment.cc - buf/buf0block_hint.cc buf/buf0buddy.cc buf/buf0buf.cc buf/buf0dblwr.cc diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index 36abb31303e..6b42b3e14ec 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -264,6 +264,8 @@ btr_root_block_get( mtr_t* mtr, /*!< in: mtr */ dberr_t* err) /*!< out: error code */ { + ut_ad(mode != RW_NO_LATCH); + if (!index->table || !index->table->space) { *err= DB_TABLESPACE_NOT_FOUND; @@ -285,13 +287,12 @@ btr_root_block_get( if (UNIV_LIKELY(block != nullptr)) { - if (UNIV_UNLIKELY(mode == RW_NO_LATCH)); - else if (!!page_is_comp(block->page.frame) != - index->table->not_redundant() || - btr_page_get_index_id(block->page.frame) != index->id || - !fil_page_index_page_check(block->page.frame) || - index->is_spatial() != - (fil_page_get_type(block->page.frame) == FIL_PAGE_RTREE)) + if (!!page_is_comp(block->page.frame) != + index->table->not_redundant() || + btr_page_get_index_id(block->page.frame) != index->id || + !fil_page_index_page_check(block->page.frame) || + index->is_spatial() != + (fil_page_get_type(block->page.frame) == FIL_PAGE_RTREE)) { *err= DB_PAGE_CORRUPTED; block= nullptr; @@ -568,6 +569,31 @@ btr_page_alloc_for_ibuf( return new_block; } +static MY_ATTRIBUTE((nonnull, warn_unused_result)) +/** Acquire a latch on the index root page for allocating or freeing pages. +@param index index tree +@param mtr mini-transaction +@param err error code +@return root page +@retval nullptr if an error occurred */ +buf_block_t *btr_root_block_sx(dict_index_t *index, mtr_t *mtr, dberr_t *err) +{ + buf_block_t *root= + mtr->get_already_latched(page_id_t{index->table->space_id, index->page}, + MTR_MEMO_PAGE_SX_FIX); + if (!root) + { + root= btr_root_block_get(index, RW_SX_LATCH, mtr, err); + if (UNIV_UNLIKELY(!root)) + return root; + } +#ifdef BTR_CUR_HASH_ADAPT + else + ut_ad(!root->index || !root->index->freed()); +#endif + return root; +} + /**************************************************************//** Allocates a new file page to be used in an index tree. NOTE: we assume that the caller has made the reservation for free extents! @@ -589,21 +615,9 @@ btr_page_alloc_low( page should be initialized. */ dberr_t* err) /*!< out: error code */ { - const auto savepoint= mtr->get_savepoint(); - buf_block_t *root= btr_root_block_get(index, RW_NO_LATCH, mtr, err); + buf_block_t *root= btr_root_block_sx(index, mtr, err); if (UNIV_UNLIKELY(!root)) return root; - - const bool have_latch= mtr->have_u_or_x_latch(*root); -#ifdef BTR_CUR_HASH_ADAPT - ut_ad(!have_latch || !root->index || !root->index->freed()); -#endif - mtr->rollback_to_savepoint(savepoint); - - if (!have_latch && - UNIV_UNLIKELY(!(root= btr_root_block_get(index, RW_SX_LATCH, mtr, err)))) - return root; - fseg_header_t *seg_header= root->page.frame + (level ? PAGE_HEADER + PAGE_BTR_SEG_TOP : PAGE_HEADER + PAGE_BTR_SEG_LEAF); return fseg_alloc_free_page_general(seg_header, hint_page_no, file_direction, @@ -696,24 +710,16 @@ dberr_t btr_page_free(dict_index_t* index, buf_block_t* block, mtr_t* mtr, fil_space_t *space= index->table->space; dberr_t err; - const auto savepoint= mtr->get_savepoint(); - if (buf_block_t *root= btr_root_block_get(index, RW_NO_LATCH, mtr, &err)) + if (buf_block_t *root= btr_root_block_sx(index, mtr, &err)) { - const bool have_latch= mtr->have_u_or_x_latch(*root); -#ifdef BTR_CUR_HASH_ADAPT - ut_ad(!have_latch || !root->index || !root->index->freed()); -#endif - mtr->rollback_to_savepoint(savepoint); - if (have_latch || - (root= btr_root_block_get(index, RW_SX_LATCH, mtr, &err))) - err= fseg_free_page(&root->page.frame[blob || - page_is_leaf(block->page.frame) - ? PAGE_HEADER + PAGE_BTR_SEG_LEAF - : PAGE_HEADER + PAGE_BTR_SEG_TOP], - space, page, mtr, space_latched); + err= fseg_free_page(&root->page.frame[blob || + page_is_leaf(block->page.frame) + ? PAGE_HEADER + PAGE_BTR_SEG_LEAF + : PAGE_HEADER + PAGE_BTR_SEG_TOP], + space, page, mtr, space_latched); + if (err == DB_SUCCESS) + buf_page_free(space, page, mtr); } - if (err == DB_SUCCESS) - buf_page_free(space, page, mtr); /* The page was marked free in the allocation bitmap, but it should remain exclusively latched until mtr_t::commit() or until it diff --git a/storage/innobase/btr/btr0bulk.cc b/storage/innobase/btr/btr0bulk.cc index eead663b32c..5dcd19fec64 100644 --- a/storage/innobase/btr/btr0bulk.cc +++ b/storage/innobase/btr/btr0bulk.cc @@ -837,7 +837,7 @@ PageBulk::release() m_block->page.fix(); /* No other threads can modify this block. */ - m_modify_clock = buf_block_get_modify_clock(m_block); + m_modify_clock = m_block->modify_clock; m_mtr.commit(); } diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index dc8e9159e6e..aa8ff37272c 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -935,7 +935,7 @@ static inline page_cur_mode_t btr_cur_nonleaf_mode(page_cur_mode_t mode) return PAGE_CUR_LE; } -static MY_ATTRIBUTE((nonnull)) +MY_ATTRIBUTE((nonnull,warn_unused_result)) /** Acquire a latch on the previous page without violating the latching order. @param block index page @param page_id page identifier with valid space identifier @@ -946,8 +946,9 @@ static MY_ATTRIBUTE((nonnull)) @retval 0 if an error occurred @retval 1 if the page could be latched in the wrong order @retval -1 if the latch on block was temporarily released */ -int btr_latch_prev(buf_block_t *block, page_id_t page_id, ulint zip_size, - rw_lock_type_t rw_latch, mtr_t *mtr, dberr_t *err) +static int btr_latch_prev(buf_block_t *block, page_id_t page_id, + ulint zip_size, + rw_lock_type_t rw_latch, mtr_t *mtr, dberr_t *err) { ut_ad(rw_latch == RW_S_LATCH || rw_latch == RW_X_LATCH); ut_ad(page_id.space() == block->page.id().space()); @@ -955,47 +956,80 @@ int btr_latch_prev(buf_block_t *block, page_id_t page_id, ulint zip_size, const auto prev_savepoint= mtr->get_savepoint(); ut_ad(block == mtr->at_savepoint(prev_savepoint - 1)); - page_id.set_page_no(btr_page_get_prev(block->page.frame)); + const page_t *const page= block->page.frame; + page_id.set_page_no(btr_page_get_prev(page)); + /* We are holding a latch on the current page. + + We will start by buffer-fixing the left sibling. Waiting for a latch + on it while holding a latch on the current page could lead to a + deadlock, because another thread could hold that latch and wait for + a right sibling page latch (the current page). + + If there is a conflict, we will temporarily release our latch on the + current block while waiting for a latch on the left sibling. The + buffer-fixes on both blocks will prevent eviction. */ + + retry: buf_block_t *prev= buf_page_get_gen(page_id, zip_size, RW_NO_LATCH, nullptr, BUF_GET, mtr, err, false); if (UNIV_UNLIKELY(!prev)) return 0; int ret= 1; - if (UNIV_UNLIKELY(rw_latch == RW_S_LATCH)) + static_assert(MTR_MEMO_PAGE_S_FIX == mtr_memo_type_t(BTR_SEARCH_LEAF), ""); + static_assert(MTR_MEMO_PAGE_X_FIX == mtr_memo_type_t(BTR_MODIFY_LEAF), ""); + + if (rw_latch == RW_S_LATCH + ? prev->page.lock.s_lock_try() : prev->page.lock.x_lock_try()) { - if (UNIV_LIKELY(prev->page.lock.s_lock_try())) + mtr->lock_register(prev_savepoint, mtr_memo_type_t(rw_latch)); + if (UNIV_UNLIKELY(prev->page.id() != page_id)) { - mtr->lock_register(prev_savepoint, MTR_MEMO_PAGE_S_FIX); - goto prev_latched; + fail: + /* the page was just read and found to be corrupted */ + mtr->rollback_to_savepoint(prev_savepoint); + return 0; } - block->page.lock.s_unlock(); } else { - if (UNIV_LIKELY(prev->page.lock.x_lock_try())) + ut_ad(mtr->at_savepoint(mtr->get_savepoint() - 1)->page.id() == page_id); + mtr->release_last_page(); + if (rw_latch == RW_S_LATCH) + block->page.lock.s_unlock(); + else + block->page.lock.x_unlock(); + + prev= buf_page_get_gen(page_id, zip_size, rw_latch, prev, + BUF_GET, mtr, err); + if (rw_latch == RW_S_LATCH) + block->page.lock.s_lock(); + else + block->page.lock.x_lock(); + + const page_id_t prev_page_id= page_id; + page_id.set_page_no(btr_page_get_prev(page)); + + if (UNIV_UNLIKELY(page_id != prev_page_id)) { - mtr->lock_register(prev_savepoint, MTR_MEMO_PAGE_X_FIX); - goto prev_latched; + mtr->release_last_page(); + if (page_id.page_no() == FIL_NULL) + return -1; + goto retry; } - block->page.lock.x_unlock(); + + if (UNIV_UNLIKELY(!prev)) + goto fail; + + ret= -1; } - ret= -1; - mtr->lock_register(prev_savepoint - 1, MTR_MEMO_BUF_FIX); - mtr->rollback_to_savepoint(prev_savepoint); - prev= buf_page_get_gen(page_id, zip_size, rw_latch, prev, - BUF_GET, mtr, err, false); - if (UNIV_UNLIKELY(!prev)) - return 0; - mtr->upgrade_buffer_fix(prev_savepoint - 1, rw_latch); - - prev_latched: - if (memcmp_aligned<2>(FIL_PAGE_TYPE + prev->page.frame, - FIL_PAGE_TYPE + block->page.frame, 2) || - memcmp_aligned<2>(PAGE_HEADER + PAGE_INDEX_ID + prev->page.frame, - PAGE_HEADER + PAGE_INDEX_ID + block->page.frame, 8) || - page_is_comp(prev->page.frame) != page_is_comp(block->page.frame)) + const page_t *const p= prev->page.frame; + if (memcmp_aligned<4>(FIL_PAGE_NEXT + p, FIL_PAGE_OFFSET + page, 4) || + memcmp_aligned<2>(FIL_PAGE_TYPE + p, FIL_PAGE_TYPE + page, 2) || + memcmp_aligned<2>(PAGE_HEADER + PAGE_INDEX_ID + p, + PAGE_HEADER + PAGE_INDEX_ID + page, 8) || + page_is_comp(p) != page_is_comp(page)) { ut_ad("corrupted" == 0); // FIXME: remove this *err= DB_CORRUPTION; diff --git a/storage/innobase/btr/btr0pcur.cc b/storage/innobase/btr/btr0pcur.cc index 0be12523ae1..3ecdf64fb5f 100644 --- a/storage/innobase/btr/btr0pcur.cc +++ b/storage/innobase/btr/btr0pcur.cc @@ -179,10 +179,8 @@ before_first: cursor->old_n_fields, &cursor->old_rec_buf, &cursor->buf_size); - cursor->block_when_stored.store(block); - - /* Function try to check if block is S/X latch. */ - cursor->modify_clock = buf_block_get_modify_clock(block); + cursor->old_page_id = block->page.id(); + cursor->modify_clock = block->modify_clock; } /**************************************************************//** @@ -214,101 +212,80 @@ btr_pcur_copy_stored_position( } /** Optimistically latches the leaf page or pages requested. -@param[in] block guessed buffer block -@param[in,out] pcur cursor -@param[in,out] latch_mode BTR_SEARCH_LEAF, ... -@param[in,out] mtr mini-transaction -@return true if success */ +@param pcur persistent cursor +@param latch_mode BTR_SEARCH_LEAF, ... +@param mtr mini-transaction +@return true on success */ TRANSACTIONAL_TARGET -static bool btr_pcur_optimistic_latch_leaves(buf_block_t *block, - btr_pcur_t *pcur, +static bool btr_pcur_optimistic_latch_leaves(btr_pcur_t *pcur, btr_latch_mode *latch_mode, mtr_t *mtr) { - ut_ad(block->page.buf_fix_count()); - ut_ad(block->page.in_file()); - ut_ad(block->page.frame); - static_assert(BTR_SEARCH_PREV & BTR_SEARCH_LEAF, ""); static_assert(BTR_MODIFY_PREV & BTR_MODIFY_LEAF, ""); static_assert((BTR_SEARCH_PREV ^ BTR_MODIFY_PREV) == (RW_S_LATCH ^ RW_X_LATCH), ""); + buf_block_t *const block= + buf_page_optimistic_fix(pcur->btr_cur.page_cur.block, pcur->old_page_id); + + if (!block) + return false; + + if (*latch_mode == BTR_SEARCH_LEAF || *latch_mode == BTR_MODIFY_LEAF) + return buf_page_optimistic_get(block, rw_lock_type_t(*latch_mode), + pcur->modify_clock, mtr); + + ut_ad(*latch_mode == BTR_SEARCH_PREV || *latch_mode == BTR_MODIFY_PREV); const rw_lock_type_t mode= rw_lock_type_t(*latch_mode & (RW_X_LATCH | RW_S_LATCH)); - switch (*latch_mode) { - default: - ut_ad(*latch_mode == BTR_SEARCH_LEAF || *latch_mode == BTR_MODIFY_LEAF); - return buf_page_optimistic_get(mode, block, pcur->modify_clock, mtr); - case BTR_SEARCH_PREV: - case BTR_MODIFY_PREV: - page_id_t id{0}; - uint32_t left_page_no; - ulint zip_size; - buf_block_t *left_block= nullptr; - { - transactional_shared_lock_guard g{block->page.lock}; - if (block->modify_clock != pcur->modify_clock) - return false; - id= block->page.id(); - zip_size= block->zip_size(); - left_page_no= btr_page_get_prev(block->page.frame); - } + uint64_t modify_clock; + uint32_t left_page_no; + const page_t *const page= block->page.frame; + { + transactional_shared_lock_guard g{block->page.lock}; + modify_clock= block->modify_clock; + left_page_no= btr_page_get_prev(page); + } - if (left_page_no != FIL_NULL) - { - left_block= - buf_page_get_gen(page_id_t(id.space(), left_page_no), zip_size, - mode, nullptr, BUF_GET_POSSIBLY_FREED, mtr); + const auto savepoint= mtr->get_savepoint(); + mtr->memo_push(block, MTR_MEMO_BUF_FIX); - if (!left_block); - else if (btr_page_get_next(left_block->page.frame) != id.page_no()) - { -release_left_block: - mtr->release_last_page(); - return false; - } - else - buf_page_make_young_if_needed(&left_block->page); - } - - if (buf_page_optimistic_get(mode, block, pcur->modify_clock, mtr)) - { - if (btr_page_get_prev(block->page.frame) == left_page_no) - { - /* block was already buffer-fixed while entering the function and - buf_page_optimistic_get() buffer-fixes it again. */ - ut_ad(2 <= block->page.buf_fix_count()); - *latch_mode= btr_latch_mode(mode); - return true; - } - - mtr->release_last_page(); - } - - ut_ad(block->page.buf_fix_count()); - if (left_block) - goto release_left_block; + if (UNIV_UNLIKELY(modify_clock != pcur->modify_clock)) + { + fail: + mtr->rollback_to_savepoint(savepoint); return false; } -} -/** Structure acts as functor to do the latching of leaf pages. -It returns true if latching of leaf pages succeeded and false -otherwise. */ -struct optimistic_latch_leaves -{ - btr_pcur_t *const cursor; - btr_latch_mode *const latch_mode; - mtr_t *const mtr; - - bool operator()(buf_block_t *hint) const + buf_block_t *prev; + if (left_page_no != FIL_NULL) { - return hint && - btr_pcur_optimistic_latch_leaves(hint, cursor, latch_mode, mtr); + prev= buf_page_get_gen(page_id_t(pcur->old_page_id.space(), + left_page_no), block->zip_size(), + mode, nullptr, BUF_GET_POSSIBLY_FREED, mtr); + if (!prev || + page_is_comp(prev->page.frame) != page_is_comp(block->page.frame) || + memcmp_aligned<2>(block->page.frame, prev->page.frame, 2) || + memcmp_aligned<2>(block->page.frame + PAGE_HEADER + PAGE_INDEX_ID, + prev->page.frame + PAGE_HEADER + PAGE_INDEX_ID, 8)) + goto fail; } -}; + else + prev= nullptr; + + mtr->upgrade_buffer_fix(savepoint, mode); + + if (UNIV_UNLIKELY(block->modify_clock != modify_clock) || + UNIV_UNLIKELY(block->page.is_freed()) || + (prev && + memcmp_aligned<4>(FIL_PAGE_NEXT + prev->page.frame, + FIL_PAGE_OFFSET + page, 4))) + goto fail; + + return true; +} /** Restores the stored position of a persistent cursor bufferfixing the page and obtaining the specified latches. If the cursor position @@ -331,6 +308,7 @@ btr_pcur_t::SAME_UNIQ cursor position is on user rec and points on the record with the same unique field values as in the stored record, btr_pcur_t::NOT_SAME cursor position is not on user rec or points on the record with not the samebuniq field values as in the stored */ +TRANSACTIONAL_TARGET btr_pcur_t::restore_status btr_pcur_t::restore_position(btr_latch_mode restore_latch_mode, mtr_t *mtr) { @@ -361,7 +339,6 @@ btr_pcur_t::restore_position(btr_latch_mode restore_latch_mode, mtr_t *mtr) latch_mode = BTR_LATCH_MODE_WITHOUT_INTENTION(restore_latch_mode); pos_state = BTR_PCUR_IS_POSITIONED; - block_when_stored.clear(); return restore_status::NOT_SAME; } @@ -378,9 +355,8 @@ btr_pcur_t::restore_position(btr_latch_mode restore_latch_mode, mtr_t *mtr) case BTR_SEARCH_PREV: case BTR_MODIFY_PREV: /* Try optimistic restoration. */ - if (block_when_stored.run_with_hint( - optimistic_latch_leaves{this, &restore_latch_mode, - mtr})) { + if (btr_pcur_optimistic_latch_leaves(this, &restore_latch_mode, + mtr)) { pos_state = BTR_PCUR_IS_POSITIONED; latch_mode = restore_latch_mode; @@ -485,9 +461,8 @@ btr_pcur_t::restore_position(btr_latch_mode restore_latch_mode, mtr_t *mtr) since the cursor can now be on a different page! But we can retain the value of old_rec */ - block_when_stored.store(btr_pcur_get_block(this)); - modify_clock= buf_block_get_modify_clock( - block_when_stored.block()); + old_page_id = btr_cur.page_cur.block->page.id(); + modify_clock = btr_cur.page_cur.block->modify_clock; mem_heap_free(heap); @@ -612,40 +587,33 @@ btr_pcur_move_backward_from_page( return true; } - buf_block_t* block = btr_pcur_get_block(cursor); + buf_block_t* block = mtr->at_savepoint(0); + ut_ad(block == btr_pcur_get_block(cursor)); + const page_t* const page = block->page.frame; + /* btr_pcur_optimistic_latch_leaves() will acquire a latch on + the preceding page if one exists; + if that fails, btr_cur_t::search_leaf() invoked by + btr_pcur_open_with_no_init() will also acquire a latch on the + succeeding page. Our caller only needs one page latch. */ + ut_ad(mtr->get_savepoint() <= 3); - if (page_has_prev(block->page.frame)) { - buf_block_t* left_block - = mtr->at_savepoint(mtr->get_savepoint() - 1); - const page_t* const left = left_block->page.frame; - if (memcmp_aligned<4>(left + FIL_PAGE_NEXT, - block->page.frame - + FIL_PAGE_OFFSET, 4)) { - /* This should be the right sibling page, or - if there is none, the current block. */ - ut_ad(left_block == block - || !memcmp_aligned<4>(left + FIL_PAGE_PREV, - block->page.frame - + FIL_PAGE_OFFSET, 4)); - /* The previous one must be the left sibling. */ - left_block - = mtr->at_savepoint(mtr->get_savepoint() - 2); - ut_ad(!memcmp_aligned<4>(left_block->page.frame - + FIL_PAGE_NEXT, - block->page.frame - + FIL_PAGE_OFFSET, 4)); - } + if (page_has_prev(page)) { + buf_block_t* const left_block = mtr->at_savepoint(1); + ut_ad(!memcmp_aligned<4>(page + FIL_PAGE_OFFSET, + left_block->page.frame + + FIL_PAGE_NEXT, 4)); if (btr_pcur_is_before_first_on_page(cursor)) { + /* Reposition on the previous page. */ page_cur_set_after_last(left_block, &cursor->btr_cur.page_cur); /* Release the right sibling. */ - } else { - /* Release the left sibling. */ + mtr->rollback_to_savepoint(0, 1); block = left_block; } - mtr->release(*block); } + mtr->rollback_to_savepoint(1); + ut_ad(block == mtr->at_savepoint(0)); cursor->latch_mode = latch_mode; cursor->old_rec = nullptr; return false; diff --git a/storage/innobase/buf/buf0block_hint.cc b/storage/innobase/buf/buf0block_hint.cc deleted file mode 100644 index 6bd01faa279..00000000000 --- a/storage/innobase/buf/buf0block_hint.cc +++ /dev/null @@ -1,59 +0,0 @@ -/***************************************************************************** - -Copyright (c) 2020, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2020, 2021, MariaDB Corporation. - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License, version 2.0, as published by the -Free Software Foundation. - -This program is also distributed with certain software (including but not -limited to OpenSSL) that is licensed under separate terms, as designated in a -particular file or component or in included license documentation. The authors -of MySQL hereby grant you an additional permission to link the program and -your derivative works with the separately licensed software that they have -included with MySQL. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, -for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., -51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*****************************************************************************/ - -#include "buf0block_hint.h" -namespace buf { - -TRANSACTIONAL_TARGET -void Block_hint::buffer_fix_block_if_still_valid() -{ - /* To check if m_block belongs to the current buf_pool, we must - prevent freeing memory while we check, and until we buffer-fix the - block. For this purpose it is enough to latch any of the many - latches taken by buf_pool_t::resize(). - - Similar to buf_page_optimistic_get(), we must validate - m_block->page.id() after acquiring the hash_lock, because the object - may have been freed and not actually attached to buf_pool.page_hash - at the moment. (The block could have been reused to store a - different page, and that slice of buf_pool.page_hash could be protected - by another hash_lock that we are not holding.) - - Finally, we must ensure that the block is not being freed. */ - if (m_block) - { - auto &cell= buf_pool.page_hash.cell_get(m_page_id.fold()); - transactional_shared_lock_guard g - {buf_pool.page_hash.lock_get(cell)}; - if (buf_pool.is_uncompressed(m_block) && m_page_id == m_block->page.id() && - m_block->page.frame && m_block->page.in_file()) - m_block->page.fix(); - else - clear(); - } -} -} // namespace buf diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 90f47f1fbf0..dc90160a668 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -2562,9 +2562,10 @@ got_block_fixed: if (state > buf_page_t::READ_FIX && state < buf_page_t::WRITE_FIX) { if (mode == BUF_PEEK_IF_IN_POOL) { ignore_block: + block->unfix(); +ignore_unfixed: ut_ad(mode == BUF_GET_POSSIBLY_FREED || mode == BUF_PEEK_IF_IN_POOL); - block->unfix(); if (err) { *err = DB_CORRUPTION; } @@ -2585,9 +2586,17 @@ ignore_block: const page_id_t id{block->page.id()}; block->page.lock.s_unlock(); - if (UNIV_UNLIKELY(id != page_id)) { - ut_ad(id == page_id_t{~0ULL}); + if (UNIV_UNLIKELY(state < buf_page_t::UNFIXED)) { block->page.unfix(); + if (UNIV_UNLIKELY(id == page_id)) { + /* The page read was completed, and + another thread marked the page as free + while we were waiting. */ + goto ignore_unfixed; + } + + ut_ad(id == page_id_t{~0ULL}); + if (++retries < BUF_PAGE_READ_MAX_RETRIES) { goto loop; } @@ -2598,6 +2607,7 @@ ignore_block: return nullptr; } + ut_ad(id == page_id); } else if (mode != BUF_PEEK_IF_IN_POOL) { } else if (!mtr) { ut_ad(!block->page.oldest_modification()); @@ -2804,83 +2814,72 @@ re_evict_fail: #endif /* UNIV_DEBUG */ ut_ad(block->page.frame); + /* The state = block->page.state() may be stale at this point, + and in fact, at any point of time if we consider its + buffer-fix component. If the block is being read into the + buffer pool, it is possible that buf_page_t::read_complete() + will invoke buf_pool_t::corrupted_evict() and therefore + invalidate it (invoke buf_page_t::set_corrupt_id() and set the + state to FREED). Therefore, after acquiring the page latch we + must recheck the state. */ + if (state >= buf_page_t::UNFIXED && allow_ibuf_merge && fil_page_get_type(block->page.frame) == FIL_PAGE_INDEX && page_is_leaf(block->page.frame)) { block->page.lock.x_lock(); - ut_ad(block->page.id() == page_id - || (state >= buf_page_t::READ_FIX - && state < buf_page_t::WRITE_FIX)); - -#ifdef BTR_CUR_HASH_ADAPT - btr_search_drop_page_hash_index(block, true); -#endif /* BTR_CUR_HASH_ADAPT */ - - dberr_t e; - - if (UNIV_UNLIKELY(block->page.id() != page_id)) { -page_id_mismatch: - state = block->page.state(); - e = DB_CORRUPTION; -ibuf_merge_corrupted: - if (err) { - *err = e; - } - - if (block->page.id().is_corrupted()) { - buf_pool.corrupted_evict(&block->page, state); - } - return nullptr; - } - state = block->page.state(); ut_ad(state < buf_page_t::READ_FIX); if (state >= buf_page_t::IBUF_EXIST && state < buf_page_t::REINIT) { block->page.clear_ibuf_exist(); - e = ibuf_merge_or_delete_for_page(block, page_id, - block->zip_size()); - if (UNIV_UNLIKELY(e != DB_SUCCESS)) { - goto ibuf_merge_corrupted; + if (dberr_t local_err = + ibuf_merge_or_delete_for_page(block, page_id, + block->zip_size())) { + if (err) { + *err = local_err; + } + goto release_and_ignore_block; } + } else if (state < buf_page_t::UNFIXED) { +release_and_ignore_block: + block->page.lock.x_unlock(); + goto ignore_block; } - if (rw_latch == RW_X_LATCH) { - goto get_latch_valid; - } else { +#ifdef BTR_CUR_HASH_ADAPT + btr_search_drop_page_hash_index(block, true); +#endif /* BTR_CUR_HASH_ADAPT */ + + switch (rw_latch) { + case RW_NO_LATCH: block->page.lock.x_unlock(); - goto get_latch; + break; + case RW_S_LATCH: + block->page.lock.x_unlock(); + block->page.lock.s_lock(); + break; + case RW_SX_LATCH: + block->page.lock.x_u_downgrade(); + break; + default: + ut_ad(rw_latch == RW_X_LATCH); } + + mtr->memo_push(block, mtr_memo_type_t(rw_latch)); } else { -get_latch: switch (rw_latch) { case RW_NO_LATCH: mtr->memo_push(block, MTR_MEMO_BUF_FIX); return block; case RW_S_LATCH: block->page.lock.s_lock(); - ut_ad(!block->page.is_read_fixed()); - if (UNIV_UNLIKELY(block->page.id() != page_id)) { - block->page.lock.s_unlock(); - block->page.lock.x_lock(); - goto page_id_mismatch; - } -get_latch_valid: - mtr->memo_push(block, mtr_memo_type_t(rw_latch)); -#ifdef BTR_CUR_HASH_ADAPT - btr_search_drop_page_hash_index(block, true); -#endif /* BTR_CUR_HASH_ADAPT */ break; case RW_SX_LATCH: block->page.lock.u_lock(); ut_ad(!block->page.is_io_fixed()); - if (UNIV_UNLIKELY(block->page.id() != page_id)) { - block->page.lock.u_x_upgrade(); - goto page_id_mismatch; - } - goto get_latch_valid; + break; default: ut_ad(rw_latch == RW_X_LATCH); if (block->page.lock.x_lock_upgraded()) { @@ -2889,17 +2888,26 @@ get_latch_valid: mtr->page_lock_upgrade(*block); return block; } - if (UNIV_UNLIKELY(block->page.id() != page_id)) { - goto page_id_mismatch; - } - goto get_latch_valid; } - ut_ad(page_id_t(page_get_space_id(block->page.frame), - page_get_page_no(block->page.frame)) - == page_id); + mtr->memo_push(block, mtr_memo_type_t(rw_latch)); + state = block->page.state(); + + if (UNIV_UNLIKELY(state < buf_page_t::UNFIXED)) { + mtr->release_last_page(); + goto ignore_unfixed; + } + + ut_ad(state < buf_page_t::READ_FIX + || state > buf_page_t::WRITE_FIX); + +#ifdef BTR_CUR_HASH_ADAPT + btr_search_drop_page_hash_index(block, true); +#endif /* BTR_CUR_HASH_ADAPT */ } + ut_ad(page_id_t(page_get_space_id(block->page.frame), + page_get_page_no(block->page.frame)) == page_id); return block; } @@ -2995,83 +3003,76 @@ buf_page_get_gen( return block; } -/********************************************************************//** -This is the general function used to get optimistic access to a database -page. -@return TRUE if success */ TRANSACTIONAL_TARGET -bool buf_page_optimistic_get(ulint rw_latch, buf_block_t *block, - uint64_t modify_clock, mtr_t *mtr) +buf_block_t *buf_page_optimistic_fix(buf_block_t *block, page_id_t id) +{ + buf_pool_t::hash_chain &chain= buf_pool.page_hash.cell_get(id.fold()); + transactional_shared_lock_guard g + {buf_pool.page_hash.lock_get(chain)}; + if (UNIV_UNLIKELY(!buf_pool.is_uncompressed(block) || + id != block->page.id() || !block->page.frame)) + return nullptr; + const auto state= block->page.state(); + if (UNIV_UNLIKELY(state < buf_page_t::UNFIXED || + state >= buf_page_t::READ_FIX)) + return nullptr; + block->page.fix(); + return block; +} + +buf_block_t *buf_page_optimistic_get(buf_block_t *block, + rw_lock_type_t rw_latch, + uint64_t modify_clock, mtr_t *mtr) { - ut_ad(block); - ut_ad(mtr); ut_ad(mtr->is_active()); ut_ad(rw_latch == RW_S_LATCH || rw_latch == RW_X_LATCH); + ut_ad(block->page.buf_fix_count()); - if (have_transactional_memory); - else if (UNIV_UNLIKELY(!block->page.frame)) - return false; - else + if (rw_latch == RW_S_LATCH) { - const auto state= block->page.state(); - if (UNIV_UNLIKELY(state < buf_page_t::UNFIXED || - state >= buf_page_t::READ_FIX)) - return false; - } - - bool success; - const page_id_t id{block->page.id()}; - buf_pool_t::hash_chain &chain= buf_pool.page_hash.cell_get(id.fold()); - bool have_u_not_x= false; - - { - transactional_shared_lock_guard g - {buf_pool.page_hash.lock_get(chain)}; - if (UNIV_UNLIKELY(id != block->page.id() || !block->page.frame)) - return false; - const auto state= block->page.state(); - if (UNIV_UNLIKELY(state < buf_page_t::UNFIXED || - state >= buf_page_t::READ_FIX)) - return false; - - if (rw_latch == RW_S_LATCH) - success= block->page.lock.s_lock_try(); - else + if (!block->page.lock.s_lock_try()) { - have_u_not_x= block->page.lock.have_u_not_x(); - success= have_u_not_x || block->page.lock.x_lock_try(); + fail: + block->page.unfix(); + return nullptr; } - } - if (!success) - return false; - - if (have_u_not_x) - { - block->page.lock.u_x_upgrade(); - mtr->page_lock_upgrade(*block); - ut_ad(id == block->page.id()); - ut_ad(modify_clock == block->modify_clock); - } - else - { - ut_ad(rw_latch == RW_S_LATCH || !block->page.is_io_fixed()); - ut_ad(id == block->page.id()); - ut_ad(!ibuf_inside(mtr) || ibuf_page(id, block->zip_size(), nullptr)); + ut_ad(!ibuf_inside(mtr) || + ibuf_page(block->page.id(), block->zip_size(), nullptr)); if (modify_clock != block->modify_clock || block->page.is_freed()) { - if (rw_latch == RW_S_LATCH) - block->page.lock.s_unlock(); - else - block->page.lock.x_unlock(); - return false; + block->page.lock.s_unlock(); + goto fail; } - block->page.fix(); ut_ad(!block->page.is_read_fixed()); buf_page_make_young_if_needed(&block->page); - mtr->memo_push(block, mtr_memo_type_t(rw_latch)); + mtr->memo_push(block, MTR_MEMO_PAGE_S_FIX); + } + else if (block->page.lock.have_u_not_x()) + { + block->page.lock.u_x_upgrade(); + block->page.unfix(); + mtr->page_lock_upgrade(*block); + ut_ad(modify_clock == block->modify_clock); + } + else if (!block->page.lock.x_lock_try()) + goto fail; + else + { + ut_ad(!block->page.is_io_fixed()); + ut_ad(!ibuf_inside(mtr) || + ibuf_page(block->page.id(), block->zip_size(), nullptr)); + + if (modify_clock != block->modify_clock || block->page.is_freed()) + { + block->page.lock.x_unlock(); + goto fail; + } + + buf_page_make_young_if_needed(&block->page); + mtr->memo_push(block, MTR_MEMO_PAGE_X_FIX); } ut_d(if (!(++buf_dbg_counter % 5771)) buf_pool.validate()); @@ -3081,7 +3082,7 @@ bool buf_page_optimistic_get(ulint rw_latch, buf_block_t *block, ut_ad(~buf_page_t::LRU_MASK & state); ut_ad(block->page.frame); - return true; + return block; } /** Try to S-latch a page. diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc index 0df9a7ded9a..fb4fcf7bc8d 100644 --- a/storage/innobase/gis/gis0sea.cc +++ b/storage/innobase/gis/gis0sea.cc @@ -672,8 +672,13 @@ dberr_t rtr_search_to_nth_level(ulint level, const dtuple_t *tuple, buf_mode, mtr, &err, false); if (!block) { - if (err == DB_DECRYPTION_FAILED) - btr_decryption_failed(*index); + if (err) + { + err_exit: + if (err == DB_DECRYPTION_FAILED) + btr_decryption_failed(*index); + mtr->rollback_to_savepoint(savepoint); + } func_exit: if (UNIV_LIKELY_NULL(heap)) mem_heap_free(heap); @@ -737,7 +742,8 @@ dberr_t rtr_search_to_nth_level(ulint level, const dtuple_t *tuple, #endif } - if (height == 0) { + if (height == 0) + { if (rw_latch == RW_NO_LATCH) { ut_ad(block == mtr->at_savepoint(block_savepoint)); @@ -821,7 +827,7 @@ dberr_t rtr_search_to_nth_level(ulint level, const dtuple_t *tuple, if (page_cur_search_with_match(tuple, page_mode, &up_match, &low_match, &cur->page_cur, nullptr)) { err= DB_CORRUPTION; - goto func_exit; + goto err_exit; } } @@ -1584,23 +1590,6 @@ rtr_check_discard_page( lock_sys.prdt_page_free_from_discard(id, true); } -/** Structure acts as functor to get the optimistic access of the page. -It returns true if it successfully gets the page. */ -struct optimistic_get -{ - btr_pcur_t *const r_cursor; - mtr_t *const mtr; - - optimistic_get(btr_pcur_t *r_cursor,mtr_t *mtr) - :r_cursor(r_cursor), mtr(mtr) {} - - bool operator()(buf_block_t *hint) const - { - return hint && buf_page_optimistic_get( - RW_X_LATCH, hint, r_cursor->modify_clock, mtr); - } -}; - /** Restore the stored position of a persistent cursor bufferfixing the page */ static bool @@ -1632,8 +1621,11 @@ rtr_cur_restore_position( r_cursor->modify_clock = 100; ); - if (r_cursor->block_when_stored.run_with_hint( - optimistic_get(r_cursor, mtr))) { + if (buf_page_optimistic_fix(r_cursor->btr_cur.page_cur.block, + r_cursor->old_page_id) + && buf_page_optimistic_get(r_cursor->btr_cur.page_cur.block, + RW_X_LATCH, r_cursor->modify_clock, + mtr)) { ut_ad(r_cursor->pos_state == BTR_PCUR_IS_POSITIONED); ut_ad(r_cursor->rel_pos == BTR_PCUR_ON); diff --git a/storage/innobase/include/btr0pcur.h b/storage/innobase/include/btr0pcur.h index c66a3bfa329..775f1536f83 100644 --- a/storage/innobase/include/btr0pcur.h +++ b/storage/innobase/include/btr0pcur.h @@ -28,7 +28,6 @@ Created 2/23/1996 Heikki Tuuri #include "dict0dict.h" #include "btr0cur.h" -#include "buf0block_hint.h" #include "btr0btr.h" #include "gis0rtree.h" @@ -332,8 +331,8 @@ struct btr_pcur_t /** BTR_PCUR_ON, BTR_PCUR_BEFORE, or BTR_PCUR_AFTER, depending on whether cursor was on, before, or after the old_rec record */ btr_pcur_pos_t rel_pos= btr_pcur_pos_t(0); - /** buffer block when the position was stored */ - buf::Block_hint block_when_stored; + /** the page identifier of old_rec */ + page_id_t old_page_id{0,0}; /** the modify clock value of the buffer block when the cursor position was stored */ ib_uint64_t modify_clock= 0; diff --git a/storage/innobase/include/buf0block_hint.h b/storage/innobase/include/buf0block_hint.h deleted file mode 100644 index d4fee7c1e99..00000000000 --- a/storage/innobase/include/buf0block_hint.h +++ /dev/null @@ -1,76 +0,0 @@ -/***************************************************************************** - -Copyright (c) 2020, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2020, MariaDB Corporation. -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License, version 2.0, as published by the -Free Software Foundation. - -This program is also distributed with certain software (including but not -limited to OpenSSL) that is licensed under separate terms, as designated in a -particular file or component or in included license documentation. The authors -of MySQL hereby grant you an additional permission to link the program and -your derivative works with the separately licensed software that they have -included with MySQL. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, -for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., -51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*****************************************************************************/ -#pragma once -#include "buf0buf.h" - -namespace buf { -class Block_hint { -public: - /** Stores the pointer to the block, which is currently buffer-fixed. - @param block a pointer to a buffer-fixed block to be stored */ - inline void store(buf_block_t *block) - { - ut_ad(block->page.buf_fix_count()); - m_block= block; - m_page_id= block->page.id(); - } - - /** Clears currently stored pointer. */ - inline void clear() { m_block= nullptr; } - - /** Invoke f on m_block(which may be null) - @param f The function to be executed. It will be passed the pointer. - If you wish to use the block pointer subsequently, - you need to ensure you buffer-fix it before returning from f. - @return the return value of f - */ - template - bool run_with_hint(const F &f) - { - buffer_fix_block_if_still_valid(); - /* m_block could be changed during f() call, so we use local - variable to remember which block we need to unfix */ - buf_block_t *block= m_block; - bool res= f(block); - if (block) - block->page.unfix(); - return res; - } - - buf_block_t *block() const { return m_block; } - - private: - /** The block pointer stored by store(). */ - buf_block_t *m_block= nullptr; - /** If m_block is non-null, the m_block->page.id at time it was stored. */ - page_id_t m_page_id{0, 0}; - - /** A helper function which checks if m_block is not a dangling pointer and - still points to block with page with m_page_id and if so, buffer-fixes it, - otherwise clear()s it */ - void buffer_fix_block_if_still_valid(); -}; -} // namespace buf diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 51e30c88a86..2a79b112bab 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -158,14 +158,25 @@ buf_block_free( #define buf_page_get(ID, SIZE, LA, MTR) \ buf_page_get_gen(ID, SIZE, LA, NULL, BUF_GET, MTR) -/** Try to acquire a page latch. -@param rw_latch RW_S_LATCH or RW_X_LATCH +/** Try to buffer-fix a page. @param block guessed block +@param id expected block->page.id() +@return block if it was buffer-fixed +@retval nullptr if the block no longer is valid */ +buf_block_t *buf_page_optimistic_fix(buf_block_t *block, page_id_t id) + MY_ATTRIBUTE((nonnull, warn_unused_result)); + +/** Try to acquire a page latch after buf_page_optimistic_fix(). +@param block buffer-fixed block +@param rw_latch RW_S_LATCH or RW_X_LATCH @param modify_clock expected value of block->modify_clock @param mtr mini-transaction -@return whether the latch was acquired (the page is an allocated file page) */ -bool buf_page_optimistic_get(ulint rw_latch, buf_block_t *block, - uint64_t modify_clock, mtr_t *mtr); +@return block if the latch was acquired +@retval nullptr if block->unfix() was called because it no longer is valid */ +buf_block_t *buf_page_optimistic_get(buf_block_t *block, + rw_lock_type_t rw_latch, + uint64_t modify_clock, mtr_t *mtr) + MY_ATTRIBUTE((nonnull, warn_unused_result)); /** Try to S-latch a page. Suitable for using when holding the lock_sys latches (as it avoids deadlock). @@ -290,15 +301,6 @@ on the block. */ UNIV_INLINE void buf_block_modify_clock_inc( -/*=======================*/ - buf_block_t* block); /*!< in: block */ -/********************************************************************//** -Returns the value of the modify clock. The caller must have an s-lock -or x-lock on the block. -@return value */ -UNIV_INLINE -ib_uint64_t -buf_block_get_modify_clock( /*=======================*/ buf_block_t* block); /*!< in: block */ #endif /* !UNIV_INNOCHECKSUM */ diff --git a/storage/innobase/include/buf0buf.inl b/storage/innobase/include/buf0buf.inl index f1af9963ab0..a72ff61161f 100644 --- a/storage/innobase/include/buf0buf.inl +++ b/storage/innobase/include/buf0buf.inl @@ -116,17 +116,3 @@ buf_block_modify_clock_inc( block->modify_clock++; } - -/********************************************************************//** -Returns the value of the modify clock. The caller must have an s-lock -or x-lock on the block. -@return value */ -UNIV_INLINE -ib_uint64_t -buf_block_get_modify_clock( -/*=======================*/ - buf_block_t* block) /*!< in: block */ -{ - ut_ad(block->page.lock.have_any()); - return(block->modify_clock); -} diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc index 4456d7d0d75..3f3158e7db4 100644 --- a/storage/innobase/mtr/mtr0mtr.cc +++ b/storage/innobase/mtr/mtr0mtr.cc @@ -985,7 +985,7 @@ void mtr_t::upgrade_buffer_fix(ulint savepoint, rw_lock_type_t rw_latch) ut_ad(slot.type == MTR_MEMO_BUF_FIX); buf_block_t *block= static_cast(slot.object); ut_d(const auto state= block->page.state()); - ut_ad(state > buf_page_t::UNFIXED); + ut_ad(state > buf_page_t::FREED); ut_ad(state > buf_page_t::WRITE_FIX || state < buf_page_t::READ_FIX); static_assert(int{MTR_MEMO_PAGE_S_FIX} == int{RW_S_LATCH}, ""); static_assert(int{MTR_MEMO_PAGE_X_FIX} == int{RW_X_LATCH}, ""); From 4aa92911c7edc99d98dd4f86c93cba2ed8fb77c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 9 Apr 2024 12:50:24 +0300 Subject: [PATCH 092/159] MDEV-33802 Weird read view after ROLLBACK of another transaction Even after commit b8a671988954870b7db22e20d1a1409fd40f8e3d there is an anomaly where a locking read could return inconsistent results. If a locking read would have to wait for a record lock, then by the definition of a read view, the modifications made by the current lock holder cannot be visible in the read view. This is because the read view must exclude any transactions that had not been committed at the time when the read view was created. lock_rec_convert_impl_to_expl_for_trx(), lock_rec_convert_impl_to_expl(): Return an unsafe-to-dereference pointer to a transaction that holds or held the lock, or nullptr if the lock was available. lock_clust_rec_modify_check_and_lock(), lock_sec_rec_read_check_and_lock(), lock_clust_rec_read_check_and_lock(): Return DB_RECORD_CHANGED if innodb_strict_isolation=ON and the lock was being held by another transaction. The test case, which is based on a bug report by Zhuang Liu, covers the function lock_sec_rec_read_check_and_lock(). Reviewed by: Vladislav Lesin --- .../suite/innodb/r/lock_isolation.result | 33 ++++- mysql-test/suite/innodb/t/lock_isolation.test | 43 +++++- storage/innobase/lock/lock0lock.cc | 134 ++++++++++-------- 3 files changed, 148 insertions(+), 62 deletions(-) diff --git a/mysql-test/suite/innodb/r/lock_isolation.result b/mysql-test/suite/innodb/r/lock_isolation.result index 88a2ad9326e..eaba6b899a1 100644 --- a/mysql-test/suite/innodb/r/lock_isolation.result +++ b/mysql-test/suite/innodb/r/lock_isolation.result @@ -82,7 +82,6 @@ SELECT * FROM t; a b 10 20 10 20 -disconnect consistent; connection default; TRUNCATE TABLE t; INSERT INTO t VALUES(NULL, 1), (2, 2); @@ -99,10 +98,40 @@ a b COMMIT; connection con_weird; COMMIT; -disconnect con_weird; connection default; SELECT * FROM t; a b 10 1 10 20 DROP TABLE t; +# +# MDEV-33802 Weird read view after ROLLBACK of other transactions +# +CREATE TABLE t(a INT PRIMARY KEY, b INT UNIQUE) ENGINE=InnoDB; +INSERT INTO t SET a=1; +BEGIN; +INSERT INTO t SET a=2; +connection consistent; +START TRANSACTION WITH CONSISTENT SNAPSHOT; +SELECT * FROM t FORCE INDEX (b) FOR UPDATE; +ERROR HY000: Record has changed since last read in table 't' +connection con_weird; +START TRANSACTION WITH CONSISTENT SNAPSHOT; +SELECT * FROM t FORCE INDEX (b) FOR UPDATE; +connection default; +ROLLBACK; +connection con_weird; +a b +1 NULL +1 NULL +SELECT * FROM t FORCE INDEX (b) FOR UPDATE; +a b +1 NULL +disconnect con_weird; +connection consistent; +SELECT * FROM t FORCE INDEX (b) FOR UPDATE; +a b +1 NULL +disconnect consistent; +connection default; +DROP TABLE t; diff --git a/mysql-test/suite/innodb/t/lock_isolation.test b/mysql-test/suite/innodb/t/lock_isolation.test index 30d2978f4f2..5c60f6e707c 100644 --- a/mysql-test/suite/innodb/t/lock_isolation.test +++ b/mysql-test/suite/innodb/t/lock_isolation.test @@ -79,7 +79,6 @@ COMMIT; --connection consistent --reap SELECT * FROM t; ---disconnect consistent --connection default TRUNCATE TABLE t; @@ -103,8 +102,48 @@ COMMIT; --connection con_weird --reap COMMIT; ---disconnect con_weird --connection default SELECT * FROM t; DROP TABLE t; + +--echo # +--echo # MDEV-33802 Weird read view after ROLLBACK of other transactions +--echo # + +CREATE TABLE t(a INT PRIMARY KEY, b INT UNIQUE) ENGINE=InnoDB; +INSERT INTO t SET a=1; + +BEGIN; INSERT INTO t SET a=2; + +--connection consistent +START TRANSACTION WITH CONSISTENT SNAPSHOT; +--disable_ps2_protocol +--error ER_CHECKREAD +SELECT * FROM t FORCE INDEX (b) FOR UPDATE; +--enable_ps2_protocol + +--connection con_weird +START TRANSACTION WITH CONSISTENT SNAPSHOT; +send +SELECT * FROM t FORCE INDEX (b) FOR UPDATE; + +--connection default +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = 'Sending data' + and info LIKE 'SELECT * FROM t %'; +--source include/wait_condition.inc +ROLLBACK; + +--connection con_weird +--reap +SELECT * FROM t FORCE INDEX (b) FOR UPDATE; +--disconnect con_weird + +--connection consistent +SELECT * FROM t FORCE INDEX (b) FOR UPDATE; +--disconnect consistent + +--connection default +DROP TABLE t; diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 69b3dd1f5c2..a210700727c 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -5586,47 +5586,43 @@ lock_rec_insert_check_and_lock( return err; } -/*********************************************************************//** -Creates an explicit record lock for a running transaction that currently only -has an implicit lock on the record. The transaction instance must have a -reference count > 0 so that it can't be committed and freed before this -function has completed. */ -static -bool -lock_rec_convert_impl_to_expl_for_trx( -/*==================================*/ - trx_t* trx, /*!< in/out: active transaction */ - const page_id_t id, /*!< in: page identifier */ - const rec_t* rec, /*!< in: user record on page */ - dict_index_t* index) /*!< in: index of record */ +/** Create an explicit record lock for a transaction that currently only +has an implicit lock on the record. +@param trx referenced, active transaction, or nullptr +@param id page identifier +@param rec record in the page +@param index the index B-tree that the record belongs to +@return trx, with the reference released */ +static trx_t *lock_rec_convert_impl_to_expl_for_trx(trx_t *trx, + const page_id_t id, + const rec_t *rec, + dict_index_t *index) { - if (!trx) - return false; - - ut_ad(trx->is_referenced()); - ut_ad(page_rec_is_leaf(rec)); - ut_ad(!rec_is_metadata(rec, *index)); - - DEBUG_SYNC_C("before_lock_rec_convert_impl_to_expl_for_trx"); - ulint heap_no= page_rec_get_heap_no(rec); - + if (trx) { - LockGuard g{lock_sys.rec_hash, id}; - trx->mutex_lock(); - ut_ad(!trx_state_eq(trx, TRX_STATE_NOT_STARTED)); + ut_ad(trx->is_referenced()); + ut_ad(page_rec_is_leaf(rec)); + ut_ad(!rec_is_metadata(rec, *index)); - if (!trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY) && - !lock_rec_has_expl(LOCK_X | LOCK_REC_NOT_GAP, g.cell(), id, heap_no, - trx)) - lock_rec_add_to_queue(LOCK_X | LOCK_REC_NOT_GAP, g.cell(), id, - page_align(rec), heap_no, index, trx, true); + ulint heap_no= page_rec_get_heap_no(rec); + + { + LockGuard g{lock_sys.rec_hash, id}; + trx->mutex_lock(); + ut_ad(!trx_state_eq(trx, TRX_STATE_NOT_STARTED)); + + if (!trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY) && + !lock_rec_has_expl(LOCK_X | LOCK_REC_NOT_GAP, g.cell(), id, heap_no, + trx)) + lock_rec_add_to_queue(LOCK_X | LOCK_REC_NOT_GAP, g.cell(), id, + page_align(rec), heap_no, index, trx, true); + } + + trx->release_reference(); + trx->mutex_unlock(); } - trx->mutex_unlock(); - trx->release_reference(); - - DEBUG_SYNC_C("after_lock_rec_convert_impl_to_expl_for_trx"); - return false; + return trx; } @@ -5717,10 +5713,11 @@ should be created. @param[in] rec record on the leaf page @param[in] index the index of the record @param[in] offsets rec_get_offsets(rec,index) -@return whether caller_trx already holds an exclusive lock on rec */ +@return unsafe pointer to a transaction that held an exclusive lock on rec +@retval nullptr if no transaction held an exclusive lock */ template static -bool +const trx_t * lock_rec_convert_impl_to_expl( trx_t* caller_trx, page_id_t id, @@ -5744,10 +5741,10 @@ lock_rec_convert_impl_to_expl( trx_id = lock_clust_rec_some_has_impl(rec, index, offsets); if (trx_id == 0) { - return false; + return nullptr; } if (UNIV_UNLIKELY(trx_id == caller_trx->id)) { - return true; + return caller_trx; } trx = trx_sys.find(caller_trx, trx_id); @@ -5758,7 +5755,7 @@ lock_rec_convert_impl_to_expl( offsets); if (trx == caller_trx) { trx->release_reference(); - return true; + return trx; } ut_d(lock_rec_other_trx_holds_expl(caller_trx, trx, rec, id)); @@ -5803,11 +5800,18 @@ lock_clust_rec_modify_check_and_lock( /* If a transaction has no explicit x-lock set on the record, set one for it */ - if (lock_rec_convert_impl_to_expl(thr_get_trx(thr), - block->page.id(), + trx_t *trx = thr_get_trx(thr); + if (const trx_t *owner = + lock_rec_convert_impl_to_expl(trx, block->page.id(), rec, index, offsets)) { - /* We already hold an implicit exclusive lock. */ - return DB_SUCCESS; + if (owner == trx) { + /* We already hold an exclusive lock. */ + return DB_SUCCESS; + } + + if (trx->snapshot_isolation && trx->read_view.is_open()) { + return DB_RECORD_CHANGED; + } } err = lock_rec_lock(true, LOCK_X | LOCK_REC_NOT_GAP, @@ -5970,12 +5974,19 @@ lock_sec_rec_read_check_and_lock( return DB_SUCCESS; } - if (!page_rec_is_supremum(rec) - && lock_rec_convert_impl_to_expl( - trx, block->page.id(), rec, index, offsets) - && gap_mode == LOCK_REC_NOT_GAP) { - /* We already hold an implicit exclusive lock. */ - return DB_SUCCESS; + if (page_rec_is_supremum(rec)) { + } else if (const trx_t *owner = + lock_rec_convert_impl_to_expl(trx, block->page.id(), + rec, index, offsets)) { + if (owner == trx) { + if (gap_mode == LOCK_REC_NOT_GAP) { + /* We already hold an exclusive lock. */ + return DB_SUCCESS; + } + } else if (trx->snapshot_isolation + && trx->read_view.is_open()) { + return DB_RECORD_CHANGED; + } } #ifdef WITH_WSREP @@ -6055,13 +6066,20 @@ lock_clust_rec_read_check_and_lock( ulint heap_no = page_rec_get_heap_no(rec); trx_t *trx = thr_get_trx(thr); - if (!lock_table_has(trx, index->table, LOCK_X) - && heap_no != PAGE_HEAP_NO_SUPREMUM - && lock_rec_convert_impl_to_expl(trx, id, - rec, index, offsets) - && gap_mode == LOCK_REC_NOT_GAP) { - /* We already hold an implicit exclusive lock. */ - return DB_SUCCESS; + if (lock_table_has(trx, index->table, LOCK_X) + || heap_no == PAGE_HEAP_NO_SUPREMUM) { + } else if (const trx_t *owner = + lock_rec_convert_impl_to_expl(trx, id, + rec, index, offsets)) { + if (owner == trx) { + if (gap_mode == LOCK_REC_NOT_GAP) { + /* We already hold an exclusive lock. */ + return DB_SUCCESS; + } + } else if (trx->snapshot_isolation + && trx->read_view.is_open()) { + return DB_RECORD_CHANGED; + } } if (heap_no > PAGE_HEAP_NO_SUPREMUM && gap_mode != LOCK_GAP From 3003a3dab0697db4da3dc70cd09707b773fac1dd Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Fri, 5 Apr 2024 11:22:28 +0200 Subject: [PATCH 093/159] galera: wsrep-lib submodule update --- wsrep-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsrep-lib b/wsrep-lib index 7d108eb8706..dfc4bdb8a5d 160000 --- a/wsrep-lib +++ b/wsrep-lib @@ -1 +1 @@ -Subproject commit 7d108eb8706962abc74705bedfc60cfc3f296ea6 +Subproject commit dfc4bdb8a5dcbd6fbea007ad3beff899a6b5b7bd From 7aa86eb1e183178063527c90094bdc2b2ed2c44e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 4 Apr 2024 14:30:59 +0300 Subject: [PATCH 094/159] MDEV-33828 : Transactional commit not supported by involved engine(s) Problem was too tight condition on ha_commit_trans to not allow non transactional storage engines participate 2pc in Galera case. This is required because transaction using e.g. procedures might read mysql.proc table inside a trasaction and these tables use at the moment Aria storage engine that does not support 2pc. Fixed by allowing read only transactions to storage engines that do not support two phase commit to participate 2pc transaction. These will be committed later separately. Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/r/MDEV-33828.result | 41 +++++++++++++++++++ mysql-test/suite/galera/r/mdev-22063.result | 26 ++++++------ mysql-test/suite/galera/t/MDEV-33828.cnf | 4 ++ mysql-test/suite/galera/t/MDEV-33828.test | 45 +++++++++++++++++++++ mysql-test/suite/galera/t/mdev-22063.test | 12 ++---- sql/handler.cc | 41 +++++++++++++++---- 6 files changed, 140 insertions(+), 29 deletions(-) create mode 100644 mysql-test/suite/galera/r/MDEV-33828.result create mode 100644 mysql-test/suite/galera/t/MDEV-33828.cnf create mode 100644 mysql-test/suite/galera/t/MDEV-33828.test diff --git a/mysql-test/suite/galera/r/MDEV-33828.result b/mysql-test/suite/galera/r/MDEV-33828.result new file mode 100644 index 00000000000..a3ce68166ab --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-33828.result @@ -0,0 +1,41 @@ +connection node_2; +connection node_1; +SET AUTOCOMMIT=ON; +SELECT @@autocommit; +@@autocommit +1 +SET LOCAL enforce_storage_engine=InnoDB; +CREATE TABLE t1(id int not null primary key auto_increment, name varchar(64)) ENGINE=InnoDB; +INSERT INTO t1(name) VALUES ('name1'),('name3'),('name6'),('name2'); +CREATE PROCEDURE sel_proc() +BEGIN +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; +SELECT * FROM t1; +END| +CREATE PROCEDURE ins_proc() +BEGIN +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; +INSERT INTO t1 VALUES ('name_proc'); +END| +SET AUTOCOMMIT=OFF; +SELECT @@autocommit; +@@autocommit +0 +START TRANSACTION; +insert into t1(name) values('name10'); +select param_list, returns, db, type from mysql.proc where name='sel_proc'; +param_list returns db type + test PROCEDURE +call ins_proc(); +COMMIT; +SET AUTOCOMMIT=ON; +SELECT * FROM t1; +id name +1 name1 +3 name3 +5 name6 +7 name2 +9 name10 +DROP TABLE t1; +DROP PROCEDURE sel_proc; +DROP PROCEDURE ins_proc; diff --git a/mysql-test/suite/galera/r/mdev-22063.result b/mysql-test/suite/galera/r/mdev-22063.result index 0f1a51e44d4..5773e70cc9d 100644 --- a/mysql-test/suite/galera/r/mdev-22063.result +++ b/mysql-test/suite/galera/r/mdev-22063.result @@ -79,7 +79,6 @@ INSERT INTO t3(id) SELECT seq FROM seq_1_to_1000; REPLACE INTO t4 SELECT * FROM t1; REPLACE INTO t5 SELECT * FROM t2; REPLACE INTO t6 SELECT * FROM t3; -ERROR HY000: Transactional commit not supported by involved engine(s) REPLACE INTO t7 SELECT * FROM t2; REPLACE INTO t8 SELECT * FROM t3; SELECT COUNT(*) AS EXPECT_1000 FROM t1; @@ -97,9 +96,9 @@ EXPECT_1000 SELECT COUNT(*) AS EXPECT_1000 FROM t5; EXPECT_1000 1000 -SELECT COUNT(*) AS EXPECT_0 FROM t6; -EXPECT_0 -0 +SELECT COUNT(*) AS EXPECT_1000 FROM t6; +EXPECT_1000 +1000 SELECT COUNT(*) AS EXPECT_1000 FROM t7; EXPECT_1000 1000 @@ -122,9 +121,9 @@ EXPECT_1000 SELECT COUNT(*) AS EXPECT_1000 FROM t5; EXPECT_1000 1000 -SELECT COUNT(*) AS EXPECT_0 FROM t6; -EXPECT_0 -0 +SELECT COUNT(*) AS EXPECT_1000 FROM t6; +EXPECT_1000 +1000 SELECT COUNT(*) AS EXPECT_1000 FROM t7; EXPECT_1000 1000 @@ -148,7 +147,6 @@ INSERT INTO t3(id) SELECT seq FROM seq_1_to_1000; INSERT INTO t4 SELECT * FROM t1; INSERT INTO t5 SELECT * FROM t2; INSERT INTO t6 SELECT * FROM t3; -ERROR HY000: Transactional commit not supported by involved engine(s) INSERT INTO t7 SELECT * FROM t2; INSERT INTO t8 SELECT * FROM t3; SELECT COUNT(*) AS EXPECT_1000 FROM t1; @@ -166,9 +164,9 @@ EXPECT_1000 SELECT COUNT(*) AS EXPECT_1000 FROM t5; EXPECT_1000 1000 -SELECT COUNT(*) AS EXPECT_0 FROM t6; -EXPECT_0 -0 +SELECT COUNT(*) AS EXPECT_1000 FROM t6; +EXPECT_1000 +1000 SELECT COUNT(*) AS EXPECT_1000 FROM t7; EXPECT_1000 1000 @@ -191,9 +189,9 @@ EXPECT_1000 SELECT COUNT(*) AS EXPECT_1000 FROM t5; EXPECT_1000 1000 -SELECT COUNT(*) AS EXPECT_0 FROM t6; -EXPECT_0 -0 +SELECT COUNT(*) AS EXPECT_1000 FROM t6; +EXPECT_1000 +1000 SELECT COUNT(*) AS EXPECT_1000 FROM t7; EXPECT_1000 1000 diff --git a/mysql-test/suite/galera/t/MDEV-33828.cnf b/mysql-test/suite/galera/t/MDEV-33828.cnf new file mode 100644 index 00000000000..4c62448fe3d --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-33828.cnf @@ -0,0 +1,4 @@ +!include ../galera_2nodes.cnf + +[mysqld] +log-bin diff --git a/mysql-test/suite/galera/t/MDEV-33828.test b/mysql-test/suite/galera/t/MDEV-33828.test new file mode 100644 index 00000000000..8e30481beee --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-33828.test @@ -0,0 +1,45 @@ +--source include/galera_cluster.inc +--source include/have_innodb.inc +--source include/have_aria.inc + +SET AUTOCOMMIT=ON; +SELECT @@autocommit; + +SET LOCAL enforce_storage_engine=InnoDB; + +CREATE TABLE t1(id int not null primary key auto_increment, name varchar(64)) ENGINE=InnoDB; +INSERT INTO t1(name) VALUES ('name1'),('name3'),('name6'),('name2'); + +DELIMITER |; +CREATE PROCEDURE sel_proc() +BEGIN + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; + SELECT * FROM t1; +END| + +CREATE PROCEDURE ins_proc() +BEGIN + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; + INSERT INTO t1 VALUES ('name_proc'); +END| +DELIMITER ;| + +SET AUTOCOMMIT=OFF; +SELECT @@autocommit; + +START TRANSACTION; + +insert into t1(name) values('name10'); + +select param_list, returns, db, type from mysql.proc where name='sel_proc'; + +call ins_proc(); + +COMMIT; + +SET AUTOCOMMIT=ON; + +SELECT * FROM t1; +DROP TABLE t1; +DROP PROCEDURE sel_proc; +DROP PROCEDURE ins_proc; diff --git a/mysql-test/suite/galera/t/mdev-22063.test b/mysql-test/suite/galera/t/mdev-22063.test index 043c5e253fd..a8e7b87ad38 100644 --- a/mysql-test/suite/galera/t/mdev-22063.test +++ b/mysql-test/suite/galera/t/mdev-22063.test @@ -81,8 +81,6 @@ INSERT INTO t3(id) SELECT seq FROM seq_1_to_1000; REPLACE INTO t4 SELECT * FROM t1; REPLACE INTO t5 SELECT * FROM t2; -# For some reason Aria storage engine does register_ha ---error ER_ERROR_DURING_COMMIT REPLACE INTO t6 SELECT * FROM t3; REPLACE INTO t7 SELECT * FROM t2; REPLACE INTO t8 SELECT * FROM t3; @@ -92,7 +90,7 @@ SELECT COUNT(*) AS EXPECT_1000 FROM t2; SELECT COUNT(*) AS EXPECT_1000 FROM t3; SELECT COUNT(*) AS EXPECT_1000 FROM t4; SELECT COUNT(*) AS EXPECT_1000 FROM t5; -SELECT COUNT(*) AS EXPECT_0 FROM t6; +SELECT COUNT(*) AS EXPECT_1000 FROM t6; SELECT COUNT(*) AS EXPECT_1000 FROM t7; SELECT COUNT(*) AS EXPECT_1000 FROM t8; @@ -107,7 +105,7 @@ SELECT COUNT(*) AS EXPECT_1000 FROM t2; SELECT COUNT(*) AS EXPECT_1000 FROM t3; SELECT COUNT(*) AS EXPECT_1000 FROM t4; SELECT COUNT(*) AS EXPECT_1000 FROM t5; -SELECT COUNT(*) AS EXPECT_0 FROM t6; +SELECT COUNT(*) AS EXPECT_1000 FROM t6; SELECT COUNT(*) AS EXPECT_1000 FROM t7; SELECT COUNT(*) AS EXPECT_1000 FROM t8; @@ -131,8 +129,6 @@ INSERT INTO t3(id) SELECT seq FROM seq_1_to_1000; INSERT INTO t4 SELECT * FROM t1; INSERT INTO t5 SELECT * FROM t2; -# For some reason Aria storage engine does register_ha ---error ER_ERROR_DURING_COMMIT INSERT INTO t6 SELECT * FROM t3; INSERT INTO t7 SELECT * FROM t2; INSERT INTO t8 SELECT * FROM t3; @@ -142,7 +138,7 @@ SELECT COUNT(*) AS EXPECT_1000 FROM t2; SELECT COUNT(*) AS EXPECT_1000 FROM t3; SELECT COUNT(*) AS EXPECT_1000 FROM t4; SELECT COUNT(*) AS EXPECT_1000 FROM t5; -SELECT COUNT(*) AS EXPECT_0 FROM t6; +SELECT COUNT(*) AS EXPECT_1000 FROM t6; SELECT COUNT(*) AS EXPECT_1000 FROM t7; SELECT COUNT(*) AS EXPECT_1000 FROM t8; @@ -157,7 +153,7 @@ SELECT COUNT(*) AS EXPECT_1000 FROM t2; SELECT COUNT(*) AS EXPECT_1000 FROM t3; SELECT COUNT(*) AS EXPECT_1000 FROM t4; SELECT COUNT(*) AS EXPECT_1000 FROM t5; -SELECT COUNT(*) AS EXPECT_0 FROM t6; +SELECT COUNT(*) AS EXPECT_1000 FROM t6; SELECT COUNT(*) AS EXPECT_1000 FROM t7; SELECT COUNT(*) AS EXPECT_1000 FROM t8; diff --git a/sql/handler.cc b/sql/handler.cc index 24bc845c694..40dfbffa667 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1531,6 +1531,29 @@ ha_check_and_coalesce_trx_read_only(THD *thd, Ha_trx_info *ha_list, return rw_ha_count; } +#ifdef WITH_WSREP +/** + Check if transaction contains storage engine not supporting + two-phase commit and transaction is read-write. + + @retval + true Transaction contains storage engine not supporting + two phase commit and transaction is read-write + @retval + false otherwise +*/ +static bool wsrep_have_no2pc_rw_ha(Ha_trx_info* ha_list) +{ + for (Ha_trx_info *ha_info=ha_list; ha_info; ha_info= ha_info->next()) + { + handlerton *ht= ha_info->ht(); + // Transaction is read-write and handler does not support 2pc + if (ha_info->is_trx_read_write() && ht->prepare==0) + return true; + } + return false; +} +#endif /* WITH_WSREP */ /** @retval @@ -1734,14 +1757,18 @@ int ha_commit_trans(THD *thd, bool all) */ if (run_wsrep_hooks) { - // This commit involves more than one storage engine and requires - // two phases, but some engines don't support it. - // Issue a message to the client and roll back the transaction. - if (trans->no_2pc && rw_ha_count > 1) + // This commit involves storage engines that do not support two phases. + // We allow read only transactions to such storage engines but not + // read write transactions. + if (trans->no_2pc && rw_ha_count > 1 && wsrep_have_no2pc_rw_ha(trans->ha_list)) { - // REPLACE|INSERT INTO ... SELECT uses TOI for MyISAM|Aria - if (WSREP(thd) && thd->wsrep_cs().mode() != wsrep::client_state::m_toi) - { + // This commit involves more than one storage engine and requires + // two phases, but some engines don't support it. + // Issue a message to the client and roll back the transaction. + + // REPLACE|INSERT INTO ... SELECT uses TOI for MyISAM|Aria + if (WSREP(thd) && thd->wsrep_cs().mode() != wsrep::client_state::m_toi) + { my_message(ER_ERROR_DURING_COMMIT, "Transactional commit not supported " "by involved engine(s)", MYF(0)); error= 1; From d4936c8b26c88ef29eecabb13ff5c1cd6d15c590 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 9 Apr 2024 14:18:29 +0400 Subject: [PATCH 095/159] MDEV-18898 SELECT using wrong index when using operator IN with mixed types These patches: # commit 74891ed257c431e5e8b4bc9479ca6456563d592f # # MDEV-11514, MDEV-11497, MDEV-11554, MDEV-11555 - IN and CASE type aggregation problems # commit 53499cd1ea1c8092460924224d78a286d617492d # # MDEV-31303 Key not used when IN clause has both signed and usigned values earlier fixed MDEV-18898. Adding only an MTR case. modified: mysql-test/main/func_in.result modified: mysql-test/main/func_in.test --- mysql-test/main/func_in.result | 54 ++++++++++++++++++++++++++++++++++ mysql-test/main/func_in.test | 39 ++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/mysql-test/main/func_in.result b/mysql-test/main/func_in.result index 21b11d74896..36b61a782bd 100644 --- a/mysql-test/main/func_in.result +++ b/mysql-test/main/func_in.result @@ -1003,5 +1003,59 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL 2 Using where; Using index DROP TABLE t1; # +# MDEV-18898 SELECT using wrong index when using operator IN with mixed types +# +CREATE TEMPORARY TABLE t1 ( +id int(10) unsigned NOT NULL AUTO_INCREMENT, +name varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +PRIMARY KEY (`id`), +UNIQUE KEY `name` (`name`) +); +FOR i IN 1..255 +DO +INSERT INTO t1 VALUES (i, MD5(i)); +END FOR +$$ +# +# Constants alone +# +ANALYZE SELECT id, name FROM t1 WHERE id = 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 NULL 100.00 NULL +ANALYZE SELECT id, name FROM t1 WHERE id = '2'; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 NULL 100.00 NULL +# +# Two constants using IN +# +ANALYZE SELECT id, name FROM t1 WHERE id IN (1, 2); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition +ANALYZE SELECT id, name FROM t1 WHERE id IN ('1', 2) /* Used a wrong index */; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition +ANALYZE SELECT id, name FROM t1 WHERE id IN (1, '2') /* Used a wrong index */; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition +ANALYZE SELECT id, name FROM t1 WHERE id IN ('1', '2'); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition +# +# Two constants using OR +# +ANALYZE SELECT id, name FROM t1 WHERE id = 1 OR id = 2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition +ANALYZE SELECT id, name FROM t1 WHERE id = '1' OR id = '2'; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition +ANALYZE SELECT id, name FROM t1 WHERE id = 1 OR id = '2'; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition +ANALYZE SELECT id, name FROM t1 WHERE id = '1' OR id = 2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition +DROP TABLE t1; +# # End of 10.5 tests # diff --git a/mysql-test/main/func_in.test b/mysql-test/main/func_in.test index d24725dbca4..1e335b4b4ad 100644 --- a/mysql-test/main/func_in.test +++ b/mysql-test/main/func_in.test @@ -777,6 +777,45 @@ EXPLAIN SELECT id FROM t1 WHERE id IN (9223372036854775807, 9223372036854775808) DROP TABLE t1; +--echo # +--echo # MDEV-18898 SELECT using wrong index when using operator IN with mixed types +--echo # + +CREATE TEMPORARY TABLE t1 ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + name varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +); +DELIMITER $$; +FOR i IN 1..255 +DO + INSERT INTO t1 VALUES (i, MD5(i)); +END FOR +$$ +DELIMITER ;$$ +--echo # +--echo # Constants alone +--echo # +ANALYZE SELECT id, name FROM t1 WHERE id = 1; +ANALYZE SELECT id, name FROM t1 WHERE id = '2'; +--echo # +--echo # Two constants using IN +--echo # +ANALYZE SELECT id, name FROM t1 WHERE id IN (1, 2); +ANALYZE SELECT id, name FROM t1 WHERE id IN ('1', 2) /* Used a wrong index */; +ANALYZE SELECT id, name FROM t1 WHERE id IN (1, '2') /* Used a wrong index */; +ANALYZE SELECT id, name FROM t1 WHERE id IN ('1', '2'); +--echo # +--echo # Two constants using OR +--echo # +ANALYZE SELECT id, name FROM t1 WHERE id = 1 OR id = 2; +ANALYZE SELECT id, name FROM t1 WHERE id = '1' OR id = '2'; +ANALYZE SELECT id, name FROM t1 WHERE id = 1 OR id = '2'; +ANALYZE SELECT id, name FROM t1 WHERE id = '1' OR id = 2; +DROP TABLE t1; + + --echo # --echo # End of 10.5 tests --echo # From 33af5575a976c86163752cce77dddb640ffeef00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 4 Sep 2023 12:22:51 +0300 Subject: [PATCH 096/159] MDEV-25731 : Assertion `mode_ == m_local' failed in void wsrep::client_state::streaming_params(wsrep::streaming_context::fragment_unit, size_t) Problem was that if wsrep_load_data_splitting was used streaming replication (SR) parameters were set for MyISAM table. Galera does not currently support SR for MyISAM. Fix is to ignore wsrep_load_data_splitting setting (with warning) if table is not InnoDB table. This is 10.6+ case of fix. Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/r/MDEV-25731.result | 23 ++++++++++++++------- mysql-test/suite/galera/t/MDEV-25731.test | 17 ++++++++++----- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/galera/r/MDEV-25731.result b/mysql-test/suite/galera/r/MDEV-25731.result index 92e1704e658..11a72730fb1 100644 --- a/mysql-test/suite/galera/r/MDEV-25731.result +++ b/mysql-test/suite/galera/r/MDEV-25731.result @@ -4,9 +4,7 @@ connection node_1; SET GLOBAL wsrep_load_data_splitting=ON; Warnings: Warning 1287 '@@wsrep_load_data_splitting' is deprecated and will be removed in a future release -SET GLOBAL wsrep_replicate_myisam=ON; -Warnings: -Warning 1287 '@@wsrep_replicate_myisam' is deprecated and will be removed in a future release. Please use '@@wsrep_mode=REPLICATE_MYISAM' instead +SET GLOBAL wsrep_mode=REPLICATE_MYISAM; CREATE TABLE t1 (c1 int) ENGINE=MYISAM; LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; Warnings: @@ -19,8 +17,11 @@ SELECT COUNT(*) AS EXPECT_6 FROM t1; EXPECT_6 6 connection node_1; -ALTER TABLE t1 ENGINE=InnoDB; +ALTER TABLE t1 ENGINE=Aria; +SET GLOBAL wsrep_mode=REPLICATE_ARIA; LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; +Warnings: +Warning 1235 wsrep_load_data_splitting for other than InnoDB tables SELECT COUNT(*) AS EXPECT_12 FROM t1; EXPECT_12 12 @@ -29,10 +30,18 @@ SELECT COUNT(*) AS EXPECT_12 FROM t1; EXPECT_12 12 connection node_1; +ALTER TABLE t1 ENGINE=InnoDB; +LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; +SELECT COUNT(*) AS EXPECT_18 FROM t1; +EXPECT_18 +18 +connection node_2; +SELECT COUNT(*) AS EXPECT_18 FROM t1; +EXPECT_18 +18 +connection node_1; DROP TABLE t1; SET GLOBAL wsrep_load_data_splitting=OFF; Warnings: Warning 1287 '@@wsrep_load_data_splitting' is deprecated and will be removed in a future release -SET GLOBAL wsrep_replicate_myisam=OFF; -Warnings: -Warning 1287 '@@wsrep_replicate_myisam' is deprecated and will be removed in a future release. Please use '@@wsrep_mode=REPLICATE_MYISAM' instead +SET GLOBAL wsrep_mode=DEFAULT; diff --git a/mysql-test/suite/galera/t/MDEV-25731.test b/mysql-test/suite/galera/t/MDEV-25731.test index c26fad2fa6a..893cccbb2bd 100644 --- a/mysql-test/suite/galera/t/MDEV-25731.test +++ b/mysql-test/suite/galera/t/MDEV-25731.test @@ -3,7 +3,7 @@ --connection node_1 SET GLOBAL wsrep_load_data_splitting=ON; -SET GLOBAL wsrep_replicate_myisam=ON; +SET GLOBAL wsrep_mode=REPLICATE_MYISAM; CREATE TABLE t1 (c1 int) ENGINE=MYISAM; LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; SELECT COUNT(*) AS EXPECT_6 FROM t1; @@ -12,16 +12,23 @@ SELECT COUNT(*) AS EXPECT_6 FROM t1; SELECT COUNT(*) AS EXPECT_6 FROM t1; --connection node_1 -ALTER TABLE t1 ENGINE=InnoDB; +ALTER TABLE t1 ENGINE=Aria; +SET GLOBAL wsrep_mode=REPLICATE_ARIA; LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; SELECT COUNT(*) AS EXPECT_12 FROM t1; --connection node_2 SELECT COUNT(*) AS EXPECT_12 FROM t1; +--connection node_1 +ALTER TABLE t1 ENGINE=InnoDB; +LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; +SELECT COUNT(*) AS EXPECT_18 FROM t1; + +--connection node_2 +SELECT COUNT(*) AS EXPECT_18 FROM t1; + --connection node_1 DROP TABLE t1; SET GLOBAL wsrep_load_data_splitting=OFF; -SET GLOBAL wsrep_replicate_myisam=OFF; - - +SET GLOBAL wsrep_mode=DEFAULT; From 4980fcb9909449f4d65886ee2c1d1080bb3d55a5 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 9 Apr 2024 13:07:23 +0200 Subject: [PATCH 097/159] MDEV-33867 main.query_cache_debug fails with heap-use-after-free What's happening: 1. Query_cache::insert() locks the QC and verifies that it's enabled 2. parallel thread tries to disable it. trylock fails (QC is locked) so the status becomes DISABLE_REQUEST 3. Query_cache::insert() calls Query_cache::write_result_data() which allocates a new block and unlocks the QC. 4. Query_cache::unlock() notices there are no more QC users and a pending DISABLE_REQUEST so it disables the QC and frees all the memory, including the new block that was just allocated 5. Query_cache::write_result_data() proceeds to write into the freed block Fix: change m_cache_status under a mutex. Approved by Oleksandr Byelkin --- sql/sql_cache.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 8655a75a455..c876636d383 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -2530,14 +2530,9 @@ void Query_cache::destroy() void Query_cache::disable_query_cache(THD *thd) { + lock(thd); m_cache_status= DISABLE_REQUEST; - /* - If there is no requests in progress try to free buffer. - try_lock(TRY) will exit immediately if there is lock. - unlock() should free block. - */ - if (m_requests_in_progress == 0 && !try_lock(thd, TRY)) - unlock(); + unlock(); } From 952ab9a59659b28f10ce2770e17249e0ff5b0681 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Mon, 8 Apr 2024 13:04:59 -0600 Subject: [PATCH 098/159] MDEV-30260: Slave crashed:reload_acl_and_cache during shutdown The signal handler thread can use various different runtime resources when processing a SIGHUP (e.g. master-info information) due to calling into reload_acl_and_cache(). Currently, the shutdown process waits for the termination of the signal thread after performing cleanup. However, this could cause resources actively used by the signal handler to be freed while reload_acl_and_cache() is processing. The specific resource that caused MDEV-30260 is a race condition for the hostname_cache, such that mysqld would delete it in clean_up()::hostname_cache_free(), before the signal handler would use it in reload_acl_and_cache()::hostname_cache_refresh(). Another similar resource is the active_mi/master_info_index. There was a race between its deletion by the main thread in end_slave(), and their usage by the Signal Handler as a part of Master_info_index::flush_all_relay_logs.read(active_mi) in reload_acl_and_cache(). This patch fixes these race conditions by relocating where server shutdown waits for the signal handler to die until after server-level threads have been killed (i.e., as a last step of close_connections()). With respect to the hostname_cache, active_mi and master_info_cache, this ensures that they cannot be destroyed while the signal handler is still active, and potentially using them. Additionally: 1) This requires that Events memory is still in place for SIGHUP handling's mysql_print_status(). So event deinitialization is moved into clean_up(), but the event scheduler still needs to be stopped in close_connections() at the same spot. 2) The function kill_server_thread is no longer used, so it is deleted 3) The timeout to wait for the death of the signal thread was not consistent with the comment. The comment mentioned up to 10 seconds, whereas it was actually 0.01s. The code has been fixed to wait up to 10 seconds. 4) A warning has been added if the signal handler thread fails to exit in time. 5) Added pthread_join() to end of wait_for_signal_thread_to_end() if it hadn't ended in 10s with a warning. Note this also removes the pthread_detached attribute from the signal_thread to allow for the pthread_join(). Reviewed By: =========== Vladislav Vaintroub Andrei Elkin --- .../suite/rpl/r/rpl_shutdown_sighup.result | 50 ++++++ .../suite/rpl/t/rpl_shutdown_sighup.test | 154 ++++++++++++++++++ sql/mysqld.cc | 67 ++++---- sql/sql_reload.cc | 23 +++ 4 files changed, 259 insertions(+), 35 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_shutdown_sighup.result create mode 100644 mysql-test/suite/rpl/t/rpl_shutdown_sighup.test diff --git a/mysql-test/suite/rpl/r/rpl_shutdown_sighup.result b/mysql-test/suite/rpl/r/rpl_shutdown_sighup.result new file mode 100644 index 00000000000..01b35f1dc58 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_shutdown_sighup.result @@ -0,0 +1,50 @@ +include/master-slave.inc +[connection master] +connection slave; +set statement sql_log_bin=0 for call mtr.add_suppression("Signal handler thread did not exit in a timely manner"); +# +# Main test +connection master; +create table t1 (a int); +insert into t1 values (1); +include/save_master_gtid.inc +connection slave; +include/sync_with_master_gtid.inc +set @@global.debug_dbug= "+d,hold_sighup_log_refresh"; +# Waiting for sighup to reach reload_acl_and_cache.. +set debug_sync="now wait_for in_reload_acl_and_cache"; +# Signalling signal handler to proceed to sleep before REFRESH_HOSTS +set debug_sync="now signal refresh_logs"; +# Starting shutdown (note this will take 3+ seconds due to DBUG my_sleep in reload_acl_and_cache) +shutdown; +connection server_2; +connection slave; +include/assert_grep.inc [Ensure Mariadbd did not segfault when shutting down] +connection master; +connection slave; +# +# Error testcase to ensure an error message is shown if the signal +# takes longer than the timeout while processing the SIGHUP +connection slave; +set @@global.debug_dbug= "+d,force_sighup_processing_timeout"; +set @@global.debug_dbug= "+d,hold_sighup_log_refresh"; +connection master; +insert into t1 values (1); +include/save_master_gtid.inc +connection slave; +include/sync_with_master_gtid.inc +# Waiting for sighup to reach reload_acl_and_cache.. +set debug_sync="now wait_for in_reload_acl_and_cache"; +# Signalling signal handler to proceed to sleep before REFRESH_HOSTS +set debug_sync="now signal refresh_logs"; +# Starting shutdown (note this will take 3+ seconds due to DBUG my_sleep in reload_acl_and_cache) +shutdown; +connection server_2; +connection slave; +include/assert_grep.inc [Ensure warning is issued that signal handler thread is still processing] +# +# Cleanup +connection master; +drop table t1; +include/rpl_end.inc +# End of rpl_shutdown_sighup.test diff --git a/mysql-test/suite/rpl/t/rpl_shutdown_sighup.test b/mysql-test/suite/rpl/t/rpl_shutdown_sighup.test new file mode 100644 index 00000000000..d1940f81a85 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_shutdown_sighup.test @@ -0,0 +1,154 @@ +# +# The signal handler thread can use various different runtime resources when +# processing a SIGHUP (e.g. master-info information), as the logic calls into +# reload_acl_and_cache(). This test ensures that SIGHUP processing, when +# concurrent with server shutdown, the shutdown logic must wait for the SIGHUP +# processing to finish before cleaning up any resources. +# +# Additionally, the error case is tested such that the signal handler thread +# takes too long processing a SIGHUP, and the main mysqld thread must skip its +# wait and output a warning. +# +# Note the SIGHUP is sent via the command-line kill program via a perl script. +# +# References: +# MDEV-30260: Slave crashed:reload_acl_and_cache during shutdown +# + +--source include/not_windows.inc +--source include/not_embedded.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc + +# Binlog format doesn't matter +--source include/have_binlog_format_statement.inc +--source include/master-slave.inc + +# For error test case which forces timeout +--connection slave +set statement sql_log_bin=0 for call mtr.add_suppression("Signal handler thread did not exit in a timely manner"); + + +--echo # +--echo # Main test +--connection master +create table t1 (a int); +insert into t1 values (1); +--source include/save_master_gtid.inc + +--connection slave +--source include/sync_with_master_gtid.inc + +# Make signal handler handle SIGHUP.. +set @@global.debug_dbug= "+d,hold_sighup_log_refresh"; +--let KILL_NODE_PIDFILE = `SELECT @@pid_file` +--perl + my $kill_sig = $ENV{'KILL_SIGNAL_VALUE'}; + my $pid_filename = $ENV{'KILL_NODE_PIDFILE'}; + my $mysqld_pid = `cat $pid_filename`; + chomp($mysqld_pid); + system("kill -HUP $mysqld_pid"); + exit(0); +EOF + +--echo # Waiting for sighup to reach reload_acl_and_cache.. +set debug_sync="now wait_for in_reload_acl_and_cache"; +--echo # Signalling signal handler to proceed to sleep before REFRESH_HOSTS +set debug_sync="now signal refresh_logs"; + +# ..while we are shutting down +--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +wait +EOF +--echo # Starting shutdown (note this will take 3+ seconds due to DBUG my_sleep in reload_acl_and_cache) +shutdown; + +--source include/wait_until_disconnected.inc +--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +restart: --skip-slave-start=0 +EOF + +--connection server_2 +--enable_reconnect +--source include/wait_until_connected_again.inc + +--connection slave +--enable_reconnect +--source include/wait_until_connected_again.inc + +--let $assert_text= Ensure Mariadbd did not segfault when shutting down +--let $assert_select= got signal 11 +--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.2.err +--let $assert_count= 0 +--let $assert_only_after = CURRENT_TEST: rpl.rpl_shutdown_sighup +--source include/assert_grep.inc + +--connection master +--sync_slave_with_master + + +--echo # +--echo # Error testcase to ensure an error message is shown if the signal +--echo # takes longer than the timeout while processing the SIGHUP + +--connection slave +set @@global.debug_dbug= "+d,force_sighup_processing_timeout"; +set @@global.debug_dbug= "+d,hold_sighup_log_refresh"; + +--connection master +insert into t1 values (1); +--source include/save_master_gtid.inc + +--connection slave +--source include/sync_with_master_gtid.inc + +# Make signal handler handle SIGHUP.. +--let KILL_NODE_PIDFILE = `SELECT @@pid_file` +--perl + my $kill_sig = $ENV{'KILL_SIGNAL_VALUE'}; + my $pid_filename = $ENV{'KILL_NODE_PIDFILE'}; + my $mysqld_pid = `cat $pid_filename`; + chomp($mysqld_pid); + system("kill -HUP $mysqld_pid"); + exit(0); +EOF +--echo # Waiting for sighup to reach reload_acl_and_cache.. +set debug_sync="now wait_for in_reload_acl_and_cache"; +--echo # Signalling signal handler to proceed to sleep before REFRESH_HOSTS +set debug_sync="now signal refresh_logs"; + +# ..while we are shutting down +--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +wait +EOF +--echo # Starting shutdown (note this will take 3+ seconds due to DBUG my_sleep in reload_acl_and_cache) +shutdown; + +--source include/wait_until_disconnected.inc +--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +restart: --skip-slave-start=0 +EOF + +--connection server_2 +--enable_reconnect +--source include/wait_until_connected_again.inc + +--connection slave +--enable_reconnect +--source include/wait_until_connected_again.inc + +--let $assert_text= Ensure warning is issued that signal handler thread is still processing +--let $assert_select= Signal handler thread did not exit in a timely manner. +--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.2.err +--let $assert_count= 1 +--let $assert_only_after = CURRENT_TEST: rpl.rpl_shutdown_sighup +--source include/assert_grep.inc + + +--echo # +--echo # Cleanup +--connection master +drop table t1; + +--source include/rpl_end.inc +--echo # End of rpl_shutdown_sighup.test diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 5d23a972cdc..5ba51bdfb74 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1766,7 +1766,8 @@ static void close_connections(void) DBUG_EXECUTE_IF("delay_shutdown_phase_2_after_semisync_wait", my_sleep(500000);); - Events::deinit(); + if (Events::inited) + Events::stop(); slave_prepare_for_shutdown(); ack_receiver.stop(); @@ -1827,6 +1828,12 @@ static void close_connections(void) } /* End of kill phase 2 */ + /* + The signal thread can use server resources, e.g. when processing SIGHUP, + and it must end gracefully before clean_up() + */ + wait_for_signal_thread_to_end(); + DBUG_PRINT("quit",("close_connections thread")); DBUG_VOID_RETURN; } @@ -1930,14 +1937,8 @@ extern "C" void unireg_abort(int exit_code) static void mysqld_exit(int exit_code) { DBUG_ENTER("mysqld_exit"); - /* - Important note: we wait for the signal thread to end, - but if a kill -15 signal was sent, the signal thread did - spawn the kill_server_thread thread, which is running concurrently. - */ rpl_deinit_gtid_waiting(); rpl_deinit_gtid_slave_state(); - wait_for_signal_thread_to_end(); #ifdef WITH_WSREP wsrep_deinit_server(); wsrep_sst_auth_free(); @@ -2016,6 +2017,9 @@ static void clean_up(bool print_message) free_status_vars(); end_thr_alarm(1); /* Free allocated memory */ end_thr_timer(); +#ifndef EMBEDDED_LIBRARY + Events::deinit(); +#endif my_free_open_file_info(); if (defaults_argv) free_defaults(defaults_argv); @@ -2083,16 +2087,32 @@ static void clean_up(bool print_message) */ static void wait_for_signal_thread_to_end() { - uint i; + uint i, n_waits= DBUG_EVALUATE("force_sighup_processing_timeout", 5, 100); + int err= 0; /* Wait up to 10 seconds for signal thread to die. We use this mainly to avoid getting warnings that my_thread_end has not been called */ - for (i= 0 ; i < 100 && signal_thread_in_use; i++) + for (i= 0 ; i < n_waits && signal_thread_in_use; i++) { - if (pthread_kill(signal_thread, MYSQL_KILL_SIGNAL) == ESRCH) + err= pthread_kill(signal_thread, MYSQL_KILL_SIGNAL); + if (err) break; - my_sleep(100); // Give it time to die + my_sleep(100000); // Give it time to die, .1s per iteration + } + + if (err && err != ESRCH) + { + sql_print_error("Failed to send kill signal to signal handler thread, " + "pthread_kill() errno: %d", + err); + } + + if (i == n_waits && signal_thread_in_use) + { + sql_print_warning("Signal handler thread did not exit in a timely manner. " + "Continuing to wait for it to stop.."); + pthread_join(signal_thread, NULL); } } #endif /*EMBEDDED_LIBRARY*/ @@ -2916,7 +2936,6 @@ static void start_signal_handler(void) (void) pthread_attr_init(&thr_attr); pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_SYSTEM); - (void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); (void) my_setstacksize(&thr_attr,my_thread_stack_size); mysql_mutex_lock(&LOCK_start_thread); @@ -2936,18 +2955,6 @@ static void start_signal_handler(void) } -#if defined(USE_ONE_SIGNAL_HAND) -pthread_handler_t kill_server_thread(void *arg __attribute__((unused))) -{ - my_thread_init(); // Initialize new thread - break_connect_loop(); - my_thread_end(); - pthread_exit(0); - return 0; -} -#endif - - /** This threads handles all signals and alarms. */ /* ARGSUSED */ pthread_handler_t signal_hand(void *arg __attribute__((unused))) @@ -3004,7 +3011,7 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) int origin; while ((error= my_sigwait(&set, &sig, &origin)) == EINTR) /* no-op */; - if (cleanup_done) + if (abort_loop) { DBUG_PRINT("quit",("signal_handler: calling my_thread_end()")); my_thread_end(); @@ -3027,18 +3034,8 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) { /* Delete the instrumentation for the signal thread */ PSI_CALL_delete_current_thread(); -#ifdef USE_ONE_SIGNAL_HAND - pthread_t tmp; - if (unlikely((error= mysql_thread_create(0, /* Not instrumented */ - &tmp, &connection_attrib, - kill_server_thread, - (void*) &sig)))) - sql_print_error("Can't create thread to kill server (errno= %d)", - error); -#else my_sigset(sig, SIG_IGN); break_connect_loop(); // MIT THREAD has a alarm thread -#endif } break; case SIGHUP: diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc index cd75cd45319..4f6356cff54 100644 --- a/sql/sql_reload.cc +++ b/sql/sql_reload.cc @@ -67,6 +67,15 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options, bool result=0; select_errors=0; /* Write if more errors */ int tmp_write_to_binlog= *write_to_binlog= 1; +#ifndef DBUG_OFF + /* + When invoked for handling a SIGHUP by rpl_shutdown_sighup.test, we need to + force the signal handler to wait after REFRESH_TABLES, as that will check + for a killed server, and we need to call hostname_cache_refresh after + server cleanup has happened to trigger MDEV-30260. + */ + int do_dbug_sleep= 0; +#endif DBUG_ASSERT(!thd || !thd->in_sub_stmt); @@ -99,6 +108,15 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options, */ my_error(ER_UNKNOWN_ERROR, MYF(0)); } + +#ifndef DBUG_OFF + DBUG_EXECUTE_IF("hold_sighup_log_refresh", { + DBUG_ASSERT(!debug_sync_set_action( + thd, STRING_WITH_LEN("now SIGNAL in_reload_acl_and_cache " + "WAIT_FOR refresh_logs"))); + do_dbug_sleep= 1; + }); +#endif } opt_noacl= 0; @@ -351,6 +369,11 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options, } my_dbopt_cleanup(); } + +#ifndef DBUG_OFF + if (do_dbug_sleep) + my_sleep(3000000); // 3s +#endif if (options & REFRESH_HOSTS) hostname_cache_refresh(); if (thd && (options & REFRESH_STATUS)) From 662bb176b412993a085fe329af559ddc3dc83ec3 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 13 Mar 2024 13:11:15 +1100 Subject: [PATCH 099/159] MDEV-33661 MENT-1591 Keep spider in memory until exit in ASAN builds Same as MDEV-29579. For some reason, libodbc does not clean up properly if unloaded too early with the dlclose() of spider. So we add UNIQUE symbols to spider so the spider does not reload in dlclose(). This change, however, uncovers some hidden problems in the spider codebase, for which we move the initialisation of some spider global variables into the initialisation of spider itself. Spider has some global variables. Their initialisation should be done in the initialisation of spider itself, otherwise, if spider were re-initialised without these symbol being unloaded, the values could be inconsistent and causing issues. One such issue is caused by the variables spider_mon_table_cache_version and spider_mon_table_cache_version_req. They are used for resetting the spider monitoring table cache and have initial values of 0 and 1 respectively. We have that always spider_mon_table_cache_version_req >= spider_mon_table_cache_version, and when the relation is strict, the cache is reset, spider_mon_table_cache_version is brought to be equal to spider_mon_table_cache_version_req, and the cache is searched for matching table_name, db_name and link_idx. If the relation is equal, no reset would happen and the cache would be searched directly. When spider is re-inited without resetting the values of spider_mon_table_cache_version and spider_mon_table_cache_version_req that were set to be equal in the previous cache reset action, the cache was emptied in the previous spider deinit, which would result in HA_ERR_KEY_NOT_FOUND unexpectedly. An alternative way to fix this issue would be to call the spider udf spider_flush_mon_cache_table(), which increments spider_mon_table_cache_version_req thus making sure the inequality is strict. However, there's no reason for spider to initialise these global variables on dlopen(), rather than on spider init, which is cleaner and "purer". To reproduce this issue, simply revert the changes involving the two variables and then run: mtr --no-reorder spider.ha{,_part} --- storage/spider/ha_spider.h | 23 +++++++++++++++++++++++ storage/spider/spd_conn.cc | 4 ++-- storage/spider/spd_db_conn.cc | 2 +- storage/spider/spd_ping_table.cc | 4 ++-- storage/spider/spd_table.cc | 11 +++++++++++ storage/spider/spd_trx.cc | 2 +- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index f5a597b88a7..3434add965c 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -1219,3 +1219,26 @@ public: int init_union_table_name_pos_sql(); int set_union_table_name_pos_sql(); }; + + +/* This is a hack for ASAN + * Libraries such as libxml2 and libodbc do not like being unloaded before + * exit and will show as a leak in ASAN with no stack trace (as the plugin + * has been unloaded from memory). + * + * The below is designed to trick the compiler into adding a "UNIQUE" symbol + * which can be seen using: + * readelf -s storage/spider/ha_spider.so | grep UNIQUE + * + * Having this symbol means that the plugin remains in memory after dlclose() + * has been called. Thereby letting the libraries clean up properly. + */ +#if defined(__SANITIZE_ADDRESS__) +__attribute__((__used__)) +inline int dummy(void) +{ + static int d; + d++; + return d; +} +#endif diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index be9b27d83ad..b55dc0fd4db 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -53,7 +53,7 @@ extern handlerton *spider_hton_ptr; extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; pthread_mutex_t spider_conn_id_mutex; pthread_mutex_t spider_ipport_conn_mutex; -ulonglong spider_conn_id = 1; +ulonglong spider_conn_id; #ifndef WITHOUT_SPIDER_BG_SEARCH extern pthread_attr_t spider_pt_attr; @@ -93,7 +93,7 @@ extern sql_mode_t pushdown_sql_mode; HASH spider_open_connections; uint spider_open_connections_id; HASH spider_ipport_conns; -long spider_conn_mutex_id = 0; +long spider_conn_mutex_id; const char *spider_open_connections_func_name; const char *spider_open_connections_file_name; diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 40dc15a2149..fd10c7cee8b 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -67,7 +67,7 @@ pthread_mutex_t spider_open_conn_mutex; const char spider_dig_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* UTC time zone for timestamp columns */ -Time_zone *UTC = 0; +Time_zone *UTC; int spider_db_connect( const SPIDER_SHARE *share, diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index 4d2c826aa28..1f5230829c3 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -74,10 +74,10 @@ ulong spider_mon_table_cache_line_no; greater than spider_mon_table_cache_version_req. When the inequality is strict, an initialisation of spider_mon_table_cache will be triggered. */ -volatile ulonglong spider_mon_table_cache_version = 0; +volatile ulonglong spider_mon_table_cache_version; /* The required mon table cache version, incremented by one by the udf spider_flush_table_mon_cache */ -volatile ulonglong spider_mon_table_cache_version_req = 1; +volatile ulonglong spider_mon_table_cache_version_req; /* Get or create a `SPIDER_TABLE_MON_LIST' for a key `str' */ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 60e1ce6bad2..c1435e0216e 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -139,6 +139,11 @@ extern SPIDER_DBTON spider_dbton_oracle; SPIDER_THREAD *spider_table_sts_threads; SPIDER_THREAD *spider_table_crd_threads; #endif +extern volatile ulonglong spider_mon_table_cache_version; +extern volatile ulonglong spider_mon_table_cache_version_req; +extern ulonglong spider_conn_id; +extern Time_zone *UTC; +extern ulonglong spider_thread_id; #ifdef HAVE_PSI_INTERFACE PSI_mutex_key spd_key_mutex_tbl; @@ -6614,6 +6619,12 @@ int spider_db_init( handlerton *spider_hton = (handlerton *)p; DBUG_ENTER("spider_db_init"); + spider_mon_table_cache_version= 0; + spider_mon_table_cache_version_req= 1; + spider_conn_id= 1; + spider_conn_mutex_id= 0; + UTC = 0; + spider_thread_id = 1; const LEX_CSTRING aria_name={STRING_WITH_LEN("Aria")}; if (!plugin_is_ready(&aria_name, MYSQL_STORAGE_ENGINE_PLUGIN)) DBUG_RETURN(HA_ERR_RETRY_INIT); diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index bdea13e7d3b..7a92a6e3f17 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.cc @@ -49,7 +49,7 @@ extern struct charset_info_st *spd_charset_utf8_bin; extern handlerton *spider_hton_ptr; extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; pthread_mutex_t spider_thread_id_mutex; -ulonglong spider_thread_id = 1; +ulonglong spider_thread_id; #ifdef HAVE_PSI_INTERFACE extern PSI_mutex_key spd_key_mutex_udf_table; From 9fb8881ef832371b905231cd5893e738f957d315 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 9 Apr 2024 17:37:08 +0400 Subject: [PATCH 100/159] MDEV-28366 GLOBAL debug_dbug setting affected by collation_connection=utf16... When the system variables @@debug_dbug was assigned to some expression, Sys_debug_dbug::do_check() did not properly convert the value from the expression character set to utf8. So the value was erroneously re-interpretted as utf8 without conversion. In case of a tricky expression character set (e.g. utf16le), this led to unexpected results. Fix: Re-using Sys_var_charptr::do_string_check() in Sys_debug_dbug::do_check(). --- .../sys_vars/r/debug_dbug_utf16le.result | 31 +++++++++++++++++++ .../suite/sys_vars/t/debug_dbug_utf16le.test | 29 +++++++++++++++++ sql/sys_vars.inl | 17 ++-------- 3 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 mysql-test/suite/sys_vars/r/debug_dbug_utf16le.result create mode 100644 mysql-test/suite/sys_vars/t/debug_dbug_utf16le.test diff --git a/mysql-test/suite/sys_vars/r/debug_dbug_utf16le.result b/mysql-test/suite/sys_vars/r/debug_dbug_utf16le.result new file mode 100644 index 00000000000..83b378f2adf --- /dev/null +++ b/mysql-test/suite/sys_vars/r/debug_dbug_utf16le.result @@ -0,0 +1,31 @@ +# +# Start of 10.5 tests +# +# +# MDEV-28366 GLOBAL debug_dbug setting affected by collation_connection=utf16... +# +SET NAMES utf8; +SET collation_connection=utf16le_general_ci; +SET debug_dbug='d,any_random_string'; +SELECT @@debug_dbug; +@@debug_dbug +d,any_random_string +SET debug_dbug=CONCAT('d,', _latin1 0xDF); +SELECT @@debug_dbug; +@@debug_dbug +d,ß +SELECT HEX(@@debug_dbug); +HEX(@@debug_dbug) +642CC39F +SET @@debug_dbug=NULL; +SELECT @@debug_dbug; +@@debug_dbug + +SET @@debug_dbug=DEFAULT; +SELECT @@debug_dbug; +@@debug_dbug + +SET NAMES latin1; +# +# End of 10.5 tests +# diff --git a/mysql-test/suite/sys_vars/t/debug_dbug_utf16le.test b/mysql-test/suite/sys_vars/t/debug_dbug_utf16le.test new file mode 100644 index 00000000000..0c4d8f92e93 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/debug_dbug_utf16le.test @@ -0,0 +1,29 @@ +--source include/have_debug.inc +--source include/have_utf16.inc + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-28366 GLOBAL debug_dbug setting affected by collation_connection=utf16... +--echo # + +SET NAMES utf8; +SET collation_connection=utf16le_general_ci; +SET debug_dbug='d,any_random_string'; +SELECT @@debug_dbug; +SET debug_dbug=CONCAT('d,', _latin1 0xDF); +SELECT @@debug_dbug; +SELECT HEX(@@debug_dbug); + +SET @@debug_dbug=NULL; +SELECT @@debug_dbug; + +SET @@debug_dbug=DEFAULT; +SELECT @@debug_dbug; +SET NAMES latin1; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/sql/sys_vars.inl b/sql/sys_vars.inl index 881a2233739..a0f2a7268a7 100644 --- a/sql/sys_vars.inl +++ b/sql/sys_vars.inl @@ -947,21 +947,10 @@ public: { option.var_type|= GET_STR; } bool do_check(THD *thd, set_var *var) { - char buff[STRING_BUFFER_USUAL_SIZE]; - String str(buff, sizeof(buff), system_charset_info), *res; - - if (!(res=var->value->val_str(&str))) - { + bool rc= Sys_var_charptr::do_string_check(thd, var, charset(thd)); + if (var->save_result.string_value.str == nullptr) var->save_result.string_value.str= const_cast(""); - var->save_result.string_value.length= 0; - } - else - { - size_t len= res->length(); - var->save_result.string_value.str= thd->strmake(res->ptr(), len); - var->save_result.string_value.length= len; - } - return false; + return rc; } bool session_update(THD *thd, set_var *var) { From 0304dbc3275fd6492dc5a1250d5c5e0aacd6890b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 1 Nov 2023 11:07:16 +0200 Subject: [PATCH 101/159] MDEV-25089 : Assertion `error.len > 0' failed in galera::ReplicatorSMM::handle_apply_error() Additional corrections after merge from 10.4 branch Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/disabled.def | 1 - mysql-test/suite/galera/t/mdev-30013.test | 1 + sql/sql_table.cc | 16 +++++++--------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index 1f41e521bd3..a5a1a6f18b1 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -18,7 +18,6 @@ galera_concurrent_ctas : MDEV-32779 galera_concurrent_ctas: assertion in the gal galera_as_slave_replay : MDEV-32780 galera_as_slave_replay: assertion in the wsrep::transaction::before_rollback() galera_slave_replay : MDEV-32780 galera_as_slave_replay: assertion in the wsrep::transaction::before_rollback() galera_sst_mysqldump_with_key : MDEV-32782 galera_sst_mysqldump_with_key test failed -mdev-31285 : MDEV-25089 Assertion `error.len > 0' failed in galera::ReplicatorSMM::handle_apply_error() galera_var_ignore_apply_errors : MENT-1997 galera_var_ignore_apply_errors test freezes MDEV-22232 : temporarily disabled at the request of Codership MW-402 : temporarily disabled at the request of Codership diff --git a/mysql-test/suite/galera/t/mdev-30013.test b/mysql-test/suite/galera/t/mdev-30013.test index 038b66600ce..3795dd32306 100644 --- a/mysql-test/suite/galera/t/mdev-30013.test +++ b/mysql-test/suite/galera/t/mdev-30013.test @@ -1,4 +1,5 @@ --source include/galera_cluster.inc +--source include/force_restart.inc # ARCHIVE plugin must be uninstalled if (!$HA_ARCHIVE_SO) { skip Needs Archive loadable plugin; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index dc1a7060643..c8f1d698ff6 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10294,14 +10294,14 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, if we can support implementing storage engine. */ if (WSREP(thd) && table && table->s->sequence && - wsrep_check_sequence(thd, thd->lex->create_info.seq_create_info, used_engine)) + wsrep_check_sequence(thd, create_info->seq_create_info, used_engine)) DBUG_RETURN(TRUE); - if (WSREP(thd) && + if (WSREP(thd) && table && (thd->lex->sql_command == SQLCOM_ALTER_TABLE || thd->lex->sql_command == SQLCOM_CREATE_INDEX || thd->lex->sql_command == SQLCOM_DROP_INDEX) && - !wsrep_should_replicate_ddl(thd, table_list->table->s->db_type()->db_type)) + !wsrep_should_replicate_ddl(thd, table->s->db_type()->db_type)) DBUG_RETURN(true); #endif /* WITH_WSREP */ @@ -12539,12 +12539,10 @@ bool Sql_cmd_create_table_like::execute(THD *thd) wsrep_check_sequence(thd, lex->create_info.seq_create_info, used_engine)) DBUG_RETURN(true); - WSREP_TO_ISOLATION_BEGIN_ALTER(create_table->db.str, - create_table->table_name.str, - first_table, &alter_info, NULL, - &create_info) - { - WSREP_WARN("CREATE TABLE isolation failure"); + WSREP_TO_ISOLATION_BEGIN_ALTER(create_table->db.str, create_table->table_name.str, + first_table, &alter_info, NULL, &create_info) + { + WSREP_WARN("CREATE TABLE isolation failure"); res= true; goto end_with_restore_list; } From d8249775980f9a6cb1a85e4799e1c1be452c2f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 10 Apr 2024 09:47:44 +0300 Subject: [PATCH 102/159] MDEV-33512 Corrupted table after IMPORT TABLESPACE and restart In commit d74d95961a31b47986d943216489513896108782 (MDEV-18543) there was an error that would cause the hidden metadata record to be deleted, and therefore cause the table to appear corrupted when it is reloaded into the data dictionary cache. PageConverter::update_records(): Do not delete the metadata record, but do validate it. RecIterator::open(): Make the API more similar to 10.6, to simplify merges. --- .../innodb/r/instant_alter_import.result | 1 + .../suite/innodb/t/instant_alter_import.test | 1 + storage/innobase/row/row0import.cc | 46 +++++++++++++++---- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/innodb/r/instant_alter_import.result b/mysql-test/suite/innodb/r/instant_alter_import.result index 9a20ed606bd..55a49e81057 100644 --- a/mysql-test/suite/innodb/r/instant_alter_import.result +++ b/mysql-test/suite/innodb/r/instant_alter_import.result @@ -61,6 +61,7 @@ alter table t1 discard tablespace; flush tables t2 for export; unlock tables; alter table t1 import tablespace; +# restart select * from t1; z 42 diff --git a/mysql-test/suite/innodb/t/instant_alter_import.test b/mysql-test/suite/innodb/t/instant_alter_import.test index 7bd5645436c..50eda83f4b0 100644 --- a/mysql-test/suite/innodb/t/instant_alter_import.test +++ b/mysql-test/suite/innodb/t/instant_alter_import.test @@ -79,6 +79,7 @@ flush tables t2 for export; unlock tables; alter table t1 import tablespace; +--source include/restart_mysqld.inc select * from t1; drop table t2; diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index a029873da90..b47333113aa 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -252,13 +252,13 @@ public: } /** Position the cursor on the first user record. */ - void open(buf_block_t* block) UNIV_NOTHROW + rec_t* open(buf_block_t* block, const dict_index_t* index) noexcept + MY_ATTRIBUTE((warn_unused_result)) { + m_cur.index = const_cast(index); page_cur_set_before_first(block, &m_cur); - - if (!end()) { - next(); - } + next(); + return page_cur_get_rec(&m_cur); } /** Move to the next record. */ @@ -1848,12 +1848,39 @@ PageConverter::update_records( bool clust_index = m_index->m_srv_index == m_cluster_index; /* This will also position the cursor on the first user record. */ + rec_t* rec = m_rec_iter.open(block, m_index->m_srv_index); - m_rec_iter.open(block); + if (!rec) { + return DB_CORRUPTION; + } + + ulint deleted; + + if (!page_has_prev(block->frame) + && m_index->m_srv_index->is_instant()) { + /* Expect to find the hidden metadata record */ + if (page_rec_is_supremum(rec)) { + return DB_CORRUPTION; + } + + const ulint info_bits = rec_get_info_bits(rec, comp); + + if (!(info_bits & REC_INFO_MIN_REC_FLAG)) { + return DB_CORRUPTION; + } + + if (!(info_bits & REC_INFO_DELETED_FLAG) + != !m_index->m_srv_index->table->instant) { + return DB_CORRUPTION; + } + + deleted = 0; + goto first; + } while (!m_rec_iter.end()) { - rec_t* rec = m_rec_iter.current(); - ibool deleted = rec_get_deleted_flag(rec, comp); + rec = m_rec_iter.current(); + deleted = rec_get_deleted_flag(rec, comp); /* For the clustered index we have to adjust the BLOB reference and the system fields irrespective of the @@ -1861,6 +1888,7 @@ PageConverter::update_records( cluster records is required for purge to work later. */ if (deleted || clust_index) { +first: m_offsets = rec_get_offsets( rec, m_index->m_srv_index, m_offsets, m_index->m_srv_index->n_core_fields, @@ -3158,7 +3186,7 @@ static size_t get_buf_size() ; } -/* find, parse instant metadata, performing variaous checks, +/* find, parse instant metadata, performing various checks, and apply it to dict_table_t @return DB_SUCCESS or some error */ static dberr_t handle_instant_metadata(dict_table_t *table, From b697dce8ca378835ae94b16cec715d88d4bf17c7 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 10 Apr 2024 11:12:47 +0400 Subject: [PATCH 103/159] MDEV-29149 Assertion `!is_valid_datetime() || fraction_remainder(((item->decimals) < (6) ? (item->decimals) : (6))) == 0' failed in Datetime_truncation_not_needed::Datetime_truncation_not_needed TIME-alike string and numeric arguments to TIMEDIFF() can get additional fractional seconds during the supported TIME range adjustment in get_time(). For example, during TIMEDIFF('839:00:00','00:00:00') evaluation in Item_func_timediff::get_date(), the call for args[0]->get_time() returns MYSQL_TIME '838:59:59.999999'. Item_func_timediff::get_date() did not handle these extra digits and returned a MYSQL_TIME result with fractional digits outside of Item_func_timediff::decimals. This mismatch could further be caught by a DBUG_ASSERT() in various other pieces of the code, leading to a crash. Fix: In case if get_time() returned MYSQL_TIMESTAMP_TIME, let's truncate all extra digits using my_time_trunc(&l_time,decimals). This guarantees that the rest of the code returns a MYSQL_TIME with second_part not conflicting with Item_func_timediff::decimals. --- mysql-test/main/func_time.result | 54 ++++++++++++++++++++++++++++++++ mysql-test/main/func_time.test | 39 +++++++++++++++++++++++ sql/item_timefunc.cc | 18 +++++++++++ 3 files changed, 111 insertions(+) diff --git a/mysql-test/main/func_time.result b/mysql-test/main/func_time.result index 0f807a691b3..eaf30f5f925 100644 --- a/mysql-test/main/func_time.result +++ b/mysql-test/main/func_time.result @@ -6373,3 +6373,57 @@ NULL SELECT FROM_UNIXTIME(LEAST(3696610869, NULL)); FROM_UNIXTIME(LEAST(3696610869, NULL)) NULL +# +# Start of 10.5 tests +# +# +# MDEV-29149 Assertion `!is_valid_datetime() || fraction_remainder(((item->decimals) < (6) ? (item->decimals) : (6))) == 0' failed in Datetime_truncation_not_needed::Datetime_truncation_not_needed +# +SET @@timestamp= UNIX_TIMESTAMP('2022-07-21 23:00:00'); +SELECT DATE_SUB('2022-07-21 00:00:00', INTERVAL 800 HOUR) AS expected_result; +expected_result +2022-06-17 16:00:00 +SELECT +IF(1,TIMEDIFF('38:59:59','839:00:00'),CAST('2022-12-12' AS DATE)) AS c1, +IF(1,TIMEDIFF('-839:00:00','-38:59:59'),CAST('2022-12-12' AS DATE)) AS c2; +c1 c2 +2022-06-17 16:00:00 2022-06-17 16:00:00 +Warnings: +Warning 1292 Truncated incorrect time value: '839:00:00' +Warning 1292 Truncated incorrect time value: '-839:00:00' +SELECT +IF(1,TIMEDIFF(385959,8390000),CAST('2022-12-12' AS DATE)) AS c1, +IF(1,TIMEDIFF(-8390000,-385959),CAST('2022-12-12' AS DATE)) AS c2; +c1 c2 +2022-06-17 16:00:00 2022-06-17 16:00:00 +Warnings: +Warning 1292 Truncated incorrect time value: '8390000' +Warning 1292 Truncated incorrect time value: '-8390000' +SELECT +TIMEDIFF('38:59:59','839:00:00') AS c1, +CAST(TIMEDIFF('38:59:59','839:00:00') AS TIME(6)) AS c2, +TIMEDIFF('839:00:00','38:59:59') AS c3, +CAST(TIMEDIFF('839:00:00','38:59:59') AS TIME(6)) AS c4; +c1 c2 c3 c4 +-800:00:00 -800:00:00.000000 800:00:00 800:00:00.000000 +Warnings: +Warning 1292 Truncated incorrect time value: '839:00:00' +Warning 1292 Truncated incorrect time value: '839:00:00' +Warning 1292 Truncated incorrect time value: '839:00:00' +Warning 1292 Truncated incorrect time value: '839:00:00' +SELECT +TIMEDIFF(385959,8390000) AS c1, +CAST(TIMEDIFF(385959,8390000) AS TIME(6)) AS c2, +TIMEDIFF(8390000,385959) AS c3, +CAST(TIMEDIFF(8390000,385959) AS TIME(6)) AS c4; +c1 c2 c3 c4 +-800:00:00 -800:00:00.000000 800:00:00 800:00:00.000000 +Warnings: +Warning 1292 Truncated incorrect time value: '8390000' +Warning 1292 Truncated incorrect time value: '8390000' +Warning 1292 Truncated incorrect time value: '8390000' +Warning 1292 Truncated incorrect time value: '8390000' +SET @@timestamp= DEFAULT; +# +# End of 10.5 tests +# diff --git a/mysql-test/main/func_time.test b/mysql-test/main/func_time.test index 089ab4b0b72..4b046ac166a 100644 --- a/mysql-test/main/func_time.test +++ b/mysql-test/main/func_time.test @@ -3213,3 +3213,42 @@ SELECT CONCAT(MAKETIME('01', '01', LEAST( -100, NULL ))); --echo # SELECT FROM_UNIXTIME(LEAST(3696610869, NULL)); + + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-29149 Assertion `!is_valid_datetime() || fraction_remainder(((item->decimals) < (6) ? (item->decimals) : (6))) == 0' failed in Datetime_truncation_not_needed::Datetime_truncation_not_needed +--echo # + +SET @@timestamp= UNIX_TIMESTAMP('2022-07-21 23:00:00'); + +SELECT DATE_SUB('2022-07-21 00:00:00', INTERVAL 800 HOUR) AS expected_result; + +SELECT + IF(1,TIMEDIFF('38:59:59','839:00:00'),CAST('2022-12-12' AS DATE)) AS c1, + IF(1,TIMEDIFF('-839:00:00','-38:59:59'),CAST('2022-12-12' AS DATE)) AS c2; + +SELECT + IF(1,TIMEDIFF(385959,8390000),CAST('2022-12-12' AS DATE)) AS c1, + IF(1,TIMEDIFF(-8390000,-385959),CAST('2022-12-12' AS DATE)) AS c2; + +SELECT + TIMEDIFF('38:59:59','839:00:00') AS c1, + CAST(TIMEDIFF('38:59:59','839:00:00') AS TIME(6)) AS c2, + TIMEDIFF('839:00:00','38:59:59') AS c3, + CAST(TIMEDIFF('839:00:00','38:59:59') AS TIME(6)) AS c4; + +SELECT + TIMEDIFF(385959,8390000) AS c1, + CAST(TIMEDIFF(385959,8390000) AS TIME(6)) AS c2, + TIMEDIFF(8390000,385959) AS c3, + CAST(TIMEDIFF(8390000,385959) AS TIME(6)) AS c4; + +SET @@timestamp= DEFAULT; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index a58f3593463..2f689acc54c 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2706,6 +2706,24 @@ bool Item_func_timediff::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzy if (l_time1.neg != l_time2.neg) l_sign= -l_sign; + if (l_time1.time_type == MYSQL_TIMESTAMP_TIME) + { + /* + In case of TIME-alike arguments: + TIMEDIFF('38:59:59', '839:00:00') + let's truncate extra fractional seconds that might appear if the argument + values were out of the supported TIME range. For example, args[n]->get_time() + for the string literal '839:00:00' returns TIME'838:59:59.999999'. + The fractional part must be truncated according to this->decimals, + to avoid returning more fractional seconds than it was detected + during this->fix_length_and_dec(). + Note, the thd rounding mode should not be important here, as we're removing + redundant digits from the maximum possible value: '838:59:59.999999'. + */ + my_time_trunc(&l_time1, decimals); + my_time_trunc(&l_time2, decimals); + } + if (calc_time_diff(&l_time1, &l_time2, l_sign, &l_time3, fuzzydate)) return (null_value= 1); From 3655cefc42902a3b3f584d252de7af488feaff55 Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 9 Apr 2024 20:56:57 +0300 Subject: [PATCH 104/159] MDEV-33813 ERROR 1021 (HY000): Disk full (./org/test1.MAI); waiting for someone to free some space Fixed that internal temporary tables are not waiting for freed disk space. Other things: - 'kill id' will now kill a query waiting for free disk space instantly. Before it could take up to 60 seconds for the kill would be noticed. - Fixed that sorting one index is not using MY_WAIT_IF_FULL for temp files. - Fixed bug where share->write_flag set MY_WAIT_IF_FULL for temp files. It is quite hard to do a test case for this. Instead I tested all combinations interactively. --- include/my_sys.h | 1 + mysys/errors.c | 9 ++++++++- sql/mysqld.cc | 4 ++++ sql/mysqld.h | 1 + sql/sql_class.cc | 28 ++++++++++++++++++++++++++++ sql/sql_class.h | 3 +++ storage/maria/ma_check.c | 2 +- storage/maria/ma_extra.c | 14 ++++++++++++++ storage/maria/ma_open.c | 2 +- storage/maria/ma_pagecache.c | 2 ++ storage/maria/maria_def.h | 1 + 11 files changed, 64 insertions(+), 3 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index da336bdf8c9..84a1e6a4752 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -652,6 +652,7 @@ extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count, myf MyFlags); extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags); extern my_off_t my_ftell(FILE *stream,myf MyFlags); +extern void (*my_sleep_for_space)(unsigned int seconds); /* implemented in my_memmem.c */ extern void *my_memmem(const void *haystack, size_t haystacklen, diff --git a/mysys/errors.c b/mysys/errors.c index d88540fe277..a8be37bf2b6 100644 --- a/mysys/errors.c +++ b/mysys/errors.c @@ -112,6 +112,13 @@ void init_glob_errs() } #endif +static void my_space_sleep(uint seconds) +{ + sleep(seconds); +} + +void (*my_sleep_for_space)(uint seconds)= my_space_sleep; + void wait_for_free_space(const char *filename, int errors) { if (errors == 0) @@ -123,7 +130,7 @@ void wait_for_free_space(const char *filename, int errors) MYF(ME_BELL | ME_ERROR_LOG | ME_WARNING), MY_WAIT_FOR_USER_TO_FIX_PANIC, MY_WAIT_GIVE_USER_A_MESSAGE * MY_WAIT_FOR_USER_TO_FIX_PANIC ); - (void) sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC); + my_sleep_for_space(MY_WAIT_FOR_USER_TO_FIX_PANIC); } const char **get_global_errmsgs(int nr __attribute__((unused))) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d10c342a6dc..16820300f1c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4880,6 +4880,9 @@ static int init_server_components() error_handler_hook= my_message_sql; proc_info_hook= set_thd_stage_info; + /* Set up hook to handle disk full */ + my_sleep_for_space= mariadb_sleep_for_space; + /* Print source revision hash, as one of the first lines, if not the first in error log, for troubleshooting and debugging purposes @@ -9216,6 +9219,7 @@ PSI_stage_info stage_user_lock= { 0, "User lock", 0}; PSI_stage_info stage_user_sleep= { 0, "User sleep", 0}; PSI_stage_info stage_verifying_table= { 0, "Verifying table", 0}; PSI_stage_info stage_waiting_for_delay_list= { 0, "Waiting for delay_list", 0}; +PSI_stage_info stage_waiting_for_disk_space= {0, "Waiting for someone to free space", 0}; PSI_stage_info stage_waiting_for_gtid_to_be_written_to_binary_log= { 0, "Waiting for GTID to be written to binary log", 0}; PSI_stage_info stage_waiting_for_handler_insert= { 0, "Waiting for handler insert", 0}; PSI_stage_info stage_waiting_for_handler_lock= { 0, "Waiting for handler lock", 0}; diff --git a/sql/mysqld.h b/sql/mysqld.h index c0a55ce49c7..fe73f14ee62 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -644,6 +644,7 @@ extern PSI_stage_info stage_user_sleep; extern PSI_stage_info stage_verifying_table; extern PSI_stage_info stage_waiting_for_ddl; extern PSI_stage_info stage_waiting_for_delay_list; +extern PSI_stage_info stage_waiting_for_disk_space; extern PSI_stage_info stage_waiting_for_flush; extern PSI_stage_info stage_waiting_for_gtid_to_be_written_to_binary_log; extern PSI_stage_info stage_waiting_for_handler_insert; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 35ab93cc8ba..6cabd7fbabd 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -8323,6 +8323,34 @@ wait_for_commit::unregister_wait_for_prior_commit2() mysql_mutex_unlock(&LOCK_wait_commit); } +/* + Wait # seconds or until someone sends a signal (through kill) + + Note that this must have same prototype as my_sleep_for_space() +*/ + +C_MODE_START + +void mariadb_sleep_for_space(unsigned int seconds) +{ + THD *thd= current_thd; + PSI_stage_info old_stage; + if (!thd) + { + sleep(seconds); + return; + } + mysql_mutex_lock(&thd->LOCK_wakeup_ready); + thd->ENTER_COND(&thd->COND_wakeup_ready, &thd->LOCK_wakeup_ready, + &stage_waiting_for_disk_space, &old_stage); + if (!thd->killed) + mysql_cond_wait(&thd->COND_wakeup_ready, &thd->LOCK_wakeup_ready); + thd->EXIT_COND(&old_stage); + return; +} + +C_MODE_END + bool Discrete_intervals_list::append(ulonglong start, ulonglong val, ulonglong incr) diff --git a/sql/sql_class.h b/sql/sql_class.h index 29efb45e097..84665979d6e 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -8185,6 +8185,9 @@ extern THD_list server_threads; void setup_tmp_table_column_bitmaps(TABLE *table, uchar *bitmaps, uint field_count); +C_MODE_START +void mariadb_sleep_for_space(unsigned int seconds); +C_MODE_END #endif /* MYSQL_SERVER */ #endif /* SQL_CLASS_INCLUDED */ diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 044be038607..ac3ede3865c 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -3390,7 +3390,7 @@ static int sort_one_index(HA_CHECK *param, MARIA_HA *info, length= page.size; bzero(buff+length,keyinfo->block_length-length); if (write_page(share, new_file, buff, keyinfo->block_length, - new_page_pos, MYF(MY_NABP | MY_WAIT_IF_FULL))) + new_page_pos, MYF(MY_NABP | MY_WAIT_IF_FULL) & param->myf_rw)) { _ma_check_print_error(param,"Can't write indexblock, error: %d",my_errno); goto err; diff --git a/storage/maria/ma_extra.c b/storage/maria/ma_extra.c index 49b731af5fc..9116edbd671 100644 --- a/storage/maria/ma_extra.c +++ b/storage/maria/ma_extra.c @@ -601,6 +601,20 @@ uint _ma_file_callback_to_id(void *callback_data) return share ? share->id : 0; } +/* + Disable MY_WAIT_IF_FULL flag for temporary tables + + Temporary tables does not have MY_WAIT_IF_FULL in share->write_flags +*/ + +uint _ma_write_flags_callback(void *callback_data, myf flags) +{ + MARIA_SHARE *share= (MARIA_SHARE*) callback_data; + if (share) + flags&= ~(~share->write_flag & MY_WAIT_IF_FULL); + return flags; +} + /** @brief flushes the data and/or index file of a table diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index 6d9ae62ca8e..2497bc41e8f 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -172,7 +172,6 @@ static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, mysql_mutex_lock(&share->intern_lock); info.read_record= share->read_record; share->reopen++; - share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL); if (share->options & HA_OPTION_READ_ONLY_DATA) { info.lock_type=F_RDLCK; @@ -987,6 +986,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags, share->options|= HA_OPTION_READ_ONLY_DATA; share->is_log_table= FALSE; + share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL); if (open_flags & HA_OPEN_TMP_TABLE || share->options & HA_OPTION_TMP_TABLE) { share->options|= HA_OPTION_TMP_TABLE; diff --git a/storage/maria/ma_pagecache.c b/storage/maria/ma_pagecache.c index 144b10a86da..49981e7964a 100644 --- a/storage/maria/ma_pagecache.c +++ b/storage/maria/ma_pagecache.c @@ -687,6 +687,8 @@ static my_bool pagecache_fwrite(PAGECACHE *pagecache, /* FIXME: ENGINE=Aria occasionally writes uninitialized data */ __msan_unpoison(args.page, pagecache->block_size); #endif + /* Reset MY_WAIT_IF_FULL for temporary tables */ + flags= _ma_write_flags_callback(filedesc->callback_data, flags); res= (int)my_pwrite(filedesc->file, args.page, pagecache->block_size, ((my_off_t) pageno << pagecache->shift), flags); (*filedesc->post_write_hook)(res, &args); diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index f3303884200..b12f21e39f9 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -1745,6 +1745,7 @@ extern my_bool ma_yield_and_check_if_killed(MARIA_HA *info, int inx); extern my_bool ma_killed_standalone(MARIA_HA *); extern uint _ma_file_callback_to_id(void *callback_data); +extern uint _ma_write_flags_callback(void *callback_data, myf flags); extern void free_maria_share(MARIA_SHARE *share); static inline void unmap_file(MARIA_HA *info __attribute__((unused))) From da47c0370dda125a941cebed8abeb724a78ef4d1 Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 9 Apr 2024 21:05:14 +0300 Subject: [PATCH 105/159] Fixed calculating of last_master_timestamp for parallel replication. This effects the Seconds_Behind_Master value. --- sql/rpl_rli.h | 4 ++++ sql/slave.cc | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index 5e259d5c8a1..151317930c3 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -564,6 +564,10 @@ private: Guarded by data_lock. Written by the sql thread. Read by client threads executing SHOW SLAVE STATUS. + + This is calculated as: + clock_time_for_event_on_master + clock_difference_between_master_and_slave + + SQL_DELAY. */ time_t sql_delay_end; diff --git a/sql/slave.cc b/sql/slave.cc index 63346d29bbb..71931df009b 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -4342,6 +4342,13 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli, rli->last_inuse_relaylog->dequeued_count))) && event_can_update_last_master_timestamp(ev)) { + /* + This is the first event from the master after the slave was up to date + and has been waiting for new events. + We update last_master_timestamp before executing the event to not + have Seconds_after_master == 0 while executing the event. + last_master_timestamp will be updated again when the event is commited. + */ if (rli->last_master_timestamp < ev->when) { rli->last_master_timestamp= ev->when; @@ -4378,7 +4385,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli, Seconds_Behind_Master is zero. */ if (ev->get_type_code() != FORMAT_DESCRIPTION_EVENT && - rli->last_master_timestamp < ev->when) + rli->last_master_timestamp < ev->when + (time_t) ev->exec_time) rli->last_master_timestamp= ev->when + (time_t) ev->exec_time; DBUG_ASSERT(rli->last_master_timestamp >= 0); From 0da1653f1bce3c238c6c0bb4a5c3a1fcde06b238 Mon Sep 17 00:00:00 2001 From: Andrei Date: Wed, 10 Apr 2024 18:19:43 +0300 Subject: [PATCH 106/159] MDEV-31779 Server crash in Rows_log_event::update_sequence upon replaying binary log The crash at running mysqlbinlog on a SEQUENCE containing binlog file was caused MDEV-29621 fixes that did not check which of the slave or binlog applier executes a block introduced there. The block is meaningful only for the parallel slave applier, so it's safe to fix this bug with identified the actual applier and skipping the block when it's the mysqlbinlog one. --- mysql-test/suite/rpl/r/rpl_parallel_seq.result | 10 ++++++++++ mysql-test/suite/rpl/t/rpl_parallel_seq.test | 18 ++++++++++++++++++ sql/log_event_server.cc | 1 + 3 files changed, 29 insertions(+) diff --git a/mysql-test/suite/rpl/r/rpl_parallel_seq.result b/mysql-test/suite/rpl/r/rpl_parallel_seq.result index 8f55f52e54c..02287d54e33 100644 --- a/mysql-test/suite/rpl/r/rpl_parallel_seq.result +++ b/mysql-test/suite/rpl/r/rpl_parallel_seq.result @@ -127,4 +127,14 @@ CREATE SEQUENCE s4; DROP SEQUENCE s2,s3,s4; DROP TABLE ti; connection slave; +connection master; +CREATE SEQUENCE s; +SELECT NEXTVAL(s); +NEXTVAL(s) +1 +flush binary logs; +DROP SEQUENCE s; +DROP SEQUENCE s; +connection slave; +connection master; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_parallel_seq.test b/mysql-test/suite/rpl/t/rpl_parallel_seq.test index b1b15412b16..cc361a7b35b 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_seq.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_seq.test @@ -195,4 +195,22 @@ DROP TABLE ti; --sync_slave_with_master +# MDEV-31779 server crash in Rows_log_event::update_sequence at replaying binlog +--connection master +--let $binlog_file = query_get_value(SHOW MASTER STATUS, File, 1) +--let $binlog_start = query_get_value(SHOW MASTER STATUS, Position, 1) +CREATE SEQUENCE s; +--disable_ps2_protocol +SELECT NEXTVAL(s); +--enable_ps2_protocol +flush binary logs; +DROP SEQUENCE s; +--exec $MYSQL_BINLOG $datadir/$binlog_file | $MYSQL test +DROP SEQUENCE s; + +--sync_slave_with_master + +--connection master + + --source include/rpl_end.inc diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index f51f5b7deec..313df13f400 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -7544,6 +7544,7 @@ int Rows_log_event::update_sequence() #if defined(WITH_WSREP) ! WSREP(thd) && #endif + table->in_use->rgi_slave && !(table->in_use->rgi_slave->gtid_ev_flags2 & Gtid_log_event::FL_DDL) && !(old_master= rpl_master_has_bug(thd->rgi_slave->rli, From 2d2172a5cf1bcc66810fa4ee07219e8c4c9a41d3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 10 Apr 2024 19:34:15 +0200 Subject: [PATCH 107/159] sporadic failures of rpl.rpl_semi_sync_master_shutdown increase the MASTER_CONNECT_RETRY time under valgrind, otherwise the slave gives up retrying before the master is ready also, cosmetic cleanup of rpl_semi_sync_master_shutdown.test --- mysql-test/include/rpl_change_topology.inc | 5 +++-- .../suite/rpl/r/rpl_semi_sync_master_shutdown.result | 3 +-- .../suite/rpl/t/rpl_semi_sync_master_shutdown.test | 9 +++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/mysql-test/include/rpl_change_topology.inc b/mysql-test/include/rpl_change_topology.inc index 1ee6e711372..2b75579568b 100644 --- a/mysql-test/include/rpl_change_topology.inc +++ b/mysql-test/include/rpl_change_topology.inc @@ -96,10 +96,11 @@ # Remove whitespace from $rpl_topology --let $rpl_topology= `SELECT REPLACE('$rpl_topology', ' ', '')` +--source include/slow_environ.inc + --let $include_filename= rpl_change_topology.inc [new topology=$rpl_topology] --source include/begin_include_file.inc - if ($rpl_debug) { --echo ---- Check input ---- @@ -233,7 +234,7 @@ if (!$rpl_skip_change_master) --echo "\$rpl_master_log_pos parameter not set for the master: $_rpl_master. Set log position to empty." } } - eval CHANGE MASTER TO MASTER_HOST = '127.0.0.1', MASTER_PORT = $_rpl_port, MASTER_USER = 'root', MASTER_LOG_FILE = '$_rpl_master_log_file'$_rpl_master_log_pos, MASTER_CONNECT_RETRY = 1; + eval CHANGE MASTER TO MASTER_HOST = '127.0.0.1', MASTER_PORT = $_rpl_port, MASTER_USER = 'root', MASTER_LOG_FILE = '$_rpl_master_log_file'$_rpl_master_log_pos, MASTER_CONNECT_RETRY = 1$_timeout_adjustment; } if ($_rpl_master == '') { diff --git a/mysql-test/suite/rpl/r/rpl_semi_sync_master_shutdown.result b/mysql-test/suite/rpl/r/rpl_semi_sync_master_shutdown.result index 6124ba01679..8803b4c3392 100644 --- a/mysql-test/suite/rpl/r/rpl_semi_sync_master_shutdown.result +++ b/mysql-test/suite/rpl/r/rpl_semi_sync_master_shutdown.result @@ -4,7 +4,7 @@ connection master; SET @@GLOBAL.rpl_semi_sync_master_enabled = 1; connection slave; include/stop_slave.inc -SET @@GLOBAL. rpl_semi_sync_slave_enabled = 1; +SET @@GLOBAL.rpl_semi_sync_slave_enabled = 1; include/start_slave.inc connection master; CREATE TABLE t1 (a INT); @@ -21,7 +21,6 @@ connection slave; include/wait_for_slave_sql_to_start.inc include/wait_for_slave_io_to_start.inc connection master; -SET @@GLOBAL.debug_dbug=""; SET @@GLOBAL. rpl_semi_sync_master_enabled = 0; connection master; DROP TABLE t1; diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync_master_shutdown.test b/mysql-test/suite/rpl/t/rpl_semi_sync_master_shutdown.test index 05e6fcca143..d653d84c3b4 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync_master_shutdown.test +++ b/mysql-test/suite/rpl/t/rpl_semi_sync_master_shutdown.test @@ -4,19 +4,17 @@ # finishes off as specified in particular trying to connect even to a shut down # master for a semisync firewell routine. -source include/not_embedded.inc; -source include/have_debug.inc; source include/master-slave.inc; --connection master ---let $sav_enabled_master=`SELECT @@GLOBAL.rpl_semi_sync_master_enabled ` +--let $sav_enabled_master=`SELECT @@GLOBAL.rpl_semi_sync_master_enabled` SET @@GLOBAL.rpl_semi_sync_master_enabled = 1; --connection slave source include/stop_slave.inc; ---let $sav_enabled_slave=`SELECT @@GLOBAL.rpl_semi_sync_slave_enabled ` -SET @@GLOBAL. rpl_semi_sync_slave_enabled = 1; +--let $sav_enabled_slave=`SELECT @@GLOBAL.rpl_semi_sync_slave_enabled` +SET @@GLOBAL.rpl_semi_sync_slave_enabled = 1; source include/start_slave.inc; --connection master @@ -52,7 +50,6 @@ source include/rpl_start_server.inc; #--source include/start_slave.inc --connection master -SET @@GLOBAL.debug_dbug=""; --eval SET @@GLOBAL. rpl_semi_sync_master_enabled = $sav_enabled_master --connection master From 37fd497c7b949be9646c213bee8fda3debb429ac Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 10 Apr 2024 17:58:36 +0400 Subject: [PATCH 108/159] MDEV-32458 ASAN unknown-crash in Inet6::ascii_to_fbt when casting character string to inet6 The condition checked the value of the leftmost byte before checking if at least one byte is still available in the buffer. Changing the order in the condition: check for a byte availability before checking the byte value. --- .../type_inet/mysql-test/type_inet/type_inet6.result | 11 +++++++++++ plugin/type_inet/mysql-test/type_inet/type_inet6.test | 10 ++++++++++ plugin/type_inet/sql_type_inet.cc | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.result b/plugin/type_inet/mysql-test/type_inet/type_inet6.result index 7484a10962c..9e48f396daf 100644 --- a/plugin/type_inet/mysql-test/type_inet/type_inet6.result +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.result @@ -2330,3 +2330,14 @@ Warning 1292 Incorrect inet6 value: '' Warning 1292 Incorrect inet6 value: '' Warning 1292 Incorrect inet6 value: '' DROP TABLE t1; +# +# MDEV-32458 ASAN unknown-crash in Inet6::ascii_to_fbt when casting character string to inet6 +# +CREATE TABLE t1 (c CHAR(3)); +INSERT INTO t1 VALUES ('1:0'),('00:'); +SELECT * FROM t1 WHERE c>CAST('::1' AS INET6); +c +Warnings: +Warning 1292 Incorrect inet6 value: '1:0' +Warning 1292 Incorrect inet6 value: '00:' +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.test b/plugin/type_inet/mysql-test/type_inet/type_inet6.test index abe9071962f..41cfa0b06ae 100644 --- a/plugin/type_inet/mysql-test/type_inet/type_inet6.test +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.test @@ -1686,3 +1686,13 @@ SELECT 1.00 + (b = a) AS f FROM t1 ORDER BY f; SELECT 1.00 + (b BETWEEN a AND '') AS f FROM t1 ORDER BY f; SELECT 1.00 + (b IN (a,'')) AS f FROM t1 ORDER BY f; DROP TABLE t1; + + +--echo # +--echo # MDEV-32458 ASAN unknown-crash in Inet6::ascii_to_fbt when casting character string to inet6 +--echo # + +CREATE TABLE t1 (c CHAR(3)); +INSERT INTO t1 VALUES ('1:0'),('00:'); +SELECT * FROM t1 WHERE c>CAST('::1' AS INET6); +DROP TABLE t1; diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc index 5817bdecc4b..3f457fd52db 100644 --- a/plugin/type_inet/sql_type_inet.cc +++ b/plugin/type_inet/sql_type_inet.cc @@ -229,7 +229,7 @@ bool Inet6::ascii_to_ipv6(const char *str, size_t str_length) continue; } - if (!*p || p >= str_end) + if (p >= str_end || !*p) { DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " "ending at ':'.", (int) str_length, str)); From 263932d505cb895367fea9f106a9e66664ae3832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 11 Apr 2024 09:58:53 +0300 Subject: [PATCH 109/159] MDEV-33325 Crash in flst_read_addr on corrupted data flst_read_addr(): Remove assertions. Instead, we will check these conditions in the callers and avoid a crash in case of corruption. We will check the conditions more carefully, because the callers know more exact bounds for the page numbers and the byte offsets withing pages. flst_remove(), flst_add_first(), flst_add_last(): Add a parameter for passing fil_space_t::free_limit. None of the lists may point to pages that are beyond the current initialized length of the tablespace. trx_rseg_mem_restore(): Access the first page of the tablespace, so that we will correctly recover rseg->space->free_limit in case some log based recovery is pending. ibuf_remove_free_page(): Only look up the root page once, and validate the last page number. Reviewed by: Debarun Banerjee --- storage/innobase/btr/btr0btr.cc | 6 +- storage/innobase/fsp/fsp0fsp.cc | 143 +++++++++++++++++++++-------- storage/innobase/fut/fut0lst.cc | 135 ++++++++++++++++----------- storage/innobase/ibuf/ibuf0ibuf.cc | 33 +++---- storage/innobase/include/fut0lst.h | 50 +++++----- storage/innobase/trx/trx0purge.cc | 52 +++++++++-- storage/innobase/trx/trx0rseg.cc | 12 +++ storage/innobase/trx/trx0undo.cc | 33 +++++-- 8 files changed, 313 insertions(+), 151 deletions(-) diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index 6b42b3e14ec..93ad4b671c8 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -562,7 +562,8 @@ btr_page_alloc_for_ibuf( { buf_page_make_young_if_needed(&new_block->page); *err= flst_remove(root, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST, new_block, - PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST_NODE, mtr); + PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST_NODE, + fil_system.sys_space->free_limit, mtr); } ut_d(if (*err == DB_SUCCESS) flst_validate(root, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST, mtr)); @@ -666,7 +667,8 @@ btr_page_free_for_ibuf( buf_block_t *root= btr_get_latched_root(*index, mtr); dberr_t err= flst_add_first(root, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST, - block, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST_NODE, mtr); + block, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST_NODE, + fil_system.sys_space->free_limit, mtr); ut_d(if (err == DB_SUCCESS) flst_validate(root, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST, mtr)); return err; diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc index 747a397fe92..314a3ae6952 100644 --- a/storage/innobase/fsp/fsp0fsp.cc +++ b/storage/innobase/fsp/fsp0fsp.cc @@ -261,6 +261,7 @@ inline void xdes_init(const buf_block_t &block, xdes_t *descr, mtr_t *mtr) } /** Mark a page used in an extent descriptor. +@param[in] space tablespace @param[in,out] seg_inode segment inode @param[in,out] iblock segment inode page @param[in] page page number @@ -270,7 +271,8 @@ inline void xdes_init(const buf_block_t &block, xdes_t *descr, mtr_t *mtr) @return error code */ static MY_ATTRIBUTE((nonnull, warn_unused_result)) dberr_t -fseg_mark_page_used(fseg_inode_t *seg_inode, buf_block_t *iblock, +fseg_mark_page_used(const fil_space_t *space, + fseg_inode_t *seg_inode, buf_block_t *iblock, uint32_t page, xdes_t *descr, buf_block_t *xdes, mtr_t *mtr) { ut_ad(fil_page_get_type(iblock->page.frame) == FIL_PAGE_INODE); @@ -280,15 +282,16 @@ fseg_mark_page_used(fseg_inode_t *seg_inode, buf_block_t *iblock, const uint16_t xoffset= uint16_t(descr - xdes->page.frame + XDES_FLST_NODE); const uint16_t ioffset= uint16_t(seg_inode - iblock->page.frame); + const uint32_t limit= space->free_limit; if (!xdes_get_n_used(descr)) { /* We move the extent from the free list to the NOT_FULL list */ if (dberr_t err= flst_remove(iblock, uint16_t(FSEG_FREE + ioffset), - xdes, xoffset, mtr)) + xdes, xoffset, limit, mtr)) return err; if (dberr_t err= flst_add_last(iblock, uint16_t(FSEG_NOT_FULL + ioffset), - xdes, xoffset, mtr)) + xdes, xoffset, limit, mtr)) return err; } @@ -305,10 +308,10 @@ fseg_mark_page_used(fseg_inode_t *seg_inode, buf_block_t *iblock, { /* We move the extent from the NOT_FULL list to the FULL list */ if (dberr_t err= flst_remove(iblock, uint16_t(FSEG_NOT_FULL + ioffset), - xdes, xoffset, mtr)) + xdes, xoffset, limit, mtr)) return err; if (dberr_t err= flst_add_last(iblock, uint16_t(FSEG_FULL + ioffset), - xdes, xoffset, mtr)) + xdes, xoffset, limit, mtr)) return err; mtr->write<4>(*iblock, seg_inode + FSEG_NOT_FULL_N_USED, not_full_n_used - FSP_EXTENT_SIZE); @@ -891,7 +894,7 @@ fsp_fill_free_list( xdes_set_free(*xdes, descr, FSP_IBUF_BITMAP_OFFSET, mtr); xdes_set_state(*xdes, descr, XDES_FREE_FRAG, mtr); if (dberr_t err= flst_add_last(header, FSP_HEADER_OFFSET + FSP_FREE_FRAG, - xdes, xoffset, mtr)) + xdes, xoffset, space->free_limit, mtr)) return err; byte *n_used= FSP_HEADER_OFFSET + FSP_FRAG_N_USED + header->page.frame; mtr->write<4>(*header, n_used, 2U + mach_read_from_4(n_used)); @@ -900,7 +903,7 @@ fsp_fill_free_list( { if (dberr_t err= flst_add_last(header, FSP_HEADER_OFFSET + FSP_FREE, - xdes, xoffset, mtr)) + xdes, xoffset, space->free_limit, mtr)) return err; count++; } @@ -951,7 +954,11 @@ corrupted: first = flst_get_first(FSP_HEADER_OFFSET + FSP_FREE + header->page.frame); - if (first.page == FIL_NULL) { + if (first.page >= space->free_limit) { + if (first.page != FIL_NULL) { + goto flst_corrupted; + } + *err = fsp_fill_free_list(false, space, header, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) { goto corrupted; @@ -962,6 +969,17 @@ corrupted: if (first.page == FIL_NULL) { return nullptr; /* No free extents left */ } + if (first.page >= space->free_limit) { + goto flst_corrupted; + } + } + + if (first.boffset < FSP_HEADER_OFFSET + FSP_HEADER_SIZE + || first.boffset >= space->physical_size() + - (XDES_SIZE + FIL_PAGE_DATA_END)) { + flst_corrupted: + *err = DB_CORRUPTION; + goto corrupted; } descr = xdes_lst_get_descriptor(*space, first, mtr, @@ -974,7 +992,7 @@ corrupted: *err = flst_remove(header, FSP_HEADER_OFFSET + FSP_FREE, desc_block, static_cast(descr - desc_block->page.frame + XDES_FLST_NODE), - mtr); + space->free_limit, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) { return nullptr; } @@ -991,11 +1009,12 @@ MY_ATTRIBUTE((nonnull, warn_unused_result)) @param[in,out] xdes extent descriptor page @param[in,out] descr extent descriptor @param[in] bit slot to allocate in the extent +@param[in] space tablespace @param[in,out] mtr mini-transaction @return error code */ static dberr_t fsp_alloc_from_free_frag(buf_block_t *header, buf_block_t *xdes, xdes_t *descr, - uint32_t bit, mtr_t *mtr) + uint32_t bit, fil_space_t *space, mtr_t *mtr) { if (UNIV_UNLIKELY(xdes_get_state(descr) != XDES_FREE_FRAG || !xdes_is_free(descr, bit))) @@ -1008,14 +1027,15 @@ fsp_alloc_from_free_frag(buf_block_t *header, buf_block_t *xdes, xdes_t *descr, if (xdes_is_full(descr)) { + const uint32_t limit= space->free_limit; /* The fragment is full: move it to another list */ const uint16_t xoffset= static_cast(descr - xdes->page.frame + XDES_FLST_NODE); if (dberr_t err= flst_remove(header, FSP_HEADER_OFFSET + FSP_FREE_FRAG, - xdes, xoffset, mtr)) + xdes, xoffset, limit, mtr)) return err; if (dberr_t err= flst_add_last(header, FSP_HEADER_OFFSET + FSP_FULL_FRAG, - xdes, xoffset, mtr)) + xdes, xoffset, limit, mtr)) return err; xdes_set_state(*xdes, descr, XDES_FULL_FRAG, mtr); n_used-= FSP_EXTENT_SIZE; @@ -1079,8 +1099,11 @@ buf_block_t *fsp_alloc_free_page(fil_space_t *space, uint32_t hint, /* Else take the first extent in free_frag list */ fil_addr_t first = flst_get_first(FSP_HEADER_OFFSET + FSP_FREE_FRAG + block->page.frame); - if (first.page == FIL_NULL) + if (first.page >= space->free_limit) { + if (first.page != FIL_NULL) + goto flst_corrupted; + /* There are no partially full fragments: allocate a free extent and add it to the FREE_FRAG list. NOTE that the allocation may have as a side-effect that an extent containing a descriptor @@ -1091,13 +1114,23 @@ buf_block_t *fsp_alloc_free_page(fil_space_t *space, uint32_t hint, return nullptr; *err= flst_add_last(block, FSP_HEADER_OFFSET + FSP_FREE_FRAG, xdes, static_cast(descr - xdes->page.frame + - XDES_FLST_NODE), mtr); + XDES_FLST_NODE), + space->free_limit, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) return nullptr; xdes_set_state(*xdes, descr, XDES_FREE_FRAG, mtr); } else { + if (first.boffset < FSP_HEADER_OFFSET + FSP_HEADER_SIZE || + first.boffset >= space->physical_size() - + (XDES_SIZE + FIL_PAGE_DATA_END)) + { + flst_corrupted: + *err= DB_CORRUPTION; + goto err_exit; + } + descr= xdes_lst_get_descriptor(*space, first, mtr, &xdes, err); if (!descr) return nullptr; @@ -1144,7 +1177,7 @@ buf_block_t *fsp_alloc_free_page(fil_space_t *space, uint32_t hint, } } - *err= fsp_alloc_from_free_frag(block, xdes, descr, free, mtr); + *err= fsp_alloc_from_free_frag(block, xdes, descr, free, space, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) goto corrupted; return fsp_page_create(space, page_no, init_mtr); @@ -1183,7 +1216,8 @@ static dberr_t fsp_free_extent(fil_space_t* space, page_no_t offset, space->free_len++; return flst_add_last(block, FSP_HEADER_OFFSET + FSP_FREE, xdes, static_cast(descr - xdes->page.frame + - XDES_FLST_NODE), mtr); + XDES_FLST_NODE), + space->free_limit, mtr); } MY_ATTRIBUTE((nonnull)) @@ -1237,16 +1271,17 @@ static dberr_t fsp_free_page(fil_space_t *space, page_no_t offset, mtr_t *mtr) const uint16_t xoffset= static_cast(descr - xdes->page.frame + XDES_FLST_NODE); + const uint32_t limit = space->free_limit; if (state == XDES_FULL_FRAG) { /* The fragment was full: move it to another list */ err = flst_remove(header, FSP_HEADER_OFFSET + FSP_FULL_FRAG, - xdes, xoffset, mtr); + xdes, xoffset, limit, mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) { return err; } err = flst_add_last(header, FSP_HEADER_OFFSET + FSP_FREE_FRAG, - xdes, xoffset, mtr); + xdes, xoffset, limit, mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) { return err; } @@ -1268,7 +1303,7 @@ static dberr_t fsp_free_page(fil_space_t *space, page_no_t offset, mtr_t *mtr) if (!xdes_get_n_used(descr)) { /* The extent has become free: move it to another list */ err = flst_remove(header, FSP_HEADER_OFFSET + FSP_FREE_FRAG, - xdes, xoffset, mtr); + xdes, xoffset, limit, mtr); if (err == DB_SUCCESS) { err = fsp_free_extent(space, offset, mtr); } @@ -1362,7 +1397,7 @@ static dberr_t fsp_alloc_seg_inode_page(fil_space_t *space, #endif return flst_add_last(header, FSP_HEADER_OFFSET + FSP_SEG_INODES_FREE, - block, FSEG_INODE_PAGE_NODE, mtr); + block, FSEG_INODE_PAGE_NODE, space->free_limit, mtr); } MY_ATTRIBUTE((nonnull, warn_unused_result)) @@ -1418,12 +1453,13 @@ fsp_alloc_seg_inode(fil_space_t *space, buf_block_t *header, { /* There are no other unused headers left on the page: move it to another list */ + const uint32_t limit= space->free_limit; *err= flst_remove(header, FSP_HEADER_OFFSET + FSP_SEG_INODES_FREE, - block, FSEG_INODE_PAGE_NODE, mtr); + block, FSEG_INODE_PAGE_NODE, limit, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) return nullptr; *err= flst_add_last(header, FSP_HEADER_OFFSET + FSP_SEG_INODES_FULL, - block, FSEG_INODE_PAGE_NODE, mtr); + block, FSEG_INODE_PAGE_NODE, limit, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) return nullptr; } @@ -1456,16 +1492,17 @@ static void fsp_free_seg_inode(fil_space_t *space, fseg_inode_t *inode, } const ulint physical_size= space->physical_size(); + const uint32_t limit= space->free_limit; if (ULINT_UNDEFINED == fsp_seg_inode_page_find_free(iblock->page.frame, 0, physical_size)) { /* Move the page to another list */ if (flst_remove(header, FSP_HEADER_OFFSET + FSP_SEG_INODES_FULL, - iblock, FSEG_INODE_PAGE_NODE, mtr) != DB_SUCCESS) + iblock, FSEG_INODE_PAGE_NODE, limit, mtr) != DB_SUCCESS) return; if (flst_add_last(header, FSP_HEADER_OFFSET + FSP_SEG_INODES_FREE, - iblock, FSEG_INODE_PAGE_NODE, mtr) != DB_SUCCESS) + iblock, FSEG_INODE_PAGE_NODE, limit, mtr) != DB_SUCCESS) return; } @@ -1477,7 +1514,7 @@ static void fsp_free_seg_inode(fil_space_t *space, fseg_inode_t *inode, /* There are no other used headers left on the page: free it */ if (flst_remove(header, FSP_HEADER_OFFSET + FSP_SEG_INODES_FREE, - iblock, FSEG_INODE_PAGE_NODE, mtr) == DB_SUCCESS) + iblock, FSEG_INODE_PAGE_NODE, limit, mtr) == DB_SUCCESS) fsp_free_page(space, iblock->page.id().page_no(), mtr); } @@ -1850,7 +1887,8 @@ static dberr_t fseg_fill_free_list(const fseg_inode_t *inode, static_cast(inode - iblock->page.frame + FSEG_FREE), xdes, static_cast(descr - xdes->page.frame + - XDES_FLST_NODE), mtr)) + XDES_FLST_NODE), + space->free_limit, mtr)) return err; xdes_set_state(*xdes, descr, XDES_FSEG, mtr); mtr->memcpy(*xdes, descr + XDES_ID, inode + FSEG_ID, 8); @@ -1885,11 +1923,25 @@ fseg_alloc_free_extent( ut_ad(!memcmp(FSEG_MAGIC_N_BYTES, FSEG_MAGIC_N + inode, 4)); ut_d(space->modify_check(*mtr)); + if (UNIV_UNLIKELY(page_offset(inode) < FSEG_ARR_OFFSET)) + { + corrupted: + *err= DB_CORRUPTION; + space->set_corrupted(); + return nullptr; + } + if (flst_get_len(inode + FSEG_FREE)) { + const fil_addr_t first= flst_get_first(inode + FSEG_FREE); + if (first.page >= space->free_limit || + first.boffset < FSP_HEADER_OFFSET + FSP_HEADER_SIZE || + first.boffset >= space->physical_size() - + (XDES_SIZE + FIL_PAGE_DATA_END)) + goto corrupted; + /* Segment free list is not empty, allocate from it */ - return xdes_lst_get_descriptor(*space, flst_get_first(inode + FSEG_FREE), - mtr, xdes, err); + return xdes_lst_get_descriptor(*space, first, mtr, xdes, err); } xdes_t* descr= fsp_alloc_free_extent(space, 0, xdes, mtr, err); @@ -1901,7 +1953,8 @@ fseg_alloc_free_extent( static_cast(inode - iblock->page.frame + FSEG_FREE), *xdes, static_cast(descr - (*xdes)->page.frame + - XDES_FLST_NODE), mtr); + XDES_FLST_NODE), + space->free_limit, mtr); if (UNIV_LIKELY(*err != DB_SUCCESS)) return nullptr; /* Try to fill the segment free list */ @@ -2042,7 +2095,8 @@ take_hinted_page: + FSEG_FREE), xdes, static_cast(ret_descr - xdes->page.frame - + XDES_FLST_NODE), mtr); + + XDES_FLST_NODE), + space->free_limit, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) { return nullptr; } @@ -2088,6 +2142,14 @@ take_hinted_page: return nullptr; } + if (first.page >= space->free_limit + || first.boffset < FSP_HEADER_OFFSET + FSP_HEADER_SIZE + || first.boffset >= space->physical_size() + - (XDES_SIZE + FIL_PAGE_DATA_END)) { + *err= DB_CORRUPTION; + return nullptr; + } + ret_descr = xdes_lst_get_descriptor(*space, first, mtr, &xdes); if (!ret_descr) { return nullptr; @@ -2181,8 +2243,8 @@ got_hinted_page: ut_ad(xdes == xxdes); ut_ad(xdes_is_free(ret_descr, ret_page % extent_size)); - *err = fseg_mark_page_used(seg_inode, iblock, ret_page, - ret_descr, xdes, mtr); + *err = fseg_mark_page_used(space, seg_inode, iblock, ret_page, + ret_descr, xdes, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) { return nullptr; } @@ -2524,18 +2586,19 @@ corrupted: const uint16_t xoffset= uint16_t(descr - xdes->page.frame + XDES_FLST_NODE); const uint16_t ioffset= uint16_t(seg_inode - iblock->page.frame); + const uint32_t limit = space->free_limit; if (xdes_is_full(descr)) { /* The fragment is full: move it to another list */ err = flst_remove(iblock, static_cast(FSEG_FULL + ioffset), - xdes, xoffset, mtr); + xdes, xoffset, limit, mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) { return err; } err = flst_add_last(iblock, static_cast(FSEG_NOT_FULL + ioffset), - xdes, xoffset, mtr); + xdes, xoffset, limit, mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) { return err; } @@ -2553,7 +2616,7 @@ corrupted: if (!xdes_get_n_used(descr)) { err = flst_remove(iblock, static_cast(FSEG_NOT_FULL + ioffset), - xdes, xoffset, mtr); + xdes, xoffset, limit, mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) { return err; } @@ -2698,11 +2761,12 @@ fseg_free_extent( #endif /* BTR_CUR_HASH_ADAPT */ uint16_t lst; + uint32_t limit = space->free_limit; if (xdes_is_full(descr)) { lst = static_cast(FSEG_FULL + ioffset); remove: - err = flst_remove(iblock, lst, xdes, xoffset, mtr); + err = flst_remove(iblock, lst, xdes, xoffset, limit, mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) { return err; } @@ -2712,7 +2776,7 @@ remove: } else { err = flst_remove( iblock, static_cast(FSEG_NOT_FULL + ioffset), - xdes, xoffset, mtr); + xdes, xoffset, limit, mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) { return err; } @@ -2962,7 +3026,10 @@ fseg_get_first_extent( return nullptr; } - if (first.page == FIL_NULL) + if (first.page >= space->free_limit || + first.boffset < FSP_HEADER_OFFSET + FSP_HEADER_SIZE || + first.boffset >= space->physical_size() - + (XDES_SIZE + FIL_PAGE_DATA_END)) goto corrupted; return xdes_lst_get_descriptor(*space, first, mtr, nullptr, err); diff --git a/storage/innobase/fut/fut0lst.cc b/storage/innobase/fut/fut0lst.cc index a52027f28bc..48e2fbe38aa 100644 --- a/storage/innobase/fut/fut0lst.cc +++ b/storage/innobase/fut/fut0lst.cc @@ -113,17 +113,18 @@ static void flst_add_to_empty(buf_block_t *base, uint16_t boffset, } /** Insert a node after another one. -@param[in,out] base base node block -@param[in] boffset byte offset of the base node -@param[in,out] cur insert position block -@param[in] coffset byte offset of the insert position -@param[in,out] add block to be added -@param[in] aoffset byte offset of the block to be added -@param[in,out] mtr mini-transaction */ +@param base base node block +@param boffset byte offset of the base node +@param cur insert position block +@param coffset byte offset of the insert position +@param add block to be added +@param aoffset byte offset of the block to be added +@param limit fil_space_t::free_limit +@param mtr mini-transaction */ static dberr_t flst_insert_after(buf_block_t *base, uint16_t boffset, buf_block_t *cur, uint16_t coffset, buf_block_t *add, uint16_t aoffset, - mtr_t *mtr) + uint32_t limit, mtr_t *mtr) { ut_ad(base != cur || boffset != coffset); ut_ad(base != add || boffset != aoffset); @@ -139,6 +140,15 @@ static dberr_t flst_insert_after(buf_block_t *base, uint16_t boffset, MTR_MEMO_PAGE_SX_FIX)); fil_addr_t next_addr= flst_get_next_addr(cur->page.frame + coffset); + if (next_addr.page >= limit) + { + if (UNIV_UNLIKELY(next_addr.page != FIL_NULL)) + return DB_CORRUPTION; + } + else if (UNIV_UNLIKELY(next_addr.boffset < FIL_PAGE_DATA || + next_addr.boffset >= base->physical_size() - + FIL_PAGE_DATA_END)) + return DB_CORRUPTION; flst_write_addr(*add, add->page.frame + aoffset + FLST_PREV, cur->page.id().page_no(), coffset, mtr); @@ -167,18 +177,19 @@ static dberr_t flst_insert_after(buf_block_t *base, uint16_t boffset, } /** Insert a node before another one. -@param[in,out] base base node block -@param[in] boffset byte offset of the base node -@param[in,out] cur insert position block -@param[in] coffset byte offset of the insert position -@param[in,out] add block to be added -@param[in] aoffset byte offset of the block to be added -@param[in,out] mtr mini-transaction +@param base base node block +@param boffset byte offset of the base node +@param cur insert position block +@param coffset byte offset of the insert position +@param add block to be added +@param aoffset byte offset of the block to be added +@param limit fil_space_t::free_limit +@param mtr mini-transaction @return error code */ static dberr_t flst_insert_before(buf_block_t *base, uint16_t boffset, buf_block_t *cur, uint16_t coffset, buf_block_t *add, uint16_t aoffset, - mtr_t *mtr) + uint32_t limit, mtr_t *mtr) { ut_ad(base != cur || boffset != coffset); ut_ad(base != add || boffset != aoffset); @@ -194,6 +205,15 @@ static dberr_t flst_insert_before(buf_block_t *base, uint16_t boffset, MTR_MEMO_PAGE_SX_FIX)); fil_addr_t prev_addr= flst_get_prev_addr(cur->page.frame + coffset); + if (prev_addr.page >= limit) + { + if (UNIV_UNLIKELY(prev_addr.page != FIL_NULL)) + return DB_CORRUPTION; + } + else if (UNIV_UNLIKELY(prev_addr.boffset < FIL_PAGE_DATA || + prev_addr.boffset >= base->physical_size() - + FIL_PAGE_DATA_END)) + return DB_CORRUPTION; flst_write_addr(*add, add->page.frame + aoffset + FLST_PREV, prev_addr.page, prev_addr.boffset, mtr); @@ -234,14 +254,9 @@ void flst_init(const buf_block_t& block, byte *base, mtr_t *mtr) flst_zero_both(block, base + FLST_FIRST, mtr); } -/** Append a file list node to a list. -@param[in,out] base base node block -@param[in] boffset byte offset of the base node -@param[in,out] add block to be added -@param[in] aoffset byte offset of the node to be added -@param[in,outr] mtr mini-transaction */ dberr_t flst_add_last(buf_block_t *base, uint16_t boffset, - buf_block_t *add, uint16_t aoffset, mtr_t *mtr) + buf_block_t *add, uint16_t aoffset, + uint32_t limit, mtr_t *mtr) { ut_ad(base != add || boffset != aoffset); ut_ad(boffset < base->physical_size()); @@ -258,6 +273,13 @@ dberr_t flst_add_last(buf_block_t *base, uint16_t boffset, else { fil_addr_t addr= flst_get_last(base->page.frame + boffset); + if (UNIV_UNLIKELY(addr.page >= limit)) + return DB_CORRUPTION; + else if (UNIV_UNLIKELY(addr.boffset < FIL_PAGE_DATA || + addr.boffset >= base->physical_size() - + FIL_PAGE_DATA_END)) + return DB_CORRUPTION; + buf_block_t *cur= add; dberr_t err; if (addr.page != add->page.id().page_no() && @@ -266,19 +288,13 @@ dberr_t flst_add_last(buf_block_t *base, uint16_t boffset, BUF_GET_POSSIBLY_FREED, mtr, &err))) return err; return flst_insert_after(base, boffset, cur, addr.boffset, - add, aoffset, mtr); + add, aoffset, limit, mtr); } } -/** Prepend a file list node to a list. -@param[in,out] base base node block -@param[in] boffset byte offset of the base node -@param[in,out] add block to be added -@param[in] aoffset byte offset of the node to be added -@param[in,out] mtr mini-transaction -@return error code */ dberr_t flst_add_first(buf_block_t *base, uint16_t boffset, - buf_block_t *add, uint16_t aoffset, mtr_t *mtr) + buf_block_t *add, uint16_t aoffset, + uint32_t limit, mtr_t *mtr) { ut_ad(base != add || boffset != aoffset); ut_ad(boffset < base->physical_size()); @@ -296,6 +312,12 @@ dberr_t flst_add_first(buf_block_t *base, uint16_t boffset, else { fil_addr_t addr= flst_get_first(base->page.frame + boffset); + if (UNIV_UNLIKELY(addr.page >= limit)) + return DB_CORRUPTION; + else if (UNIV_UNLIKELY(addr.boffset < FIL_PAGE_DATA || + addr.boffset >= base->physical_size() - + FIL_PAGE_DATA_END)) + return DB_CORRUPTION; buf_block_t *cur= add; dberr_t err; if (addr.page != add->page.id().page_no() && @@ -304,19 +326,13 @@ dberr_t flst_add_first(buf_block_t *base, uint16_t boffset, BUF_GET_POSSIBLY_FREED, mtr, &err))) return err; return flst_insert_before(base, boffset, cur, addr.boffset, - add, aoffset, mtr); + add, aoffset, limit, mtr); } } -/** Remove a file list node. -@param[in,out] base base node block -@param[in] boffset byte offset of the base node -@param[in,out] cur block to be removed -@param[in] coffset byte offset of the current record to be removed -@param[in,out] mtr mini-transaction -@return error code */ dberr_t flst_remove(buf_block_t *base, uint16_t boffset, - buf_block_t *cur, uint16_t coffset, mtr_t *mtr) + buf_block_t *cur, uint16_t coffset, + uint32_t limit, mtr_t *mtr) { ut_ad(boffset < base->physical_size()); ut_ad(coffset < cur->physical_size()); @@ -329,9 +345,27 @@ dberr_t flst_remove(buf_block_t *base, uint16_t boffset, const fil_addr_t next_addr= flst_get_next_addr(cur->page.frame + coffset); dberr_t err= DB_SUCCESS; - if (prev_addr.page == FIL_NULL) + if (next_addr.page >= limit) + { + if (next_addr.page != FIL_NULL) + return DB_CORRUPTION; + } + else if (UNIV_UNLIKELY(next_addr.boffset < FIL_PAGE_DATA || + next_addr.boffset >= base->physical_size() - + FIL_PAGE_DATA_END)) + return DB_CORRUPTION; + + if (prev_addr.page >= limit) + { + if (prev_addr.page != FIL_NULL) + return DB_CORRUPTION; flst_write_addr(*base, base->page.frame + boffset + FLST_FIRST, next_addr.page, next_addr.boffset, mtr); + } + else if (UNIV_UNLIKELY(prev_addr.boffset < FIL_PAGE_DATA || + prev_addr.boffset >= base->physical_size() - + FIL_PAGE_DATA_END)) + return DB_CORRUPTION; else { buf_block_t *b= cur; @@ -375,25 +409,19 @@ void flst_validate(const buf_block_t *base, uint16_t boffset, mtr_t *mtr) ut_ad(mtr->memo_contains_flagged(base, MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX)); - /* We use two mini-transaction handles: the first is used to lock - the base node, and prevent other threads from modifying the list. - The second is used to traverse the list. We cannot run the second - mtr without committing it at times, because if the list is long, - the x-locked pages could fill the buffer, resulting in a deadlock. */ - mtr_t mtr2; - const uint32_t len= flst_get_len(base->page.frame + boffset); fil_addr_t addr= flst_get_first(base->page.frame + boffset); for (uint32_t i= len; i--; ) { - mtr2.start(); + ut_ad(addr.boffset >= FIL_PAGE_DATA); + ut_ad(addr.boffset < base->physical_size() - FIL_PAGE_DATA_END); const buf_block_t *b= buf_page_get_gen(page_id_t(base->page.id().space(), addr.page), base->zip_size(), RW_SX_LATCH, nullptr, BUF_GET, mtr); ut_ad(b); addr= flst_get_next_addr(b->page.frame + addr.boffset); - mtr2.commit(); + mtr->release_last_page(); } ut_ad(addr.page == FIL_NULL); @@ -402,13 +430,14 @@ void flst_validate(const buf_block_t *base, uint16_t boffset, mtr_t *mtr) for (uint32_t i= len; i--; ) { - mtr2.start(); + ut_ad(addr.boffset >= FIL_PAGE_DATA); + ut_ad(addr.boffset < base->physical_size() - FIL_PAGE_DATA_END); const buf_block_t *b= buf_page_get_gen(page_id_t(base->page.id().space(), addr.page), base->zip_size(), RW_SX_LATCH, nullptr, BUF_GET, mtr); ut_ad(b); addr= flst_get_prev_addr(b->page.frame + addr.boffset); - mtr2.commit(); + mtr->release_last_page(); } ut_ad(addr.page == FIL_NULL); diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index d627c8843a1..70824cff8a5 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -1831,7 +1831,7 @@ corrupted: err = flst_add_last(ibuf_root, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST, block, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST_NODE, - &mtr); + fil_system.sys_space->free_limit, &mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) { goto corrupted; } @@ -1862,7 +1862,6 @@ Removes a page from the free list and frees it to the fsp system. */ static void ibuf_remove_free_page() { mtr_t mtr; - mtr_t mtr2; page_t* header_page; log_free_check(); @@ -1889,26 +1888,28 @@ early_exit: return; } - ibuf_mtr_start(&mtr2); - - buf_block_t* root = ibuf_tree_root_get(&mtr2); + const auto root_savepoint = mtr.get_savepoint(); + buf_block_t* root = ibuf_tree_root_get(&mtr); if (UNIV_UNLIKELY(!root)) { - ibuf_mtr_commit(&mtr2); goto early_exit; } - mysql_mutex_unlock(&ibuf_mutex); - const uint32_t page_no = flst_get_last(PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST + root->page.frame).page; + if (page_no >= fil_system.sys_space->free_limit) { + goto early_exit; + } + + mysql_mutex_unlock(&ibuf_mutex); + /* NOTE that we must release the latch on the ibuf tree root because in fseg_free_page we access level 1 pages, and the root is a level 2 page. */ - - ibuf_mtr_commit(&mtr2); + root->page.lock.u_unlock(); + mtr.lock_register(root_savepoint, MTR_MEMO_BUF_FIX); ibuf_exit(&mtr); /* Since pessimistic inserts were prevented, we know that the @@ -1931,15 +1932,7 @@ early_exit: ibuf_enter(&mtr); mysql_mutex_lock(&ibuf_mutex); - - root = ibuf_tree_root_get(&mtr, &err); - if (UNIV_UNLIKELY(!root)) { - mysql_mutex_unlock(&ibuf_pessimistic_insert_mutex); - goto func_exit; - } - - ut_ad(page_no == flst_get_last(PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST - + root->page.frame).page); + mtr.upgrade_buffer_fix(root_savepoint, RW_X_LATCH); /* Remove the page from the free list and update the ibuf size data */ if (buf_block_t* block = @@ -1948,7 +1941,7 @@ early_exit: err = flst_remove(root, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST, block, PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST_NODE, - &mtr); + fil_system.sys_space->free_limit, &mtr); } mysql_mutex_unlock(&ibuf_pessimistic_insert_mutex); diff --git a/storage/innobase/include/fut0lst.h b/storage/innobase/include/fut0lst.h index 746dab80400..1adec365f2b 100644 --- a/storage/innobase/include/fut0lst.h +++ b/storage/innobase/include/fut0lst.h @@ -78,34 +78,40 @@ void flst_init(const buf_block_t &block, byte *base, mtr_t *mtr) MY_ATTRIBUTE((nonnull)); /** Append a file list node to a list. -@param[in,out] base base node block -@param[in] boffset byte offset of the base node -@param[in,out] add block to be added -@param[in] aoffset byte offset of the node to be added -@param[in,out] mtr mini-transaction +@param base base node block +@param boffset byte offset of the base node +@param add block to be added +@param aoffset byte offset of the node to be added +@param limit fil_space_t::free_limit +@param mtr mini-transaction @return error code */ dberr_t flst_add_last(buf_block_t *base, uint16_t boffset, - buf_block_t *add, uint16_t aoffset, mtr_t *mtr) + buf_block_t *add, uint16_t aoffset, + uint32_t limit, mtr_t *mtr) MY_ATTRIBUTE((nonnull, warn_unused_result)); /** Prepend a file list node to a list. -@param[in,out] base base node block -@param[in] boffset byte offset of the base node -@param[in,out] add block to be added -@param[in] aoffset byte offset of the node to be added -@param[in,out] mtr mini-transaction +@param base base node block +@param boffset byte offset of the base node +@param add block to be added +@param aoffset byte offset of the node to be added +@param limit fil_space_t::free_limit +@param mtr mini-transaction @return error code */ dberr_t flst_add_first(buf_block_t *base, uint16_t boffset, - buf_block_t *add, uint16_t aoffset, mtr_t *mtr) + buf_block_t *add, uint16_t aoffset, + uint32_t limit, mtr_t *mtr) MY_ATTRIBUTE((nonnull, warn_unused_result)); /** Remove a file list node. -@param[in,out] base base node block -@param[in] boffset byte offset of the base node -@param[in,out] cur block to be removed -@param[in] coffset byte offset of the current record to be removed -@param[in,out] mtr mini-transaction +@param base base node block +@param boffset byte offset of the base node +@param cur block to be removed +@param coffset byte offset of the current record to be removed +@param limit fil_space_t::free_limit +@param mtr mini-transaction @return error code */ dberr_t flst_remove(buf_block_t *base, uint16_t boffset, - buf_block_t *cur, uint16_t coffset, mtr_t *mtr) + buf_block_t *cur, uint16_t coffset, + uint32_t limit, mtr_t *mtr) MY_ATTRIBUTE((nonnull, warn_unused_result)); /** @return the length of a list */ @@ -117,11 +123,9 @@ inline uint32_t flst_get_len(const flst_base_node_t *base) /** @return a file address */ inline fil_addr_t flst_read_addr(const byte *faddr) { - fil_addr_t addr= { mach_read_from_4(faddr + FIL_ADDR_PAGE), - mach_read_from_2(faddr + FIL_ADDR_BYTE) }; - ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA); - ut_a(ut_align_offset(faddr, srv_page_size) >= FIL_PAGE_DATA); - return addr; + ut_ad(ut_align_offset(faddr, srv_page_size) >= FIL_PAGE_DATA); + return fil_addr_t{mach_read_from_4(faddr + FIL_ADDR_PAGE), + mach_read_from_2(faddr + FIL_ADDR_BYTE)}; } /** @return list first node address */ diff --git a/storage/innobase/trx/trx0purge.cc b/storage/innobase/trx/trx0purge.cc index 0f5d59ffb2d..00cd2b89e3a 100644 --- a/storage/innobase/trx/trx0purge.cc +++ b/storage/innobase/trx/trx0purge.cc @@ -266,7 +266,8 @@ trx_purge_add_undo_to_history(const trx_t* trx, trx_undo_t*& undo, mtr_t* mtr) that is known to be corrupted. */ ut_a(flst_add_first(rseg_header, TRX_RSEG + TRX_RSEG_HISTORY, undo_page, uint16_t(page_offset(undo_header) + - TRX_UNDO_HISTORY_NODE), mtr) == DB_SUCCESS); + TRX_UNDO_HISTORY_NODE), rseg->space->free_limit, + mtr) == DB_SUCCESS); mtr->write<2>(*undo_page, TRX_UNDO_SEG_HDR + TRX_UNDO_STATE + undo_page->page.frame, undo_state); @@ -356,6 +357,19 @@ inline dberr_t purge_sys_t::iterator::free_history_rseg(trx_rseg_t &rseg) const mtr_t mtr; bool freed= false; uint32_t rseg_ref= 0; + const auto last_boffset= srv_page_size - TRX_UNDO_LOG_OLD_HDR_SIZE; + /* Technically, rseg.space->free_limit is not protected by + rseg.latch, which we are holding, but rseg.space->latch. The value + that we are reading may become stale (too small) if other pages are + being allocated in this tablespace, for other rollback + segments. Nothing can be added to this rseg without holding + rseg.latch, and hence we can validate the entire file-based list + against the limit that we are reading here. + + Note: The read here may look like a data race. On none of our target + architectures this should be an actual problem, because the uint32_t + value should always fit in a register and be correctly aligned. */ + const auto last_page= rseg.space->free_limit; mtr.start(); @@ -371,13 +385,23 @@ func_exit: } hdr_addr= flst_get_last(TRX_RSEG + TRX_RSEG_HISTORY + rseg_hdr->page.frame); + + if (hdr_addr.page == FIL_NULL) + goto func_exit; + + if (hdr_addr.page >= last_page || + hdr_addr.boffset < TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE || + hdr_addr.boffset >= last_boffset) + { + corrupted: + err= DB_CORRUPTION; + goto func_exit; + } + hdr_addr.boffset= static_cast(hdr_addr.boffset - TRX_UNDO_HISTORY_NODE); loop: - if (hdr_addr.page == FIL_NULL) - goto func_exit; - buf_block_t *b= buf_page_get_gen(page_id_t(rseg.space->id, hdr_addr.page), 0, RW_X_LATCH, nullptr, BUF_GET_POSSIBLY_FREED, @@ -426,11 +450,18 @@ loop: fil_addr_t prev_hdr_addr= flst_get_prev_addr(b->page.frame + hdr_addr.boffset + TRX_UNDO_HISTORY_NODE); + if (prev_hdr_addr.page == FIL_NULL); + else if (prev_hdr_addr.page >= last_page || + prev_hdr_addr.boffset < TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE || + prev_hdr_addr.boffset >= last_boffset) + goto corrupted; + prev_hdr_addr.boffset= static_cast(prev_hdr_addr.boffset - TRX_UNDO_HISTORY_NODE); err= flst_remove(rseg_hdr, TRX_RSEG + TRX_RSEG_HISTORY, b, - uint16_t(hdr_addr.boffset + TRX_UNDO_HISTORY_NODE), &mtr); + uint16_t(hdr_addr.boffset + TRX_UNDO_HISTORY_NODE), + last_page, &mtr); if (UNIV_UNLIKELY(err != DB_SUCCESS)) goto func_exit; @@ -490,6 +521,9 @@ loop: ut_ad(rseg_hdr->page.id() == rseg.page_id()); mtr.memo_push(rseg_hdr, MTR_MEMO_PAGE_X_FIX); + if (hdr_addr.page == FIL_NULL) + goto func_exit; + goto loop; } @@ -780,13 +814,17 @@ bool purge_sys_t::rseg_get_next_history_log() { const byte *log_hdr= undo_page->page.frame + rseg->last_offset(); prev_log_addr= flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE); + if (prev_log_addr.boffset < TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE || + prev_log_addr.boffset >= srv_page_size - TRX_UNDO_LOG_OLD_HDR_SIZE) + goto corrupted; prev_log_addr.boffset = static_cast(prev_log_addr.boffset - TRX_UNDO_HISTORY_NODE); } else - prev_log_addr.page= FIL_NULL; + goto corrupted; - if (prev_log_addr.page == FIL_NULL) + if (prev_log_addr.page >= rseg->space->free_limit) + corrupted: rseg->last_page_no= FIL_NULL; else { diff --git a/storage/innobase/trx/trx0rseg.cc b/storage/innobase/trx/trx0rseg.cc index 8732ae81005..86f5b064b7f 100644 --- a/storage/innobase/trx/trx0rseg.cc +++ b/storage/innobase/trx/trx0rseg.cc @@ -448,7 +448,14 @@ static dberr_t trx_rseg_mem_restore(trx_rseg_t *rseg, mtr_t *mtr) { if (!rseg->space) return DB_TABLESPACE_NOT_FOUND; + + /* Access the tablespace header page to recover rseg->space->free_limit */ + page_id_t page_id{rseg->space->id, 0}; dberr_t err; + if (!buf_page_get_gen(page_id, 0, RW_S_LATCH, nullptr, BUF_GET, mtr, &err)) + return err; + mtr->release_last_page(); + page_id.set_page_no(rseg->page_no); const buf_block_t *rseg_hdr= buf_page_get_gen(rseg->page_id(), 0, RW_S_LATCH, nullptr, BUF_GET, mtr, &err); @@ -518,6 +525,11 @@ static dberr_t trx_rseg_mem_restore(trx_rseg_t *rseg, mtr_t *mtr) fil_addr_t node_addr= flst_get_last(TRX_RSEG + TRX_RSEG_HISTORY + rseg_hdr->page.frame); + if (node_addr.page >= rseg->space->free_limit || + node_addr.boffset < TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE || + node_addr.boffset >= srv_page_size - TRX_UNDO_LOG_OLD_HDR_SIZE) + return DB_CORRUPTION; + node_addr.boffset= static_cast(node_addr.boffset - TRX_UNDO_HISTORY_NODE); rseg->last_page_no= node_addr.page; diff --git a/storage/innobase/trx/trx0undo.cc b/storage/innobase/trx/trx0undo.cc index 8f1ff53e9d8..c0f5b1fb22c 100644 --- a/storage/innobase/trx/trx0undo.cc +++ b/storage/innobase/trx/trx0undo.cc @@ -513,7 +513,7 @@ trx_undo_seg_create(fil_space_t *space, buf_block_t *rseg_hdr, ulint *id, *err = flst_add_last(block, TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST, block, TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE, - mtr); + space->free_limit, mtr); *id = slot_no; mtr->write<4>(*rseg_hdr, TRX_RSEG + TRX_RSEG_UNDO_SLOTS @@ -696,7 +696,8 @@ buf_block_t *trx_undo_add_page(trx_undo_t *undo, mtr_t *mtr, dberr_t *err) mtr->undo_create(*new_block); trx_undo_page_init(*new_block); *err= flst_add_last(header_block, TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST, - new_block, TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE, mtr); + new_block, TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE, + rseg->space->free_limit, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) new_block= nullptr; else @@ -747,9 +748,11 @@ trx_undo_free_page( buf_page_make_young_if_needed(&header_block->page); + const uint32_t limit = rseg->space->free_limit; + *err = flst_remove(header_block, TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST, undo_block, TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE, - mtr); + limit, mtr); if (UNIV_UNLIKELY(*err != DB_SUCCESS)) { return FIL_NULL; @@ -758,7 +761,13 @@ trx_undo_free_page( const fil_addr_t last_addr = flst_get_last( TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST + header_block->page.frame); - if (UNIV_UNLIKELY(last_addr.page == page_no)) { + if (UNIV_UNLIKELY(last_addr.page == page_no) + || UNIV_UNLIKELY(last_addr.page != FIL_NULL + && last_addr.page >= limit) + || UNIV_UNLIKELY(last_addr.boffset < TRX_UNDO_PAGE_HDR + + TRX_UNDO_PAGE_NODE) + || UNIV_UNLIKELY(last_addr.boffset >= srv_page_size + - TRX_UNDO_LOG_OLD_HDR_SIZE)) { *err = DB_CORRUPTION; return FIL_NULL; } @@ -975,8 +984,8 @@ trx_undo_mem_create_at_db_start(trx_rseg_t *rseg, ulint id, uint32_t page_no) ut_ad(id < TRX_RSEG_N_SLOTS); mtr.start(); - const buf_block_t* block = buf_page_get( - page_id_t(rseg->space->id, page_no), 0, RW_X_LATCH, &mtr); + const page_id_t page_id{rseg->space->id, page_no}; + const buf_block_t* block = buf_page_get(page_id, 0, RW_X_LATCH, &mtr); if (UNIV_UNLIKELY(!block)) { corrupted: mtr.commit(); @@ -1078,6 +1087,15 @@ corrupted_type: fil_addr_t last_addr = flst_get_last( TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST + block->page.frame); + if (last_addr.page >= rseg->space->free_limit + || last_addr.boffset < TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE + || last_addr.boffset >= srv_page_size + - TRX_UNDO_LOG_OLD_HDR_SIZE) { + corrupted_undo: + ut_free(undo); + goto corrupted; + } + undo->last_page_no = last_addr.page; undo->top_page_no = last_addr.page; @@ -1086,8 +1104,7 @@ corrupted_type: RW_X_LATCH, &mtr); if (UNIV_UNLIKELY(!last)) { - ut_free(undo); - goto corrupted; + goto corrupted_undo; } if (const trx_undo_rec_t* rec = trx_undo_page_get_last_rec( From 8785b79763af4f8894be6124d27e885c0a5948a9 Mon Sep 17 00:00:00 2001 From: Ian Gilfillan Date: Mon, 8 Apr 2024 23:11:14 +0200 Subject: [PATCH 110/159] Update README.md --- README.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 58dbf105fb9..f721e0d9a75 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Code status: * [![Appveyor CI status](https://ci.appveyor.com/api/projects/status/4u6pexmtpuf8jq66?svg=true)](https://ci.appveyor.com/project/rasmushoj/server) ci.appveyor.com -## MariaDB: The open source relational database +## MariaDB: The innovative open source database MariaDB was designed as a drop-in replacement of MySQL(R) with more features, new storage engines, fewer bugs, and better performance. @@ -37,24 +37,14 @@ Help ----- More help is available from the Maria Discuss mailing list -https://launchpad.net/~maria-discuss, MariaDB's Zulip +https://lists.mariadb.org/postorius/lists/discuss.lists.mariadb.org/ and MariaDB's Zulip instance, https://mariadb.zulipchat.com/ -Live QA for beginner contributors ----- -MariaDB has a dedicated time each week when we answer new contributor questions live on Zulip. -From 8:00 to 10:00 UTC on Mondays, and 10:00 to 12:00 UTC on Thursdays, -anyone can ask any questions they’d like, and a live developer will be available to assist. - -New contributors can ask questions any time, but we will provide immediate feedback during that interval. - Licensing --------- *************************************************************************** -NOTE: - MariaDB is specifically available only under version 2 of the GNU General Public License (GPLv2). (I.e. Without the "any later version" clause.) This is inherited from MySQL. Please see the README file in From f131c609380a246f193ce09d8616efa6c7a159ce Mon Sep 17 00:00:00 2001 From: anson1014 <56494179+anson1014@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:20:18 -0700 Subject: [PATCH 111/159] Link beginner instructions in README.md When navigating through the existing links in the README, it is not immediately obvious where to go to find instructions in building and testing the source code. Since the README is often the first thing people see when looking at a repository, this information should be front and centre so that newcomers to the project can get setup as quickly as possible. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f721e0d9a75..5fe95f46a6b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,11 @@ https://mariadb.com/kb/en/mariadb-versus-mysql-compatibility/ https://mariadb.com/kb/en/new-and-old-releases/ +Getting the code, building it and testing it +--------------------------------------------------------------- + +Refer to the following guide: https://mariadb.org/get-involved/getting-started-for-developers/get-code-build-test/ which outlines how to correctly build the source code and run the MariaDB testing framework. + Help ----- From 04be12a8f5f8060869b9995898d53dc7c4cee86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 11 Apr 2024 15:51:30 +0300 Subject: [PATCH 112/159] Fix g++-14 -Wtemplate-id-cdtor --- storage/perfschema/pfs_buffer_container.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/storage/perfschema/pfs_buffer_container.h b/storage/perfschema/pfs_buffer_container.h index d5745e76249..b5506fe0195 100644 --- a/storage/perfschema/pfs_buffer_container.h +++ b/storage/perfschema/pfs_buffer_container.h @@ -1084,8 +1084,7 @@ template class PFS_buffer_processor { public: - virtual ~PFS_buffer_processor () - {} + virtual ~PFS_buffer_processor()= default; virtual void operator()(T *element) = 0; }; From e5c9904ebaab48b42b34c79b699a3e2c5a1dd933 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 11 Apr 2024 14:53:12 +0200 Subject: [PATCH 113/159] make innodb.monitor test idempotent --- mysql-test/suite/innodb/r/monitor.result | 44 ++++++++++++++++++++++-- mysql-test/suite/innodb/t/monitor.test | 44 ++++++++++++++++++++---- 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/mysql-test/suite/innodb/r/monitor.result b/mysql-test/suite/innodb/r/monitor.result index 8240c0f4321..ec160a8b4fe 100644 --- a/mysql-test/suite/innodb/r/monitor.result +++ b/mysql-test/suite/innodb/r/monitor.result @@ -213,6 +213,7 @@ icp_attempts disabled icp_no_match disabled icp_out_of_range disabled icp_match disabled +create temporary table orig_innodb_metrics as select name, enabled from information_schema.innodb_metrics; set global innodb_monitor_disable = All; select name from information_schema.innodb_metrics where enabled; name @@ -745,6 +746,43 @@ DROP TABLE t1; DROP TABLE fl2; DROP TABLE fl1; DROP TABLE fl0; -SET GLOBAL innodb_monitor_enable=default; -SET GLOBAL innodb_monitor_disable=default; -SET GLOBAL innodb_monitor_reset_all=default; +set global innodb_monitor_disable = 'adaptive\\_hash\\_p%'; +set global innodb_monitor_disable = 'adaptive\\_hash\\_r%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_batch\\_n%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_batch\\_s%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_g%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_s%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_u%'; +set global innodb_monitor_disable = 'buffer\\_f%'; +set global innodb_monitor_disable = 'buffer\\_page\\_%'; +set global innodb_monitor_disable = 'c%'; +set global innodb_monitor_disable = 'ddl%'; +set global innodb_monitor_disable = 'dml\\_reads%'; +set global innodb_monitor_disable = 'icp%'; +set global innodb_monitor_disable = 'index\\_p%'; +set global innodb_monitor_disable = 'innodb\\_di%'; +set global innodb_monitor_disable = 'innodb\\_l%'; +set global innodb_monitor_disable = 'innodb\\_m%'; +set global innodb_monitor_disable = 'lock\\_re%'; +set global innodb_monitor_disable = 'lock\\_ta%'; +set global innodb_monitor_disable = 'log%'; +set global innodb_monitor_disable = 'm%'; +set global innodb_monitor_disable = 'p%'; +set global innodb_monitor_disable = 't%'; +set global innodb_monitor_enable = 'log_padded'; +set global innodb_monitor_enable = 'log\\_w%'; +set global innodb_monitor_enable = 'trx_rseg_history_len'; +set global innodb_monitor_enable = 'trx_undo_slots_cached'; +set global innodb_monitor_enable=default; +Warnings: +Warning 1230 Default value is not defined for this set option. Please specify correct counter or module name. +set global innodb_monitor_disable=default; +Warnings: +Warning 1230 Default value is not defined for this set option. Please specify correct counter or module name. +set global innodb_monitor_reset_all=default; +Warnings: +Warning 1230 Default value is not defined for this set option. Please specify correct counter or module name. +select name, orig.enabled, new.enabled from +orig_innodb_metrics orig join information_schema.innodb_metrics new using(name) +where orig.enabled != new.enabled; +name enabled enabled diff --git a/mysql-test/suite/innodb/t/monitor.test b/mysql-test/suite/innodb/t/monitor.test index b07f2d32daa..a39e5982b79 100644 --- a/mysql-test/suite/innodb/t/monitor.test +++ b/mysql-test/suite/innodb/t/monitor.test @@ -5,11 +5,11 @@ # sys_vars.innodb_monitor_enable_basic --source include/have_innodb.inc -# Test turn on/off the monitor counter with "all" option -# By default, they will be off. select name, if(enabled,'enabled','disabled') status from information_schema.innodb_metrics; +create temporary table orig_innodb_metrics as select name, enabled from information_schema.innodb_metrics; + set global innodb_monitor_disable = All; select name from information_schema.innodb_metrics where enabled; @@ -557,8 +557,38 @@ DROP TABLE fl2; DROP TABLE fl1; DROP TABLE fl0; ---disable_warnings -SET GLOBAL innodb_monitor_enable=default; -SET GLOBAL innodb_monitor_disable=default; -SET GLOBAL innodb_monitor_reset_all=default; ---enable_warnings +set global innodb_monitor_disable = 'adaptive\\_hash\\_p%'; +set global innodb_monitor_disable = 'adaptive\\_hash\\_r%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_batch\\_n%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_batch\\_s%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_g%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_s%'; +set global innodb_monitor_disable = 'buffer\\_LRU\\_u%'; +set global innodb_monitor_disable = 'buffer\\_f%'; +set global innodb_monitor_disable = 'buffer\\_page\\_%'; +set global innodb_monitor_disable = 'c%'; +set global innodb_monitor_disable = 'ddl%'; +set global innodb_monitor_disable = 'dml\\_reads%'; +set global innodb_monitor_disable = 'icp%'; +set global innodb_monitor_disable = 'index\\_p%'; +set global innodb_monitor_disable = 'innodb\\_di%'; +set global innodb_monitor_disable = 'innodb\\_l%'; +set global innodb_monitor_disable = 'innodb\\_m%'; +set global innodb_monitor_disable = 'lock\\_re%'; +set global innodb_monitor_disable = 'lock\\_ta%'; +set global innodb_monitor_disable = 'log%'; +set global innodb_monitor_disable = 'm%'; +set global innodb_monitor_disable = 'p%'; +set global innodb_monitor_disable = 't%'; +set global innodb_monitor_enable = 'log_padded'; +set global innodb_monitor_enable = 'log\\_w%'; +set global innodb_monitor_enable = 'trx_rseg_history_len'; +set global innodb_monitor_enable = 'trx_undo_slots_cached'; + +set global innodb_monitor_enable=default; +set global innodb_monitor_disable=default; +set global innodb_monitor_reset_all=default; + +select name, orig.enabled, new.enabled from + orig_innodb_metrics orig join information_schema.innodb_metrics new using(name) + where orig.enabled != new.enabled; From 340d93a8ccb7de2747dc0d267ad7dc8cc1745a5d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 11 Apr 2024 15:06:39 +0200 Subject: [PATCH 114/159] cleanup: rpl.rpl_semi_sync_shutdown_await_ack avoid using multiple files with the same functionality. --- .../rpl/r/rpl_semi_sync_shutdown_await_ack.result | 4 ++-- .../rpl/t/rpl_semi_sync_shutdown_await_ack.test | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_semi_sync_shutdown_await_ack.result b/mysql-test/suite/rpl/r/rpl_semi_sync_shutdown_await_ack.result index a8e158a25e4..3048b6b5635 100644 --- a/mysql-test/suite/rpl/r/rpl_semi_sync_shutdown_await_ack.result +++ b/mysql-test/suite/rpl/r/rpl_semi_sync_shutdown_await_ack.result @@ -505,8 +505,8 @@ disconnect con1; connection default; connection con2; SHUTDOWN WAIT FOR ALL SLAVES; -connection server_2; -include/assert_grep.inc [Ensure the primary waited for the ACK of the killed thread] +# Ensure the primary waited for the ACK of the killed thread +FOUND 5 /Delaying shutdown to await semi-sync ACK/ in mysqld.1.err connection default; connection server_1; connection server_2; diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync_shutdown_await_ack.test b/mysql-test/suite/rpl/t/rpl_semi_sync_shutdown_await_ack.test index c321f2bf72f..4ed9ca0aa7c 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync_shutdown_await_ack.test +++ b/mysql-test/suite/rpl/t/rpl_semi_sync_shutdown_await_ack.test @@ -206,7 +206,6 @@ SET GLOBAL debug_dbug="+d,simulate_delay_semisync_slave_reply"; --echo # Wait for thd to begin semi-sync wait.. --let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist WHERE state = 'Waiting for semi-sync ACK from slave' --source include/wait_condition.inc ---source include/wait_condition.inc --echo # ..done --disconnect con1 @@ -220,15 +219,10 @@ EOF SHUTDOWN WAIT FOR ALL SLAVES; --source include/wait_until_disconnected.inc -# Run assert_grep on server_2 as it uses SQL commands for verification, but -# server_1 has gone away ---connection server_2 ---let $assert_text= Ensure the primary waited for the ACK of the killed thread ---let $assert_select= Delaying shutdown to await semi-sync ACK ---let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err ---let $assert_count= 5 ---let $assert_only_after=CURRENT_TEST ---source include/assert_grep.inc +--echo # Ensure the primary waited for the ACK of the killed thread +--let $SEARCH_PATTERN= Delaying shutdown to await semi-sync ACK +--let $SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err +--source include/search_pattern_in_file.inc --connection default --source include/wait_until_disconnected.inc From a6aecbb036a0511c9275b0aa31e5d33126d26971 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Thu, 11 Apr 2024 09:48:07 -0600 Subject: [PATCH 115/159] MDEV-10684: rpl.rpl_domain_id_filter_restart fails in buildbot The test failure in rpl.rpl_domain_id_filter_restart is caused by MDEV-33887. That is, the test uses master_pos_wait() (called indirectly by sync_slave_with_master) to try and wait for the replica to catch up to the master. However, the waited on transaction is ignored by the configured CHANGE MASTER TO IGNORE_DOMAIN_IDS=() As MDEV-33887 reports, due to the IO thread updating the binlog coordinates and the SQL thread updating the GTID state, if the replica is stopped in-between these updates, the replica state will be inconsistent. That is, the test expects that the GTID state will be updated, so upon restart, the replica will be up-to-date. However, if the replica is stopped before the SQL thread updates its GTID state, then upon restart, the replica will fetch the previously ignored event, which is no longer ignored upon restart, and execute it. This leads to the sporadic extra row in t2. This patch changes master_pos_wait() to use master_gtid_wait() to ensure the replica state is consistent with the master state. --- mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result | 3 ++- mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result b/mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result index f6eff3f9efc..948b4f48737 100644 --- a/mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result +++ b/mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result @@ -21,8 +21,9 @@ INSERT INTO t2 VALUES(1); SELECT * FROM t2; i 1 +include/save_master_gtid.inc connection slave; -connection slave; +include/sync_with_master_gtid.inc SELECT * FROM t1; i 1 diff --git a/mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test b/mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test index 8083b8f232f..38cbbdec7f3 100644 --- a/mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test +++ b/mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test @@ -35,9 +35,10 @@ SET @@session.gtid_domain_id= 1; INSERT INTO t2 VALUES(1); SELECT * FROM t2; -sync_slave_with_master; +source include/save_master_gtid.inc; connection slave; +source include/sync_with_master_gtid.inc; SELECT * FROM t1; SELECT * FROM t2; From 8dda6027019c93fb58d34095cb15908cdfa209e6 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 11 Apr 2024 21:00:39 +0200 Subject: [PATCH 116/159] spider should suppress errors in close_connection because stmt_da no longer expects errors at this stage, but mysql_close() call can still hit my_error() in net_serv.cc --- storage/spider/mysql-test/spider/include/clean_up_spider.inc | 1 - storage/spider/spd_table.cc | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/storage/spider/mysql-test/spider/include/clean_up_spider.inc b/storage/spider/mysql-test/spider/include/clean_up_spider.inc index 1c977bfb66f..249606ec774 100644 --- a/storage/spider/mysql-test/spider/include/clean_up_spider.inc +++ b/storage/spider/mysql-test/spider/include/clean_up_spider.inc @@ -3,7 +3,6 @@ DROP FUNCTION spider_copy_tables; DROP FUNCTION spider_ping_table; DROP FUNCTION spider_bg_direct_sql; DROP FUNCTION spider_direct_sql; ---replace_regex /\.dll/.so/ UNINSTALL SONAME IF EXISTS 'ha_spider'; DROP TABLE IF EXISTS mysql.spider_xa; DROP TABLE IF EXISTS mysql.spider_xa_member; diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 9defa33c8f1..27f11a8d96c 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -6813,7 +6813,11 @@ int spider_close_connection( } spider_rollback(spider_hton_ptr, thd, TRUE); + + Dummy_error_handler deh; // suppress network errors at this stage + thd->push_internal_handler(&deh); spider_free_trx(trx, TRUE, false); + thd->pop_internal_handler(); DBUG_RETURN(0); } From d7fc975cfe3326c7cdbc188250a8a0bed9d9968d Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Tue, 2 Apr 2024 20:45:29 +0300 Subject: [PATCH 117/159] MDEV-33802 Weird read view after ROLLBACK of other transactions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the case if some unique key fields are nullable, there can be several records with the same key fields in unique index with at least one key field equal to NULL, as NULL != NULL. When transaction is resumed after waiting on the record with at least one key field equal to NULL, and stored in persistent cursor record is deleted, persistent cursor can be restored to the record with all key fields equal to the stored ones, but with at least one field equal to NULL. And such record is wrongly treated as a record with the same unique key as stored in persistent cursor record one, what is wrong as NULL != NULL. The fix is to check if at least one unique field is NULL in restored persistent cursor position, and, if so, then don't treat the record as one with the same unique key as in the stored record key. dict_index_t::nulls_equal was removed, as it was initially developed for never existed in MariaDB "intrinsic tables", and there is no code, which would set it to "true". Reviewed by Marko Mäkelä. --- .../r/cursor-restore-unique-null.result | 24 +++++++++++++ .../innodb/t/cursor-restore-unique-null.test | 36 +++++++++++++++++++ storage/innobase/btr/btr0pcur.cc | 11 ++++-- storage/innobase/dict/dict0dict.cc | 1 - storage/innobase/include/data0data.h | 13 +++---- storage/innobase/include/data0data.inl | 30 ++++++---------- storage/innobase/include/dict0mem.h | 2 -- storage/innobase/include/dict0mem.inl | 1 - storage/innobase/row/row0ins.cc | 14 ++------ 9 files changed, 87 insertions(+), 45 deletions(-) create mode 100644 mysql-test/suite/innodb/r/cursor-restore-unique-null.result create mode 100644 mysql-test/suite/innodb/t/cursor-restore-unique-null.test diff --git a/mysql-test/suite/innodb/r/cursor-restore-unique-null.result b/mysql-test/suite/innodb/r/cursor-restore-unique-null.result new file mode 100644 index 00000000000..b5e2de88e7a --- /dev/null +++ b/mysql-test/suite/innodb/r/cursor-restore-unique-null.result @@ -0,0 +1,24 @@ +CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, UNIQUE KEY `b_c` (`b`,`c`)) +ENGINE=InnoDB, STATS_PERSISTENT=0; +INSERT INTO t SET a = 1, c = 2; +connect con1,localhost,root; +BEGIN; +INSERT INTO t SET a=2, c=2; +connection default; +BEGIN; +SET DEBUG_SYNC="lock_wait_suspend_thread_enter SIGNAL select_locked"; +SELECT * FROM t FORCE INDEX(b) FOR UPDATE; +connection con1; +SET DEBUG_SYNC="now WAIT_FOR select_locked"; +ROLLBACK; +connection default; +# If the bug is not fixed, and the both unique index key fields are +# NULL, there will be two (1, NULL, 2) rows in the result, +# because cursor will be restored to (NULL, 2, 1) position for +# secondary key instead of "supremum". +a b c +1 NULL 2 +COMMIT; +SET DEBUG_SYNC="RESET"; +disconnect con1; +DROP TABLE t; diff --git a/mysql-test/suite/innodb/t/cursor-restore-unique-null.test b/mysql-test/suite/innodb/t/cursor-restore-unique-null.test new file mode 100644 index 00000000000..c22ddf89d8f --- /dev/null +++ b/mysql-test/suite/innodb/t/cursor-restore-unique-null.test @@ -0,0 +1,36 @@ +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/count_sessions.inc + + +CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, UNIQUE KEY `b_c` (`b`,`c`)) + ENGINE=InnoDB, STATS_PERSISTENT=0; +INSERT INTO t SET a = 1, c = 2; + +--connect con1,localhost,root +BEGIN; + INSERT INTO t SET a=2, c=2; + +--connection default +BEGIN; +SET DEBUG_SYNC="lock_wait_suspend_thread_enter SIGNAL select_locked"; +--send SELECT * FROM t FORCE INDEX(b) FOR UPDATE + +--connection con1 +SET DEBUG_SYNC="now WAIT_FOR select_locked"; +ROLLBACK; + +--connection default +--echo # If the bug is not fixed, and the both unique index key fields are +--echo # NULL, there will be two (1, NULL, 2) rows in the result, +--echo # because cursor will be restored to (NULL, 2, 1) position for +--echo # secondary key instead of "supremum". +--reap +COMMIT; + +SET DEBUG_SYNC="RESET"; + +--disconnect con1 +DROP TABLE t; +--source include/wait_until_count_sessions.inc diff --git a/storage/innobase/btr/btr0pcur.cc b/storage/innobase/btr/btr0pcur.cc index 90084ef4379..4296d94fe5e 100644 --- a/storage/innobase/btr/btr0pcur.cc +++ b/storage/innobase/btr/btr0pcur.cc @@ -453,8 +453,15 @@ btr_pcur_t::restore_position(ulint restore_latch_mode, const char *file, return SAME_ALL; } - if (n_matched_fields >= index->n_uniq) - ret_val= SAME_UNIQ; + if (n_matched_fields >= index->n_uniq + /* Unique indexes can contain "NULL" keys, and if all + unique fields are NULL and not all tuple + fields match to record fields, then treat it as if + restored cursor position points to the record with + not the same unique key. */ + && !(index->n_nullable + && dtuple_contains_null(tuple, index->n_uniq))) + ret_val= SAME_UNIQ; } mem_heap_free(heap); diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index d0f8ac21dd8..26671d85b3d 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -1849,7 +1849,6 @@ dict_index_add_to_cache( new_index->n_fields = new_index->n_def; new_index->trx_id = index->trx_id; new_index->set_committed(index->is_committed()); - new_index->nulls_equal = index->nulls_equal; #ifdef MYSQL_INDEX_DISABLE_AHI new_index->disable_ahi = index->disable_ahi; #endif diff --git a/storage/innobase/include/data0data.h b/storage/innobase/include/data0data.h index c2b8c3e00b6..a2c39ecaed8 100644 --- a/storage/innobase/include/data0data.h +++ b/storage/innobase/include/data0data.h @@ -349,15 +349,12 @@ dtuple_set_types_binary( dtuple_t* tuple, /*!< in: data tuple */ ulint n) /*!< in: number of fields to set */ MY_ATTRIBUTE((nonnull)); -/**********************************************************************//** -Checks if a dtuple contains an SQL null value. -@return TRUE if some field is SQL null */ +/** Checks if a dtuple contains an SQL null value. +@param tuple tuple +@param fields_number number of fields in the tuple to check +@return true if some field is SQL null */ UNIV_INLINE -ibool -dtuple_contains_null( -/*=================*/ - const dtuple_t* tuple) /*!< in: dtuple */ - MY_ATTRIBUTE((nonnull, warn_unused_result)); +bool dtuple_contains_null(const dtuple_t *tuple, ulint fields_number = 0); /**********************************************************//** Checks that a data field is typed. Asserts an error if not. @return TRUE if ok */ diff --git a/storage/innobase/include/data0data.inl b/storage/innobase/include/data0data.inl index 39ade7b1e09..f4ae7528d3f 100644 --- a/storage/innobase/include/data0data.inl +++ b/storage/innobase/include/data0data.inl @@ -599,28 +599,18 @@ data_write_sql_null( memset(data, 0, len); } -/**********************************************************************//** -Checks if a dtuple contains an SQL null value. -@return TRUE if some field is SQL null */ +/** Checks if a dtuple contains an SQL null value. +@param tuple tuple +@param fields_number number of fields in the tuple to check +@return true if some field is SQL null */ UNIV_INLINE -ibool -dtuple_contains_null( -/*=================*/ - const dtuple_t* tuple) /*!< in: dtuple */ +bool dtuple_contains_null(const dtuple_t *tuple, ulint fields_number) { - ulint n; - ulint i; - - n = dtuple_get_n_fields(tuple); - - for (i = 0; i < n; i++) { - if (dfield_is_null(dtuple_get_nth_field(tuple, i))) { - - return(TRUE); - } - } - - return(FALSE); + ulint n= fields_number ? fields_number : dtuple_get_n_fields(tuple); + for (ulint i= 0; i < n; i++) + if (dfield_is_null(dtuple_get_nth_field(tuple, i))) + return true; + return false; } /**************************************************************//** diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index f0d4eb7bebf..d81bbb51b43 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -1011,8 +1011,6 @@ struct dict_index_t { /*!< number of columns the user defined to be in the index: in the internal representation we add more columns */ - unsigned nulls_equal:1; - /*!< if true, SQL NULL == SQL NULL */ #ifdef BTR_CUR_HASH_ADAPT #ifdef MYSQL_INDEX_DISABLE_AHI unsigned disable_ahi:1; diff --git a/storage/innobase/include/dict0mem.inl b/storage/innobase/include/dict0mem.inl index 090ec73278b..28900c9062f 100644 --- a/storage/innobase/include/dict0mem.inl +++ b/storage/innobase/include/dict0mem.inl @@ -63,7 +63,6 @@ dict_mem_fill_index_struct( index->n_core_fields = (unsigned int) n_fields; /* The '1 +' above prevents allocation of an empty mem block */ - index->nulls_equal = false; #ifdef BTR_CUR_HASH_ADAPT #ifdef MYSQL_INDEX_DISABLE_AHI index->disable_ahi = false; diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 088981e5b5b..6e68f46825a 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -2038,7 +2038,7 @@ row_ins_dupl_error_with_rec( /* In a unique secondary index we allow equal key values if they contain SQL NULLs */ - if (!dict_index_is_clust(index) && !index->nulls_equal) { + if (!dict_index_is_clust(index)) { for (i = 0; i < n_unique; i++) { if (dfield_is_null(dtuple_get_nth_field(entry, i))) { @@ -2143,16 +2143,8 @@ row_ins_scan_sec_index_for_duplicate( /* If the secondary index is unique, but one of the fields in the n_unique first fields is NULL, a unique key violation cannot occur, since we define NULL != NULL in this case */ - - if (!index->nulls_equal) { - for (ulint i = 0; i < n_unique; i++) { - if (UNIV_SQL_NULL == dfield_get_len( - dtuple_get_nth_field(entry, i))) { - - DBUG_RETURN(DB_SUCCESS); - } - } - } + if (index->n_nullable && dtuple_contains_null(entry, n_unique)) + DBUG_RETURN(DB_SUCCESS); /* Store old value on n_fields_cmp */ From dd639985c179e484115bfabd83dbbd2c4ab3f392 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Fri, 8 Mar 2024 22:56:14 +0000 Subject: [PATCH 118/159] Simplify MTR for handling multiple invalid options In 69a4d6ae, an MTR test was added to verify that we handled multiple invalid options. However, the logic to perform this test relied on a non-trivial regex to filter out the noise in the logs. Instead, we now just simply search for what we expect to be in the logs. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysql-test/main/mysqld_option_err.result | 12 ++++++------ mysql-test/main/mysqld_option_err.test | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/mysql-test/main/mysqld_option_err.result b/mysql-test/main/mysqld_option_err.result index e2c7b0bd213..13a004b77d1 100644 --- a/mysql-test/main/mysqld_option_err.result +++ b/mysql-test/main/mysqld_option_err.result @@ -4,13 +4,13 @@ Test bad default storage engine. Test non-numeric value passed to number option. Test that bad value for plugin enum option is rejected correctly. Test to see if multiple unknown options will be displayed in the error output -unknown option '--nonexistentoption' -unknown option '--alsononexistent' -unknown variable 'nonexistentvariable=1' +FOUND 1 /unknown option '--nonexistentoption2'/ in mysqltest.log +FOUND 1 /unknown option '--alsononexistent'/ in mysqltest.log +FOUND 1 /unknown variable 'nonexistentvariable=1'/ in mysqltest.log Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output -Error while setting value 'invalid_value' to 'sql_mode' -ambiguous option '--character' (character-set-client-handshake, character_sets_dir) -option '--bootstrap' cannot take an argument +FOUND 1 /Error while setting value 'invalid_value' to 'sql_mode'/ in mysqltest.log +FOUND 1 /ambiguous option '--character'/ in mysqltest.log +FOUND 1 /option '--bootstrap' cannot take an argument/ in mysqltest.log Test that --help --verbose works Test that --not-known-option --help --verbose gives error Done. diff --git a/mysql-test/main/mysqld_option_err.test b/mysql-test/main/mysqld_option_err.test index ad4df61b0f8..2c77b868ebf 100644 --- a/mysql-test/main/mysqld_option_err.test +++ b/mysql-test/main/mysqld_option_err.test @@ -46,17 +46,29 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --error 7 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --plugin-dir=$MYSQLTEST_VARDIR/plugins --plugin-load=example=ha_example.so --plugin-example-enum-var=noexist >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 +--let SEARCH_FILE = $MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log + --echo Test to see if multiple unknown options will be displayed in the error output -# Remove the noise to make the test robust ---replace_regex /^((?!nonexistent).)*$// /.*unknown/unknown/ --error 7 ---exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --nonexistentoption --alsononexistent --nonexistentvariable=1 2>&1 +--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --nonexistentoption2 --alsononexistent --nonexistentvariable=1 >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 + +--let SEARCH_PATTERN=unknown option '--nonexistentoption2' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=unknown option '--alsononexistent' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=unknown variable 'nonexistentvariable=1' +--source include/search_pattern_in_file.inc --echo Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output -# Remove the noise to make the test robust ---replace_regex /^((?!('sql_mode'|'--character'|'--bootstrap')).)*$// /.*Error while setting value/Error while setting value/ /.*ambiguous option/ambiguous option/ /.*option '--bootstrap'/option '--bootstrap'/ --error 1 ---exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob 2>&1 +--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 + +--let SEARCH_PATTERN=Error while setting value 'invalid_value' to 'sql_mode' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=ambiguous option '--character' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=option '--bootstrap' cannot take an argument +--source include/search_pattern_in_file.inc # # Test that an wrong option with --help --verbose gives an error From 47d75cdd80133c4e488d293533a124defd645040 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Sun, 25 Feb 2024 02:03:44 +0000 Subject: [PATCH 119/159] MDEV-33469 Fix behavior on invalid arguments When passing in an invalid value (e.g. incorrect data type) for a variable, the server startup will fail with misleading error messages. The behavior **before** this change: For server options: - The error message will indicate that the argument is being adjusted to a valid value - Server startup still fails For plugin options: - The error message will indicate that the argument is being adjusted to a valid value - The plugin is still disabled - Server startup fails with a message that it does not recognize the plugin option The behavior **after** this change: For server options: - Output that an invalid argument was provided - Exit server startup For plugin options: - Output that an invalid argument was provided - Disable the plugin - Attempt to continue server startup All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysql-test/main/mysqld_option_err.result | 2 ++ mysql-test/main/mysqld_option_err.test | 6 +++++- mysys/my_getopt.c | 6 +++++- sql/sql_plugin.cc | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/mysqld_option_err.result b/mysql-test/main/mysqld_option_err.result index 13a004b77d1..2ad24ffe195 100644 --- a/mysql-test/main/mysqld_option_err.result +++ b/mysql-test/main/mysqld_option_err.result @@ -11,6 +11,8 @@ Test to see if multiple ambiguous options and invalid arguments will be displaye FOUND 1 /Error while setting value 'invalid_value' to 'sql_mode'/ in mysqltest.log FOUND 1 /ambiguous option '--character'/ in mysqltest.log FOUND 1 /option '--bootstrap' cannot take an argument/ in mysqltest.log +FOUND 1 /Incorrect integer value: '18446744073709551616'/ in mysqltest.log +FOUND 1 /Error while setting value '18446744073709551616' to 'binlog_cache_size'/ in mysqltest.log Test that --help --verbose works Test that --not-known-option --help --verbose gives error Done. diff --git a/mysql-test/main/mysqld_option_err.test b/mysql-test/main/mysqld_option_err.test index 2c77b868ebf..e89eba33199 100644 --- a/mysql-test/main/mysqld_option_err.test +++ b/mysql-test/main/mysqld_option_err.test @@ -61,7 +61,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --echo Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output --error 1 ---exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 +--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob --binlog_cache_size=18446744073709551616 >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 --let SEARCH_PATTERN=Error while setting value 'invalid_value' to 'sql_mode' --source include/search_pattern_in_file.inc @@ -69,6 +69,10 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --source include/search_pattern_in_file.inc --let SEARCH_PATTERN=option '--bootstrap' cannot take an argument --source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Incorrect integer value: '18446744073709551616' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Error while setting value '18446744073709551616' to 'binlog_cache_size' +--source include/search_pattern_in_file.inc # # Test that an wrong option with --help --verbose gives an error diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index be8a89d2b08..e67407ca188 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -133,7 +133,7 @@ double getopt_ulonglong2double(ulonglong v) return u.dbl; } -#define SET_HO_ERROR_AND_CONTINUE(e) { ho_error= (e); continue; } +#define SET_HO_ERROR_AND_CONTINUE(e) { ho_error= (e); (*argc)--; continue; } /** Handle command line options. @@ -1077,6 +1077,8 @@ static ulonglong eval_num_suffix_ull(char *argument, static longlong getopt_ll(char *arg, const struct my_option *optp, int *err) { longlong num=eval_num_suffix_ll(arg, err, (char*) optp->name); + if (*err) + return(0); return getopt_ll_limit_value(num, optp, NULL); } @@ -1154,6 +1156,8 @@ longlong getopt_ll_limit_value(longlong num, const struct my_option *optp, static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err) { ulonglong num= eval_num_suffix_ull(arg, err, (char*) optp->name); + if (*err) + return(0); return getopt_ull_limit_value(num, optp, NULL); } diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 84ea95305ba..979407bf3ea 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -4258,7 +4258,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, if (unlikely(error)) { - sql_print_error("Parsing options for plugin '%s' failed.", + sql_print_error("Parsing options for plugin '%s' failed. Disabling plugin", tmp->name.str); goto err; } From 79706fd386ac29f85b13e906b55b70fe2d4b5ae2 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Fri, 8 Mar 2024 23:53:24 +0000 Subject: [PATCH 120/159] Minor improvements to options error handling - Add additional MTRs for more coverage on invalid options - Updating a few error messages to be more informative - Use the exit code from handle_options() when there is an error processing user options All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysql-test/main/mysqld_option_err.result | 4 +++- mysql-test/main/mysqld_option_err.test | 14 ++++++++----- mysys/my_getopt.c | 26 +++++++++++++----------- sql/mysqld.cc | 5 +++-- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/mysql-test/main/mysqld_option_err.result b/mysql-test/main/mysqld_option_err.result index 2ad24ffe195..e740cb7631b 100644 --- a/mysql-test/main/mysqld_option_err.result +++ b/mysql-test/main/mysqld_option_err.result @@ -11,8 +11,10 @@ Test to see if multiple ambiguous options and invalid arguments will be displaye FOUND 1 /Error while setting value 'invalid_value' to 'sql_mode'/ in mysqltest.log FOUND 1 /ambiguous option '--character'/ in mysqltest.log FOUND 1 /option '--bootstrap' cannot take an argument/ in mysqltest.log -FOUND 1 /Incorrect integer value: '18446744073709551616'/ in mysqltest.log +FOUND 1 /Integer value out of range for uint64: '18446744073709551616'/ in mysqltest.log FOUND 1 /Error while setting value '18446744073709551616' to 'binlog_cache_size'/ in mysqltest.log +FOUND 1 /Unknown suffix 'y' used for variable 'bulk_insert_buffer_size' \(value '123y'\). Legal suffix characters are: K, M, G, T, P, E/ in mysqltest.log +FOUND 1 /Error while setting value '123y' to 'bulk_insert_buffer_size'/ in mysqltest.log Test that --help --verbose works Test that --not-known-option --help --verbose gives error Done. diff --git a/mysql-test/main/mysqld_option_err.test b/mysql-test/main/mysqld_option_err.test index e89eba33199..88c53794f53 100644 --- a/mysql-test/main/mysqld_option_err.test +++ b/mysql-test/main/mysqld_option_err.test @@ -25,7 +25,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --echo Test bad binlog format. ---error 1 +--error 13 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --log-bin --binlog-format=badformat >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 @@ -35,7 +35,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --echo Test non-numeric value passed to number option. ---error 1 +--error 9 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --min-examined-row-limit=notanumber >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 @@ -60,8 +60,8 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --source include/search_pattern_in_file.inc --echo Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output ---error 1 ---exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob --binlog_cache_size=18446744073709551616 >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 +--error 9 +--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob --binlog_cache_size=18446744073709551616 --bulk_insert_buffer_size=123y >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 --let SEARCH_PATTERN=Error while setting value 'invalid_value' to 'sql_mode' --source include/search_pattern_in_file.inc @@ -69,10 +69,14 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --source include/search_pattern_in_file.inc --let SEARCH_PATTERN=option '--bootstrap' cannot take an argument --source include/search_pattern_in_file.inc ---let SEARCH_PATTERN=Incorrect integer value: '18446744073709551616' +--let SEARCH_PATTERN=Integer value out of range for uint64: '18446744073709551616' --source include/search_pattern_in_file.inc --let SEARCH_PATTERN=Error while setting value '18446744073709551616' to 'binlog_cache_size' --source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Unknown suffix 'y' used for variable 'bulk_insert_buffer_size' \(value '123y'\). Legal suffix characters are: K, M, G, T, P, E +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Error while setting value '123y' to 'bulk_insert_buffer_size' +--source include/search_pattern_in_file.inc # # Test that an wrong option with --help --verbose gives an error diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index e67407ca188..bed80d3efe2 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -858,7 +858,7 @@ static int setval(const struct my_option *opts, void *value, char *argument, } if (err) { - res= EXIT_UNKNOWN_SUFFIX; + res= err; goto ret; }; } @@ -992,7 +992,7 @@ static inline ulonglong eval_num_suffix(char *suffix, int *error) case 'E': return 1ULL << 60; default: - *error= 1; + *error= EXIT_UNKNOWN_SUFFIX; return 0ULL; } } @@ -1018,15 +1018,16 @@ static longlong eval_num_suffix_ll(char *argument, if (errno == ERANGE) { my_getopt_error_reporter(ERROR_LEVEL, - "Incorrect integer value: '%s'", argument); - *error= 1; + "Integer value out of range for int64: '%s'", argument); + *error= EXIT_ARGUMENT_INVALID; DBUG_RETURN(0); } num*= eval_num_suffix(endchar, error); if (*error) - fprintf(stderr, - "Unknown suffix '%c' used for variable '%s' (value '%s')\n", - *endchar, option_name, argument); + my_getopt_error_reporter(ERROR_LEVEL, + "Unknown suffix '%c' used for variable '%s' (value '%s'). " + "Legal suffix characters are: K, M, G, T, P, E", + *endchar, option_name, argument); DBUG_RETURN(num); } @@ -1050,15 +1051,16 @@ static ulonglong eval_num_suffix_ull(char *argument, if (errno == ERANGE) { my_getopt_error_reporter(ERROR_LEVEL, - "Incorrect integer value: '%s'", argument); - *error= 1; + "Integer value out of range for uint64: '%s'", argument); + *error= EXIT_ARGUMENT_INVALID; DBUG_RETURN(0); } num*= eval_num_suffix(endchar, error); if (*error) - fprintf(stderr, - "Unknown suffix '%c' used for variable '%s' (value '%s')\n", - *endchar, option_name, argument); + my_getopt_error_reporter(ERROR_LEVEL, + "Unknown suffix '%c' used for variable '%s' (value '%s'). " + "Legal suffix characters are: K, M, G, T, P, E", + *endchar, option_name, argument); DBUG_RETURN(num); } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 5ba51bdfb74..128899cb347 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3860,8 +3860,9 @@ static int init_common_variables() SQLCOM_END + 11); #endif - if (get_options(&remaining_argc, &remaining_argv)) - exit(1); + int opt_err; + if ((opt_err= get_options(&remaining_argc, &remaining_argv))) + exit(opt_err); if (IS_SYSVAR_AUTOSIZE(&server_version_ptr)) set_server_version(server_version, sizeof(server_version)); From 69b5fdf32a7f4a51b8bd28a29fd1d7cbc696e5ad Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 11 Apr 2024 16:19:13 +0200 Subject: [PATCH 121/159] galera/suite.pm: perl warning Unescaped left brace in regex is passed through in regex --- mysql-test/suite/galera/suite.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/galera/suite.pm b/mysql-test/suite/galera/suite.pm index d09cb89df5c..4c4d26db4c5 100644 --- a/mysql-test/suite/galera/suite.pm +++ b/mysql-test/suite/galera/suite.pm @@ -1,5 +1,6 @@ package My::Suite::Galera; +use warnings; use lib 'suite'; use wsrep::common; @@ -63,7 +64,7 @@ push @::global_suppressions, qr(WSREP: Failed to remove page file .*), qr(WSREP: wsrep_sst_method is set to 'mysqldump' yet mysqld bind_address is set to .*), qr|WSREP: Sending JOIN failed: -107 \(Transport endpoint is not connected\). Will retry in new primary component.|, - qr|WSREP: Send action {.* STATE_REQUEST} returned -107 \(Transport endpoint is not connected\)|, + qr|WSREP: Send action \{.* STATE_REQUEST} returned -107 \(Transport endpoint is not connected\)|, qr|WSREP: Trying to continue unpaused monitor|, qr|WSREP: Wait for gtid returned error 3 while waiting for prior transactions to commit before setting position|, qr|WSREP: Failed to report last committed|, From 6a4ac4c72d41cb2edbcc5ff27c354783afce2c1a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 13 Apr 2024 14:36:15 +0200 Subject: [PATCH 122/159] Fixed random failure in main.kill_processlist-6619 (take 3) followup for 81f75ca83ae6 improve over take 2. It's technically possible, though unlikely, to see THD after it already reset the info to NULL, but has not changed the command to COM_SLEEP yet (see THD::mark_connection_idle()). Let's wait for "Sleep", not for NULL. --- mysql-test/main/kill_processlist-6619.test | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/kill_processlist-6619.test b/mysql-test/main/kill_processlist-6619.test index 09c41f28a8f..36692b18ec9 100644 --- a/mysql-test/main/kill_processlist-6619.test +++ b/mysql-test/main/kill_processlist-6619.test @@ -10,7 +10,7 @@ source include/wait_condition.inc; --connect (con1,localhost,root,,) --let $con_id = `SELECT CONNECTION_ID()` -let $wait_condition=select info is NULL from information_schema.processlist where id != $con_id; +let $wait_condition=select command = 'sleep' from information_schema.processlist where id != $con_id; source include/wait_condition.inc; --replace_result Execute Query @@ -32,9 +32,7 @@ reap; SET DEBUG_SYNC='reset'; # Wait until default connection has reset query string -let $wait_condition= - SELECT COUNT(*) = 1 from information_schema.processlist - WHERE info is NULL; +let $wait_condition=select command = 'sleep' from information_schema.processlist where id != $con_id; --source include/wait_condition.inc --replace_result Execute Query From 8bc32410160265dcd27d595ed610843d08d32034 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 13 Apr 2024 16:27:08 +0200 Subject: [PATCH 123/159] feedback plugin: abort sending the report on server shutdown network timeouts might be rather large and feedback plugin waits forever for the sender thread to exit. an alternative could've been to use GNU-specific pthread_timedjoin_np(), where _np mean "not portable". --- plugin/feedback/feedback.cc | 4 ++++ plugin/feedback/feedback.h | 1 + plugin/feedback/url_http.cc | 18 +++++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index 160545995d0..c1794f0987e 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -340,6 +340,10 @@ static int free(void *p) shutdown_plugin= true; mysql_cond_signal(&sleep_condition); mysql_mutex_unlock(&sleep_mutex); + + for (uint i= 0; i < url_count; i++) + urls[i]->abort(); + pthread_join(sender_thread, NULL); mysql_mutex_destroy(&sleep_mutex); diff --git a/plugin/feedback/feedback.h b/plugin/feedback/feedback.h index 04fe1ab6aa1..6021eb85860 100644 --- a/plugin/feedback/feedback.h +++ b/plugin/feedback/feedback.h @@ -52,6 +52,7 @@ class Url { const char *url() { return full_url.str; } size_t url_length() { return full_url.length; } + virtual void abort() = 0; virtual int send(const char* data, size_t data_length) = 0; virtual int set_proxy(const char *proxy, size_t proxy_len) { diff --git a/plugin/feedback/url_http.cc b/plugin/feedback/url_http.cc index 98116dd04f1..590bb06cc5f 100644 --- a/plugin/feedback/url_http.cc +++ b/plugin/feedback/url_http.cc @@ -37,8 +37,9 @@ static const uint FOR_WRITING= 1; class Url_http: public Url { protected: const LEX_STRING host, port, path; - bool ssl; LEX_STRING proxy_host, proxy_port; + my_socket fd; + bool ssl; bool use_proxy() { @@ -47,7 +48,8 @@ class Url_http: public Url { Url_http(LEX_STRING &url_arg, LEX_STRING &host_arg, LEX_STRING &port_arg, LEX_STRING &path_arg, bool ssl_arg) : - Url(url_arg), host(host_arg), port(port_arg), path(path_arg), ssl(ssl_arg) + Url(url_arg), host(host_arg), port(port_arg), path(path_arg), + fd(INVALID_SOCKET), ssl(ssl_arg) { proxy_host.length= 0; } @@ -60,6 +62,7 @@ class Url_http: public Url { } public: + void abort(); int send(const char* data, size_t data_length); int set_proxy(const char *proxy, size_t proxy_len) { @@ -158,13 +161,18 @@ Url* http_create(const char *url, size_t url_length) return new Url_http(full_url, host, port, path, ssl); } +void Url_http::abort() +{ + if (fd != INVALID_SOCKET) + closesocket(fd); // interrupt I/O waits +} + /* do the vio_write and check that all data were sent ok */ #define write_check(VIO, DATA, LEN) \ (vio_write((VIO), (uchar*)(DATA), (LEN)) != (LEN)) int Url_http::send(const char* data, size_t data_length) { - my_socket fd= INVALID_SOCKET; char buf[1024]; size_t len= 0; @@ -180,6 +188,7 @@ int Url_http::send(const char* data, size_t data_length) return 1; } + DBUG_ASSERT(fd == INVALID_SOCKET); for (addr= addrs; addr != NULL; addr= addr->ai_next) { fd= socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); @@ -208,6 +217,7 @@ int Url_http::send(const char* data, size_t data_length) sql_print_error("feedback plugin: vio_new failed for url '%s'", full_url.str); closesocket(fd); + fd= INVALID_SOCKET; return 1; } @@ -236,6 +246,7 @@ int Url_http::send(const char* data, size_t data_length) free_vio_ssl_acceptor_fd(ssl_fd); closesocket(fd); vio_delete(vio); + fd= INVALID_SOCKET; return 1; } } @@ -334,6 +345,7 @@ int Url_http::send(const char* data, size_t data_length) } #endif + fd= INVALID_SOCKET; return res; } From 99dc0f030f049ba41e19f31d82734a96a1082da0 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 20 Mar 2024 17:23:49 +1100 Subject: [PATCH 124/159] MDEV-28993 spider: revert removal of ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC It was done in MDEV-29447. --- storage/spider/spd_db_mysql.cc | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index a2262956d44..2691f62a5c1 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -5548,7 +5548,9 @@ int spider_db_mbase_util::check_item_func( { case Item_func::TRIG_COND_FUNC: case Item_func::CASE_SEARCHED_FUNC: +#ifndef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC case Item_func::CASE_SIMPLE_FUNC: +#endif DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::NOT_FUNC: /* Why the following check is necessary? */ @@ -6488,7 +6490,70 @@ int spider_db_mbase_util::print_item_func( DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::CASE_SEARCHED_FUNC: case Item_func::CASE_SIMPLE_FUNC: +#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC + Item_func_case *item_func_case = (Item_func_case *) item_func; + if (str) + { + if (str->reserve(SPIDER_SQL_CASE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); + } + if (item_func_case->first_expr_num != -1) + { + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->first_expr_num], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + for (roop_count = 0; roop_count < item_func_case->ncases; + roop_count += 2) + { + if (str) + { + if (str->reserve(SPIDER_SQL_WHEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_THEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count + 1], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + if (item_func_case->else_expr_num != -1) + { + if (str) + { + if (str->reserve(SPIDER_SQL_ELSE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->else_expr_num], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +#else DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); +#endif case Item_func::JSON_EXTRACT_FUNC: func_name = (char*) item_func->func_name(); func_name_length = strlen(func_name); From 18b93d6eb074ab183e08ed0da0d9106017aa648d Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 20 Mar 2024 17:20:39 +1100 Subject: [PATCH 125/159] MDEV-28993 Spider: Push down CASE statement --- .../spider/bugfix/r/mdev_27172.result | 6 +- .../spider/feature/r/pushdown_case.result | 57 +++++++++++++++++++ .../spider/feature/t/pushdown_case.test | 50 ++++++++++++++++ storage/spider/spd_db_include.h | 3 - storage/spider/spd_db_mysql.cc | 57 +++++++++++-------- 5 files changed, 143 insertions(+), 30 deletions(-) create mode 100644 storage/spider/mysql-test/spider/feature/r/pushdown_case.result create mode 100644 storage/spider/mysql-test/spider/feature/t/pushdown_case.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result index d4c8c7e8ec2..1be2b98964a 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result @@ -66,9 +66,9 @@ id greeting connection child2_1; SELECT argument FROM mysql.general_log WHERE argument LIKE 'select %'; argument -select `id`,`greeting` from `auto_test_remote`.`tbl_a` where `greeting` = 'Aloha!' and ((`greeting` = 'Aloha!')) -select `id`,`greeting` from `auto_test_remote`.`tbl_b` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!')) -select `id`,`greeting` from `auto_test_remote`.`tbl_c` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!')) +select t0.`id` `id`,t0.`greeting` `greeting` from `auto_test_remote`.`tbl_a` t0 where ((t0.`greeting` = 'Aloha!') and ((case t0.`greeting` when 'Aloha!' then _latin1'one' else _latin1'more' end) = _latin1'one')) +select t0.`id` `id`,t0.`greeting` `greeting` from `auto_test_remote`.`tbl_b` t0 where ((t0.`greeting` = 'Aloha!') and ((case t0.`greeting` when 'Aloha!' then _latin1'one' else _latin1'more' end) = _latin1'one')) +select t0.`id` `id`,t0.`greeting` `greeting` from `auto_test_remote`.`tbl_c` t0 where ((t0.`greeting` = 'Aloha!') and ((case t0.`greeting` when 'Aloha!' then _latin1'one' else _latin1'more' end) = _latin1'one')) SELECT argument FROM mysql.general_log WHERE argument LIKE 'select %' connection child2_1; SET @@global.general_log = @general_log_backup; diff --git a/storage/spider/mysql-test/spider/feature/r/pushdown_case.result b/storage/spider/mysql-test/spider/feature/r/pushdown_case.result new file mode 100644 index 00000000000..613ce377865 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/pushdown_case.result @@ -0,0 +1,57 @@ +# +# MDEV-28993 Spider: Push down CASE statement +# +for master_1 +for child2 +for child3 +set spider_same_server_link= 1; +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 (c int); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +insert into t1 values (42), (3), (848), (100); +explain select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +case c when 3 then "three" when 42 then "answer" else "other" end +answer +three +other +other +explain select case c when 3 then "three" when 42 then "answer" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case c when 3 then "three" when 42 then "answer" end from t1; +case c when 3 then "three" when 42 then "answer" end +answer +three +NULL +NULL +explain select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +case when c = 3 then "three" when c = 42 then "answer" else "other" end +answer +three +other +other +explain select case when c = 3 then "three" when c = 42 then "answer" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case when c = 3 then "three" when c = 42 then "answer" end from t1; +case when c = 3 then "three" when c = 42 then "answer" end +answer +three +NULL +NULL +drop table t1, t2; +drop server srv; +for master_1 +for child2 +for child3 +# +# end of test pushdown_case +# diff --git a/storage/spider/mysql-test/spider/feature/t/pushdown_case.test b/storage/spider/mysql-test/spider/feature/t/pushdown_case.test new file mode 100644 index 00000000000..b86edceb615 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/pushdown_case.test @@ -0,0 +1,50 @@ +--echo # +--echo # MDEV-28993 Spider: Push down CASE statement +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +set spider_same_server_link= 1; +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 (c int); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +insert into t1 values (42), (3), (848), (100); + +# everything +let $query= +select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +eval explain $query; +eval $query; + +# no else +let $query= +select case c when 3 then "three" when 42 then "answer" end from t1; +eval explain $query; +eval $query; + +# no value +let $query= +select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +eval explain $query; +eval $query; + +# neither +let $query= +select case when c = 3 then "three" when c = 42 then "answer" end from t1; +eval explain $query; +eval $query; + +drop table t1, t2; +drop server srv; +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--echo # +--echo # end of test pushdown_case +--echo # diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 20bd82e48da..7c07b6998d4 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -25,7 +25,6 @@ #define PLUGIN_VAR_CAN_MEMALLOC /* -#define ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC #define HASH_UPDATE_WITH_HASH_VALUE */ @@ -106,7 +105,6 @@ typedef st_spider_result SPIDER_RESULT; #define SPIDER_SQL_HS_LTEQUAL_STR "<=" #define SPIDER_SQL_HS_LTEQUAL_LEN (sizeof(SPIDER_SQL_HS_LTEQUAL_STR) - 1) -#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC #define SPIDER_SQL_CASE_STR "case " #define SPIDER_SQL_CASE_LEN (sizeof(SPIDER_SQL_CASE_STR) - 1) #define SPIDER_SQL_WHEN_STR " when " @@ -117,7 +115,6 @@ typedef st_spider_result SPIDER_RESULT; #define SPIDER_SQL_ELSE_LEN (sizeof(SPIDER_SQL_ELSE_STR) - 1) #define SPIDER_SQL_END_STR " end" #define SPIDER_SQL_END_LEN (sizeof(SPIDER_SQL_END_STR) - 1) -#endif #define SPIDER_SQL_USING_STR " using " #define SPIDER_SQL_USING_LEN (sizeof(SPIDER_SQL_USING_STR) - 1) diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 2691f62a5c1..2624190f432 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -5547,10 +5547,6 @@ int spider_db_mbase_util::check_item_func( switch (func_type) { case Item_func::TRIG_COND_FUNC: - case Item_func::CASE_SEARCHED_FUNC: -#ifndef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC - case Item_func::CASE_SIMPLE_FUNC: -#endif DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::NOT_FUNC: /* Why the following check is necessary? */ @@ -5620,15 +5616,15 @@ int spider_db_mbase_util::print_item_func( Item *item, **item_list = item_func->arguments(); Field *field; spider_string tmp_str; - uint roop_count, item_count = item_func->argument_count(), start_item = 0; + uint i, item_count = item_func->argument_count(), start_item = 0; const char *func_name = SPIDER_SQL_NULL_CHAR_STR, *separator_str = SPIDER_SQL_NULL_CHAR_STR, *last_str = SPIDER_SQL_NULL_CHAR_STR; int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, separator_str_length = SPIDER_SQL_NULL_CHAR_LEN, last_str_length = SPIDER_SQL_NULL_CHAR_LEN; - int use_pushdown_udf; - bool merge_func = FALSE; + int use_pushdown_udf, case_when_start, case_when_count; + bool merge_func = FALSE, case_with_else; DBUG_ENTER("spider_db_mbase_util::print_item_func"); DBUG_ASSERT(!check_item_func(item_func, spider, alias, alias_length, use_fields, fields)); @@ -6490,23 +6486,39 @@ int spider_db_mbase_util::print_item_func( DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::CASE_SEARCHED_FUNC: case Item_func::CASE_SIMPLE_FUNC: -#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC - Item_func_case *item_func_case = (Item_func_case *) item_func; + /* + Arrangement of arguments: + - Item_func_case_searched: + when1 when2 ... whenk then1 then2 .. thenk [else] + - Item_func_case_simple: + value when1 when2 ... whenk then1 then2 .. thenk [else] + */ + if (item_func->functype() == Item_func::CASE_SEARCHED_FUNC) + { + case_when_start= 0; + case_when_count= item_count / 2; + case_with_else= item_count % 2; + } + else + { + case_when_start= 1; + case_when_count= (item_count - 1) / 2; + case_with_else= item_count % 2 == 0; + } if (str) { if (str->reserve(SPIDER_SQL_CASE_LEN)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); } - if (item_func_case->first_expr_num != -1) + if (case_when_start > 0) { if ((error_num = spider_db_print_item_type( - item_list[item_func_case->first_expr_num], NULL, spider, str, + item_list[0], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); } - for (roop_count = 0; roop_count < item_func_case->ncases; - roop_count += 2) + for (i = 0; i < (uint) case_when_count; i++) { if (str) { @@ -6515,7 +6527,7 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); } if ((error_num = spider_db_print_item_type( - item_list[roop_count], NULL, spider, str, + item_list[i + case_when_start], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); if (str) @@ -6525,11 +6537,11 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); } if ((error_num = spider_db_print_item_type( - item_list[roop_count + 1], NULL, spider, str, + item_list[i + case_when_start + case_when_count], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); } - if (item_func_case->else_expr_num != -1) + if (case_with_else) { if (str) { @@ -6538,7 +6550,7 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); } if ((error_num = spider_db_print_item_type( - item_list[item_func_case->else_expr_num], NULL, spider, str, + item_list[item_count - 1], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); } @@ -6551,9 +6563,6 @@ int spider_db_mbase_util::print_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif case Item_func::JSON_EXTRACT_FUNC: func_name = (char*) item_func->func_name(); func_name_length = strlen(func_name); @@ -6607,13 +6616,13 @@ int spider_db_mbase_util::print_item_func( Loop through the items of the current function expression to print its portion of the statement */ - for (roop_count = start_item; roop_count < item_count; roop_count++) + for (i = start_item; i < item_count; i++) { - item = item_list[roop_count]; + item = item_list[i]; if ((error_num = spider_db_print_item_type(item, field, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); - if (roop_count == 1) + if (i == 1) { /* Remaining operands need to be preceded by the separator */ func_name = separator_str; @@ -6627,7 +6636,7 @@ int spider_db_mbase_util::print_item_func( } /* Print the last operand value */ - item = item_list[roop_count]; + item = item_list[i]; if ((error_num = spider_db_print_item_type(item, field, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); From 051a1fa0e9fb61a3347d7ca8c41ddc8d95261729 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 27 Mar 2024 11:15:25 +1100 Subject: [PATCH 126/159] MDEV-33777 Spider: Correct checks for show index column numbers It was updated for 10.6+ in MDEV-7317. Because a lower version spider node may connect to a higher version data node, we need to change this for 10.4 and 10.5 as well. --- storage/spider/spd_db_mysql.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 2624190f432..aa51b369712 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -1186,9 +1186,9 @@ int spider_db_mbase_result::fetch_table_cardinality( if (mode == 1) { uint num_fields = this->num_fields(); - if (num_fields < 12 || num_fields > 13) + if (num_fields < 12 || num_fields > 14) { - DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 13")); + DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 14")); DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM); } From ea810b04cb9c3f9af812964fb68ef04c1b7058a0 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 6 Mar 2024 15:59:30 +1100 Subject: [PATCH 127/159] MDEV-30676 rpl.parallel_backup* tests sometimes fail Raise innodb_lock_wait_timeout from 1 to 5 --- mysql-test/suite/rpl/r/parallel_backup.result | 4 ++-- mysql-test/suite/rpl/r/parallel_backup_lsu_off.result | 4 ++-- .../suite/rpl/r/parallel_backup_slave_binlog_off.result | 4 ++-- mysql-test/suite/rpl/t/parallel_backup_xa.inc | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mysql-test/suite/rpl/r/parallel_backup.result b/mysql-test/suite/rpl/r/parallel_backup.result index 570069c731c..1962bc593df 100644 --- a/mysql-test/suite/rpl/r/parallel_backup.result +++ b/mysql-test/suite/rpl/r/parallel_backup.result @@ -124,7 +124,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; @@ -167,7 +167,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; diff --git a/mysql-test/suite/rpl/r/parallel_backup_lsu_off.result b/mysql-test/suite/rpl/r/parallel_backup_lsu_off.result index 4e648ae5a7a..cd8ffc9707a 100644 --- a/mysql-test/suite/rpl/r/parallel_backup_lsu_off.result +++ b/mysql-test/suite/rpl/r/parallel_backup_lsu_off.result @@ -127,7 +127,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; @@ -170,7 +170,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; diff --git a/mysql-test/suite/rpl/r/parallel_backup_slave_binlog_off.result b/mysql-test/suite/rpl/r/parallel_backup_slave_binlog_off.result index c4bceb41dfe..b179d0d3d20 100644 --- a/mysql-test/suite/rpl/r/parallel_backup_slave_binlog_off.result +++ b/mysql-test/suite/rpl/r/parallel_backup_slave_binlog_off.result @@ -127,7 +127,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; @@ -170,7 +170,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; diff --git a/mysql-test/suite/rpl/t/parallel_backup_xa.inc b/mysql-test/suite/rpl/t/parallel_backup_xa.inc index 83a6fb79345..5f287aa0ca6 100644 --- a/mysql-test/suite/rpl/t/parallel_backup_xa.inc +++ b/mysql-test/suite/rpl/t/parallel_backup_xa.inc @@ -41,7 +41,7 @@ if ($slave_ooo_error) { SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; - SET @@global.innodb_lock_wait_timeout =1; + SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; } --source include/start_slave.inc From a032f14b342c782b82dfcd9235805bee446e6fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 15 Apr 2024 09:04:11 +0300 Subject: [PATCH 128/159] MDEV-33559 matched_rec::block should be allocated from the buffer pool matched_rec::rec_buf[], matched_rec::bufp: Remove. matched_rec::block: Make this a pointer to something that is allocated by buf_block_alloc(). In this way, the only case where buf_block_t is constructed outside buf_pool is ALTER TABLE...IMPORT TABLESPACE. rtr_info::heap: Remove. This was only used for allocating matched_rec, which now is smaller. mtr_t::memmove(): Simplify some code to avoid GCC 9.4.0 -Wconversion in the 10.6 branch as a result of these changes. Reviewed by: Debarun Banerjee --- storage/innobase/gis/gis0sea.cc | 81 ++++++----------------------- storage/innobase/include/gis0type.h | 6 +-- storage/innobase/include/mtr0log.h | 25 ++++----- storage/innobase/row/row0sel.cc | 10 ++-- 4 files changed, 36 insertions(+), 86 deletions(-) diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc index 7432aab1a29..b9567ff03c3 100644 --- a/storage/innobase/gis/gis0sea.cc +++ b/storage/innobase/gis/gis0sea.cc @@ -498,7 +498,7 @@ rtr_pcur_move_to_next( mutex_exit(&rtr_info->matches->rtr_match_mutex); cursor->btr_cur.page_cur.rec = rec.r_rec; - cursor->btr_cur.page_cur.block = &rtr_info->matches->block; + cursor->btr_cur.page_cur.block = rtr_info->matches->block; DEBUG_SYNC_C("rtr_pcur_move_to_next_return"); return(true); @@ -939,22 +939,14 @@ rtr_create_rtr_info( rtr_info->index = index; if (init_matches) { - rtr_info->heap = mem_heap_create(sizeof(*(rtr_info->matches))); rtr_info->matches = static_cast( - mem_heap_zalloc( - rtr_info->heap, - sizeof(*rtr_info->matches))); + ut_zalloc_nokey(sizeof *rtr_info->matches)); rtr_info->matches->matched_recs = UT_NEW_NOKEY(rtr_rec_vector()); - rtr_info->matches->bufp = page_align(rtr_info->matches->rec_buf - + UNIV_PAGE_SIZE_MAX + 1); mutex_create(LATCH_ID_RTR_MATCH_MUTEX, &rtr_info->matches->rtr_match_mutex); - rw_lock_create(PFS_NOT_INSTRUMENTED, - &(rtr_info->matches->block.lock), - SYNC_LEVEL_VARYING); } rtr_info->path = UT_NEW_NOKEY(rtr_node_path_t()); @@ -1016,7 +1008,6 @@ rtr_init_rtr_info( rtr_info->mbr.ymin = 0.0; rtr_info->mbr.ymax = 0.0; rtr_info->thr = NULL; - rtr_info->heap = NULL; rtr_info->cursor = NULL; rtr_info->index = NULL; rtr_info->need_prdt_lock = false; @@ -1095,17 +1086,15 @@ rtr_clean_rtr_info( if (free_all) { if (rtr_info->matches) { - if (rtr_info->matches->matched_recs != NULL) { - UT_DELETE(rtr_info->matches->matched_recs); + if (rtr_info->matches->block) { + buf_block_free(rtr_info->matches->block); + rtr_info->matches->block = nullptr; } - rw_lock_free(&(rtr_info->matches->block.lock)); + UT_DELETE(rtr_info->matches->matched_recs); mutex_destroy(&rtr_info->matches->rtr_match_mutex); - } - - if (rtr_info->heap) { - mem_heap_free(rtr_info->heap); + ut_free(rtr_info->matches); } if (initialized) { @@ -1215,7 +1204,7 @@ rtr_check_discard_page( if (rtr_info->matches) { mutex_enter(&rtr_info->matches->rtr_match_mutex); - if ((&rtr_info->matches->block)->page.id().page_no() + if (rtr_info->matches->block->page.id().page_no() == pageno) { if (!rtr_info->matches->matched_recs->empty()) { rtr_info->matches->matched_recs->clear(); @@ -1425,7 +1414,7 @@ rtr_leaf_push_match_rec( ulint data_len; rtr_rec_t rtr_rec; - buf = match_rec->block.frame + match_rec->used; + buf = match_rec->block->frame + match_rec->used; ut_ad(page_rec_is_leaf(rec)); copy = rec_copy(buf, rec, offsets); @@ -1522,43 +1511,6 @@ rtr_non_leaf_insert_stack_push( new_seq, level, child_no, my_cursor, mbr_inc); } -/** Copy a buf_block_t, except "block->lock". -@param[in,out] matches copy to match->block -@param[in] block block to copy */ -static -void -rtr_copy_buf( - matched_rec_t* matches, - const buf_block_t* block) -{ - /* Copy all members of "block" to "matches->block" except "lock". - We skip "lock" because it is not used - from the dummy buf_block_t we create here and because memcpy()ing - it generates (valid) compiler warnings that the vtable pointer - will be copied. */ - new (&matches->block.page) buf_page_t(block->page); - matches->block.frame = block->frame; - matches->block.unzip_LRU = block->unzip_LRU; - - ut_d(matches->block.in_unzip_LRU_list = block->in_unzip_LRU_list); - ut_d(matches->block.in_withdraw_list = block->in_withdraw_list); - - /* Skip buf_block_t::lock */ - matches->block.modify_clock = block->modify_clock; -#ifdef BTR_CUR_HASH_ADAPT - matches->block.n_hash_helps = block->n_hash_helps; - matches->block.n_fields = block->n_fields; - matches->block.left_side = block->left_side; -#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG - matches->block.n_pointers = 0; -#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - matches->block.curr_n_fields = block->curr_n_fields; - matches->block.curr_left_side = block->curr_left_side; - matches->block.index = block->index; -#endif /* BTR_CUR_HASH_ADAPT */ - ut_d(matches->block.debug_latch = NULL); -} - /****************************************************************//** Generate a shadow copy of the page block header to save the matched records */ @@ -1572,17 +1524,18 @@ rtr_init_match( { ut_ad(matches->matched_recs->empty()); matches->locked = false; - rtr_copy_buf(matches, block); - matches->block.frame = matches->bufp; matches->valid = false; - /* We have to copy PAGE_W*_SUPREMUM_END bytes so that we can + if (!matches->block) { + matches->block = buf_block_alloc(); + } + + matches->block->page.init(block->page.id()); + /* We have to copy PAGE_*_SUPREMUM_END bytes so that we can use infimum/supremum of this page as normal btr page for search. */ - memcpy(matches->block.frame, page, page_is_comp(page) - ? PAGE_NEW_SUPREMUM_END - : PAGE_OLD_SUPREMUM_END); matches->used = page_is_comp(page) ? PAGE_NEW_SUPREMUM_END : PAGE_OLD_SUPREMUM_END; + memcpy(matches->block->frame, page, matches->used); #ifdef RTR_SEARCH_DIAGNOSTIC ulint pageno = page_get_page_no(page); fprintf(stderr, "INNODB_RTR: Searching leaf page %d\n", @@ -2002,7 +1955,7 @@ rtr_cur_search_with_match( #endif /* UNIV_DEBUG */ /* Pop the last match record and position on it */ match_rec->matched_recs->pop_back(); - page_cur_position(test_rec.r_rec, &match_rec->block, + page_cur_position(test_rec.r_rec, match_rec->block, cursor); } } else { diff --git a/storage/innobase/include/gis0type.h b/storage/innobase/include/gis0type.h index 55944bfcce3..f964ef9e4f4 100644 --- a/storage/innobase/include/gis0type.h +++ b/storage/innobase/include/gis0type.h @@ -66,10 +66,7 @@ typedef std::vector > rtr_rec_vector; /* Structure for matched records on the leaf page */ typedef struct matched_rec { - byte* bufp; /*!< aligned buffer point */ - byte rec_buf[UNIV_PAGE_SIZE_MAX * 2]; - /*!< buffer used to copy matching rec */ - buf_block_t block; /*!< the shadow buffer block */ + buf_block_t* block; /*!< the shadow buffer block */ ulint used; /*!< memory used */ rtr_rec_vector* matched_recs; /*!< vector holding the matching rec */ ib_mutex_t rtr_match_mutex;/*!< mutex protect the match_recs @@ -113,7 +110,6 @@ typedef struct rtr_info{ on each level and leaf level */ rtr_mbr_t mbr; /*!< the search MBR */ que_thr_t* thr; /*!< the search thread */ - mem_heap_t* heap; /*!< memory heap */ btr_cur_t* cursor; /*!< cursor used for search */ dict_index_t* index; /*!< index it is searching */ bool need_prdt_lock; diff --git a/storage/innobase/include/mtr0log.h b/storage/innobase/include/mtr0log.h index 285672be898..b8455f927bf 100644 --- a/storage/innobase/include/mtr0log.h +++ b/storage/innobase/include/mtr0log.h @@ -347,11 +347,12 @@ inline void mtr_t::memmove(const buf_block_t &b, ulint d, ulint s, ulint len) ut_ad(d >= 8); ut_ad(s >= 8); ut_ad(len); - ut_ad(s <= ulint(srv_page_size)); - ut_ad(s + len <= ulint(srv_page_size)); + ut_d(const ulint ps= srv_page_size); + ut_ad(s <= ps); + ut_ad(s + len <= ps); ut_ad(s != d); - ut_ad(d <= ulint(srv_page_size)); - ut_ad(d + len <= ulint(srv_page_size)); + ut_ad(d <= ps); + ut_ad(d + len <= ps); set_modified(b); if (m_log_mode != MTR_LOG_ALL) @@ -359,17 +360,17 @@ inline void mtr_t::memmove(const buf_block_t &b, ulint d, ulint s, ulint len) static_assert(MIN_4BYTE > UNIV_PAGE_SIZE_MAX, "consistency"); size_t lenlen= (len < MIN_2BYTE ? 1 : len < MIN_3BYTE ? 2 : 3); /* The source offset is encoded relative to the destination offset, - with the sign in the least significant bit. */ - if (s > d) - s= (s - d) << 1; - else - s= (d - s) << 1 | 1; + with the sign in the least significant bit. + Because the source offset 0 is not possible, our encoding + subtracts 1 from the offset. */ + const uint16_t S= s > d + ? uint16_t((s - d - 1) << 1) + : uint16_t((d - s - 1) << 1 | 1); /* The source offset 0 is not possible. */ - s-= 1 << 1; - size_t slen= (s < MIN_2BYTE ? 1 : s < MIN_3BYTE ? 2 : 3); + size_t slen= (S < MIN_2BYTE ? 1 : S < MIN_3BYTE ? 2 : 3); byte *l= log_write(b.page.id(), &b.page, lenlen + slen, true, d); l= mlog_encode_varint(l, len); - l= mlog_encode_varint(l, s); + l= mlog_encode_varint(l, S); m_log.close(l); m_last_offset= static_cast(d + len); } diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 98a9aa8e494..2a34685e7cc 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -1151,10 +1151,10 @@ sel_set_rtr_rec_lock( ut_ad(page_align(first_rec) == cur_block->frame); ut_ad(match->valid); - rw_lock_x_lock(&(match->block.lock)); + rw_lock_x_lock(&match->block->lock); retry: cur_block = btr_pcur_get_block(pcur); - ut_ad(rw_lock_own_flagged(&match->block.lock, + ut_ad(rw_lock_own_flagged(&match->block->lock, RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); ut_ad(page_is_leaf(buf_block_get_frame(cur_block))); @@ -1255,7 +1255,7 @@ re_scan: ULINT_UNDEFINED, &heap); err = lock_sec_rec_read_check_and_lock( - 0, &match->block, rtr_rec->r_rec, index, + 0, match->block, rtr_rec->r_rec, index, my_offsets, static_cast(mode), type, thr); @@ -1271,7 +1271,7 @@ re_scan: match->locked = true; func_end: - rw_lock_x_unlock(&(match->block.lock)); + rw_lock_x_unlock(&match->block->lock); if (heap != NULL) { mem_heap_free(heap); } @@ -3352,7 +3352,7 @@ Row_sel_get_clust_rec_for_mysql::operator()( if (dict_index_is_spatial(sec_index) && btr_cur->rtr_info->matches && (page_align(rec) - == btr_cur->rtr_info->matches->block.frame + == btr_cur->rtr_info->matches->block->frame || rec != btr_pcur_get_rec(prebuilt->pcur))) { #ifdef UNIV_DEBUG rtr_info_t* rtr_info = btr_cur->rtr_info; From 10272f3709be9dd0bd7871c70b252827c9c5f000 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Mon, 15 Apr 2024 10:23:22 +0200 Subject: [PATCH 129/159] Distinguish "manager stopped" from "manager not started" This way, if manager thread somehow starts and stops again quickly before main thread wakes up to check if it started correctly, we will not hang. Patch suggested by Monty as follow-up to 7f498fbab888bd24d76a0292f4d22cacfb2f95b2 Signed-off-by: Kristian Nielsen --- sql/sql_manager.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sql/sql_manager.cc b/sql/sql_manager.cc index 5cd66d8047a..a286497235e 100644 --- a/sql/sql_manager.cc +++ b/sql/sql_manager.cc @@ -26,6 +26,10 @@ #include "sql_manager.h" #include "sql_base.h" // flush_tables +/* + Values for manager_thread_in_use: 0 means "not started". 1 means "started + and active". 2 means "stopped". +*/ static bool volatile manager_thread_in_use = 0; static bool abort_manager = false; @@ -44,7 +48,7 @@ static struct handler_cb *cb_list; // protected by LOCK_manager bool mysql_manager_submit(void (*action)(void *), void *data) { bool result= FALSE; - DBUG_ASSERT(manager_thread_in_use); + DBUG_ASSERT(manager_thread_in_use == 1); struct handler_cb **cb; mysql_mutex_lock(&LOCK_manager); cb= &cb_list; @@ -119,7 +123,7 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) mysql_mutex_lock(&LOCK_manager); } DBUG_ASSERT(cb_list == NULL); - manager_thread_in_use = 0; + manager_thread_in_use = 2; mysql_mutex_unlock(&LOCK_manager); mysql_mutex_destroy(&LOCK_manager); mysql_cond_destroy(&COND_manager); @@ -148,6 +152,15 @@ void start_handle_manager() } mysql_mutex_lock(&LOCK_manager); + /* + Wait for manager thread to have started, otherwise in extreme cases the + server may start up and have initiated shutdown at the time the manager + thread even starts to run. + + Allow both values 1 and 2 for manager_thread_in_use, so that we will not + get stuck here if the manager thread somehow manages to start up and + abort again before we have time to test it here. + */ while (!manager_thread_in_use) mysql_cond_wait(&COND_manager, &LOCK_manager); mysql_mutex_unlock(&LOCK_manager); From ce104d41714f5d4d68dc5c56e1e9cbe9ef192ba4 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Mon, 15 Apr 2024 18:54:30 +0200 Subject: [PATCH 130/159] Fix windows build failure Signed-off-by: Kristian Nielsen --- sql/sql_manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_manager.cc b/sql/sql_manager.cc index a286497235e..b3d95c9ed31 100644 --- a/sql/sql_manager.cc +++ b/sql/sql_manager.cc @@ -30,7 +30,7 @@ Values for manager_thread_in_use: 0 means "not started". 1 means "started and active". 2 means "stopped". */ -static bool volatile manager_thread_in_use = 0; +static int volatile manager_thread_in_use = 0; static bool abort_manager = false; pthread_t manager_thread; From 50998a6c6f82d40c72370bb017669af704565ea0 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 15 Apr 2024 16:39:01 +0200 Subject: [PATCH 131/159] MDEV-33861 main.query_cache fails with embedded after enabling WITH_PROTECT_STATEMENT_MEMROOT Synopsis: If SELECT returned answer from Query Cache it is not really executed. The reason for firing of assertion DBUG_ASSERT((mem_root->flags & ROOT_FLAG_READ_ONLY) == 0); is that in case the query_cache is on and the same query run by different stored routines the following use case can take place: First, lets say that bodies of routines used by the test case are the same and contains the only query 'SELECT * FROM t1'; call p1() -- a result set is stored in query cache for further use. call p2() -- the same query is run against the table t1, that result in not running the actual query but using its cached result. On finishing execution of this routine, its memory root is marked for read only since every SP instruction that this routine contains has been executed. INSERT INT t1 VALUE (1); -- force following invalidation of query cache call p2() -- query the table t1 will result in assertion failure since its execution would require allocation on the memory root that has been already marked as read only memory root The root cause of firing the assertion is that memory root of the stored routine 'p2' was marked as read only although actual execution of the query contained inside hadn't been performed. To fix the issue, mark a SP instruction as not yet run in case its execution doesn't result in real query processing and a result set got from query cache instead. Note that, this issue relates server built in debug mode AND with the protect statement memory root feature turned on. It doesn't affect server built in release mode. --- mysql-test/main/query_cache.result | 27 +++++++++++++++++++++++ mysql-test/main/query_cache.test | 35 ++++++++++++++++++++++++++++++ sql/sp_head.cc | 3 +++ sql/sp_head.h | 18 ++++++++++----- 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/mysql-test/main/query_cache.result b/mysql-test/main/query_cache.result index fc7ca726c48..a98ab3cab76 100644 --- a/mysql-test/main/query_cache.result +++ b/mysql-test/main/query_cache.result @@ -2207,6 +2207,33 @@ Variable_name Value Qcache_queries_in_cache 0 DROP FUNCTION foo; drop table t1; +# +# MDEV-33861: main.query_cache fails with embedded after +# enabling WITH_PROTECT_STATEMENT_MEMROOT +# +create table t1 (s1 int); +create procedure f3 () begin +select * from t1; +end; +// +create procedure f4 () begin +select * from t1; +end; +// +Call f4(); +s1 +cAll f3(); +s1 +insert into t1 values (2); +caLl f3(); +s1 +2 +drop procedure f3; +drop procedure f4; +drop table t1; +# +# End of 10.4 tests +# restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size=@save_query_cache_size; diff --git a/mysql-test/main/query_cache.test b/mysql-test/main/query_cache.test index f4913c99d1c..5d523764dce 100644 --- a/mysql-test/main/query_cache.test +++ b/mysql-test/main/query_cache.test @@ -1803,6 +1803,41 @@ show status like "Qcache_queries_in_cache"; DROP FUNCTION foo; drop table t1; + +--echo # +--echo # MDEV-33861: main.query_cache fails with embedded after +--echo # enabling WITH_PROTECT_STATEMENT_MEMROOT +--echo # + +create table t1 (s1 int); +--delimiter // +create procedure f3 () begin +select * from t1; +end; +// +create procedure f4 () begin +select * from t1; +end; +// +--delimiter ; + +Call f4(); + +cAll f3(); + +insert into t1 values (2); + +caLl f3(); + +drop procedure f3; +drop procedure f4; +drop table t1; + + +--echo # +--echo # End of 10.4 tests +--echo # + --echo restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size=@save_query_cache_size; diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 312d779b05a..faf483c4a35 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -3702,6 +3702,9 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) thd->update_stats(); thd->lex->sql_command= save_sql_command; *nextp= m_ip+1; +#ifdef PROTECT_STATEMENT_MEMROOT + mark_as_qc_used(); +#endif } thd->set_query(query_backup); thd->query_name_consts= 0; diff --git a/sql/sp_head.h b/sql/sp_head.h index 693a5e78703..c9b6ae63c2b 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -1100,7 +1100,7 @@ public: sp_instr(uint ip, sp_pcontext *ctx) :Query_arena(0, STMT_INITIALIZED_FOR_SP), marked(0), m_ip(ip), m_ctx(ctx) #ifdef PROTECT_STATEMENT_MEMROOT - , m_has_been_run(false) + , m_has_been_run(NON_RUN) #endif {} @@ -1194,21 +1194,29 @@ public: #ifdef PROTECT_STATEMENT_MEMROOT bool has_been_run() const { - return m_has_been_run; + return m_has_been_run == RUN; + } + + void mark_as_qc_used() + { + m_has_been_run= QC; } void mark_as_run() { - m_has_been_run= true; + if (m_has_been_run == QC) + m_has_been_run= NON_RUN; // answer was from WC => not really executed + else + m_has_been_run= RUN; } void mark_as_not_run() { - m_has_been_run= false; + m_has_been_run= NON_RUN; } private: - bool m_has_been_run; + enum {NON_RUN, QC, RUN} m_has_been_run; #endif }; // class sp_instr : public Sql_alloc From a8a75ba2d0dd639b2b14337a6c4f495fcaaff7e4 Mon Sep 17 00:00:00 2001 From: Dave Gosselin Date: Fri, 12 Apr 2024 11:35:02 -0400 Subject: [PATCH 132/159] Factor TABLE_LIST creation from add_table_to_list Ideally our methods and functions should do one thing, do that well, and do only that. add_table_to_list does far more than adding a table to a list, so this commit factors the TABLE_LIST creation out to a new TABLE_LIST constructor. It then uses placement new() to create it in the correct memory area (result of thd->calloc). Benefits of this approach: 1. add_table_to_list now returns as early as possible on an error 2. fewer side-effects incurred on creating the TABLE_LIST object 3. TABLE_LIST won't be calloc'd if copy_to_db fails 4. local declarations moved closer to their respective first uses 5. improved code readability and logical flow Also factored a couple of other functions to keep the happy path more to the left, which makes them easier to follow at a glance. --- sql/sql_class.h | 30 +++++++------- sql/sql_lex.cc | 23 +++++------ sql/sql_parse.cc | 101 +++++++++++++++++------------------------------ sql/table.cc | 54 +++++++++++++++++++++++++ sql/table.h | 15 +++++++ 5 files changed, 133 insertions(+), 90 deletions(-) diff --git a/sql/sql_class.h b/sql/sql_class.h index 84665979d6e..a9b36f9dfb1 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4832,24 +4832,24 @@ public: */ bool copy_db_to(LEX_CSTRING *to) { - if (db.str == NULL) + if (db.str) { - /* - No default database is set. In this case if it's guaranteed that - no CTE can be used in the statement then we can throw an error right - now at the parser stage. Otherwise the decision about throwing such - a message must be postponed until a post-parser stage when we are able - to resolve all CTE names as we don't need this message to be thrown - for any CTE references. - */ - if (!lex->with_cte_resolution) - my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); - return TRUE; + to->str= strmake(db.str, db.length); + to->length= db.length; + return to->str == NULL; /* True on error */ } - to->str= strmake(db.str, db.length); - to->length= db.length; - return to->str == NULL; /* True on error */ + /* + No default database is set. In this case if it's guaranteed that + no CTE can be used in the statement then we can throw an error right + now at the parser stage. Otherwise the decision about throwing such + a message must be postponed until a post-parser stage when we are able + to resolve all CTE names as we don't need this message to be thrown + for any CTE references. + */ + if (!lex->with_cte_resolution) + my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); + return TRUE; } /* Get db name or "". Use for printing current db */ const char *get_db() diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 5d5d967b9ab..8b9cc2473bf 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -4290,17 +4290,18 @@ uint8 LEX::get_effective_with_check(TABLE_LIST *view) bool LEX::copy_db_to(LEX_CSTRING *to) { - if (sphead && sphead->m_name.str) - { - DBUG_ASSERT(sphead->m_db.str && sphead->m_db.length); - /* - It is safe to assign the string by-pointer, both sphead and - its statements reside in the same memory root. - */ - *to= sphead->m_db; - return FALSE; - } - return thd->copy_db_to(to); + if (!sphead || !sphead->m_name.str) + return thd->copy_db_to(to); + + DBUG_ASSERT(sphead->m_db.str); + DBUG_ASSERT(sphead->m_db.length); + + /* + It is safe to assign the string by-pointer, both sphead and + its statements reside in the same memory root. + */ + *to= sphead->m_db; + return FALSE; } /** diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index ad1abc4c4a0..60b4fed9fb3 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -8283,10 +8283,6 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, List *partition_names, LEX_STRING *option) { - TABLE_LIST *ptr; - TABLE_LIST *UNINIT_VAR(previous_table_ref); /* The table preceding the current one. */ - LEX_CSTRING alias_str; - LEX *lex= thd->lex; DBUG_ENTER("add_table_to_list"); DBUG_PRINT("enter", ("Table '%s' (%p) Select %p (%u)", (alias ? alias->str : table->table.str), @@ -8296,9 +8292,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (unlikely(!table)) DBUG_RETURN(0); // End of memory - alias_str= alias ? *alias : table->table; - DBUG_ASSERT(alias_str.str); - if (!MY_TEST(table_options & TL_OPTION_ALIAS) && + if (!(table_options & TL_OPTION_ALIAS) && unlikely(check_table_name(table->table.str, table->table.length, FALSE))) { my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str); @@ -8313,6 +8307,34 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, DBUG_RETURN(0); } + LEX_CSTRING db{0, 0}; + bool fqtn= false; + LEX *lex= thd->lex; + if (table->db.str) + { + fqtn= TRUE; + db= table->db; + } + else if (!lex->with_cte_resolution && lex->copy_db_to(&db)) + DBUG_RETURN(0); + else + fqtn= FALSE; + bool info_schema= is_infoschema_db(&db); + if (!table->sel && info_schema && + (table_options & TL_OPTION_UPDATING) && + /* Special cases which are processed by commands itself */ + lex->sql_command != SQLCOM_CHECK && + lex->sql_command != SQLCOM_CHECKSUM) + { + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->security_ctx->priv_user, + thd->security_ctx->priv_host, + INFORMATION_SCHEMA_NAME.str); + DBUG_RETURN(0); + } + + LEX_CSTRING alias_str= alias ? *alias : table->table; + DBUG_ASSERT(alias_str.str); if (!alias) /* Alias is case sensitive */ { if (unlikely(table->sel)) @@ -8325,65 +8347,15 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (unlikely(!(alias_str.str= (char*) thd->memdup(alias_str.str, alias_str.length+1)))) DBUG_RETURN(0); } - if (unlikely(!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))) - DBUG_RETURN(0); /* purecov: inspected */ - if (table->db.str) - { - ptr->is_fqtn= TRUE; - ptr->db= table->db; - } - else if (!lex->with_cte_resolution && lex->copy_db_to(&ptr->db)) - DBUG_RETURN(0); - else - ptr->is_fqtn= FALSE; - ptr->alias= alias_str; - ptr->is_alias= alias ? TRUE : FALSE; - if (lower_case_table_names) - { - if (table->table.length) - table->table.length= my_casedn_str(files_charset_info, - (char*) table->table.str); - if (ptr->db.length && ptr->db.str != any_db.str) - ptr->db.length= my_casedn_str(files_charset_info, (char*) ptr->db.str); - } + bool has_alias_ptr= alias != nullptr; + void *memregion= thd->calloc(sizeof(TABLE_LIST)); + TABLE_LIST *ptr= new (memregion) TABLE_LIST(thd, db, fqtn, alias_str, + has_alias_ptr, table, lock_type, + mdl_type, table_options, + info_schema, this, + index_hints_arg, option); - ptr->table_name= table->table; - ptr->lock_type= lock_type; - ptr->mdl_type= mdl_type; - ptr->table_options= table_options; - ptr->updating= MY_TEST(table_options & TL_OPTION_UPDATING); - /* TODO: remove TL_OPTION_FORCE_INDEX as it looks like it's not used */ - ptr->force_index= MY_TEST(table_options & TL_OPTION_FORCE_INDEX); - ptr->ignore_leaves= MY_TEST(table_options & TL_OPTION_IGNORE_LEAVES); - ptr->sequence= MY_TEST(table_options & TL_OPTION_SEQUENCE); - ptr->derived= table->sel; - if (!ptr->derived && is_infoschema_db(&ptr->db)) - { - if (ptr->updating && - /* Special cases which are processed by commands itself */ - lex->sql_command != SQLCOM_CHECK && - lex->sql_command != SQLCOM_CHECKSUM) - { - my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), - thd->security_ctx->priv_user, - thd->security_ctx->priv_host, - INFORMATION_SCHEMA_NAME.str); - DBUG_RETURN(0); - } - ST_SCHEMA_TABLE *schema_table; - schema_table= find_schema_table(thd, &ptr->table_name); - ptr->schema_table_name= ptr->table_name; - ptr->schema_table= schema_table; - } - ptr->select_lex= this; - /* - We can't cache internal temporary tables between prepares as the - table may be deleted before next exection. - */ - ptr->cacheable_table= !table->is_derived_table(); - ptr->index_hints= index_hints_arg; - ptr->option= option ? option->str : 0; /* check that used name is unique. Sequences are ignored */ if (lock_type != TL_IGNORE && !ptr->sequence) { @@ -8406,6 +8378,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, } } /* Store the table reference preceding the current one. */ + TABLE_LIST *UNINIT_VAR(previous_table_ref); /* The table preceding the current one. */ if (table_list.elements > 0 && likely(!ptr->sequence)) { /* diff --git a/sql/table.cc b/sql/table.cc index cff651f5d1c..9c2423e5a2d 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -49,6 +49,7 @@ #include "wsrep_schema.h" #endif #include "log_event.h" // MAX_TABLE_MAP_ID +#include "sql_class.h" /* For MySQL 5.7 virtual fields */ #define MYSQL57_GENERATED_FIELD 128 @@ -5850,6 +5851,59 @@ void TABLE::reset_item_list(List *item_list, uint skip) const } } +TABLE_LIST::TABLE_LIST(THD *thd, + LEX_CSTRING db_str, + bool fqtn, + LEX_CSTRING alias_str, + bool has_alias_ptr, + Table_ident *table_ident, + thr_lock_type lock_t, + enum_mdl_type mdl_t, + ulong table_opts, + bool info_schema, + st_select_lex *sel, + List *index_hints_ptr, + LEX_STRING *option_ptr) +{ + db= db_str; + is_fqtn= fqtn; + alias= alias_str; + is_alias= has_alias_ptr; + if (lower_case_table_names) + { + if (table_ident->table.length) + table_ident->table.length= my_casedn_str(files_charset_info, + (char*) table_ident->table.str); + if (db.length && db.str != any_db.str) + db.length= my_casedn_str(files_charset_info, (char*) db.str); + } + + table_name= table_ident->table; + lock_type= lock_t; + mdl_type= mdl_t; + table_options= table_opts; + updating= table_options & TL_OPTION_UPDATING; + /* TODO: remove TL_OPTION_FORCE_INDEX as it looks like it's not used */ + force_index= table_options & TL_OPTION_FORCE_INDEX; + ignore_leaves= table_options & TL_OPTION_IGNORE_LEAVES; + sequence= table_options & TL_OPTION_SEQUENCE; + derived= table_ident->sel; + + if (!table_ident->sel && info_schema) + { + schema_table= find_schema_table(thd, &table_name); + schema_table_name= table_name; + } + select_lex= sel; + /* + We can't cache internal temporary tables between prepares as the + table may be deleted before next exection. + */ + cacheable_table= !table_ident->is_derived_table(); + index_hints= index_hints_ptr; + option= option_ptr ? option_ptr->str : 0; +} + /* calculate md5 of query diff --git a/sql/table.h b/sql/table.h index 2ef61ee9f7e..a991462230e 100644 --- a/sql/table.h +++ b/sql/table.h @@ -2175,8 +2175,23 @@ struct TABLE_CHAIN void set_end_pos(TABLE_LIST **pos) { end_pos= pos; } }; +class Table_ident; struct TABLE_LIST { + TABLE_LIST(THD *thd, + LEX_CSTRING db_str, + bool fqtn, + LEX_CSTRING alias_str, + bool has_alias_ptr, + Table_ident *table_ident, + thr_lock_type lock_t, + enum_mdl_type mdl_t, + ulong table_opts, + bool info_schema, + st_select_lex *sel, + List *index_hints_ptr, + LEX_STRING *option_ptr); + TABLE_LIST() = default; /* Remove gcc warning */ enum prelocking_types From 41e7ceb0ac5a320e40817c31893dc336c2223713 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 15 Apr 2024 22:54:20 +0200 Subject: [PATCH 133/159] MDEV-33889 Read only server throws error when running a create temporary table as select statement create_partitioning_metadata() should only mark transaction r/w if it actually did anything (that is, the table is partitioned). otherwise it's a no-op, called even for temporary tables and it shouldn't do anything at all --- mysql-test/main/read_only_innodb.result | 25 +++++++++++++++++- mysql-test/main/read_only_innodb.test | 28 ++++++++++++++++++++- mysql-test/suite/galera/r/MDEV-27806.result | 2 +- sql/ha_partition.cc | 1 + sql/handler.cc | 2 -- 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/mysql-test/main/read_only_innodb.result b/mysql-test/main/read_only_innodb.result index abfc5322ed0..03046f7dad8 100644 --- a/mysql-test/main/read_only_innodb.result +++ b/mysql-test/main/read_only_innodb.result @@ -70,7 +70,7 @@ UNLOCK TABLES; DROP TABLE t1; DROP USER test@localhost; disconnect con1; -echo End of 5.1 tests +# End of 5.1 tests # # Bug#33669: Transactional temporary tables do not work under --read-only # @@ -244,3 +244,26 @@ connection default; SET GLOBAL READ_ONLY = OFF; DROP USER bug33669@localhost; DROP DATABASE db1; +# End of 5.5 tests +# +# MDEV-33889 Read only server throws error when running a create temporary table as select statement +# +create table t1(a int) engine=innodb; +create user u1@localhost; +grant insert, select, update, delete, create temporary tables on test.* to u1@localhost; +insert into t1 values (1); +set global read_only=1; +connect u1,localhost,u1; +set default_tmp_storage_engine=innodb; +create temporary table tt1 (a int); +create temporary table tt2 like t1; +create temporary table tt3 as select * from t1; +select * from tt3; +a +1 +disconnect u1; +connection default; +drop table t1; +drop user u1@localhost; +set global read_only=0; +# End of 10.5 tests diff --git a/mysql-test/main/read_only_innodb.test b/mysql-test/main/read_only_innodb.test index 4b00c32b185..7ad05ca55af 100644 --- a/mysql-test/main/read_only_innodb.test +++ b/mysql-test/main/read_only_innodb.test @@ -103,7 +103,7 @@ DROP USER test@localhost; disconnect con1; ---echo echo End of 5.1 tests +--echo # End of 5.1 tests --echo # --echo # Bug#33669: Transactional temporary tables do not work under --read-only @@ -250,3 +250,29 @@ SET GLOBAL READ_ONLY = OFF; DROP USER bug33669@localhost; DROP DATABASE db1; +--echo # End of 5.5 tests + +--echo # +--echo # MDEV-33889 Read only server throws error when running a create temporary table as select statement +--echo # +create table t1(a int) engine=innodb; +create user u1@localhost; +grant insert, select, update, delete, create temporary tables on test.* to u1@localhost; +insert into t1 values (1); +set global read_only=1; + +connect u1,localhost,u1; +set default_tmp_storage_engine=innodb; + +create temporary table tt1 (a int); +create temporary table tt2 like t1; +create temporary table tt3 as select * from t1; +select * from tt3; +disconnect u1; + +connection default; +drop table t1; +drop user u1@localhost; +set global read_only=0; + +--echo # End of 10.5 tests diff --git a/mysql-test/suite/galera/r/MDEV-27806.result b/mysql-test/suite/galera/r/MDEV-27806.result index 0f7ac79e4cd..6fe288f4e8e 100644 --- a/mysql-test/suite/galera/r/MDEV-27806.result +++ b/mysql-test/suite/galera/r/MDEV-27806.result @@ -37,7 +37,7 @@ mysqld-bin.000002 # Gtid # # BEGIN GTID #-#-# mysqld-bin.000002 # Query # # use `test`; CREATE TABLE `ts1` ( `f1` int(11) NOT NULL ) -mysqld-bin.000002 # Xid # # COMMIT /* XID */ +mysqld-bin.000002 # Query # # COMMIT connection node_2; include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index de003bad628..8606c28d046 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -690,6 +690,7 @@ int ha_partition::create_partitioning_metadata(const char *path, partition_element *part; DBUG_ENTER("ha_partition::create_partitioning_metadata"); + mark_trx_read_write(); /* We need to update total number of parts since we might write the handler file as part of a partition management command diff --git a/sql/handler.cc b/sql/handler.cc index 40dfbffa667..8b299ae1b9e 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5251,8 +5251,6 @@ handler::ha_create_partitioning_metadata(const char *name, DBUG_ASSERT(m_lock_type == F_UNLCK || (!old_name && strcmp(name, table_share->path.str))); - - mark_trx_read_write(); return create_partitioning_metadata(name, old_name, action_flag); } From 4aeba2590b86b41fde0bbb0f16148bf16afb41c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 12 Apr 2024 09:15:53 +0300 Subject: [PATCH 134/159] MDEV-33895 : Galera test failure on galera_sr.MDEV-25718 Test was waiting INSERT-clause to make rollback but wait_condition was too tight. State could be Freeing items or Rollback. Fixed wait_condition to expect one of them. --- mysql-test/suite/galera_sr/t/MDEV-25718.test | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/galera_sr/t/MDEV-25718.test b/mysql-test/suite/galera_sr/t/MDEV-25718.test index 9aebbdc7c5c..037cd300709 100644 --- a/mysql-test/suite/galera_sr/t/MDEV-25718.test +++ b/mysql-test/suite/galera_sr/t/MDEV-25718.test @@ -43,8 +43,9 @@ SET SESSION wsrep_sync_wait = 0; SET debug_sync = "now SIGNAL write_row_continue"; # Let's give the INSERT some time, to make sure it does rollback ---let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO = "INSERT INTO t1 VALUES (1)" AND STATE = "Freeing items"; ---source include/wait_condition.inc +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO = "INSERT INTO t1 VALUES (1)" AND (STATE = "Freeing items" OR STATE = 'Rollback'); +--let $wait_condition_on_error_output = SELECT INFO, STATE FROM INFORMATION_SCHEMA.PROCESSLIST +--source include/wait_condition_with_debug.inc # Resume the DDL in streaming_rollback SET SESSION debug_sync = "now SIGNAL wsrep_streaming_rollback_continue"; From 9164c2b8bbad6e0e8b0729ca0704f8dfcf826a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 17 Apr 2024 10:10:23 +0300 Subject: [PATCH 135/159] Tests: remove a duplicated check This fixes up the merge commit 9b18275623026ccfbffb348d56cb629b6255f574 --- mysql-test/main/kill_processlist-6619.test | 3 --- 1 file changed, 3 deletions(-) diff --git a/mysql-test/main/kill_processlist-6619.test b/mysql-test/main/kill_processlist-6619.test index 3000387f797..9d523b2264b 100644 --- a/mysql-test/main/kill_processlist-6619.test +++ b/mysql-test/main/kill_processlist-6619.test @@ -4,9 +4,6 @@ --source include/not_embedded.inc --source include/have_debug_sync.inc -let $wait_condition=select count(*) = 1 from information_schema.processlist; -source include/wait_condition.inc; - # Ensure no lingering connections from an earlier test run, which can very # rarely still be visible in SHOW PROCESSLIST here. --let $wait_condition= SELECT COUNT(*) = 1 from information_schema.processlist From 2ba79aba2ba44e1774d572f4127c2e69e060dc40 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 17 Apr 2024 09:58:34 +0200 Subject: [PATCH 136/159] Revert "MDEV-33840 tpool : switch off maintenance timer when not needed." This reverts commit 09bae92c16f9c37c931ab3f7932664f55bb9a842. --- tpool/tpool_generic.cc | 70 ++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc index 0a2f9f8f5e1..8dbd7c94d30 100644 --- a/tpool/tpool_generic.cc +++ b/tpool/tpool_generic.cc @@ -270,10 +270,10 @@ class thread_pool_generic : public thread_pool OFF, ON }; timer_state_t m_timer_state= timer_state_t::OFF; - void switch_timer(timer_state_t state,std::unique_lock &lk); + void switch_timer(timer_state_t state); /* Updates idle_since, and maybe switches the timer off */ - void check_idle(std::chrono::system_clock::time_point now, std::unique_lock &lk); + void check_idle(std::chrono::system_clock::time_point now); /** time point when timer last ran, used as a coarse clock. */ std::chrono::system_clock::time_point m_timestamp; @@ -306,9 +306,9 @@ class thread_pool_generic : public thread_pool { ((thread_pool_generic *)arg)->maintenance(); } - bool add_thread(std::unique_lock &lk); + bool add_thread(); bool wake(worker_wake_reason reason, task *t = nullptr); - void maybe_wake_or_create_thread(std::unique_lock &lk); + void maybe_wake_or_create_thread(); bool too_many_active_threads(); bool get_task(worker_data *thread_var, task **t); bool wait_for_tasks(std::unique_lock &lk, @@ -616,11 +616,11 @@ void thread_pool_generic::worker_main(worker_data *thread_var) */ static const auto invalid_timestamp= std::chrono::system_clock::time_point::max(); -constexpr auto max_idle_time= std::chrono::seconds(20); +constexpr auto max_idle_time= std::chrono::minutes(1); /* Time since maintenance timer had nothing to do */ static std::chrono::system_clock::time_point idle_since= invalid_timestamp; -void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now, std::unique_lock &lk) +void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now) { DBUG_ASSERT(m_task_queue.empty()); @@ -647,7 +647,7 @@ void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now, if (now - idle_since > max_idle_time) { idle_since= invalid_timestamp; - switch_timer(timer_state_t::OFF,lk); + switch_timer(timer_state_t::OFF); } } @@ -681,7 +681,7 @@ void thread_pool_generic::maintenance() if (m_task_queue.empty()) { - check_idle(m_timestamp, lk); + check_idle(m_timestamp); m_last_activity = m_tasks_dequeued + m_wakeups; return; } @@ -701,7 +701,7 @@ void thread_pool_generic::maintenance() } } - maybe_wake_or_create_thread(lk); + maybe_wake_or_create_thread(); size_t thread_cnt = (int)thread_count(); if (m_last_activity == m_tasks_dequeued + m_wakeups && @@ -709,7 +709,7 @@ void thread_pool_generic::maintenance() { // no progress made since last iteration. create new // thread - add_thread(lk); + add_thread(); } m_last_activity = m_tasks_dequeued + m_wakeups; m_last_thread_count= thread_cnt; @@ -736,14 +736,14 @@ static int throttling_interval_ms(size_t n_threads,size_t concurrency) } /* Create a new worker.*/ -bool thread_pool_generic::add_thread(std::unique_lock &lk) +bool thread_pool_generic::add_thread() { size_t n_threads = thread_count(); if (n_threads >= m_max_threads) return false; - if (n_threads >= m_min_threads && m_min_threads != m_max_threads) + if (n_threads >= m_min_threads) { auto now = std::chrono::system_clock::now(); if (now - m_last_thread_creation < @@ -753,7 +753,7 @@ bool thread_pool_generic::add_thread(std::unique_lock &lk) Throttle thread creation and wakeup deadlock detection timer, if is it off. */ - switch_timer(timer_state_t::ON, lk); + switch_timer(timer_state_t::ON); return false; } @@ -835,10 +835,12 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) : if (!m_concurrency) m_concurrency = 1; + // start the timer + m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); } -void thread_pool_generic::maybe_wake_or_create_thread(std::unique_lock &lk) +void thread_pool_generic::maybe_wake_or_create_thread() { if (m_task_queue.empty()) return; @@ -851,7 +853,7 @@ void thread_pool_generic::maybe_wake_or_create_thread(std::unique_lockadd_ref(); m_tasks_enqueued++; m_task_queue.push(task); - maybe_wake_or_create_thread(lk); + maybe_wake_or_create_thread(); } @@ -893,7 +895,7 @@ void thread_pool_generic::wait_begin() m_waiting_task_count++; /* Maintain concurrency */ - maybe_wake_or_create_thread(lk); + maybe_wake_or_create_thread(); } @@ -908,30 +910,26 @@ void thread_pool_generic::wait_end() } -void thread_pool_generic::switch_timer(timer_state_t state, std::unique_lock &lk) +void thread_pool_generic::switch_timer(timer_state_t state) { if (m_timer_state == state) return; - /* No maintenance timer for fixed threadpool size.*/ - DBUG_ASSERT(m_min_threads != m_max_threads); - DBUG_ASSERT(lk.owns_lock()); + /* + We can't use timer::set_time, because mysys timers are deadlock + prone. + Instead, to switch off we increase the timer period + and decrease period to switch on. + + This might introduce delays in thread creation when needed, + as period will only be changed when timer fires next time. + For this reason, we can't use very long periods for the "off" state. + */ m_timer_state= state; - if(state == timer_state_t::OFF) - { - m_maintenance_timer.set_period(0); - } - else - { - /* - It is necessary to unlock the thread_pool::m_mtx - to avoid the deadlock with thr_timer's LOCK_timer. - Otherwise, lock order would be violated. - */ - lk.unlock(); - m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); - lk.lock(); - } + long long period= (state == timer_state_t::OFF) ? + m_timer_interval.count()*10: m_timer_interval.count(); + + m_maintenance_timer.set_period((int)period); } From f6e9600f42f7e74e9a26d9a9a12c067b122889f8 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 17 Apr 2024 10:48:24 +0200 Subject: [PATCH 137/159] MDEV-33840 tpool- switch to longer maintainence timer interval, if pool is idle Previous solution, that would entirely switch timer off, turned out to be deadlock prone. This patch fixed previous attempt to switch between long/short interval periods in MDEV-24295. Now, initial state of the timer is fixed (it is ON). Also, avoid switching timer to longer periods if there is any activity in the pool. --- tpool/tpool_generic.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc index 8dbd7c94d30..6d2dc22926b 100644 --- a/tpool/tpool_generic.cc +++ b/tpool/tpool_generic.cc @@ -644,7 +644,7 @@ void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now) } /* Switch timer off after 1 minute of idle time */ - if (now - idle_since > max_idle_time) + if (now - idle_since > max_idle_time && m_active_threads.empty()) { idle_since= invalid_timestamp; switch_timer(timer_state_t::OFF); @@ -743,6 +743,12 @@ bool thread_pool_generic::add_thread() if (n_threads >= m_max_threads) return false; + /* + Deadlock danger exists, so monitor pool health + with maintenance timer. + */ + switch_timer(timer_state_t::ON); + if (n_threads >= m_min_threads) { auto now = std::chrono::system_clock::now(); @@ -753,8 +759,6 @@ bool thread_pool_generic::add_thread() Throttle thread creation and wakeup deadlock detection timer, if is it off. */ - switch_timer(timer_state_t::ON); - return false; } } @@ -837,6 +841,7 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) : // start the timer m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); + m_timer_state = timer_state_t::ON; } From 040069f4baead789bcb9dd55bb4932f6d1388d7c Mon Sep 17 00:00:00 2001 From: mariadb-DebarunBanerjee Date: Wed, 17 Apr 2024 15:16:50 +0530 Subject: [PATCH 138/159] MDEV-33431 Latching order violation reported fil_system.sys_space.latch and ibuf_pessimistic_insert_mutex Issue: ------ The actual order of acquisition of the IBUF pessimistic insert mutex (SYNC_IBUF_PESS_INSERT_MUTEX) and IBUF header page latch (SYNC_IBUF_HEADER) w.r.t space latch (SYNC_FSP) differs from the order defined in sync0types.h. It was not discovered earlier as the path to ibuf_remove_free_page was not covered by the mtr test. Ideal order and one defined in sync0types.h is as follows. SYNC_IBUF_HEADER -> SYNC_IBUF_PESS_INSERT_MUTEX -> SYNC_FSP In ibuf_remove_free_page, we acquire space latch earlier and we have the order as follows resulting in the assert with innodb_sync_debug=on. SYNC_FSP -> SYNC_IBUF_HEADER -> SYNC_IBUF_PESS_INSERT_MUTEX Fix: --- We do maintain this order in other places and there doesn't seem to be any real issue here. To reduce impact in GA versions, we avoid doing extensive changes in mutex ordering to match the current SYNC_IBUF_PESS_INSERT_MUTEX order. Instead we relax the ordering check for IBUF pessimistic insert mutex using SYNC_NO_ORDER_CHECK. --- .../suite/innodb/r/change_buffer_free.result | 32 +++++++++++ .../suite/innodb/t/change_buffer_free.opt | 2 + .../suite/innodb/t/change_buffer_free.test | 54 +++++++++++++++++++ storage/innobase/ibuf/ibuf0ibuf.cc | 5 ++ storage/innobase/sync/sync0debug.cc | 19 ++++++- 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/innodb/r/change_buffer_free.result create mode 100644 mysql-test/suite/innodb/t/change_buffer_free.opt create mode 100644 mysql-test/suite/innodb/t/change_buffer_free.test diff --git a/mysql-test/suite/innodb/r/change_buffer_free.result b/mysql-test/suite/innodb/r/change_buffer_free.result new file mode 100644 index 00000000000..a22ed16917e --- /dev/null +++ b/mysql-test/suite/innodb/r/change_buffer_free.result @@ -0,0 +1,32 @@ +SET @saved_change_buffering = @@GLOBAL.innodb_change_buffering; +SET @saved_file_per_table = @@GLOBAL.innodb_file_per_table; +SET @saved_change_buffering_debug = @@GLOBAL.innodb_change_buffering_debug; +SET GLOBAL innodb_change_buffering = NONE; +SET GLOBAL innodb_file_per_table = OFF; +CREATE TABLE t2(c1 INT AUTO_INCREMENT PRIMARY KEY,c2 CHAR(100))ENGINE=InnoDB; +CREATE INDEX i1 ON t2 (c2); +INSERT INTO t2(c2) VALUES('mariadb'); +INSERT INTO t2(c2) SELECT c2 FROM t2; +INSERT INTO t2(c2) SELECT c2 FROM t2; +INSERT INTO t2(c2) SELECT c2 FROM t2; +INSERT INTO t2(c2) SELECT c2 FROM t2; +INSERT INTO t2(c2) SELECT c2 FROM t2; +CREATE TABLE t1(c1 INT AUTO_INCREMENT PRIMARY KEY,c2 CHAR(100))ENGINE=InnoDB; +CREATE INDEX i1 ON t1 (c2); +INSERT INTO t1(c2) VALUES('mariadb'); +INSERT INTO t1(c2) SELECT c2 FROM t1; +INSERT INTO t1(c2) SELECT c2 FROM t1; +INSERT INTO t1(c2) SELECT c2 FROM t1; +INSERT INTO t1(c2) SELECT c2 FROM t1; +INSERT INTO t1(c2) SELECT c2 FROM t1; +SET GLOBAL innodb_change_buffering = all; +SET GLOBAL innodb_change_buffering_debug = 1; +SET DEBUG_DBUG='+d,ibuf_force_remove_free_page'; +INSERT INTO t2(c2) SELECT c2 FROM t2 IGNORE INDEX (i1) LIMIT 4; +INSERT INTO t1(c2) SELECT c2 FROM t1 IGNORE INDEX (i1) LIMIT 4; +SET DEBUG_DBUG='-d,ibuf_force_remove_free_page'; +SET GLOBAL innodb_change_buffering_debug = @saved_change_buffering_debug; +SET GLOBAL innodb_change_buffering = @saved_change_buffering; +DROP TABLE t2; +DROP TABLE t1; +SET GLOBAL innodb_file_per_table = @saved_file_per_table; diff --git a/mysql-test/suite/innodb/t/change_buffer_free.opt b/mysql-test/suite/innodb/t/change_buffer_free.opt new file mode 100644 index 00000000000..296def4f05a --- /dev/null +++ b/mysql-test/suite/innodb/t/change_buffer_free.opt @@ -0,0 +1,2 @@ +--innodb-page-size=4k +--innodb_sync_debug=on diff --git a/mysql-test/suite/innodb/t/change_buffer_free.test b/mysql-test/suite/innodb/t/change_buffer_free.test new file mode 100644 index 00000000000..0db9e3186ae --- /dev/null +++ b/mysql-test/suite/innodb/t/change_buffer_free.test @@ -0,0 +1,54 @@ +# +# MDEV 33431: Latching order violation reported fil_system.sys_space.latch and ibuf_pessimistic_insert_mutex +# +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc + +SET @saved_change_buffering = @@GLOBAL.innodb_change_buffering; +SET @saved_file_per_table = @@GLOBAL.innodb_file_per_table; +SET @saved_change_buffering_debug = @@GLOBAL.innodb_change_buffering_debug; + +SET GLOBAL innodb_change_buffering = NONE; +SET GLOBAL innodb_file_per_table = OFF; + +let $loop=2; +while ($loop) +{ + eval CREATE TABLE t$loop(c1 INT AUTO_INCREMENT PRIMARY KEY,c2 CHAR(100))ENGINE=InnoDB; + eval CREATE INDEX i1 ON t$loop (c2); + + eval INSERT INTO t$loop(c2) VALUES('mariadb'); + eval INSERT INTO t$loop(c2) SELECT c2 FROM t$loop; + eval INSERT INTO t$loop(c2) SELECT c2 FROM t$loop; + eval INSERT INTO t$loop(c2) SELECT c2 FROM t$loop; + eval INSERT INTO t$loop(c2) SELECT c2 FROM t$loop; + eval INSERT INTO t$loop(c2) SELECT c2 FROM t$loop; + + dec $loop; +} + +SET GLOBAL innodb_change_buffering = all; +SET GLOBAL innodb_change_buffering_debug = 1; + +SET DEBUG_DBUG='+d,ibuf_force_remove_free_page'; +let $loop=2; + +while ($loop) +{ + eval INSERT INTO t$loop(c2) SELECT c2 FROM t$loop IGNORE INDEX (i1) LIMIT 4; + dec $loop; +} +SET DEBUG_DBUG='-d,ibuf_force_remove_free_page'; + +SET GLOBAL innodb_change_buffering_debug = @saved_change_buffering_debug; +SET GLOBAL innodb_change_buffering = @saved_change_buffering; + +let $loop=2; +while ($loop) +{ + eval DROP TABLE t$loop; + dec $loop; +} + +SET GLOBAL innodb_file_per_table = @saved_file_per_table; diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index cdb4967b663..8888e538e05 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -2011,6 +2011,11 @@ ibuf_free_excess_pages(void) /* Free at most a few pages at a time, so that we do not delay the requested service too much */ + DBUG_EXECUTE_IF("ibuf_force_remove_free_page", + ibuf_remove_free_page(); + return; + ); + for (ulint i = 0; i < 4; i++) { ibool too_much_free; diff --git a/storage/innobase/sync/sync0debug.cc b/storage/innobase/sync/sync0debug.cc index dd40e95dd50..78f6028b60d 100644 --- a/storage/innobase/sync/sync0debug.cc +++ b/storage/innobase/sync/sync0debug.cc @@ -1208,7 +1208,24 @@ sync_latch_meta_init() LATCH_ADD_MUTEX(IBUF, SYNC_IBUF_MUTEX, ibuf_mutex_key); - LATCH_ADD_MUTEX(IBUF_PESSIMISTIC_INSERT, SYNC_IBUF_PESS_INSERT_MUTEX, + /* The actual order of acquisition of the IBUF pessimistic insert mutex + (SYNC_IBUF_PESS_INSERT_MUTEX) and IBUF header page latch + (SYNC_IBUF_HEADER) w.r.t space latch (SYNC_FSP) differs from the order + defined in sync0types.h. It was not discovered earlier as the path to + ibuf_remove_free_page was not covered by the mtr test. Ideal order and + one defined in sync0types.h is as follows. + SYNC_IBUF_HEADER -> SYNC_IBUF_PESS_INSERT_MUTEX -> SYNC_FSP + + In ibuf_remove_free_page, we acquire space latch earlier and we have + the order as follows resulting in the assert with innodb_sync_debug=on. + SYNC_FSP -> SYNC_IBUF_HEADER -> SYNC_IBUF_PESS_INSERT_MUTEX + + We do maintain this order in other places and there doesn't seem to be + any real issue here. To reduce impact in GA versions, we avoid doing + extensive changes in mutex ordering to match the current + SYNC_IBUF_PESS_INSERT_MUTEX order. Instead we relax the ordering check + for IBUF pessimistic insert mutex using SYNC_NO_ORDER_CHECK. */ + LATCH_ADD_MUTEX(IBUF_PESSIMISTIC_INSERT, SYNC_NO_ORDER_CHECK, ibuf_pessimistic_insert_mutex_key); LATCH_ADD_MUTEX(PURGE_SYS_PQ, SYNC_PURGE_QUEUE, From 46e9e92e22cd9b38b4130cfe0ce9790e04d81380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 17 Apr 2024 13:25:12 +0300 Subject: [PATCH 139/159] MDEV-33855 MSAN use-of-uninitialized-value in rtr_pcur_getnext_from_path() rtr_pcur_getnext_from_path(): Remove a bogus assertion that may cause a data races with buf_LRU_block_free_non_file_page(). If my_latch_mode == BTR_MODIFY_LEAF, we would have released all page latches and buffer-fixes by invoking mtr->rollback_to_savepoint(1). After this point, the btr_cur->page_cur.block is no longer valid and must not be accessed. Before 03ca6495df31313c96e38834b9a235245e2ae2a8 this assertion had been disabled, because the preprocessor symbol UNIV_RTR_DEBUG had never been enabled (except when explicitly specified in CMAKE_CXX_FLAGS). Reviewed by: Debarun Banerjee --- storage/innobase/gis/gis0sea.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc index fb4fcf7bc8d..9aedd4af69c 100644 --- a/storage/innobase/gis/gis0sea.cc +++ b/storage/innobase/gis/gis0sea.cc @@ -289,10 +289,6 @@ rtr_pcur_getnext_from_path( mtr->rollback_to_savepoint(1); } - ut_ad((my_latch_mode | 4) == BTR_CONT_MODIFY_TREE - || !page_is_leaf(btr_cur_get_page(btr_cur)) - || !btr_cur->page_cur.block->page.lock.have_any()); - const auto block_savepoint = mtr->get_savepoint(); block = buf_page_get_gen( page_id_t(index->table->space_id, From e459ce8336ba37ea12a405f29e5fae866fd28701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 17 Apr 2024 16:47:41 +0300 Subject: [PATCH 140/159] MDEV-33779 InnoDB row operations could be faster We have quite a few assertions ut_a(m_prebuilt->trx == thd_to_trx(ha_thd())); in low-level functions. These had better be debug assertions for performance reasons. It should suffice to check that condition in the less frequently invoked ha_innobase::change_active_index(). convert_search_mode_to_innobase(): Return whether the mode is unsupported, and optionally update ha_innobase::m_last_match_mode. ha_innobase::index_read(): Only branch on find_flag once, and simplify the error handling after invoking row_search_mvcc(). ha_innobase::rnd_pos(): Remove an assertion that is duplicating one in ha_innobase::index_read(), which we are calling unconditionally. ha_innobase::records_in_range(): Check only once whether min_key, max_key are null pointers. row_sel_convert_mysql_key_to_innobase(): Declare all parameters except the conversion buffer pointer (buf) to be nonnull. Reviewed by: Debarun Banerjee --- storage/innobase/handler/ha_innodb.cc | 280 ++++++++++++-------------- storage/innobase/include/row0sel.h | 4 +- 2 files changed, 128 insertions(+), 156 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index d6210c5bfaa..418f39885f7 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -8883,47 +8883,63 @@ ha_innobase::index_end(void) DBUG_RETURN(0); } -/*********************************************************************//** -Converts a search mode flag understood by MySQL to a flag understood -by InnoDB. */ -page_cur_mode_t -convert_search_mode_to_innobase( -/*============================*/ - ha_rkey_function find_flag) +/** Convert a MariaDB search mode to an InnoDB search mode. +@tparam last_match whether last_match_mode is to be set +@param find_flag MariaDB search mode +@param mode InnoDB search mode +@param last_match_mode pointer to ha_innobase::m_last_match_mode +@return whether the search mode is unsupported */ +template +static bool convert_search_mode_to_innobase(ha_rkey_function find_flag, + page_cur_mode_t &mode, + uint *last_match_mode= nullptr) { - switch (find_flag) { - case HA_READ_KEY_EXACT: - /* this does not require the index to be UNIQUE */ - case HA_READ_KEY_OR_NEXT: - return(PAGE_CUR_GE); - case HA_READ_AFTER_KEY: - return(PAGE_CUR_G); - case HA_READ_BEFORE_KEY: - return(PAGE_CUR_L); - case HA_READ_KEY_OR_PREV: - case HA_READ_PREFIX_LAST: - case HA_READ_PREFIX_LAST_OR_PREV: - return(PAGE_CUR_LE); - case HA_READ_MBR_CONTAIN: - return(PAGE_CUR_CONTAIN); - case HA_READ_MBR_INTERSECT: - return(PAGE_CUR_INTERSECT); - case HA_READ_MBR_WITHIN: - return(PAGE_CUR_WITHIN); - case HA_READ_MBR_DISJOINT: - return(PAGE_CUR_DISJOINT); - case HA_READ_MBR_EQUAL: - return(PAGE_CUR_MBR_EQUAL); - case HA_READ_PREFIX: - return(PAGE_CUR_UNSUPP); - /* do not use "default:" in order to produce a gcc warning: - enumeration value '...' not handled in switch - (if -Wswitch or -Wall is used) */ - } + mode= PAGE_CUR_LE; + if (last_match) + *last_match_mode= 0; - my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "this functionality"); + switch (find_flag) { + case HA_READ_KEY_EXACT: + /* this does not require the index to be UNIQUE */ + if (last_match) + *last_match_mode= ROW_SEL_EXACT; + /* fall through */ + case HA_READ_KEY_OR_NEXT: + mode= PAGE_CUR_GE; + return false; + case HA_READ_AFTER_KEY: + mode= PAGE_CUR_G; + return false; + case HA_READ_BEFORE_KEY: + mode= PAGE_CUR_L; + return false; + case HA_READ_PREFIX_LAST: + if (last_match) + *last_match_mode= ROW_SEL_EXACT_PREFIX; + /* fall through */ + case HA_READ_KEY_OR_PREV: + case HA_READ_PREFIX_LAST_OR_PREV: + return false; + case HA_READ_MBR_CONTAIN: + mode= PAGE_CUR_CONTAIN; + return false; + case HA_READ_MBR_INTERSECT: + mode= PAGE_CUR_INTERSECT; + return false; + case HA_READ_MBR_WITHIN: + mode= PAGE_CUR_WITHIN; + return false; + case HA_READ_MBR_DISJOINT: + mode= PAGE_CUR_DISJOINT; + return false; + case HA_READ_MBR_EQUAL: + mode= PAGE_CUR_MBR_EQUAL; + return false; + case HA_READ_PREFIX: + break; + } - return(PAGE_CUR_UNSUPP); + return true; } /* @@ -9001,8 +9017,7 @@ ha_innobase::index_read( mariadb_set_stats set_stats_temporary(handler_stats); DEBUG_SYNC_C("ha_innobase_index_read_begin"); - ut_a(m_prebuilt->trx == thd_to_trx(m_user_thd)); - ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT); + ut_ad(m_prebuilt->trx == thd_to_trx(m_user_thd)); dict_index_t* index = m_prebuilt->index; @@ -9038,7 +9053,8 @@ ha_innobase::index_read( build_template(false); } - if (key_ptr != NULL) { + if (key_len) { + ut_ad(key_ptr); /* Convert the search key value to InnoDB format into m_prebuilt->search_tuple */ @@ -9048,42 +9064,31 @@ ha_innobase::index_read( m_prebuilt->srch_key_val_len, index, (byte*) key_ptr, - (ulint) key_len); + key_len); DBUG_ASSERT(m_prebuilt->search_tuple->n_fields > 0); } else { + ut_ad(find_flag != HA_READ_KEY_EXACT); /* We position the cursor to the last or the first entry in the index */ dtuple_set_n_fields(m_prebuilt->search_tuple, 0); } - page_cur_mode_t mode = convert_search_mode_to_innobase(find_flag); + page_cur_mode_t mode; - ulint match_mode = 0; - - if (find_flag == HA_READ_KEY_EXACT) { - - match_mode = ROW_SEL_EXACT; - - } else if (find_flag == HA_READ_PREFIX_LAST) { - - match_mode = ROW_SEL_EXACT_PREFIX; + if (convert_search_mode_to_innobase(find_flag, mode, + &m_last_match_mode)) { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_UNSUPPORTED); } - m_last_match_mode = (uint) match_mode; - - dberr_t ret = mode == PAGE_CUR_UNSUPP ? DB_UNSUPPORTED - : row_search_mvcc(buf, mode, m_prebuilt, match_mode, 0); + dberr_t ret = + row_search_mvcc(buf, mode, m_prebuilt, m_last_match_mode, 0); DBUG_EXECUTE_IF("ib_select_query_failure", ret = DB_ERROR;); - int error; - - switch (ret) { - case DB_SUCCESS: - error = 0; - table->status = 0; + if (UNIV_LIKELY(ret == DB_SUCCESS)) { if (m_prebuilt->table->is_system_db) { srv_stats.n_system_rows_read.add( thd_get_thread_id(m_prebuilt->trx->mysql_thd), 1); @@ -9091,48 +9096,33 @@ ha_innobase::index_read( srv_stats.n_rows_read.add( thd_get_thread_id(m_prebuilt->trx->mysql_thd), 1); } - break; + table->status = 0; + DBUG_RETURN(0); + } - case DB_RECORD_NOT_FOUND: - error = HA_ERR_KEY_NOT_FOUND; - table->status = STATUS_NOT_FOUND; - break; - - case DB_END_OF_INDEX: - error = HA_ERR_KEY_NOT_FOUND; - table->status = STATUS_NOT_FOUND; - break; + table->status = STATUS_NOT_FOUND; + switch (ret) { case DB_TABLESPACE_DELETED: ib_senderrf( m_prebuilt->trx->mysql_thd, IB_LOG_LEVEL_ERROR, ER_TABLESPACE_DISCARDED, table->s->table_name.str); - - table->status = STATUS_NOT_FOUND; - error = HA_ERR_TABLESPACE_MISSING; - break; - + DBUG_RETURN(HA_ERR_TABLESPACE_MISSING); + case DB_RECORD_NOT_FOUND: + case DB_END_OF_INDEX: + DBUG_RETURN(HA_ERR_KEY_NOT_FOUND); case DB_TABLESPACE_NOT_FOUND: - ib_senderrf( m_prebuilt->trx->mysql_thd, IB_LOG_LEVEL_ERROR, ER_TABLESPACE_MISSING, table->s->table_name.str); - - table->status = STATUS_NOT_FOUND; - error = HA_ERR_TABLESPACE_MISSING; - break; - + DBUG_RETURN(HA_ERR_TABLESPACE_MISSING); default: - error = convert_error_code_to_mysql( - ret, m_prebuilt->table->flags, m_user_thd); - - table->status = STATUS_NOT_FOUND; - break; + DBUG_RETURN(convert_error_code_to_mysql( + ret, m_prebuilt->table->flags, + m_user_thd)); } - - DBUG_RETURN(error); } /*******************************************************************//** @@ -9566,8 +9556,6 @@ ha_innobase::rnd_pos( DBUG_ENTER("rnd_pos"); DBUG_DUMP("key", pos, ref_length); - ut_a(m_prebuilt->trx == thd_to_trx(ha_thd())); - /* Note that we assume the length of the row reference is fixed for the table, and it is == ref_length */ @@ -14301,14 +14289,14 @@ ha_innobase::records_in_range( dict_index_t* index; dtuple_t* range_start; dtuple_t* range_end; - ha_rows n_rows; + ha_rows n_rows = HA_POS_ERROR; page_cur_mode_t mode1; page_cur_mode_t mode2; mem_heap_t* heap; DBUG_ENTER("records_in_range"); - ut_a(m_prebuilt->trx == thd_to_trx(ha_thd())); + ut_ad(m_prebuilt->trx == thd_to_trx(ha_thd())); m_prebuilt->trx->op_info = "estimating records in index range"; @@ -14321,12 +14309,7 @@ ha_innobase::records_in_range( /* There exists possibility of not being able to find requested index due to inconsistency between MySQL and InoDB dictionary info. Necessary message should have been printed in innobase_get_index() */ - if (!m_prebuilt->table->space) { - n_rows = HA_POS_ERROR; - goto func_exit; - } - if (!index) { - n_rows = HA_POS_ERROR; + if (!index || !m_prebuilt->table->space) { goto func_exit; } if (index->is_corrupted()) { @@ -14342,61 +14325,50 @@ ha_innobase::records_in_range( + sizeof(dtuple_t))); range_start = dtuple_create(heap, key->ext_key_parts); - dict_index_copy_types(range_start, index, key->ext_key_parts); range_end = dtuple_create(heap, key->ext_key_parts); - dict_index_copy_types(range_end, index, key->ext_key_parts); - row_sel_convert_mysql_key_to_innobase( - range_start, - m_prebuilt->srch_key_val1, - m_prebuilt->srch_key_val_len, - index, - (byte*) (min_key ? min_key->key : (const uchar*) 0), - (ulint) (min_key ? min_key->length : 0)); - - DBUG_ASSERT(min_key - ? range_start->n_fields > 0 - : range_start->n_fields == 0); - - row_sel_convert_mysql_key_to_innobase( - range_end, - m_prebuilt->srch_key_val2, - m_prebuilt->srch_key_val_len, - index, - (byte*) (max_key ? max_key->key : (const uchar*) 0), - (ulint) (max_key ? max_key->length : 0)); - - DBUG_ASSERT(max_key - ? range_end->n_fields > 0 - : range_end->n_fields == 0); - - mode1 = convert_search_mode_to_innobase( - min_key ? min_key->flag : HA_READ_KEY_EXACT); - - mode2 = convert_search_mode_to_innobase( - max_key ? max_key->flag : HA_READ_KEY_EXACT); - - if (mode1 != PAGE_CUR_UNSUPP && mode2 != PAGE_CUR_UNSUPP) { - - if (dict_index_is_spatial(index)) { - /*Only min_key used in spatial index. */ - n_rows = rtr_estimate_n_rows_in_range( - index, range_start, mode1); - } else { - btr_pos_t tuple1(range_start, mode1, pages->first_page); - btr_pos_t tuple2(range_end, mode2, pages->last_page); - n_rows = btr_estimate_n_rows_in_range( - index, &tuple1, &tuple2); - pages->first_page= tuple1.page_id.raw(); - pages->last_page= tuple2.page_id.raw(); - } + if (!min_key) { + mode1 = PAGE_CUR_GE; + dtuple_set_n_fields(range_start, 0); + } else if (convert_search_mode_to_innobase(min_key->flag, mode1)) { + goto unsupported; } else { - - n_rows = HA_POS_ERROR; + dict_index_copy_types(range_start, index, key->ext_key_parts); + row_sel_convert_mysql_key_to_innobase( + range_start, + m_prebuilt->srch_key_val1, + m_prebuilt->srch_key_val_len, + index, min_key->key, min_key->length); + DBUG_ASSERT(range_start->n_fields > 0); } - mem_heap_free(heap); + if (!max_key) { + mode2 = PAGE_CUR_GE; + dtuple_set_n_fields(range_end, 0); + } else if (convert_search_mode_to_innobase(max_key->flag, mode2)) { + goto unsupported; + } else { + dict_index_copy_types(range_end, index, key->ext_key_parts); + row_sel_convert_mysql_key_to_innobase( + range_end, + m_prebuilt->srch_key_val2, + m_prebuilt->srch_key_val_len, + index, max_key->key, max_key->length); + DBUG_ASSERT(range_end->n_fields > 0); + } + + if (dict_index_is_spatial(index)) { + /*Only min_key used in spatial index. */ + n_rows = rtr_estimate_n_rows_in_range( + index, range_start, mode1); + } else { + btr_pos_t tuple1(range_start, mode1, pages->first_page); + btr_pos_t tuple2(range_end, mode2, pages->last_page); + n_rows = btr_estimate_n_rows_in_range(index, &tuple1, &tuple2); + pages->first_page= tuple1.page_id.raw(); + pages->last_page= tuple2.page_id.raw(); + } DBUG_EXECUTE_IF( "print_btr_estimate_n_rows_in_range_return_value", @@ -14407,11 +14379,7 @@ ha_innobase::records_in_range( (longlong) n_rows); ); -func_exit: - - m_prebuilt->trx->op_info = (char*)""; - - /* The MySQL optimizer seems to believe an estimate of 0 rows is + /* The MariaDB optimizer seems to believe an estimate of 0 rows is always accurate and may return the result 'Empty set' based on that. The accuracy is not guaranteed, and even if it were, for a locking read we should anyway perform the search to set the next-key lock. @@ -14421,6 +14389,10 @@ func_exit: n_rows = 1; } +unsupported: + mem_heap_free(heap); +func_exit: + m_prebuilt->trx->op_info = ""; DBUG_RETURN((ha_rows) n_rows); } diff --git a/storage/innobase/include/row0sel.h b/storage/innobase/include/row0sel.h index 8134c60fe72..54e4a1d283f 100644 --- a/storage/innobase/include/row0sel.h +++ b/storage/innobase/include/row0sel.h @@ -115,8 +115,8 @@ row_sel_convert_mysql_key_to_innobase( ulint buf_len, /*!< in: buffer length */ dict_index_t* index, /*!< in: index of the key value */ const byte* key_ptr, /*!< in: MySQL key value */ - ulint key_len); /*!< in: MySQL key value length */ - + ulint key_len) /*!< in: MySQL key value length */ + MY_ATTRIBUTE((nonnull(1,4,5))); /** Search for rows in the database using cursor. Function is mainly used for tables that are shared across connections and From e87a175b3adcd9e7d25e9f874c2fc640951911e0 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 10 Apr 2024 12:37:06 +0200 Subject: [PATCH 141/159] Fix LTO (aka interprocedural optimization) build with MSVC Also, disable MSVC LTO for static client libraries - they won't be usable for end-users. --- cmake/libutils.cmake | 6 ++++++ cmake/mariadb_connector_c.cmake | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/cmake/libutils.cmake b/cmake/libutils.cmake index 4c8401971f6..c1293980717 100644 --- a/cmake/libutils.cmake +++ b/cmake/libutils.cmake @@ -370,5 +370,11 @@ ENDFUNCTION() FUNCTION (MAYBE_DISABLE_IPO target) IF(MSVC AND NOT CLANG_CL) SET_TARGET_PROPERTIES(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + IF(CMAKE_CONFIGURATION_TYPES) + FOREACH(cfg ${CMAKE_CONFIGURATION_TYPES}) + STRING(TOUPPER "${cfg}" cfg_upper) + SET_TARGET_PROPERTIES(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_${cfg_upper} OFF) + ENDFOREACH() + ENDIF() ENDIF() ENDFUNCTION() diff --git a/cmake/mariadb_connector_c.cmake b/cmake/mariadb_connector_c.cmake index a9b103345cd..b4f56597775 100644 --- a/cmake/mariadb_connector_c.cmake +++ b/cmake/mariadb_connector_c.cmake @@ -40,6 +40,13 @@ SET(CLIENT_PLUGIN_PVIO_SOCKET STATIC) MESSAGE("== Configuring MariaDB Connector/C") ADD_SUBDIRECTORY(libmariadb) +IF(MSVC AND TARGET mariadb_obj AND TARGET mariadbclient) + # With MSVC, do not produce LTCG-compiled static client libraries. + # They are not usable by end-users, being tied to exact compiler version + MAYBE_DISABLE_IPO(mariadb_obj) + MAYBE_DISABLE_IPO(mariadbclient) +ENDIF() + IF(UNIX) INSTALL(CODE "EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E make_directory \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${INSTALL_BINDIR}) From 173847b76a72135e1379f0cef7eccde39b570b0f Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 17 Apr 2024 15:56:45 +0200 Subject: [PATCH 142/159] Do not run maria_recover_encrypted with embedded. It uses shutdown/restart etc, features not compatible the embedded. also add have_debug.inc , since it uses debug_dbug variable --- mysql-test/suite/large_tests/t/maria_recover_encrypted.test | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/suite/large_tests/t/maria_recover_encrypted.test b/mysql-test/suite/large_tests/t/maria_recover_encrypted.test index 4c590e5e1f9..640bbacbc72 100644 --- a/mysql-test/suite/large_tests/t/maria_recover_encrypted.test +++ b/mysql-test/suite/large_tests/t/maria_recover_encrypted.test @@ -3,6 +3,8 @@ --source include/have_maria.inc --source include/default_charset.inc +--source include/not_embedded.inc +--source include/have_debug.inc # Cleanup --disable_warnings From b48de9737b0451a95df68d6327d7271ae54a3f44 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 17 Apr 2024 16:07:15 +0200 Subject: [PATCH 143/159] Remove duplicate key "Language" from .clang-format Latest Visual Studio complains about invalid format, it breaks formatting in the IDE --- .clang-format | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-format b/.clang-format index 7ce45951173..3633507cb13 100644 --- a/.clang-format +++ b/.clang-format @@ -70,7 +70,6 @@ IndentPPDirectives: None IndentWidth: 2 IndentWrappedFunctionNames: false KeepEmptyLinesAtTheStartOfBlocks: true -Language: Cpp MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 From 061adae9a26e9086f0072e49e06823299f8ce34f Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 15 Apr 2024 15:46:50 +0200 Subject: [PATCH 144/159] MDEV-16944 Fix file sharing issues on Windows in mysqltest On Windows systems, occurrences of ERROR_SHARING_VIOLATION due to conflicting share modes between processes accessing the same file can result in CreateFile failures. mysys' my_open() already incorporates a workaround by implementing wait/retry logic on Windows. But this does not help if files are opened using shell redirection like mysqltest traditionally did it, i.e via --echo exec "some text" > output_file In such cases, it is cmd.exe, that opens the output_file, and it won't do any sharing-violation retries. This commit addresses the issue by introducing a new built-in command, 'write_line', in mysqltest. This new command serves as a brief alternative to 'write_file', with a single line output, that also resolves variables like "exec" would. Internally, this command will use my_open(), and therefore retry-on-error logic. Hopefully this will eliminate the very sporadic "can't open file because it is used by another process" error on CI. --- client/mysqltest.cc | 49 ++++++++++++++++++- mysql-test/include/crash_mysqld.inc | 2 +- mysql-test/include/expect_crash.inc | 2 +- .../include/kill_and_restart_mysqld.inc | 2 +- mysql-test/include/kill_galera.inc | 2 +- mysql-test/include/kill_mysqld.inc | 2 +- mysql-test/include/rpl_start_server.inc | 2 +- mysql-test/include/rpl_stop_server.inc | 2 +- mysql-test/include/search_pattern_in_file.inc | 2 +- mysql-test/include/shutdown_mysqld.inc | 2 +- mysql-test/include/start_mysqld.inc | 4 +- mysql-test/main/crash_commit_before.test | 2 +- mysql-test/main/empty_server_name-8224.test | 4 +- .../main/host_cache_size_functionality.test | 8 +-- .../main/init_file_set_password-7656.test | 4 +- mysql-test/main/log_errchk.test | 4 +- mysql-test/main/lowercase_fs_on.test | 4 +- .../main/myisam_crash_before_flush_keys.test | 4 +- mysql-test/main/mysql_client_test.test | 2 +- mysql-test/main/mysql_client_test_comp.test | 2 +- .../main/mysql_client_test_nonblock.test | 2 +- mysql-test/main/openssl_1.test | 2 +- mysql-test/main/plugin_loaderr.test | 4 +- mysql-test/main/shutdown.test | 4 +- .../suite/binlog/include/binlog_index.inc | 12 ++--- .../t/binlog_autocommit_off_no_hang.test | 4 +- .../suite/binlog/t/binlog_rotate_perf.test | 4 +- .../binlog_encryption/restart_server.inc | 4 +- .../encryption/t/innodb-bad-key-change3.test | 12 ++--- .../encryption/t/innodb_encrypt_freed.test | 2 +- .../suite/galera/include/kill_galera.inc | 2 +- .../suite/galera/include/start_mysqld.inc | 4 +- .../galera/t/galera_ist_restart_joiner.test | 2 +- .../suite/galera/t/galera_pc_recovery.test | 8 +-- .../t/galera_restart_on_unknown_option.test | 4 +- mysql-test/suite/galera/t/mdev-22543.test | 2 +- .../suite/galera_3nodes_sr/t/GCF-832.test | 2 +- mysql-test/suite/innodb/t/alter_crash.test | 6 +-- .../suite/innodb/t/alter_rename_existing.test | 2 +- .../suite/innodb/t/doublewrite_debug.test | 4 +- .../suite/innodb/t/group_commit_crash.test | 2 +- ...group_commit_crash_no_optimize_thread.test | 2 +- .../suite/innodb/t/innodb-alter-tempfile.test | 2 +- .../t/innodb-change-buffer-recovery.test | 2 +- .../innodb/t/innodb-corrupted-table.test | 4 +- .../suite/innodb/t/innodb-wl5522-debug.test | 6 +-- .../suite/innodb/t/innodb_bug60196.test | 4 +- mysql-test/suite/innodb/t/log_file_name.test | 2 +- .../suite/innodb/t/temporary_table.test | 2 +- .../suite/innodb/t/undo_space_dblwr.test | 2 +- mysql-test/suite/innodb_fts/t/sync.test | 2 +- mysql-test/suite/innodb_gis/t/rollback.test | 2 +- mysql-test/suite/innodb_zip/t/restart.test | 18 +++---- .../suite/innodb_zip/t/wl5522_debug_zip.test | 6 +-- .../t/maria_recover_encrypted.test | 6 +-- mysql-test/suite/maria/bulk_insert_crash.test | 2 +- mysql-test/suite/maria/encrypt-no-key.test | 8 +-- mysql-test/suite/maria/encrypt-wrong-key.test | 12 ++--- .../suite/parts/inc/partition_crash.inc | 4 +- mysql-test/suite/perfschema/t/bad_option.test | 4 +- .../suite/perfschema/t/processlist_57.test | 10 ++-- .../t/setup_instruments_defaults.test | 4 +- .../t/statement_program_lost_inst.test | 4 +- .../t/rpl_domain_id_filter_master_crash.test | 4 +- .../suite/rpl/t/rpl_relay_max_extension.test | 4 +- mysql-test/suite/rpl/t/rpl_sync.test | 4 +- 66 files changed, 179 insertions(+), 134 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 7267cd6e036..fdee3e09851 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -398,7 +398,7 @@ enum enum_commands { Q_IF, Q_DISABLE_PARSING, Q_ENABLE_PARSING, Q_REPLACE_REGEX, Q_REMOVE_FILE, Q_FILE_EXIST, - Q_WRITE_FILE, Q_COPY_FILE, Q_PERL, Q_DIE, Q_EXIT, Q_SKIP, + Q_WRITE_FILE, Q_WRITE_LINE, Q_COPY_FILE, Q_PERL, Q_DIE, Q_EXIT, Q_SKIP, Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE, Q_DIFF_FILES, Q_SEND_QUIT, Q_CHANGE_USER, Q_MKDIR, Q_RMDIR, Q_LIST_FILES, Q_LIST_FILES_WRITE_FILE, Q_LIST_FILES_APPEND_FILE, @@ -501,6 +501,7 @@ const char *command_names[]= "remove_file", "file_exists", "write_file", + "write_line", "copy_file", "perl", "die", @@ -4302,6 +4303,49 @@ void do_write_file(struct st_command *command) do_write_file_command(command, FALSE); } +/** + Write a line to the start of the file. + Truncates existing file, creates new one if it doesn't exist. + + Usage + write_line ; + + Example + --write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect + + @note Both the file and the line parameters are evaluated + (can be variables). + + @note This is a better alternative to + exec echo > file, as it doesn't depend on shell, + and can better handle sporadic file access errors caused + by antivirus or backup software on Windows. +*/ +void do_write_line(struct st_command *command) +{ + DYNAMIC_STRING ds_line; + DYNAMIC_STRING ds_filename; + + struct command_arg write_line_args[] = { + { "line", ARG_STRING, FALSE, &ds_line, "line to add" }, + { "filename", ARG_STRING, TRUE, &ds_filename, "File to write to" }, + }; + DBUG_ENTER("do_write_line"); + + check_command_args(command, + command->first_argument, + write_line_args, + sizeof(write_line_args)/sizeof(struct command_arg), + ' '); + + if (bad_path(ds_filename.str)) + DBUG_VOID_RETURN; + dynstr_append_mem(&ds_line, "\n", 1); + str_to_file2(ds_filename.str, ds_line.str, ds_line.length, FALSE); + dynstr_free(&ds_filename); + dynstr_free(&ds_line); + DBUG_VOID_RETURN; +} /* SYNOPSIS @@ -7423,7 +7467,7 @@ void str_to_file2(const char *fname, char *str, size_t size, my_bool append) die("Could not open '%s' for writing, errno: %d", buff, errno); if (append && my_seek(fd, 0, SEEK_END, MYF(0)) == MY_FILEPOS_ERROR) die("Could not find end of file '%s', errno: %d", buff, errno); - if (my_write(fd, (uchar*)str, size, MYF(MY_WME|MY_FNABP))) + if (size > 0 && my_write(fd, (uchar*)str, size, MYF(MY_WME|MY_FNABP))) die("write failed, errno: %d", errno); my_close(fd, MYF(0)); } @@ -10160,6 +10204,7 @@ int main(int argc, char **argv) break; case Q_FILE_EXIST: do_file_exist(command); break; case Q_WRITE_FILE: do_write_file(command); break; + case Q_WRITE_LINE: do_write_line(command); break; case Q_APPEND_FILE: do_append_file(command); break; case Q_DIFF_FILES: do_diff_files(command); break; case Q_SEND_QUIT: do_send_quit(command); break; diff --git a/mysql-test/include/crash_mysqld.inc b/mysql-test/include/crash_mysqld.inc index 4190d24d801..89bc8ced416 100644 --- a/mysql-test/include/crash_mysqld.inc +++ b/mysql-test/include/crash_mysqld.inc @@ -4,7 +4,7 @@ --source include/not_embedded.inc # Write file to make mysql-test-run.pl expect crash and restart ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Setup the mysqld to crash at shutdown SET debug_dbug="d,crash_shutdown"; diff --git a/mysql-test/include/expect_crash.inc b/mysql-test/include/expect_crash.inc index b4bd9828a08..56abc88ae24 100644 --- a/mysql-test/include/expect_crash.inc +++ b/mysql-test/include/expect_crash.inc @@ -2,4 +2,4 @@ --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect # There should be a debug crash after using this .inc file ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name diff --git a/mysql-test/include/kill_and_restart_mysqld.inc b/mysql-test/include/kill_and_restart_mysqld.inc index b67fb7350b4..50b28bcd494 100644 --- a/mysql-test/include/kill_and_restart_mysqld.inc +++ b/mysql-test/include/kill_and_restart_mysqld.inc @@ -7,7 +7,7 @@ if (!$restart_parameters) --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect --echo # Kill and $restart_parameters ---exec echo "$restart_parameters" > $_expect_file_name +--write_line "$restart_parameters" $_expect_file_name --shutdown_server 0 --source include/wait_until_disconnected.inc --enable_reconnect diff --git a/mysql-test/include/kill_galera.inc b/mysql-test/include/kill_galera.inc index aba672d8a89..887e21f5f79 100644 --- a/mysql-test/include/kill_galera.inc +++ b/mysql-test/include/kill_galera.inc @@ -3,7 +3,7 @@ # Write file to make mysql-test-run.pl expect the crash, but don't start it --let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name # Kill the connected server --disable_reconnect diff --git a/mysql-test/include/kill_mysqld.inc b/mysql-test/include/kill_mysqld.inc index 01ee7f82bdc..a41af2d74a6 100644 --- a/mysql-test/include/kill_mysqld.inc +++ b/mysql-test/include/kill_mysqld.inc @@ -2,6 +2,6 @@ --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --echo # Kill the server ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name --shutdown_server 0 --source include/wait_until_disconnected.inc diff --git a/mysql-test/include/rpl_start_server.inc b/mysql-test/include/rpl_start_server.inc index 932fc9da7ef..0479dbbd8ac 100644 --- a/mysql-test/include/rpl_start_server.inc +++ b/mysql-test/include/rpl_start_server.inc @@ -49,7 +49,7 @@ if ($rpl_server_parameters) --source include/rpl_connection.inc # Write file to make mysql-test-run.pl start up the server again ---exec echo "$_rpl_start_server_command" > $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect +--write_line "$_rpl_start_server_command" $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect if (!$rpl_server_error) { diff --git a/mysql-test/include/rpl_stop_server.inc b/mysql-test/include/rpl_stop_server.inc index 470e86a139d..1e4a64cca25 100644 --- a/mysql-test/include/rpl_stop_server.inc +++ b/mysql-test/include/rpl_stop_server.inc @@ -44,7 +44,7 @@ if ($rpl_debug) # Write file to make mysql-test-run.pl expect the "crash", but don't start # it until it's told to ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect # Send shutdown to the connected server and give # it 60 seconds (of mysqltest's default) to die before zapping it diff --git a/mysql-test/include/search_pattern_in_file.inc b/mysql-test/include/search_pattern_in_file.inc index a899a9294cc..e02b7ac8d64 100644 --- a/mysql-test/include/search_pattern_in_file.inc +++ b/mysql-test/include/search_pattern_in_file.inc @@ -38,7 +38,7 @@ # let SEARCH_FILE= $error_log; # # Stop the server # let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; -# --exec echo "wait" > $restart_file +# --write_line wait $restart_file # --shutdown_server # --source include/wait_until_disconnected.inc # diff --git a/mysql-test/include/shutdown_mysqld.inc b/mysql-test/include/shutdown_mysqld.inc index 2db4624e4ac..1684d81970a 100644 --- a/mysql-test/include/shutdown_mysqld.inc +++ b/mysql-test/include/shutdown_mysqld.inc @@ -24,7 +24,7 @@ if ($rpl_inited) # Write file to make mysql-test-run.pl expect the "crash", but don't start it --let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name # Avoid warnings from connection threads that does not have time to exit --disable_query_log diff --git a/mysql-test/include/start_mysqld.inc b/mysql-test/include/start_mysqld.inc index 6e448cb2efd..91b06997d6e 100644 --- a/mysql-test/include/start_mysqld.inc +++ b/mysql-test/include/start_mysqld.inc @@ -21,7 +21,7 @@ if ($restart_bindir) if ($restart_parameters) { - --exec echo "$restart_cmd: $restart_parameters" > $_expect_file_name + --write_line "$restart_cmd: $restart_parameters" $_expect_file_name if (!$restart_noprint) { --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR $MYSQLTEST_VARDIR MYSQLTEST_VARDIR @@ -34,7 +34,7 @@ if ($restart_parameters) } if (!$restart_parameters) { - --exec echo "$restart_cmd" > $_expect_file_name + --write_line "$restart_cmd" $_expect_file_name if ($restart_noprint < 2) { --exec echo "# $restart_cmd" diff --git a/mysql-test/main/crash_commit_before.test b/mysql-test/main/crash_commit_before.test index 93b96de6e53..30b59ce4480 100644 --- a/mysql-test/main/crash_commit_before.test +++ b/mysql-test/main/crash_commit_before.test @@ -17,7 +17,7 @@ insert into t1 values(9); SET GLOBAL debug_dbug="d,crash_commit_before"; # Write file to make mysql-test-run.pl expect crash and restart ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Run the crashing query --error 2013 diff --git a/mysql-test/main/empty_server_name-8224.test b/mysql-test/main/empty_server_name-8224.test index 5c5140be2e0..31760713bc8 100644 --- a/mysql-test/main/empty_server_name-8224.test +++ b/mysql-test/main/empty_server_name-8224.test @@ -3,10 +3,10 @@ # --source include/not_embedded.inc create server '' foreign data wrapper w2 options (host '127.0.0.1'); ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect -- enable_reconnect -- source include/wait_until_connected_again.inc diff --git a/mysql-test/main/host_cache_size_functionality.test b/mysql-test/main/host_cache_size_functionality.test index 9ec26010ab6..f37b2ab8c9e 100644 --- a/mysql-test/main/host_cache_size_functionality.test +++ b/mysql-test/main/host_cache_size_functionality.test @@ -43,10 +43,10 @@ select @@global.Host_Cache_Size > 0; --echo # Restart server with Host_Cache_Size 1 let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; ---exec echo "wait" > $restart_file +--write_line wait $restart_file --shutdown_server --source include/wait_until_disconnected.inc --- exec echo "restart:--host_cache_size=1 " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--host_cache_size=1 " $MYSQLTEST_VARDIR/tmp/mysqld.1.expect -- enable_reconnect -- source include/wait_until_connected_again.inc @@ -142,10 +142,10 @@ SELECT Host_Cache_Size = @@SESSION.Host_Cache_Size; #--remove_file $MYSQL_TMP_DIR/bind_ip #let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; -#--exec echo "wait" > $restart_file +#--write_line wait $restart_file #--shutdown_server #--source include/wait_until_disconnected.inc -#-- exec echo "restart:--bind-address=$bind_ip " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +#-- write_line "restart:--bind-address=$bind_ip " $MYSQLTEST_VARDIR/tmp/mysqld.1.expect #-- enable_reconnect #-- source include/wait_until_connected_again.inc diff --git a/mysql-test/main/init_file_set_password-7656.test b/mysql-test/main/init_file_set_password-7656.test index 7bca34a0fcf..ac5baa3b04f 100644 --- a/mysql-test/main/init_file_set_password-7656.test +++ b/mysql-test/main/init_file_set_password-7656.test @@ -15,12 +15,12 @@ EOF --enable_reconnect ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc ---exec echo "restart:--init-file=$MYSQLTEST_VARDIR/init.file " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--init-file=$MYSQLTEST_VARDIR/init.file " $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --source include/wait_until_connected_again.inc select user,host,password,plugin,authentication_string from mysql.user where user='foo'; diff --git a/mysql-test/main/log_errchk.test b/mysql-test/main/log_errchk.test index 1afc0e29f3a..c64f6e3c106 100644 --- a/mysql-test/main/log_errchk.test +++ b/mysql-test/main/log_errchk.test @@ -30,12 +30,12 @@ --echo # Case 2: Starting server with fifo file as general log file --echo # and slow query log file. # Restart server with fifo file as general log file. ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc --enable_reconnect # Write file to make mysql-test-run.pl start up the server again ---exec echo "restart: --general-log-file=$gen_log_file --slow-query-log-file=$slow_query_log_file" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart: --general-log-file=$gen_log_file --slow-query-log-file=$slow_query_log_file" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --source include/wait_until_connected_again.inc # Error 6 is reported, because the other end is closed diff --git a/mysql-test/main/lowercase_fs_on.test b/mysql-test/main/lowercase_fs_on.test index 1d306826e27..9a7fc369207 100644 --- a/mysql-test/main/lowercase_fs_on.test +++ b/mysql-test/main/lowercase_fs_on.test @@ -16,7 +16,7 @@ let SEARCH_FILE= $MYSQLTEST_VARDIR/log/my_restart.err; --remove_file $SEARCH_FILE #Shutdown the server ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -30,7 +30,7 @@ let SEARCH_PATTERN= \[ERROR\] The server option \'lower_case_table_names\' is co --source include/search_pattern_in_file.inc #Restart the server ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --source include/wait_until_connected_again.inc #Cleanup diff --git a/mysql-test/main/myisam_crash_before_flush_keys.test b/mysql-test/main/myisam_crash_before_flush_keys.test index 8df81f73ec0..34bd0aa1e10 100644 --- a/mysql-test/main/myisam_crash_before_flush_keys.test +++ b/mysql-test/main/myisam_crash_before_flush_keys.test @@ -26,14 +26,14 @@ INSERT INTO t1 VALUES (1,2),(2,3),(3,4),(4,5),(5,6); SET SESSION debug_dbug="d,crash_before_flush_keys"; --echo # Write file to make mysql-test-run.pl expect crash ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --echo # Run the crashing query --error 2013 FLUSH TABLE t1; --echo # Write file to make mysql-test-run.pl start the server ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --echo # Turn on reconnect --enable_reconnect diff --git a/mysql-test/main/mysql_client_test.test b/mysql-test/main/mysql_client_test.test index 09efc99796d..2b573702c15 100644 --- a/mysql-test/main/mysql_client_test.test +++ b/mysql-test/main/mysql_client_test.test @@ -25,7 +25,7 @@ call mtr.add_suppression(" IP address .* could not be resolved"); # server or run mysql-test-run --debug mysql_client_test and check # var/log/mysql_client_test.trace ---exec echo "$MYSQL_CLIENT_TEST" > $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1 +--write_line "$MYSQL_CLIENT_TEST" $MYSQLTEST_VARDIR/log/mysql_client_test.out.log --exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1 # End of 4.1 tests diff --git a/mysql-test/main/mysql_client_test_comp.test b/mysql-test/main/mysql_client_test_comp.test index 36a12b6691e..f37d82a20e5 100644 --- a/mysql-test/main/mysql_client_test_comp.test +++ b/mysql-test/main/mysql_client_test_comp.test @@ -12,7 +12,7 @@ SET @old_slow_query_log= @@global.slow_query_log; call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'"); call mtr.add_suppression(" IP address .* could not be resolved"); ---exec echo "$MYSQL_CLIENT_TEST" > $MYSQLTEST_VARDIR/log/mysql_client_test_comp.out.log 2>&1 +--write_line "$MYSQL_CLIENT_TEST" $MYSQLTEST_VARDIR/log/mysql_client_test_comp.out.log --exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test_comp.out.log 2>&1 # End of test diff --git a/mysql-test/main/mysql_client_test_nonblock.test b/mysql-test/main/mysql_client_test_nonblock.test index 73e7a6d378d..158ddc131f0 100644 --- a/mysql-test/main/mysql_client_test_nonblock.test +++ b/mysql-test/main/mysql_client_test_nonblock.test @@ -19,7 +19,7 @@ call mtr.add_suppression(" IP address .* could not be resolved"); # server or run mysql-test-run --debug mysql_client_test and check # var/log/mysql_client_test.trace ---exec echo "$MYSQL_CLIENT_TEST --non-blocking-api" > $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1 +---write_line "$MYSQL_CLIENT_TEST --non-blocking-api" $MYSQLTEST_VARDIR/log/mysql_client_test.out.log --exec $MYSQL_CLIENT_TEST --non-blocking-api --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1 # End of 4.1 tests diff --git a/mysql-test/main/openssl_1.test b/mysql-test/main/openssl_1.test index 639fd0a294d..83c176b47fd 100644 --- a/mysql-test/main/openssl_1.test +++ b/mysql-test/main/openssl_1.test @@ -68,7 +68,7 @@ drop table t1; # Test that we can't open connection to server if we are using # a different cacert # ---exec echo "this query should not execute;" > $MYSQLTEST_VARDIR/tmp/test.sql +--write_line "this query should not execute;" $MYSQLTEST_VARDIR/tmp/test.sql # Handle that openssl gives different error messages from YaSSL. --replace_regex /2026 TLS\/SSL error.*/2026 TLS\/SSL error: xxxx/ --error 1 diff --git a/mysql-test/main/plugin_loaderr.test b/mysql-test/main/plugin_loaderr.test index 85621ad047d..1623630bb81 100644 --- a/mysql-test/main/plugin_loaderr.test +++ b/mysql-test/main/plugin_loaderr.test @@ -13,14 +13,14 @@ FROM INFORMATION_SCHEMA.PLUGINS WHERE plugin_name = 'innodb'; --echo # --echo # MDEV-6351 --plugin=force has no effect for built-in plugins --echo # ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc --error 1 --exec $MYSQLD_CMD --innodb=force --innodb-page-size=6000 --disable-log-error ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc --disable_reconnect diff --git a/mysql-test/main/shutdown.test b/mysql-test/main/shutdown.test index 71f2156a17f..b26a6d4b6f6 100644 --- a/mysql-test/main/shutdown.test +++ b/mysql-test/main/shutdown.test @@ -20,13 +20,13 @@ drop procedure try_shutdown; --let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name --send shutdown --connection default --source include/wait_until_disconnected.inc ---exec echo "restart" > $_expect_file_name +--write_line restart $_expect_file_name --enable_reconnect --source include/wait_until_connected_again.inc diff --git a/mysql-test/suite/binlog/include/binlog_index.inc b/mysql-test/suite/binlog/include/binlog_index.inc index d73091d59ab..eee58e78f4b 100644 --- a/mysql-test/suite/binlog/include/binlog_index.inc +++ b/mysql-test/suite/binlog/include/binlog_index.inc @@ -98,7 +98,7 @@ reset master; --echo # crash_purge_before_update_index flush logs; ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect SET SESSION debug_dbug="+d,crash_purge_before_update_index"; --source include/wait_for_binlog_checkpoint.inc --error 2013 @@ -119,7 +119,7 @@ SELECT @index; --echo # crash_purge_non_critical_after_update_index flush logs; ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect SET SESSION debug_dbug="+d,crash_purge_non_critical_after_update_index"; --source include/wait_for_binlog_checkpoint.inc --error 2013 @@ -143,7 +143,7 @@ SELECT @index; --echo # crash_purge_critical_after_update_index flush logs; ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect SET SESSION debug_dbug="+d,crash_purge_critical_after_update_index"; --source include/wait_for_binlog_checkpoint.inc --error 2013 @@ -167,7 +167,7 @@ file_exists $MYSQLD_DATADIR/master-bin.000008; SELECT @index; --echo # crash_create_non_critical_before_update_index ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect SET SESSION debug_dbug="+d,crash_create_non_critical_before_update_index"; --error 2013 flush logs; @@ -185,7 +185,7 @@ file_exists $MYSQLD_DATADIR/master-bin.000009; SELECT @index; --echo # crash_create_critical_before_update_index ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect SET SESSION debug_dbug="+d,crash_create_critical_before_update_index"; --error 2013 flush logs; @@ -205,7 +205,7 @@ file_exists $MYSQLD_DATADIR/master-bin.000011; SELECT @index; --echo # crash_create_after_update_index ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect SET SESSION debug_dbug="+d,crash_create_after_update_index"; --error 2013 flush logs; diff --git a/mysql-test/suite/binlog/t/binlog_autocommit_off_no_hang.test b/mysql-test/suite/binlog/t/binlog_autocommit_off_no_hang.test index 8f1dbb2a2dd..149b1a8d97d 100644 --- a/mysql-test/suite/binlog/t/binlog_autocommit_off_no_hang.test +++ b/mysql-test/suite/binlog/t/binlog_autocommit_off_no_hang.test @@ -26,10 +26,10 @@ ALTER TABLE mysql.gtid_slave_pos ENGINE=innodb; --echo # Restart the server so mysqld reads the gtid_slave_pos using innodb ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc diff --git a/mysql-test/suite/binlog/t/binlog_rotate_perf.test b/mysql-test/suite/binlog/t/binlog_rotate_perf.test index 74c91feca97..512471e2de1 100644 --- a/mysql-test/suite/binlog/t/binlog_rotate_perf.test +++ b/mysql-test/suite/binlog/t/binlog_rotate_perf.test @@ -68,10 +68,10 @@ while ($loop_times) { # try to change the log-bin configs and restart --echo # ======= now try to change the log-bin config for mysqld ======= ---let $restart_parameters="--log-bin=new_log_bin" +--let $restart_parameters=--log-bin=new_log_bin --echo #begin to restart mysqld --source include/restart_mysqld.inc ---let $restart_parameters= "" +--let $restart_parameters= --source include/show_binary_logs.inc let $loop_times= 10; diff --git a/mysql-test/suite/binlog_encryption/restart_server.inc b/mysql-test/suite/binlog_encryption/restart_server.inc index 8f0fe7d8970..f71858be741 100644 --- a/mysql-test/suite/binlog_encryption/restart_server.inc +++ b/mysql-test/suite/binlog_encryption/restart_server.inc @@ -20,7 +20,7 @@ --connection $_cur_con --enable_reconnect ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect shutdown_server; @@ -31,5 +31,5 @@ if ($rpl_server_parameters) { --let $_rpl_start_server_command= restart:$rpl_server_parameters } ---exec echo "$_rpl_start_server_command" > $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect +--write_line "$_rpl_start_server_command" $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect --source include/wait_until_connected_again.inc diff --git a/mysql-test/suite/encryption/t/innodb-bad-key-change3.test b/mysql-test/suite/encryption/t/innodb-bad-key-change3.test index 9c2918f3118..f4065290938 100644 --- a/mysql-test/suite/encryption/t/innodb-bad-key-change3.test +++ b/mysql-test/suite/encryption/t/innodb-bad-key-change3.test @@ -16,7 +16,7 @@ call mtr.add_suppression("InnoDB: Cannot calculate statistics for table .* becau --let $MYSQLD_DATADIR = `SELECT @@datadir` --let SEARCH_RANGE = 10000000 --let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -25,7 +25,7 @@ call mtr.add_suppression("InnoDB: Cannot calculate statistics for table .* becau 4;770A8A65DA156D24EE2A093277530143 EOF ---exec echo "restart:--innodb-encrypt-tables --innodb-stats-persistent --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--innodb-encrypt-tables --innodb-stats-persistent --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc @@ -47,7 +47,7 @@ UNLOCK TABLES; ALTER TABLE t1 DISCARD TABLESPACE; ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -62,7 +62,7 @@ ib_discard_tablespaces("test", "t1"); ib_restore_tablespaces("test", "t1"); EOF ---exec echo "restart:--innodb-encrypt-tables --innodb-stats-persistent --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys2.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--innodb-encrypt-tables --innodb-stats-persistent --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys2.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc --source include/restart_mysqld.inc @@ -80,7 +80,7 @@ SELECT * FROM t1; -- let SEARCH_FILE=$t1_IBD -- source include/search_pattern_in_file.inc ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc --remove_file $MYSQLTEST_VARDIR/keys1.txt @@ -89,7 +89,7 @@ SELECT * FROM t1; 4;770A8A65DA156D24EE2A093277530143 EOF ---exec echo "restart:--innodb-encrypt-tables --innodb-stats-persistent --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--innodb-encrypt-tables --innodb-stats-persistent --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc DROP TABLE t1; diff --git a/mysql-test/suite/encryption/t/innodb_encrypt_freed.test b/mysql-test/suite/encryption/t/innodb_encrypt_freed.test index 785b4e9e498..3ce5620df98 100644 --- a/mysql-test/suite/encryption/t/innodb_encrypt_freed.test +++ b/mysql-test/suite/encryption/t/innodb_encrypt_freed.test @@ -20,7 +20,7 @@ CREATE TABLE t1(f1 BIGINT PRIMARY KEY, f2 int not null, SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0; CREATE TABLE t2 (f1 int not null)engine=innodb; -let $restart_parameters="--debug=d,ib_log_checkpoint_avoid"; +let $restart_parameters=--debug=d,ib_log_checkpoint_avoid; --source include/restart_mysqld.inc # Stop the purge diff --git a/mysql-test/suite/galera/include/kill_galera.inc b/mysql-test/suite/galera/include/kill_galera.inc index 28a1b0f368c..3c218a19bee 100644 --- a/mysql-test/suite/galera/include/kill_galera.inc +++ b/mysql-test/suite/galera/include/kill_galera.inc @@ -8,7 +8,7 @@ if (!$kill_signal) # Write file to make mysql-test-run.pl expect the crash, but don't start it --let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name # Kill the connected server --disable_reconnect diff --git a/mysql-test/suite/galera/include/start_mysqld.inc b/mysql-test/suite/galera/include/start_mysqld.inc index 57af9203d0f..c9bed71f517 100644 --- a/mysql-test/suite/galera/include/start_mysqld.inc +++ b/mysql-test/suite/galera/include/start_mysqld.inc @@ -4,12 +4,12 @@ if ($galera_wsrep_start_position != '') { --echo Using --wsrep-start-position when starting mysqld ... - --exec echo "restart:$start_mysqld_params --wsrep-start-position=$galera_wsrep_start_position" > $_expect_file_name + --write_line "restart:$start_mysqld_params --wsrep-start-position=$galera_wsrep_start_position" $_expect_file_name --let $galera_wsrep_start_position = 0 } if ($galera_wsrep_start_position == '') { - --exec echo "restart:$start_mysqld_params" > $_expect_file_name + --write_line "restart:$start_mysqld_params" $_expect_file_name } --source include/galera_wait_ready.inc diff --git a/mysql-test/suite/galera/t/galera_ist_restart_joiner.test b/mysql-test/suite/galera/t/galera_ist_restart_joiner.test index b36a0de57b6..940b511f752 100644 --- a/mysql-test/suite/galera/t/galera_ist_restart_joiner.test +++ b/mysql-test/suite/galera/t/galera_ist_restart_joiner.test @@ -37,7 +37,7 @@ UPDATE t1 SET f2 = 'c' WHERE f1 > 2; # Write file to make mysql-test-run.pl expect the crash, but don't start it --let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name --let KILL_NODE_PIDFILE = `SELECT @@pid_file` diff --git a/mysql-test/suite/galera/t/galera_pc_recovery.test b/mysql-test/suite/galera/t/galera_pc_recovery.test index 1621414aff5..16abe6fc9ba 100644 --- a/mysql-test/suite/galera/t/galera_pc_recovery.test +++ b/mysql-test/suite/galera/t/galera_pc_recovery.test @@ -27,8 +27,8 @@ INSERT INTO t1 VALUES (1); SELECT COUNT(*) = 1 FROM t1; --let $NODE_2_PIDFILE = `SELECT @@pid_file` ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --exec kill -9 `cat $NODE_1_PIDFILE` `cat $NODE_2_PIDFILE` # Perform --wsrep-recover and preserve the positions into variables by placing them in $MYSQL_TMP_DIR/galera_wsrep_start_position.inc and then --source'ing it @@ -66,8 +66,8 @@ if ($galera_wsrep_start_position2 == '') { # Instruct MTR to perform the actual restart using --wsrep-start-position . Proper --wsrep_cluster_address is used as my.cnf only contains 'gcomm://' for node #1 ---exec echo "restart: --wsrep-start-position=$galera_wsrep_start_position1 --wsrep_cluster_address=gcomm://127.0.0.1:$NODE_GALERAPORT_1,127.0.0.1:$NODE_GALERAPORT_2" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect ---exec echo "restart: --wsrep-start-position=$galera_wsrep_start_position2 --wsrep_cluster_address=gcomm://127.0.0.1:$NODE_GALERAPORT_1,127.0.0.1:$NODE_GALERAPORT_2" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +--write_line "restart: --wsrep-start-position=$galera_wsrep_start_position1 --wsrep_cluster_address=gcomm://127.0.0.1:$NODE_GALERAPORT_1,127.0.0.1:$NODE_GALERAPORT_2" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart: --wsrep-start-position=$galera_wsrep_start_position2 --wsrep_cluster_address=gcomm://127.0.0.1:$NODE_GALERAPORT_1,127.0.0.1:$NODE_GALERAPORT_2" $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --sleep 5 --connection node_1 diff --git a/mysql-test/suite/galera/t/galera_restart_on_unknown_option.test b/mysql-test/suite/galera/t/galera_restart_on_unknown_option.test index 6a0f24dbaae..e3a8b749cb4 100644 --- a/mysql-test/suite/galera/t/galera_restart_on_unknown_option.test +++ b/mysql-test/suite/galera/t/galera_restart_on_unknown_option.test @@ -62,7 +62,7 @@ SELECT * FROM t1; --let $start_mysqld_params=--galera-unknown-option --echo Starting server ... ---exec echo "try:$start_mysqld_params" > $_expect_file_name +--write_line "try:$start_mysqld_params" $_expect_file_name # Sleep to ensure that server exited... @@ -107,7 +107,7 @@ SELECT * FROM t1; --let $start_mysqld_params=--galera-unknown-option --echo Starting server ... ---exec echo "try:$start_mysqld_params" > $_expect_file_name +--write_line "try:$start_mysqld_params" $_expect_file_name # Sleep to ensure that server exited... diff --git a/mysql-test/suite/galera/t/mdev-22543.test b/mysql-test/suite/galera/t/mdev-22543.test index 1e7d3712639..26257b28814 100644 --- a/mysql-test/suite/galera/t/mdev-22543.test +++ b/mysql-test/suite/galera/t/mdev-22543.test @@ -36,7 +36,7 @@ SET DEBUG_SYNC = "now WAIT_FOR sync_point_reached"; # Restart without waiting. The UPDATE should block FTWRL on node_1, # so the SST cannot be completed and node_2 cannot join before # UPDATE connection is signalled to continue. ---exec echo "restart:$start_mysqld_params" > $_expect_file_name +--write_line "restart:$start_mysqld_params" $_expect_file_name # If the bug is present, FTWRL times out on node_1 in couple of # seconds and node_2 fails to join. --sleep 10 diff --git a/mysql-test/suite/galera_3nodes_sr/t/GCF-832.test b/mysql-test/suite/galera_3nodes_sr/t/GCF-832.test index ab8b62b969a..d18ec470c50 100644 --- a/mysql-test/suite/galera_3nodes_sr/t/GCF-832.test +++ b/mysql-test/suite/galera_3nodes_sr/t/GCF-832.test @@ -17,7 +17,7 @@ SET GLOBAL debug_dbug="d,crash_last_fragment_commit_after_fragment_removal"; --let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name CREATE TABLE t1 (f1 VARCHAR(30)) ENGINE=InnoDB; diff --git a/mysql-test/suite/innodb/t/alter_crash.test b/mysql-test/suite/innodb/t/alter_crash.test index 6f6a6dc5cbc..2fd8fd735bf 100644 --- a/mysql-test/suite/innodb/t/alter_crash.test +++ b/mysql-test/suite/innodb/t/alter_crash.test @@ -70,7 +70,7 @@ let $orig_table_id = `SELECT table_id WHERE name = 'test/t1'`; # Write file to make mysql-test-run.pl expect crash ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --error 2013 ALTER TABLE t1 ADD PRIMARY KEY (f2, f1); @@ -123,7 +123,7 @@ let $orig_table_id = `SELECT table_id WHERE name = 'test/t2'`; # Write file to make mysql-test-run.pl expect crash ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --error 2013 ALTER TABLE t2 ADD PRIMARY KEY (f2, f1); @@ -165,7 +165,7 @@ let $orig_table_id = `select table_id from information_schema.innodb_sys_tables where name = 'test/t1'`; # Write file to make mysql-test-run.pl expect crash ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # --error 2013 ALTER TABLE t1 ADD INDEX (b), CHANGE c d int, ALGORITHM=INPLACE; diff --git a/mysql-test/suite/innodb/t/alter_rename_existing.test b/mysql-test/suite/innodb/t/alter_rename_existing.test index 06602ae8e74..c6886619d73 100644 --- a/mysql-test/suite/innodb/t/alter_rename_existing.test +++ b/mysql-test/suite/innodb/t/alter_rename_existing.test @@ -18,7 +18,7 @@ INSERT INTO t1(b) VALUES('one'), ('two'), ('three'); --echo # --echo # Create a file called MYSQLD_DATADIR/test/t1.ibd ---exec echo "This is not t1.ibd" > $MYSQLD_DATADIR/test/t1.ibd +--write_line "This is not t1.ibd" $MYSQLD_DATADIR/test/t1.ibd --echo # Directory listing of test/*.ibd --echo # diff --git a/mysql-test/suite/innodb/t/doublewrite_debug.test b/mysql-test/suite/innodb/t/doublewrite_debug.test index 3d96a74e698..66c24648a73 100644 --- a/mysql-test/suite/innodb/t/doublewrite_debug.test +++ b/mysql-test/suite/innodb/t/doublewrite_debug.test @@ -45,7 +45,7 @@ commit work; # Slow shutdown and restart to make sure ibuf merge is finished SET GLOBAL innodb_fast_shutdown = 0; let $shutdown_timeout=; -let $restart_parameters="--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0"; +let $restart_parameters=--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0; --source include/restart_mysqld.inc --source ../include/no_checkpoint_start.inc begin; @@ -95,7 +95,7 @@ select f1, f2 from t1; --echo # Test Begin: Test if recovery works if 1st page of --echo # system tablespace is corrupted and 2nd page as corrupted. -let $restart_parameters="--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0"; +let $restart_parameters=--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0; --source include/restart_mysqld.inc --source ../include/no_checkpoint_start.inc begin; diff --git a/mysql-test/suite/innodb/t/group_commit_crash.test b/mysql-test/suite/innodb/t/group_commit_crash.test index 12f7ba202e3..b0ed854f4f3 100644 --- a/mysql-test/suite/innodb/t/group_commit_crash.test +++ b/mysql-test/suite/innodb/t/group_commit_crash.test @@ -51,7 +51,7 @@ while ($numtests) START TRANSACTION; insert into t1 select * from t2; # Write file to make mysql-test-run.pl expect crash - --exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect + --write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect eval call setcrash($numtests); diff --git a/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test b/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test index 6115e3f0050..9b7de7cea56 100644 --- a/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test +++ b/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test @@ -51,7 +51,7 @@ while ($numtests) START TRANSACTION; insert into t1 select * from t2; # Write file to make mysql-test-run.pl expect crash - --exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect + --write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect eval call setcrash($numtests); diff --git a/mysql-test/suite/innodb/t/innodb-alter-tempfile.test b/mysql-test/suite/innodb/t/innodb-alter-tempfile.test index 26576129a16..81911a558dc 100644 --- a/mysql-test/suite/innodb/t/innodb-alter-tempfile.test +++ b/mysql-test/suite/innodb/t/innodb-alter-tempfile.test @@ -35,7 +35,7 @@ let datadir= `select @@datadir`; CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=innodb; SET debug_dbug='+d,innodb_alter_commit_crash_before_commit'; ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --error 2013 ALTER TABLE t1 ADD PRIMARY KEY (f2, f1); diff --git a/mysql-test/suite/innodb/t/innodb-change-buffer-recovery.test b/mysql-test/suite/innodb/t/innodb-change-buffer-recovery.test index c15a7a4cb7e..616f8e21705 100644 --- a/mysql-test/suite/innodb/t/innodb-change-buffer-recovery.test +++ b/mysql-test/suite/innodb/t/innodb-change-buffer-recovery.test @@ -51,7 +51,7 @@ DELETE FROM t1 WHERE a=1; INSERT INTO t1 VALUES(1,'X',1); SET DEBUG_DBUG='+d,crash_after_log_ibuf_upd_inplace'; ---exec echo "wait" > $_expect_file_name +--write_line wait $_expect_file_name --error 2013 # This should force a change buffer merge SELECT b FROM t1 LIMIT 3; diff --git a/mysql-test/suite/innodb/t/innodb-corrupted-table.test b/mysql-test/suite/innodb/t/innodb-corrupted-table.test index a064f08d677..dcdaa61859f 100644 --- a/mysql-test/suite/innodb/t/innodb-corrupted-table.test +++ b/mysql-test/suite/innodb/t/innodb-corrupted-table.test @@ -23,14 +23,14 @@ alter table t1 add primary key (pk); --echo # Stop the server, replace the frm with the old one and restart the server ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc --remove_file $datadir/test/t1.frm --copy_file $MYSQLTEST_VARDIR/tmp/t1.frm $datadir/test/t1.frm ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc diff --git a/mysql-test/suite/innodb/t/innodb-wl5522-debug.test b/mysql-test/suite/innodb/t/innodb-wl5522-debug.test index cebb8ce7ec4..372dfdfdc6a 100644 --- a/mysql-test/suite/innodb/t/innodb-wl5522-debug.test +++ b/mysql-test/suite/innodb/t/innodb-wl5522-debug.test @@ -41,7 +41,7 @@ INSERT INTO t1 VALUES(1),(2),(3); --let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo wait > $_expect_file_name +--write_line wait $_expect_file_name SET SESSION debug_dbug="+d,ib_discard_before_commit_crash"; --error 2013 ALTER TABLE t1 DISCARD TABLESPACE; @@ -55,7 +55,7 @@ SET GLOBAL innodb_file_per_table = 1; CREATE TABLE t1 (c1 INT) ENGINE = InnoDB; INSERT INTO t1 VALUES(1),(2),(3); ---exec echo wait > $_expect_file_name +--write_line wait $_expect_file_name SET SESSION debug_dbug="+d,ib_discard_after_commit_crash"; --error 2013 ALTER TABLE t1 DISCARD TABLESPACE; @@ -99,7 +99,7 @@ EOF --error ER_TABLESPACE_DISCARDED SELECT * FROM t1; ---exec echo wait > $_expect_file_name +--write_line wait $_expect_file_name SET SESSION debug_dbug="+d,ib_import_before_commit_crash"; --error 2013 ALTER TABLE t1 IMPORT TABLESPACE; diff --git a/mysql-test/suite/innodb/t/innodb_bug60196.test b/mysql-test/suite/innodb/t/innodb_bug60196.test index 7f1f5c40585..41b9a4d8476 100644 --- a/mysql-test/suite/innodb/t/innodb_bug60196.test +++ b/mysql-test/suite/innodb/t/innodb_bug60196.test @@ -58,7 +58,7 @@ SELECT * FROM bug_60196; --echo # Restart server. # Write file to make mysql-test-run.pl start up the server again ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Turn on reconnect --enable_reconnect @@ -132,7 +132,7 @@ SELECT * FROM Bug_60309; --echo # Restart server. # Write file to make mysql-test-run.pl start up the server again ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Turn on reconnect --enable_reconnect diff --git a/mysql-test/suite/innodb/t/log_file_name.test b/mysql-test/suite/innodb/t/log_file_name.test index a95b5b37fb9..3d43248491b 100644 --- a/mysql-test/suite/innodb/t/log_file_name.test +++ b/mysql-test/suite/innodb/t/log_file_name.test @@ -205,7 +205,7 @@ print FILE "\0" x 16384; close(FILE); EOF ---exec echo "" > $MYSQLD_DATADIR/test/u2.ibd +--write_line "" $MYSQLD_DATADIR/test/u2.ibd # TODO: Test with this, once # Bug#18131883 IMPROVE INNODB ERROR MESSAGES REGARDING FILES diff --git a/mysql-test/suite/innodb/t/temporary_table.test b/mysql-test/suite/innodb/t/temporary_table.test index 12885f40a92..bbeadcfa98e 100644 --- a/mysql-test/suite/innodb/t/temporary_table.test +++ b/mysql-test/suite/innodb/t/temporary_table.test @@ -135,7 +135,7 @@ AND support IN ('YES', 'DEFAULT', 'ENABLED'); # We cannot use include/restart_mysqld.inc in this particular test, # because SHOW STATUS would fail due to unwritable (nonexistent) tmpdir. --source include/shutdown_mysqld.inc ---exec echo "restart: --tmpdir=/dev/null/$MYSQL_TMP_DIR --skip-innodb-fast-shutdown" > $_expect_file_name +--write_line "restart: --tmpdir=/dev/null/$MYSQL_TMP_DIR --skip-innodb-fast-shutdown" $_expect_file_name --enable_reconnect --disable_result_log --disable_query_log diff --git a/mysql-test/suite/innodb/t/undo_space_dblwr.test b/mysql-test/suite/innodb/t/undo_space_dblwr.test index 3f61e91ddf5..52b19a4b7fb 100644 --- a/mysql-test/suite/innodb/t/undo_space_dblwr.test +++ b/mysql-test/suite/innodb/t/undo_space_dblwr.test @@ -12,7 +12,7 @@ insert into t1 values (1, 1); # Slow shutdown and restart to make sure ibuf merge is finished SET GLOBAL innodb_fast_shutdown = 0; let $shutdown_timeout=; -let $restart_parameters="--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0"; +let $restart_parameters=--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0; --source include/restart_mysqld.inc --source ../include/no_checkpoint_start.inc diff --git a/mysql-test/suite/innodb_fts/t/sync.test b/mysql-test/suite/innodb_fts/t/sync.test index 168309a5c92..56b9052a47a 100644 --- a/mysql-test/suite/innodb_fts/t/sync.test +++ b/mysql-test/suite/innodb_fts/t/sync.test @@ -115,7 +115,7 @@ CREATE TABLE t1 ( INSERT INTO t1(title) VALUES('database'); ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect SET debug_dbug = '+d,fts_instrument_sync_debug,fts_write_node_crash'; diff --git a/mysql-test/suite/innodb_gis/t/rollback.test b/mysql-test/suite/innodb_gis/t/rollback.test index fcfe71e2f80..a09986692ee 100644 --- a/mysql-test/suite/innodb_gis/t/rollback.test +++ b/mysql-test/suite/innodb_gis/t/rollback.test @@ -463,7 +463,7 @@ rollback; # Test partial update rollback after recovered. # Crash the server in partial update. ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect set session debug="+d,row_mysql_crash_if_error"; --error 2013 update t1 set a=point(5,5), b=point(5,5), c=5 where i < 3; diff --git a/mysql-test/suite/innodb_zip/t/restart.test b/mysql-test/suite/innodb_zip/t/restart.test index 0c1f11363e6..82090da87f2 100644 --- a/mysql-test/suite/innodb_zip/t/restart.test +++ b/mysql-test/suite/innodb_zip/t/restart.test @@ -426,13 +426,13 @@ SHOW CREATE TABLE t77_restart; --echo # Moving tablespace 't4_restart' from MYSQL_DATA_DIR to MYSQL_TMP_DIR/new_dir --copy_file $MYSQL_DATA_DIR/test/t4_restart.ibd $MYSQL_TMP_DIR/new_dir/test/t4_restart.ibd --remove_file $MYSQL_DATA_DIR/test/t4_restart.ibd ---exec echo $MYSQL_TMP_DIR/new_dir/test/t4_restart.ibd > $MYSQL_DATA_DIR/test/t4_restart.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t4_restart.ibd $MYSQL_DATA_DIR/test/t4_restart.isl --echo # Moving tablespace 't55_restart' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir --copy_file $MYSQL_TMP_DIR/alt_dir/test/t55_restart.ibd $MYSQL_TMP_DIR/new_dir/test/t55_restart.ibd --remove_file $MYSQL_TMP_DIR/alt_dir/test/t55_restart.ibd --remove_file $MYSQL_DATA_DIR/test/t55_restart.isl ---exec echo $MYSQL_TMP_DIR/new_dir/test/t55_restart.ibd > $MYSQL_DATA_DIR/test/t55_restart.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t55_restart.ibd $MYSQL_DATA_DIR/test/t55_restart.isl --echo # Moving tablespace 't66_restart' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir --copy_file $MYSQL_TMP_DIR/alt_dir/test/t66_restart#P#p0.ibd $MYSQL_TMP_DIR/new_dir/test/t66_restart#P#p0.ibd @@ -444,9 +444,9 @@ SHOW CREATE TABLE t77_restart; --remove_file $MYSQL_DATA_DIR/test/t66_restart#P#p0.isl --remove_file $MYSQL_DATA_DIR/test/t66_restart#P#p1.isl --remove_file $MYSQL_DATA_DIR/test/t66_restart#P#p2.isl ---exec echo $MYSQL_TMP_DIR/new_dir/test/t66_restart#P#p0.ibd > $MYSQL_DATA_DIR/test/t66_restart#P#p0.isl ---exec echo $MYSQL_TMP_DIR/new_dir/test/t66_restart#P#p1.ibd > $MYSQL_DATA_DIR/test/t66_restart#P#p1.isl ---exec echo $MYSQL_TMP_DIR/new_dir/test/t66_restart#P#p2.ibd > $MYSQL_DATA_DIR/test/t66_restart#P#p2.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t66_restart#P#p0.ibd $MYSQL_DATA_DIR/test/t66_restart#P#p0.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t66_restart#P#p1.ibd $MYSQL_DATA_DIR/test/t66_restart#P#p1.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t66_restart#P#p2.ibd $MYSQL_DATA_DIR/test/t66_restart#P#p2.isl --echo # Moving tablespace 't77_restart' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir --copy_file $MYSQL_TMP_DIR/alt_dir/test/t77_restart#P#p0#SP#s0.ibd $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p0#SP#s0.ibd @@ -461,10 +461,10 @@ SHOW CREATE TABLE t77_restart; --remove_file $MYSQL_DATA_DIR/test/t77_restart#P#p0#SP#s1.isl --remove_file $MYSQL_DATA_DIR/test/t77_restart#P#p1#SP#s2.isl --remove_file $MYSQL_DATA_DIR/test/t77_restart#P#p1#SP#s3.isl ---exec echo $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p0#SP#s0.ibd > $MYSQL_DATA_DIR/test/t77_restart#P#p0#SP#s0.isl ---exec echo $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p0#SP#s1.ibd > $MYSQL_DATA_DIR/test/t77_restart#P#p0#SP#s1.isl ---exec echo $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p1#SP#s2.ibd > $MYSQL_DATA_DIR/test/t77_restart#P#p1#SP#s2.isl ---exec echo $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p1#SP#s3.ibd > $MYSQL_DATA_DIR/test/t77_restart#P#p1#SP#s3.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p0#SP#s0.ibd $MYSQL_DATA_DIR/test/t77_restart#P#p0#SP#s0.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p0#SP#s1.ibd $MYSQL_DATA_DIR/test/t77_restart#P#p0#SP#s1.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p1#SP#s2.ibd $MYSQL_DATA_DIR/test/t77_restart#P#p1#SP#s2.isl +--write_line $MYSQL_TMP_DIR/new_dir/test/t77_restart#P#p1#SP#s3.ibd $MYSQL_DATA_DIR/test/t77_restart#P#p1#SP#s3.isl --echo ---- MYSQL_DATA_DIR/test --list_files_write_file $MYSQLD_DATADIR.files.txt $MYSQL_DATA_DIR/test diff --git a/mysql-test/suite/innodb_zip/t/wl5522_debug_zip.test b/mysql-test/suite/innodb_zip/t/wl5522_debug_zip.test index a7916477e0a..05801e53f84 100644 --- a/mysql-test/suite/innodb_zip/t/wl5522_debug_zip.test +++ b/mysql-test/suite/innodb_zip/t/wl5522_debug_zip.test @@ -73,7 +73,7 @@ SET SESSION debug_dbug="+d,ib_import_before_commit_crash"; SELECT * FROM t1; # Write file to make mysql-test-run.pl start up the server again ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Execute the statement that causes the crash --error 2013 @@ -94,7 +94,7 @@ SET SESSION debug_dbug="+d,ib_import_before_checkpoint_crash"; SELECT COUNT(*) FROM t1; # Don't start up the server right away. ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Execute the statement that causes the crash --error 2013 @@ -111,7 +111,7 @@ EOF --echo # Restart and reconnect to the server --enable_reconnect ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --source include/wait_until_connected_again.inc --disable_reconnect diff --git a/mysql-test/suite/large_tests/t/maria_recover_encrypted.test b/mysql-test/suite/large_tests/t/maria_recover_encrypted.test index 640bbacbc72..1064c2c0884 100644 --- a/mysql-test/suite/large_tests/t/maria_recover_encrypted.test +++ b/mysql-test/suite/large_tests/t/maria_recover_encrypted.test @@ -15,7 +15,7 @@ DROP PROCEDURE IF EXISTS proc_insert_many; # -------- # Configure encryption ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -23,7 +23,7 @@ DROP PROCEDURE IF EXISTS proc_insert_many; 1;76025E3ADC78D74819927DB02AAA4C35 EOF ---exec echo "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/key.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/key.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc @@ -75,7 +75,7 @@ CALL proc_insert_many(); UNLOCK TABLES; # Crash and restart the server while it's still flushing index ---exec echo "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/key.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/key.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect SET debug_dbug="d,crash_shutdown"; --error 2013 shutdown; diff --git a/mysql-test/suite/maria/bulk_insert_crash.test b/mysql-test/suite/maria/bulk_insert_crash.test index d9167c3f0d7..04f3a148ad4 100644 --- a/mysql-test/suite/maria/bulk_insert_crash.test +++ b/mysql-test/suite/maria/bulk_insert_crash.test @@ -12,7 +12,7 @@ # # Write file to make mysql-test-run.pl expect crash and restart ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect create table t1 (a int primary key, b int, c int, unique key(b), key(c)) engine=aria transactional=1; insert into t1 values (1000,1000,1000); diff --git a/mysql-test/suite/maria/encrypt-no-key.test b/mysql-test/suite/maria/encrypt-no-key.test index 89c50d79a54..da7bcb0fac5 100644 --- a/mysql-test/suite/maria/encrypt-no-key.test +++ b/mysql-test/suite/maria/encrypt-no-key.test @@ -26,10 +26,10 @@ CREATE TABLE t1 (a INT KEY,b INT,KEY(b)) ENGINE=Aria; --echo # Restart with encryption enabled ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc ---exec echo "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc @@ -40,10 +40,10 @@ LOAD INDEX INTO CACHE t1; # Restart without encryption. Above table should be unreadable ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc ---exec echo "restart:--aria-encrypt-tables=0" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--aria-encrypt-tables=0" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc diff --git a/mysql-test/suite/maria/encrypt-wrong-key.test b/mysql-test/suite/maria/encrypt-wrong-key.test index ac060c4e9dd..274a165ca4d 100644 --- a/mysql-test/suite/maria/encrypt-wrong-key.test +++ b/mysql-test/suite/maria/encrypt-wrong-key.test @@ -9,7 +9,7 @@ call mtr.add_suppression("System key id 1 is missing"); call mtr.add_suppression("Unknown key id 1"); call mtr.add_suppression("Initialization of encryption failed.*"); ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -17,14 +17,14 @@ call mtr.add_suppression("Initialization of encryption failed.*"); 1;770A8A65DA156D24EE2A093277530142 EOF ---exec echo "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc CREATE TABLE t1 (i INT, KEY(i)) ENGINE=Aria; INSERT INTO t1 VALUES (1); ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -32,7 +32,7 @@ INSERT INTO t1 VALUES (1); 2;770A8A65DA156D24EE2A093277530143 EOF ---exec echo "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys2.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys2.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc @@ -43,11 +43,11 @@ repair table t1; --error HA_ERR_NO_ENCRYPTION INSERT INTO t1 VALUES (2); ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server --source include/wait_until_disconnected.inc ---exec echo "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--aria-encrypt-tables=1 --plugin-load-add=file_key_management --file-key-management --file-key-management-filename=$MYSQLTEST_VARDIR/keys1.txt" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc diff --git a/mysql-test/suite/parts/inc/partition_crash.inc b/mysql-test/suite/parts/inc/partition_crash.inc index 32bf5c10423..fc5fd929c4e 100644 --- a/mysql-test/suite/parts/inc/partition_crash.inc +++ b/mysql-test/suite/parts/inc/partition_crash.inc @@ -12,7 +12,7 @@ SHOW CREATE TABLE t1; --sorted_result SELECT * FROM t1; ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --disable_reconnect # CR_SERVER_LOST --error 2013 @@ -23,7 +23,7 @@ SELECT * FROM t1; --replace_regex /sql-exchange.*\./sql-exchange./ /sql-shadow-[0-9a-f]*-/sql-shadow-/ /#sql-ib[1-9][0-9]*\.ibd\n// --cat_file $DATADIR.files.txt --remove_file $DATADIR.files.txt ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc --echo # State after crash recovery diff --git a/mysql-test/suite/perfschema/t/bad_option.test b/mysql-test/suite/perfschema/t/bad_option.test index 5d4d49ed12c..0989f01f3b3 100644 --- a/mysql-test/suite/perfschema/t/bad_option.test +++ b/mysql-test/suite/perfschema/t/bad_option.test @@ -13,7 +13,7 @@ let $error_log= $MYSQLTEST_VARDIR/log/my_restart.err; let SEARCH_FILE= $error_log; # Stop the server let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; ---exec echo "wait" > $restart_file +--write_line wait $restart_file --shutdown_server --source include/wait_until_disconnected.inc --error 7 @@ -61,7 +61,7 @@ let SEARCH_PATTERN= Can.t change dir to .*bad_option_h_param; --remove_file $error_log # Write file to make mysql-test-run.pl start up the server again ---exec echo "restart" > $restart_file +--write_line restart $restart_file # Turn on reconnect --enable_reconnect diff --git a/mysql-test/suite/perfschema/t/processlist_57.test b/mysql-test/suite/perfschema/t/processlist_57.test index 748d8b7402b..fe8898ed049 100644 --- a/mysql-test/suite/perfschema/t/processlist_57.test +++ b/mysql-test/suite/perfschema/t/processlist_57.test @@ -23,7 +23,7 @@ DROP TABLE performance_schema.processlist; SHOW CREATE TABLE performance_schema.processlist; let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; ---exec echo "wait" > $restart_file +--write_line wait $restart_file --echo ## --echo ## Server shutdown --echo ## @@ -93,7 +93,7 @@ SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST; --error ER_BAD_FIELD_ERROR SHOW PROCESSLIST; ---exec echo "wait" > $restart_file +--write_line wait $restart_file --echo ## --echo ## Server shutdown --echo ## @@ -166,7 +166,7 @@ SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST; # Works and returns no data, innodb table is empty. SHOW PROCESSLIST; ---exec echo "wait" > $restart_file +--write_line wait $restart_file --echo ## --echo ## Server shutdown --echo ## @@ -231,7 +231,7 @@ SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST; # Works and returns no data, innodb table is empty. SHOW PROCESSLIST; ---exec echo "wait" > $restart_file +--write_line wait $restart_file --echo ## --echo ## Server shutdown --echo ## @@ -306,7 +306,7 @@ SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST; --replace_column 3 [HOST:PORT] 6 [TIME] SHOW PROCESSLIST; ---exec echo "wait" > $restart_file +--write_line wait $restart_file --echo ## --echo ## Server shutdown --echo ## diff --git a/mysql-test/suite/perfschema/t/setup_instruments_defaults.test b/mysql-test/suite/perfschema/t/setup_instruments_defaults.test index ea59cd4f266..bd33c559d9a 100644 --- a/mysql-test/suite/perfschema/t/setup_instruments_defaults.test +++ b/mysql-test/suite/perfschema/t/setup_instruments_defaults.test @@ -69,7 +69,7 @@ SELECT * FROM performance_schema.setup_instruments WHERE name like "%wait/io/table/sql/handler%"; # Write file to make mysql-test-run.pl wait for the server to stop ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Restart the server --echo # @@ -79,7 +79,7 @@ WHERE name like "%wait/io/table/sql/handler%"; --echo # Restart server with wait/io/table/sql/handler disabled ---exec echo "restart:--loose-performance-schema-instrument=%wait/io/table/sql/%=off" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line "restart:--loose-performance-schema-instrument=%wait/io/table/sql/%=off" $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Turn on reconnect --echo # Enable reconnect diff --git a/mysql-test/suite/perfschema/t/statement_program_lost_inst.test b/mysql-test/suite/perfschema/t/statement_program_lost_inst.test index 023180b9d2b..0742043bba3 100644 --- a/mysql-test/suite/perfschema/t/statement_program_lost_inst.test +++ b/mysql-test/suite/perfschema/t/statement_program_lost_inst.test @@ -19,10 +19,10 @@ --source include/have_perfschema.inc let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; ---exec echo "wait" > $restart_file +--write_line wait $restart_file --shutdown_server --source include/wait_until_disconnected.inc ---exec echo "restart:--performance_schema_max_program_instances=7 --performance_schema_max_statement_stack=2 --thread_stack=655360">$restart_file +--write_line "restart:--performance_schema_max_program_instances=7 --performance_schema_max_statement_stack=2 --thread_stack=655360" $restart_file --enable_reconnect --source include/wait_until_connected_again.inc diff --git a/mysql-test/suite/rpl/t/rpl_domain_id_filter_master_crash.test b/mysql-test/suite/rpl/t/rpl_domain_id_filter_master_crash.test index cdfdc098f5a..f6f2062a252 100644 --- a/mysql-test/suite/rpl/t/rpl_domain_id_filter_master_crash.test +++ b/mysql-test/suite/rpl/t/rpl_domain_id_filter_master_crash.test @@ -39,7 +39,7 @@ insert into ti set a=null; insert into tm set a=null; set @@global.debug_dbug="+d,crash_before_send_xid"; ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.1.expect connection slave; let $do_domain_ids_before= query_get_value(SHOW SLAVE STATUS, Replicate_Do_Domain_Ids, 1); @@ -61,7 +61,7 @@ connection master; --enable_reconnect --let $rpl_server_number=1 --source include/rpl_start_server.inc -#--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +#--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --source include/wait_until_connected_again.inc --echo # Master has restarted successfully save_master_pos; diff --git a/mysql-test/suite/rpl/t/rpl_relay_max_extension.test b/mysql-test/suite/rpl/t/rpl_relay_max_extension.test index acca2f6954c..b6a8ccb545c 100644 --- a/mysql-test/suite/rpl/t/rpl_relay_max_extension.test +++ b/mysql-test/suite/rpl/t/rpl_relay_max_extension.test @@ -47,7 +47,7 @@ RESET SLAVE; --echo # --let $datadir = `select @@datadir` ---exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --shutdown_server 10 --source include/wait_until_disconnected.inc @@ -64,7 +64,7 @@ RESET SLAVE; --echo # Restart slave server --echo # ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --enable_reconnect --source include/wait_until_connected_again.inc SET @save_slave_parallel_threads= @@GLOBAL.slave_parallel_threads; diff --git a/mysql-test/suite/rpl/t/rpl_sync.test b/mysql-test/suite/rpl/t/rpl_sync.test index 1e2ec2ca83b..3dd99e736f2 100644 --- a/mysql-test/suite/rpl/t/rpl_sync.test +++ b/mysql-test/suite/rpl/t/rpl_sync.test @@ -82,7 +82,7 @@ print FILE "failure"; close ($file); EOF ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.2.expect SET SESSION debug_dbug="d,crash_before_rotate_relaylog"; --error 2013 FLUSH LOGS; @@ -130,7 +130,7 @@ print FILE @content; close FILE; EOF ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.2.expect SET SESSION debug_dbug="d,crash_before_rotate_relaylog"; --error 2013 FLUSH LOGS; From 0ad52e4d6aa0204a616b18fa81dc75a46aa356cb Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Wed, 10 Apr 2024 12:00:02 -0600 Subject: [PATCH 145/159] MDEV-27512: Assertion !thd->transaction_rollback_request failed in rows_event_stmt_cleanup If replicating an event in ROW format, and InnoDB detects a deadlock while searching for a row, the row event will error and rollback in InnoDB and indicate that the binlog cache also needs to be cleared, i.e. by marking thd->transaction_rollback_request. In the normal case, this will trigger an error in Rows_log_event::do_apply_event() and cause a rollback. During the Rows_log_event::do_apply_event() cleanup of a successful event application, there is a DBUG_ASSERT in log_event_server.cc::rows_event_stmt_cleanup(), which sets the expectation that thd->transaction_rollback_request cannot be set because the general rollback (i.e. not the InnoDB rollback) should have happened already. However, if the replica is configured to skip deadlock errors, the rows event logic will clear the error and continue on, as if no error happened. This results in thd->transaction_rollback_request being set while in rows_event_stmt_cleanup(), thereby triggering the assertion. This patch fixes this in the following ways: 1) The assertion is invalid, and thereby removed. 2) The rollback case is forced in rows_event_stmt_cleanup() if transaction_rollback_request is set. Note the differing behavior between transactions which are skipped due to deadlock errors and other errors. When a transaction is skipped due to an ignored deadlock error, the entire transaction is rolled back and skipped (though note MDEV-33930 which allows statements in the same transaction after the deadlock-inducing one to commit). When a transaction is skipped due to ignoring a different error, only the erroring statements are rolled-back and skipped - the rest of the transaction will execute as normal. The effect of this can be seen in the test results. The added test case to rpl_skip_error.test shows that only statements which are ignored due to non-deadlock errors are ignored in larger transactions. A diff between rpl_temporary_error2_skip_all.result and rpl_temporary_error2.result shows that all statements in the errored transaction are rolled back (diff pasted below): : diff rpl_temporary_error2.result rpl_temporary_error2_skip_all.result 49c49 < 2 1 --- > 2 NULL 51c51 < 4 1 --- > 4 NULL 53c53 < * There will be two rows in t2 due to the retry. --- > * There will be one row in t2 because the ignored deadlock does not retry. 57d56 < 1 59c58 < 1 --- > 0 Reviewed By: ============ Andrei Elkin --- mysql-test/suite/rpl/r/rpl_skip_error.result | 25 ++++++++ .../r/rpl_temporary_error2_skip_all.result | 64 +++++++++++++++++++ mysql-test/suite/rpl/t/rpl_skip_error.test | 42 +++++++++++- .../suite/rpl/t/rpl_temporary_error2.test | 9 ++- .../t/rpl_temporary_error2_skip_all-slave.opt | 1 + .../rpl/t/rpl_temporary_error2_skip_all.test | 3 + sql/log_event_server.cc | 10 +-- 7 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_temporary_error2_skip_all.result create mode 100644 mysql-test/suite/rpl/t/rpl_temporary_error2_skip_all-slave.opt create mode 100644 mysql-test/suite/rpl/t/rpl_temporary_error2_skip_all.test diff --git a/mysql-test/suite/rpl/r/rpl_skip_error.result b/mysql-test/suite/rpl/r/rpl_skip_error.result index eb6324ff987..03fc8a7836f 100644 --- a/mysql-test/suite/rpl/r/rpl_skip_error.result +++ b/mysql-test/suite/rpl/r/rpl_skip_error.result @@ -122,6 +122,31 @@ connection slave; # Slave_skipped_errros = 5 **** We cannot execute a select as there are differences in the **** behavior between STMT and RBR. +**** +**** Ensure transactions which are skipped due to encountering a +**** non-deadlock error which is present in --slave-skip-errors result +**** in partially committed transactions +connection master; +CREATE TABLE t3 (a INT UNIQUE) ENGINE=InnoDB; +connection slave; +connection slave; +INSERT INTO t3 VALUES (3); +connection master; +BEGIN; +INSERT INTO t3 VALUES (1); +INSERT INTO t3 VALUES (2); +INSERT INTO t3 VALUES (3); +INSERT INTO t3 VALUES (4); +COMMIT; +connection slave; +**** Master and slave tables should have the same data, due to the +**** partially replicated transaction's data overlapping with the data +**** that pre-existed on the slave. That is, despite the transaction +**** consisting of 4 statements, the errored statement should be ignored +**** and the other 3 should commit successfully. +include/diff_tables.inc [master:t3,slave:t3] +connection master; +DROP TABLE t3; ==== Clean Up ==== connection master; DROP TABLE t1; diff --git a/mysql-test/suite/rpl/r/rpl_temporary_error2_skip_all.result b/mysql-test/suite/rpl/r/rpl_temporary_error2_skip_all.result new file mode 100644 index 00000000000..9819aafa5cf --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_temporary_error2_skip_all.result @@ -0,0 +1,64 @@ +include/master-slave.inc +[connection master] +call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); +*** Provoke a deadlock on the slave, check that transaction retry succeeds. *** +connection master; +CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; +CREATE TABLE t2 (a INT) ENGINE=InnoDB; +INSERT INTO t1(a) VALUES (1), (2), (3), (4), (5); +connection slave; +SELECT * FROM t1 ORDER BY a; +a b +1 NULL +2 NULL +3 NULL +4 NULL +5 NULL +SET sql_log_bin=0; +ALTER TABLE t2 ENGINE=MyISAM; +SET sql_log_bin=1; +connect con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,; +connection con_temp1; +BEGIN; +UPDATE t1 SET b=2 WHERE a=4; +INSERT INTO t2 VALUES (2); +DELETE FROM t2 WHERE a=2; +connection master; +BEGIN; +UPDATE t1 SET b=1 WHERE a=2; +INSERT INTO t2 VALUES (1); +UPDATE t1 SET b=1 WHERE a=4; +COMMIT; +connection slave; +connection con_temp1; +UPDATE t1 SET b=2 WHERE a=2; +SELECT * FROM t1 WHERE a<10 ORDER BY a; +a b +1 NULL +2 2 +3 NULL +4 2 +5 NULL +ROLLBACK; +Warnings: +Warning 1196 Some non-transactional changed tables couldn't be rolled back +connection slave; +SELECT * FROM t1 ORDER BY a; +a b +1 NULL +2 NULL +3 NULL +4 NULL +5 NULL +* There will be one row in t2 because the ignored deadlock does not retry. +SELECT * FROM t2 ORDER BY a; +a +1 +retries +0 +Last_SQL_Errno = '0' +Last_SQL_Error = '' +connection master; +DROP TABLE t1; +DROP TABLE t2; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_skip_error.test b/mysql-test/suite/rpl/t/rpl_skip_error.test index d3ef834e8ec..ee11ce5ac92 100644 --- a/mysql-test/suite/rpl/t/rpl_skip_error.test +++ b/mysql-test/suite/rpl/t/rpl_skip_error.test @@ -3,7 +3,11 @@ # Verify that --slave-skip-errors works correctly. The error messages # specified by --slave-skip-errors on slave should be ignored. If # such errors occur, they should not be reported and not cause the -# slave to stop. +# slave to stop. If a skipped-due-to-error statement is a part of a +# larger transaction, and the error is not a deadlock error, the rest +# of the transaction should still commit, with just the errored statement +# ignored (note transactions which are skipped due to deadlocks are +# rolled back fully, see rpl_temporary_error2_skip_all.test). # # ==== Method ==== # @@ -164,6 +168,42 @@ let $current_skipped_error= query_get_value(show global status like "Slave_skipp --echo **** We cannot execute a select as there are differences in the --echo **** behavior between STMT and RBR. + +--echo **** +--echo **** Ensure transactions which are skipped due to encountering a +--echo **** non-deadlock error which is present in --slave-skip-errors result +--echo **** in partially committed transactions +# Slave will insert 3 first, and master will insert 3 within a larger trx +--let $value_preexisting_on_slave= 3 + +--connection master +CREATE TABLE t3 (a INT UNIQUE) ENGINE=InnoDB; + +--sync_slave_with_master +--connection slave +--eval INSERT INTO t3 VALUES ($value_preexisting_on_slave) + +--connection master +BEGIN; +INSERT INTO t3 VALUES (1); +INSERT INTO t3 VALUES (2); +--eval INSERT INTO t3 VALUES ($value_preexisting_on_slave) +INSERT INTO t3 VALUES (4); +COMMIT; +--sync_slave_with_master + +--echo **** Master and slave tables should have the same data, due to the +--echo **** partially replicated transaction's data overlapping with the data +--echo **** that pre-existed on the slave. That is, despite the transaction +--echo **** consisting of 4 statements, the errored statement should be ignored +--echo **** and the other 3 should commit successfully. +let $diff_tables=master:t3,slave:t3; +source include/diff_tables.inc; + +--connection master +DROP TABLE t3; + + --echo ==== Clean Up ==== connection master; diff --git a/mysql-test/suite/rpl/t/rpl_temporary_error2.test b/mysql-test/suite/rpl/t/rpl_temporary_error2.test index 49194c5d914..3537499d562 100644 --- a/mysql-test/suite/rpl/t/rpl_temporary_error2.test +++ b/mysql-test/suite/rpl/t/rpl_temporary_error2.test @@ -64,7 +64,14 @@ ROLLBACK; --connection slave --sync_with_master SELECT * FROM t1 ORDER BY a; ---echo * There will be two rows in t2 due to the retry. +if (!$ignored_db_deadlock) +{ + --echo * There will be two rows in t2 due to the retry. +} +if ($ignored_db_deadlock) +{ + --echo * There will be one row in t2 because the ignored deadlock does not retry. +} SELECT * FROM t2 ORDER BY a; let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1); --disable_query_log diff --git a/mysql-test/suite/rpl/t/rpl_temporary_error2_skip_all-slave.opt b/mysql-test/suite/rpl/t/rpl_temporary_error2_skip_all-slave.opt new file mode 100644 index 00000000000..a9ddd73510c --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_temporary_error2_skip_all-slave.opt @@ -0,0 +1 @@ +--slave-skip-errors=all diff --git a/mysql-test/suite/rpl/t/rpl_temporary_error2_skip_all.test b/mysql-test/suite/rpl/t/rpl_temporary_error2_skip_all.test new file mode 100644 index 00000000000..6801bf184d5 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_temporary_error2_skip_all.test @@ -0,0 +1,3 @@ +--source include/have_binlog_format_row.inc +--let $ignored_db_deadlock= 1 +--source rpl_temporary_error2.test diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 313df13f400..38e8b062f18 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -5926,11 +5926,13 @@ static int rows_event_stmt_cleanup(rpl_group_info *rgi, THD * thd) Xid_log_event will come next which will, if some transactional engines are involved, commit the transaction and flush the pending event to the binlog. - If there was a deadlock the transaction should have been rolled back - already. So there should be no need to rollback the transaction. + We check for thd->transaction_rollback_request because it is possible + there was a deadlock that was ignored by slave-skip-errors. Normally, the + deadlock would have been rolled back already. */ - DBUG_ASSERT(! thd->transaction_rollback_request); - error|= (int)(error ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); + error|= (int) ((error || thd->transaction_rollback_request) + ? trans_rollback_stmt(thd) + : trans_commit_stmt(thd)); /* Now what if this is not a transactional engine? we still need to From 5928e04d5f9a6900d4ac8f5f296978f01b368be1 Mon Sep 17 00:00:00 2001 From: mariadb-DebarunBanerjee Date: Tue, 16 Apr 2024 12:25:48 +0530 Subject: [PATCH 146/159] MDEV-32489 Change buffer index fails to delete the records When the change buffer records for a page span across multiple change buffer leaf pages or the starting record is at the beginning of a page with a left sibling, ibuf_delete_recs deletes only the records in first page and fails to move to subsequent pages. Subsequently a slow shutdown hangs trying to delete those left over records. Fix-A: Position the cursor to an user record in B-tree and exit only when all records are exhausted. Fix-B: Make sure we call ibuf_delete_recs during slow shutdown for pages with IBUF entries to cleanup any previously left over records. --- storage/innobase/btr/btr0pcur.cc | 14 +++++++--- storage/innobase/ibuf/ibuf0ibuf.cc | 42 +++++++++++++++------------- storage/innobase/include/btr0pcur.h | 5 ++-- storage/innobase/include/ibuf0ibuf.h | 3 +- storage/innobase/srv/srv0srv.cc | 2 +- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/storage/innobase/btr/btr0pcur.cc b/storage/innobase/btr/btr0pcur.cc index 1358a51d78d..7c28650bfd4 100644 --- a/storage/innobase/btr/btr0pcur.cc +++ b/storage/innobase/btr/btr0pcur.cc @@ -657,8 +657,9 @@ user record satisfying the search condition, in the case PAGE_CUR_L or PAGE_CUR_LE, on the last user record. If no such user record exists, then in the first case sets the cursor after last in tree, and in the latter case before first in tree. The latching mode must be BTR_SEARCH_LEAF or -BTR_MODIFY_LEAF. */ -void +BTR_MODIFY_LEAF. +@return DB_SUCCESS or error code */ +dberr_t btr_pcur_open_on_user_rec_func( /*===========================*/ dict_index_t* index, /*!< in: index */ @@ -672,8 +673,12 @@ btr_pcur_open_on_user_rec_func( unsigned line, /*!< in: line where called */ mtr_t* mtr) /*!< in: mtr */ { - btr_pcur_open_low(index, 0, tuple, mode, latch_mode, cursor, - file, line, 0, mtr); + auto err = btr_pcur_open_low(index, 0, tuple, mode, latch_mode, cursor, + file, line, 0, mtr); + + if (UNIV_UNLIKELY(err != DB_SUCCESS)) { + return err; + } if ((mode == PAGE_CUR_GE) || (mode == PAGE_CUR_G)) { @@ -688,4 +693,5 @@ btr_pcur_open_on_user_rec_func( ut_error; } + return DB_SUCCESS; } diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index 8888e538e05..33527b11bea 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -24,6 +24,7 @@ Insert buffer Created 7/19/1997 Heikki Tuuri *******************************************************/ +#include #include "ibuf0ibuf.h" #include "sync0sync.h" #include "btr0sea.h" @@ -2331,9 +2332,11 @@ static void ibuf_delete_recs(const page_id_t page_id) loop: btr_pcur_t pcur; ibuf_mtr_start(&mtr); - if (btr_pcur_open(ibuf.index, &tuple, PAGE_CUR_GE, BTR_MODIFY_LEAF, - &pcur, &mtr) != DB_SUCCESS) + if (btr_pcur_open_on_user_rec(ibuf.index, &tuple, PAGE_CUR_GE, + BTR_MODIFY_LEAF, &pcur, &mtr) != DB_SUCCESS) + { goto func_exit; + } if (!btr_pcur_is_on_user_rec(&pcur)) { ut_ad(btr_pcur_is_after_last_on_page(&pcur)); @@ -2370,7 +2373,8 @@ func_exit: /** Merge the change buffer to some pages. */ static void ibuf_read_merge_pages(const uint32_t* space_ids, - const uint32_t* page_nos, ulint n_stored) + const uint32_t* page_nos, ulint n_stored, + bool slow_shutdown_cleanup) { for (ulint i = 0; i < n_stored; i++) { const ulint space_id = space_ids[i]; @@ -2394,26 +2398,25 @@ tablespace_deleted: if (UNIV_LIKELY(page_nos[i] < size)) { mtr.start(); dberr_t err; - buf_block_t *block = + /* Load the page and apply change buffers. */ + std::ignore = buf_page_get_gen(page_id_t(space_id, page_nos[i]), zip_size, RW_X_LATCH, nullptr, BUF_GET_POSSIBLY_FREED, __FILE__, __LINE__, &mtr, &err, true); - bool remove = !block - || fil_page_get_type(block->frame) - != FIL_PAGE_INDEX - || !page_is_leaf(block->frame); mtr.commit(); if (err == DB_TABLESPACE_DELETED) { goto tablespace_deleted; } - if (!remove) { - continue; - } } - if (srv_shutdown_state == SRV_SHUTDOWN_NONE - || srv_fast_shutdown) { + /* During slow shutdown cleanup, we apply all pending IBUF + changes and need to cleanup any left-over IBUF records. There + are a few cases when the changes are already discarded and IBUF + bitmap is cleaned but we miss to delete the record. Even after + the issues are fixed, we need to keep this safety measure for + upgraded DBs with such left over records. */ + if (!slow_shutdown_cleanup) { continue; } @@ -2445,10 +2448,11 @@ tablespace_deleted: } /** Contract the change buffer by reading pages to the buffer pool. +@param slow_shutdown true, if called during slow shutdown @return a lower limit for the combined size in bytes of entries which will be merged from ibuf trees to the pages read @retval 0 if ibuf.empty */ -ulint ibuf_contract() +ulint ibuf_contract(bool slow_shutdown) { if (UNIV_UNLIKELY(!ibuf.index)) return 0; mtr_t mtr; @@ -2492,7 +2496,7 @@ ulint ibuf_contract() ibuf_mtr_commit(&mtr); btr_pcur_close(&pcur); - ibuf_read_merge_pages(space_ids, page_nos, n_pages); + ibuf_read_merge_pages(space_ids, page_nos, n_pages, slow_shutdown); return(sum_sizes + 1); } @@ -2574,7 +2578,7 @@ ibuf_merge_space( } #endif /* UNIV_DEBUG */ - ibuf_read_merge_pages(spaces, pages, n_pages); + ibuf_read_merge_pages(spaces, pages, n_pages, false); } return(n_pages); @@ -2599,7 +2603,7 @@ ibuf_contract_after_insert( ulint size; do { - size = ibuf_contract(); + size = ibuf_contract(false); sum_sizes += size; } while (size > 0 && sum_sizes < entry_size); } @@ -3228,7 +3232,7 @@ ibuf_insert_low( #ifdef UNIV_IBUF_DEBUG fputs("Ibuf too big\n", stderr); #endif - ibuf_contract(); + ibuf_contract(false); return(DB_STRONG_FAIL); } @@ -3478,7 +3482,7 @@ func_exit: #ifdef UNIV_IBUF_DEBUG ut_a(n_stored <= IBUF_MAX_N_PAGES_MERGED); #endif - ibuf_read_merge_pages(space_ids, page_nos, n_stored); + ibuf_read_merge_pages(space_ids, page_nos, n_stored, false); } return(err); diff --git a/storage/innobase/include/btr0pcur.h b/storage/innobase/include/btr0pcur.h index 584cc143359..dd44042bf9d 100644 --- a/storage/innobase/include/btr0pcur.h +++ b/storage/innobase/include/btr0pcur.h @@ -181,8 +181,9 @@ user record satisfying the search condition, in the case PAGE_CUR_L or PAGE_CUR_LE, on the last user record. If no such user record exists, then in the first case sets the cursor after last in tree, and in the latter case before first in tree. The latching mode must be BTR_SEARCH_LEAF or -BTR_MODIFY_LEAF. */ -void +BTR_MODIFY_LEAF. +@return DB_SUCCESS or error code */ +dberr_t btr_pcur_open_on_user_rec_func( /*===========================*/ dict_index_t* index, /*!< in: index */ diff --git a/storage/innobase/include/ibuf0ibuf.h b/storage/innobase/include/ibuf0ibuf.h index 73be4b0a8e8..c5a852c3497 100644 --- a/storage/innobase/include/ibuf0ibuf.h +++ b/storage/innobase/include/ibuf0ibuf.h @@ -370,10 +370,11 @@ in DISCARD TABLESPACE, IMPORT TABLESPACE, or read-ahead. void ibuf_delete_for_discarded_space(ulint space); /** Contract the change buffer by reading pages to the buffer pool. +@param slow_shutdown true, if called during slow shutdown @return a lower limit for the combined size in bytes of entries which will be merged from ibuf trees to the pages read @retval 0 if ibuf.empty */ -ulint ibuf_contract(); +ulint ibuf_contract(bool slow_shutdown); /** Contracts insert buffer trees by reading pages referring to space_id to the buffer pool. diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index aaa9dafcbb1..10f9da71df2 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -1665,7 +1665,7 @@ void srv_shutdown(bool ibuf_merge) ibuf_read_merge_pages() */ ibuf_max_size_update(0); log_free_check(); - n_read = ibuf_contract(); + n_read = ibuf_contract(true); } if (n_tables_to_drop || ibuf_merge) { From 2e84560dc48a4dc1b43f84056375f1c259b96673 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 18 Apr 2024 09:32:33 +0200 Subject: [PATCH 147/159] MDEV-16944 postfix. Fix a typo --- mysql-test/main/mysql_client_test_nonblock.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/main/mysql_client_test_nonblock.test b/mysql-test/main/mysql_client_test_nonblock.test index 158ddc131f0..c4bc4304307 100644 --- a/mysql-test/main/mysql_client_test_nonblock.test +++ b/mysql-test/main/mysql_client_test_nonblock.test @@ -19,7 +19,7 @@ call mtr.add_suppression(" IP address .* could not be resolved"); # server or run mysql-test-run --debug mysql_client_test and check # var/log/mysql_client_test.trace ----write_line "$MYSQL_CLIENT_TEST --non-blocking-api" $MYSQLTEST_VARDIR/log/mysql_client_test.out.log +--write_line "$MYSQL_CLIENT_TEST --non-blocking-api" $MYSQLTEST_VARDIR/log/mysql_client_test.out.log --exec $MYSQL_CLIENT_TEST --non-blocking-api --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1 # End of 4.1 tests From 8e663f5e9041e8e0998c792bf8d0c297a8b0721a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 19 Apr 2024 11:04:51 +0300 Subject: [PATCH 148/159] MDEV-32791 MariaDB cannot be installed on Red Hat ubi9 The libpmem dependency that had been added in commit 3daef523af25e4f1e4e75d2c26a9b25475f0c679 (MDEV-17084) did not achieve any measurable performance improvement when comparing the same PMEM device with and without "mount -o dax" using the Linux ext4 file system. Because Red Hat has deprecated libpmem, let us remove the code altogether. Note: This is a 10.6 version of commit 3f9f5ca48e6be55613926964314f550c8ca8542d which will retain PMEM support in MariaDB Server 10.11. --- cmake/FindPMEM.cmake | 18 ----- debian/autobake-deb.sh | 18 ----- debian/control | 1 - debian/rules | 6 -- storage/innobase/CMakeLists.txt | 13 ---- storage/innobase/log/log0log.cc | 114 -------------------------------- 6 files changed, 170 deletions(-) delete mode 100644 cmake/FindPMEM.cmake diff --git a/cmake/FindPMEM.cmake b/cmake/FindPMEM.cmake deleted file mode 100644 index 73e71bc29f4..00000000000 --- a/cmake/FindPMEM.cmake +++ /dev/null @@ -1,18 +0,0 @@ -if(PMEM_LIBRARIES) - set(PMEM_FOUND TRUE) - return() -endif() -if(DEFINED PMEM_LIBRARIES) - set(PMEM_FOUND FALSE) - return() -endif() - -find_path(PMEM_INCLUDE_DIR NAMES libpmem.h) -find_library(PMEM_LIBRARIES NAMES pmem) - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( - PMEM DEFAULT_MSG - PMEM_LIBRARIES PMEM_INCLUDE_DIR) - -mark_as_advanced(PMEM_INCLUDE_DIR PMEM_LIBRARIES) diff --git a/debian/autobake-deb.sh b/debian/autobake-deb.sh index 500fef5a4dd..a0c0f2d30de 100755 --- a/debian/autobake-deb.sh +++ b/debian/autobake-deb.sh @@ -61,12 +61,6 @@ replace_uring_with_aio() -e '/-DWITH_URING=ON/d' -i debian/rules } -disable_pmem() -{ - sed '/libpmem-dev/d' -i debian/control - sed '/-DWITH_PMEM=ON/d' -i debian/rules -} - architecture=$(dpkg-architecture -q DEB_BUILD_ARCH) # Parse release name and number from Linux standard base release @@ -99,18 +93,10 @@ in # Debian "buster") replace_uring_with_aio - if [ ! "$architecture" = amd64 ] - then - disable_pmem - fi ;& "bullseye"|"bookworm") # mariadb-plugin-rocksdb in control is 4 arches covered by the distro rocksdb-tools # so no removal is necessary. - if [[ ! "$architecture" =~ amd64|arm64|ppc64el ]] - then - disable_pmem - fi if [[ ! "$architecture" =~ amd64|arm64|armel|armhf|i386|mips64el|mipsel|ppc64el|s390x ]] then replace_uring_with_aio @@ -132,10 +118,6 @@ in then remove_rocksdb_tools fi - if [[ ! "$architecture" =~ amd64|arm64|ppc64el ]] - then - disable_pmem - fi if [[ ! "$architecture" =~ amd64|arm64|armhf|ppc64el|s390x ]] then replace_uring_with_aio diff --git a/debian/control b/debian/control index 30a31b6a6f9..2af21b88ded 100644 --- a/debian/control +++ b/debian/control @@ -30,7 +30,6 @@ Build-Depends: bison, libnuma-dev [linux-any], libpam0g-dev, libpcre2-dev, - libpmem-dev [amd64 arm64 ppc64el riscv64], libsnappy-dev, libssl-dev, libssl-dev:native, diff --git a/debian/rules b/debian/rules index 5b797d50648..b92e49e12c5 100755 --- a/debian/rules +++ b/debian/rules @@ -49,12 +49,6 @@ ifeq (32,$(DEB_HOST_ARCH_BITS)) CMAKEFLAGS += -DPLUGIN_ROCKSDB=NO endif -# Only attempt to build with PMEM on archs that have package libpmem-dev available -# See https://packages.debian.org/search?searchon=names&keywords=libpmem-dev -ifneq (,$(filter $(DEB_HOST_ARCH),amd64 arm64 ppc64el riscv64)) - CMAKEFLAGS += -DWITH_PMEM=ON -endif - # Add support for verbose builds MAKEFLAGS += VERBOSE=1 diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index aaf0640cebd..a554f0e04d7 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -439,24 +439,11 @@ SET(INNOBASE_SOURCES ut/ut0vec.cc ut/ut0wqueue.cc) -OPTION(WITH_PMEM "Support redo log in persistent memory" OFF) -FIND_PACKAGE(PMEM) -IF(PMEM_FOUND) - INCLUDE_DIRECTORIES(${PMEM_INCLUDES}) - ADD_COMPILE_FLAGS(log/log0log.cc COMPILE_FLAGS "-DHAVE_PMEM") - SET(PMEM_LIBRARY ${PMEM_LIBRARIES}) -ELSE() - IF(WITH_PMEM) - MESSAGE(FATAL_ERROR "WITH_PMEM=ON cannot be satisfied") - ENDIF() -ENDIF() - MYSQL_ADD_PLUGIN(innobase ${INNOBASE_SOURCES} STORAGE_ENGINE MODULE_OUTPUT_NAME ha_innodb DEFAULT RECOMPILE_FOR_EMBEDDED LINK_LIBRARIES ${ZLIB_LIBRARY} - ${PMEM_LIBRARY} ${NUMA_LIBRARY} ${LIBSYSTEMD} ${LINKER_SCRIPT}) diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc index 666e4418d27..18726f6cbd7 100644 --- a/storage/innobase/log/log0log.cc +++ b/storage/innobase/log/log0log.cc @@ -295,125 +295,11 @@ dberr_t file_os_io::flush() noexcept return os_file_flush(m_fd) ? DB_SUCCESS : DB_ERROR; } -#ifdef HAVE_PMEM - -#include - -/** Memory mapped file */ -class mapped_file_t -{ -public: - mapped_file_t()= default; - mapped_file_t(const mapped_file_t &)= delete; - mapped_file_t &operator=(const mapped_file_t &)= delete; - mapped_file_t(mapped_file_t &&)= delete; - mapped_file_t &operator=(mapped_file_t &&)= delete; - ~mapped_file_t() noexcept; - - dberr_t map(const char *path, bool read_only= false, - bool nvme= false) noexcept; - dberr_t unmap() noexcept; - byte *data() noexcept { return m_area.data(); } - -private: - span m_area; -}; - -mapped_file_t::~mapped_file_t() noexcept -{ - if (!m_area.empty()) - unmap(); -} - -dberr_t mapped_file_t::map(const char *path, bool read_only, - bool nvme) noexcept -{ - auto fd= mysql_file_open(innodb_log_file_key, path, - read_only ? O_RDONLY : O_RDWR, MYF(MY_WME)); - if (fd == -1) - return DB_ERROR; - - const auto file_size= size_t{os_file_get_size(path).m_total_size}; - - const int nvme_flag= nvme ? MAP_SYNC : 0; - void *ptr= - my_mmap(0, file_size, read_only ? PROT_READ : PROT_READ | PROT_WRITE, - MAP_SHARED_VALIDATE | nvme_flag, fd, 0); - mysql_file_close(fd, MYF(MY_WME)); - - if (ptr == MAP_FAILED) - return DB_ERROR; - - m_area= {static_cast(ptr), file_size}; - return DB_SUCCESS; -} - -dberr_t mapped_file_t::unmap() noexcept -{ - ut_ad(!m_area.empty()); - - if (my_munmap(m_area.data(), m_area.size())) - return DB_ERROR; - - m_area= {}; - return DB_SUCCESS; -} - -static bool is_pmem(const char *path) noexcept -{ - mapped_file_t mf; - return mf.map(path, true, true) == DB_SUCCESS ? true : false; -} - -class file_pmem_io final : public file_io -{ -public: - file_pmem_io() noexcept : file_io(true) {} - - dberr_t open(const char *path, bool read_only) noexcept final - { - return m_file.map(path, read_only, true); - } - dberr_t rename(const char *old_path, const char *new_path) noexcept final - { - return os_file_rename(innodb_log_file_key, old_path, new_path) ? DB_SUCCESS - : DB_ERROR; - } - dberr_t close() noexcept final { return m_file.unmap(); } - __attribute__((warn_unused_result)) - dberr_t read(os_offset_t offset, span buf) noexcept final - { - memcpy(buf.data(), m_file.data() + offset, buf.size()); - return DB_SUCCESS; - } - dberr_t write(const char *, os_offset_t offset, - span buf) noexcept final - { - pmem_memcpy_persist(m_file.data() + offset, buf.data(), buf.size()); - return DB_SUCCESS; - } - dberr_t flush() noexcept final - { - ut_ad(0); - return DB_SUCCESS; - } - -private: - mapped_file_t m_file; -}; -#endif - dberr_t log_file_t::open(bool read_only) noexcept { ut_a(!is_opened()); -#ifdef HAVE_PMEM - auto ptr= is_pmem(m_path.c_str()) - ? std::unique_ptr(new file_pmem_io) - : std::unique_ptr(new file_os_io); -#else auto ptr= std::unique_ptr(new file_os_io); -#endif if (dberr_t err= ptr->open(m_path.c_str(), read_only)) return err; From ec7db2bdf849fc1a5bad906764920edda4121bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 19 Apr 2024 12:39:48 +0300 Subject: [PATCH 149/159] MDEV-33325 fixup ibuf_remove_free_page(): Correct the calculation of root_savepoint(). The first entry acquired by ibuf_tree_root_get() will be ibuf.index.lock and not the change buffer root page. Thanks to Matthias Leich for finding this bug in RQG. Unfortunately, this code is very difficult to cover in our regression test suite. --- storage/innobase/ibuf/ibuf0ibuf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index 70824cff8a5..10310a0b94a 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -1888,13 +1888,13 @@ early_exit: return; } - const auto root_savepoint = mtr.get_savepoint(); buf_block_t* root = ibuf_tree_root_get(&mtr); if (UNIV_UNLIKELY(!root)) { goto early_exit; } + const auto root_savepoint = mtr.get_savepoint() - 1; const uint32_t page_no = flst_get_last(PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST + root->page.frame).page; From 4c34339426f390c7d55b8e74376ce3e1bb75f0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 19 Apr 2024 15:46:21 +0300 Subject: [PATCH 150/159] MDEV-33946: OPT_PAGE_CHECKSUM mismatch due to mtr_t::memmove() mtr_t::memmove(): Revert to the parent of commit a032f14b342c782b82dfcd9235805bee446e6fe8 where there was supposed to be an equivalent change that would avoid hitting a warning in some old version of GCC when this change was part of another 10.6 based developmet branch. For some reason, this change is not equivalent but will cause massive amounts of backup failures in the stress tests run by Matthias Leich, caught by commit 4179f93d28035ea2798cb1c16feeaaef87ab4775 in 10.6. --- storage/innobase/include/mtr0log.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/storage/innobase/include/mtr0log.h b/storage/innobase/include/mtr0log.h index b8455f927bf..285672be898 100644 --- a/storage/innobase/include/mtr0log.h +++ b/storage/innobase/include/mtr0log.h @@ -347,12 +347,11 @@ inline void mtr_t::memmove(const buf_block_t &b, ulint d, ulint s, ulint len) ut_ad(d >= 8); ut_ad(s >= 8); ut_ad(len); - ut_d(const ulint ps= srv_page_size); - ut_ad(s <= ps); - ut_ad(s + len <= ps); + ut_ad(s <= ulint(srv_page_size)); + ut_ad(s + len <= ulint(srv_page_size)); ut_ad(s != d); - ut_ad(d <= ps); - ut_ad(d + len <= ps); + ut_ad(d <= ulint(srv_page_size)); + ut_ad(d + len <= ulint(srv_page_size)); set_modified(b); if (m_log_mode != MTR_LOG_ALL) @@ -360,17 +359,17 @@ inline void mtr_t::memmove(const buf_block_t &b, ulint d, ulint s, ulint len) static_assert(MIN_4BYTE > UNIV_PAGE_SIZE_MAX, "consistency"); size_t lenlen= (len < MIN_2BYTE ? 1 : len < MIN_3BYTE ? 2 : 3); /* The source offset is encoded relative to the destination offset, - with the sign in the least significant bit. - Because the source offset 0 is not possible, our encoding - subtracts 1 from the offset. */ - const uint16_t S= s > d - ? uint16_t((s - d - 1) << 1) - : uint16_t((d - s - 1) << 1 | 1); + with the sign in the least significant bit. */ + if (s > d) + s= (s - d) << 1; + else + s= (d - s) << 1 | 1; /* The source offset 0 is not possible. */ - size_t slen= (S < MIN_2BYTE ? 1 : S < MIN_3BYTE ? 2 : 3); + s-= 1 << 1; + size_t slen= (s < MIN_2BYTE ? 1 : s < MIN_3BYTE ? 2 : 3); byte *l= log_write(b.page.id(), &b.page, lenlen + slen, true, d); l= mlog_encode_varint(l, len); - l= mlog_encode_varint(l, S); + l= mlog_encode_varint(l, s); m_log.close(l); m_last_offset= static_cast(d + len); } From 7432a487b1334aacd1ed535f8a29cf939a13cde7 Mon Sep 17 00:00:00 2001 From: Zhibo Zhang Date: Tue, 19 Mar 2024 19:16:46 +0000 Subject: [PATCH 151/159] Update tests to be compatible with OpenSSL 3.2.0 As of version 3.2.0, OpenSSL updated the error message in new versions ("https://github.com/openssl/openssl/commit/81b741f68984"). Update the tests and result files such that they are compatible with both original and new error messages. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysql-test/main/ssl_crl.result | 2 +- mysql-test/main/ssl_crl.test | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/ssl_crl.result b/mysql-test/main/ssl_crl.result index d5603254ea5..58e3e07f746 100644 --- a/mysql-test/main/ssl_crl.result +++ b/mysql-test/main/ssl_crl.result @@ -2,4 +2,4 @@ Variable_name Value Ssl_version TLS_VERSION # try logging in with a certificate in the server's --ssl-crl : should fail -ERROR 2026 (HY000): TLS/SSL error: sslv3 alert certificate revoked +ERROR 2026 (HY000): TLS/SSL error: ssl/tls alert certificate revoked diff --git a/mysql-test/main/ssl_crl.test b/mysql-test/main/ssl_crl.test index 7ed5c210215..80188001396 100644 --- a/mysql-test/main/ssl_crl.test +++ b/mysql-test/main/ssl_crl.test @@ -7,7 +7,7 @@ --exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/server-new-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/server-new-cert.pem test -e "SHOW STATUS LIKE 'Ssl_version'" --echo # try logging in with a certificate in the server's --ssl-crl : should fail -# OpenSSL 1.1.1a correctly rejects the certificate, but the error message is different ---replace_regex /ERROR 2013 \(HY000\): Lost connection to MySQL server at '.*', system error: [0-9]+/ERROR 2026 (HY000): TLS\/SSL error: sslv3 alert certificate revoked/ +# OpenSSL 1.1.1a and later releases correctly rejects the certificate, but the error message is different +--replace_regex /(ERROR 2013 \(HY000\): Lost connection to MySQL server at '.*', system error: [0-9]+|ERROR 2026 \(HY000\): TLS\/SSL error: sslv3 alert certificate revoked)/ERROR 2026 (HY000): TLS\/SSL error: ssl\/tls alert certificate revoked/ --error 1 --exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SHOW STATUS LIKE 'Ssl_version'" 2>&1 From 4a2e03453a5b2ae575d87152263f5ff715242dc2 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 19 Apr 2024 22:09:06 +0200 Subject: [PATCH 152/159] MDEV-33952 galera_create_table_as_select fails sporadically disable until fixed --- mysql-test/suite/galera/disabled.def | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index a5a1a6f18b1..4aacbd0c699 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -22,3 +22,4 @@ galera_var_ignore_apply_errors : MENT-1997 galera_var_ignore_apply_errors test f MDEV-22232 : temporarily disabled at the request of Codership MW-402 : temporarily disabled at the request of Codership galera_desync_overlapped : MDEV-21538 galera_desync_overlapped MTR failed: Result content mismatch +galera_create_table_as_select : MDEV-33952 fails sporadically From 0c249ad718f2ee96aaceebfa5ce21927cfa2f0d4 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Tue, 16 Apr 2024 10:08:31 +0200 Subject: [PATCH 153/159] MDEV-30232: rpl.rpl_gtid_crash fails sporadically in BB The root cause of the failure is a bug in the Linux network stack: https://lore.kernel.org/netdev/87sf0ldk41.fsf@urd.knielsen-hq.org/T/#u If the slave does a connect(2) at the exact same time that kill -9 of the master process closes the listening socket, the FIN or RST packet is lost in the kernel, and the slave ends up timing out waiting for the initial communication from the server. This timeout defaults to --slave-net-timeout=120, which causes include/master_gtid_wait.inc to time out first and fail the test. Work-around this problem by reducing the --slave-net-timeout for this test case. If this problem turns up in other tests, we can consider reducing the default value for all tests. Signed-off-by: Kristian Nielsen --- mysql-test/suite/rpl/t/rpl_gtid_crash-slave.opt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/rpl/t/rpl_gtid_crash-slave.opt b/mysql-test/suite/rpl/t/rpl_gtid_crash-slave.opt index 69c1a64e388..5b3fb44c910 100644 --- a/mysql-test/suite/rpl/t/rpl_gtid_crash-slave.opt +++ b/mysql-test/suite/rpl/t/rpl_gtid_crash-slave.opt @@ -1 +1 @@ ---master-retry-count=100 +--master-retry-count=100 --slave-net-timeout=10 From 57f6a1ca98b94e9bed5ba3b8d98ad1a620810089 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Tue, 16 Apr 2024 12:39:54 +0200 Subject: [PATCH 154/159] MDEV-19415: use-after-free on charsets_dir from slave connect The slave IO thread sets MYSQL_SET_CHARSET_DIR. The code for this option however is not thread-safe in sql-common/client.c. The value set is temporarily written to mysys global variable `charsets-dir` and can be seen by other threads running in parallel, which can result in use-after-free error. Problem was visible as random failures of test cases in suite multi_source with Valgrind or MSAN. Work-around by not setting this option for slave connect, it is redundant anyway as it is just setting the default value. Signed-off-by: Kristian Nielsen --- sql/slave.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sql/slave.cc b/sql/slave.cc index f70336e980a..5948d11825d 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -7412,9 +7412,6 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi, default_client_charset_info->csname); } - /* This one is not strictly needed but we have it here for completeness */ - mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir); - /* Set MYSQL_PLUGIN_DIR in case master asks for an external authentication plugin */ if (opt_plugin_dir_ptr && *opt_plugin_dir_ptr) mysql_options(mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir_ptr); @@ -7557,8 +7554,6 @@ MYSQL *rpl_connect_master(MYSQL *mysql) #endif mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset_info->csname); - /* This one is not strictly needed but we have it here for completeness */ - mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir); if (mi->user == NULL || mi->user[0] == 0 From c7c396718105c74cbaec920f28c90d5b18e39861 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 20 Apr 2024 18:34:03 +0200 Subject: [PATCH 155/159] use correct thd for DEBUG_SYNC in group commit it always has to be current_thd, DBUG_SYNC asserts that. fixes sporadic SIGABRT's in binlog_encryption.rpl_parallel_slave_bgc_kill --- sql/log.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index 281bb3eecde..b2f6ef596da 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -8029,9 +8029,9 @@ MYSQL_BIN_LOG::queue_for_group_commit(group_commit_entry *orig_entry) if (entry->cache_mngr->using_xa) { - DEBUG_SYNC(entry->thd, "commit_before_prepare_ordered"); + DEBUG_SYNC(orig_entry->thd, "commit_before_prepare_ordered"); run_prepare_ordered(entry->thd, entry->all); - DEBUG_SYNC(entry->thd, "commit_after_prepare_ordered"); + DEBUG_SYNC(orig_entry->thd, "commit_after_prepare_ordered"); } if (cur) From a4b6409ff6526a4b82934514139e1217910b26f0 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 21 Apr 2024 01:15:37 +0200 Subject: [PATCH 156/159] sporadic failures of binlog_encryption.rpl_parallel_slave_bgc_kill do CHANGE MASTER before sync_with_master to have the slave in a predictable fully synced state before the next test --- .../rpl_parallel_slave_bgc_kill.result | 8 +++----- .../suite/rpl/r/rpl_parallel_slave_bgc_kill.result | 8 +++----- .../suite/rpl/t/rpl_parallel_slave_bgc_kill.test | 10 +++------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.result b/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.result index ba131ea094f..6b75dbf6181 100644 --- a/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.result +++ b/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.result @@ -206,10 +206,12 @@ RETURN x; END || SET sql_log_bin=1; +include/stop_slave_io.inc connection server_1; INSERT INTO t3 VALUES (49,0); connection server_2; -START SLAVE SQL_THREAD; +CHANGE MASTER TO master_use_gtid=no; +include/start_slave.inc SELECT * FROM t3 WHERE a >= 40 ORDER BY a; a b 41 41 @@ -239,10 +241,6 @@ SET GLOBAL slave_parallel_threads=0; SET GLOBAL slave_parallel_threads=10; include/start_slave.inc *** 3. Same as (2), but not using gtid mode *** -connection server_2; -include/stop_slave.inc -CHANGE MASTER TO master_use_gtid=no; -include/start_slave.inc connection server_1; connection con_temp3; SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; diff --git a/mysql-test/suite/rpl/r/rpl_parallel_slave_bgc_kill.result b/mysql-test/suite/rpl/r/rpl_parallel_slave_bgc_kill.result index ba131ea094f..6b75dbf6181 100644 --- a/mysql-test/suite/rpl/r/rpl_parallel_slave_bgc_kill.result +++ b/mysql-test/suite/rpl/r/rpl_parallel_slave_bgc_kill.result @@ -206,10 +206,12 @@ RETURN x; END || SET sql_log_bin=1; +include/stop_slave_io.inc connection server_1; INSERT INTO t3 VALUES (49,0); connection server_2; -START SLAVE SQL_THREAD; +CHANGE MASTER TO master_use_gtid=no; +include/start_slave.inc SELECT * FROM t3 WHERE a >= 40 ORDER BY a; a b 41 41 @@ -239,10 +241,6 @@ SET GLOBAL slave_parallel_threads=0; SET GLOBAL slave_parallel_threads=10; include/start_slave.inc *** 3. Same as (2), but not using gtid mode *** -connection server_2; -include/stop_slave.inc -CHANGE MASTER TO master_use_gtid=no; -include/start_slave.inc connection server_1; connection con_temp3; SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; diff --git a/mysql-test/suite/rpl/t/rpl_parallel_slave_bgc_kill.test b/mysql-test/suite/rpl/t/rpl_parallel_slave_bgc_kill.test index efb998b0443..94f19a6cdd7 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_slave_bgc_kill.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_slave_bgc_kill.test @@ -295,13 +295,14 @@ CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) || --delimiter ; SET sql_log_bin=1; - +--source include/stop_slave_io.inc --connection server_1 INSERT INTO t3 VALUES (49,0); --save_master_pos --connection server_2 -START SLAVE SQL_THREAD; +CHANGE MASTER TO master_use_gtid=no; +--source include/start_slave.inc --sync_with_master SELECT * FROM t3 WHERE a >= 40 ORDER BY a; # Restore the foo() function. @@ -334,11 +335,6 @@ SET GLOBAL slave_parallel_threads=10; --echo *** 3. Same as (2), but not using gtid mode *** ---connection server_2 ---source include/stop_slave.inc -CHANGE MASTER TO master_use_gtid=no; ---source include/start_slave.inc - --connection server_1 # Set up three transactions on the master that will be group-committed # together so they can be replicated in parallel on the slave. From 1437e734f7e2c7413cf6871e34268b15ce179a5e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 21 Apr 2024 10:47:20 +0200 Subject: [PATCH 157/159] adjust timeout value in main.ssl_timeout test fixes sporadic failures under --valgrind --- mysql-test/main/ssl_timeout.result | 2 +- mysql-test/main/ssl_timeout.test | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/ssl_timeout.result b/mysql-test/main/ssl_timeout.result index 208be527a6b..d94cfed8571 100644 --- a/mysql-test/main/ssl_timeout.result +++ b/mysql-test/main/ssl_timeout.result @@ -1,5 +1,5 @@ # connect with read timeout so SLEEP() should timeout -connect ssl_con,localhost,root,,,,,SSL read_timeout=5; +connect ssl_con,localhost,root,,,,,SSL read_timeout=5$_timeout_adjustment; # Check ssl turned on SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'; have_ssl diff --git a/mysql-test/main/ssl_timeout.test b/mysql-test/main/ssl_timeout.test index f5965f874ff..d762ebc35a9 100644 --- a/mysql-test/main/ssl_timeout.test +++ b/mysql-test/main/ssl_timeout.test @@ -1,10 +1,11 @@ --source include/have_ssl_communication.inc +--source include/slow_environ.inc # Save the initial number of concurrent sessions --source include/count_sessions.inc --echo # connect with read timeout so SLEEP() should timeout -connect (ssl_con,localhost,root,,,,,SSL read_timeout=5); +connect (ssl_con,localhost,root,,,,,SSL read_timeout=5$_timeout_adjustment); --echo # Check ssl turned on SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'; From 6242783f24092946db695c0ff0b7debba6042059 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 21 Apr 2024 11:14:04 +0200 Subject: [PATCH 158/159] rpl.rpl_semi_sync_fail_over improve debugability --- .../rpl/r/rpl_semi_sync_fail_over.result | 42 ++++++++++++------- .../suite/rpl/t/rpl_semi_sync_crash.inc | 8 +--- .../suite/rpl/t/rpl_semi_sync_fail_over.test | 6 +-- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result b/mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result index ca7c802bfbe..96150209af9 100644 --- a/mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result +++ b/mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result @@ -44,7 +44,9 @@ SET DEBUG_SYNC= "now WAIT_FOR con1_ready"; connection server_2; include/wait_for_slave_param.inc [Slave_SQL_Running_State] include/stop_slave.inc -include/assert.inc [Table t1 should have 2 rows.] +select count(*) 'on slave must be 2' from t1; +on slave must be 2 +2 SELECT @@GLOBAL.gtid_current_pos; @@GLOBAL.gtid_current_pos 0-1-4 @@ -52,7 +54,9 @@ SELECT @@GLOBAL.gtid_current_pos; connection server_1; # Ensuring variable rpl_semi_sync_slave_enabled is ON.. # Ensuring status rpl_semi_sync_slave_status is OFF.. -include/assert.inc [Table t1 should have 1 rows.] +select count(*) 'on master must be 1' from t1; +on master must be 1 +1 FOUND 1 /truncated binlog file:.*master.*000001/ in mysqld.1.err disconnect conn_client; connection server_2; @@ -79,9 +83,9 @@ SHOW VARIABLES LIKE 'gtid_slave_pos'; Variable_name Value gtid_slave_pos 0-1-4 connection server_1; -SELECT COUNT(*) = 3 as 'true' FROM t1; -true -1 +SELECT COUNT(*) 'must be 3' FROM t1; +must be 3 +3 # ... the gtid states on the slave: SHOW VARIABLES LIKE 'gtid_slave_pos'; Variable_name Value @@ -124,7 +128,9 @@ SET DEBUG_SYNC= "now WAIT_FOR eof_reached"; connection server_1; include/wait_for_slave_param.inc [Slave_SQL_Running_State] include/stop_slave.inc -include/assert.inc [Table t1 should have 5 rows.] +select count(*) 'on slave must be 5' from t1; +on slave must be 5 +5 SELECT @@GLOBAL.gtid_current_pos; @@GLOBAL.gtid_current_pos 0-2-7 @@ -132,7 +138,9 @@ SELECT @@GLOBAL.gtid_current_pos; connection server_2; # Ensuring variable rpl_semi_sync_slave_enabled is ON.. # Ensuring status rpl_semi_sync_slave_status is OFF.. -include/assert.inc [Table t1 should have 3 rows.] +select count(*) 'on master must be 3' from t1; +on master must be 3 +3 FOUND 1 /truncated binlog file:.*slave.*000002.* to remove transactions starting from GTID 0-1-6/ in mysqld.2.err disconnect conn_client; connection server_1; @@ -159,9 +167,9 @@ SHOW VARIABLES LIKE 'gtid_slave_pos'; Variable_name Value gtid_slave_pos 0-2-7 connection server_2; -SELECT COUNT(*) = 6 as 'true' FROM t1; -true -1 +SELECT COUNT(*) 'must be 6 as' FROM t1; +must be 6 as +6 # ... the gtid states on the slave: SHOW VARIABLES LIKE 'gtid_slave_pos'; Variable_name Value @@ -205,7 +213,9 @@ SET DEBUG_SYNC= "now WAIT_FOR con3_ready"; connection server_2; include/wait_for_slave_param.inc [Slave_SQL_Running_State] include/stop_slave.inc -include/assert.inc [Table t1 should have 7 rows.] +select count(*) 'on slave must be 7' from t1; +on slave must be 7 +7 SELECT @@GLOBAL.gtid_current_pos; @@GLOBAL.gtid_current_pos 0-1-9 @@ -213,7 +223,9 @@ SELECT @@GLOBAL.gtid_current_pos; connection server_1; # Ensuring variable rpl_semi_sync_slave_enabled is ON.. # Ensuring status rpl_semi_sync_slave_status is OFF.. -include/assert.inc [Table t1 should have 6 rows.] +select count(*) 'on master must be 6' from t1; +on master must be 6 +6 FOUND 1 /truncated binlog file:.*master.*000002.* to remove transactions starting from GTID 0-1-9/ in mysqld.1.err disconnect conn_client; connection server_2; @@ -242,9 +254,9 @@ Variable_name Value gtid_slave_pos 0-1-9 connection server_1; include/sync_with_master_gtid.inc -SELECT COUNT(*) = 8 as 'true' FROM t1; -true -1 +SELECT COUNT(*) 'must be 8' FROM t1; +must be 8 +8 # ... the gtid states on the slave: SHOW VARIABLES LIKE 'gtid_slave_pos'; Variable_name Value diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc b/mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc index b092d0018b0..5454600edf7 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc +++ b/mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc @@ -68,9 +68,7 @@ source include/wait_for_slave_param.inc; --error 2003 --source include/stop_slave.inc ---let $assert_cond= COUNT(*) = $expected_rows_on_slave FROM t1 ---let $assert_text= Table t1 should have $expected_rows_on_slave rows. ---source include/assert.inc +--eval select count(*) 'on slave must be $expected_rows_on_slave' from t1 SELECT @@GLOBAL.gtid_current_pos; @@ -95,9 +93,7 @@ if (`SELECT strcmp("OFF", "$slave_semi_sync_status") != 0`) --die Slave started with skip-slave-start yet started with rpl_semi_sync_slave_status=ON } ---let $assert_cond= COUNT(*) = $expected_rows_on_master FROM t1 ---let $assert_text= Table t1 should have $expected_rows_on_master rows. ---source include/assert.inc +--eval select count(*) 'on master must be $expected_rows_on_master' from t1 # Check error log for correct messages. let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.$server_to_crash.err; diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync_fail_over.test b/mysql-test/suite/rpl/t/rpl_semi_sync_fail_over.test index e1e7a4f1de3..e4d0bc0acd1 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync_fail_over.test +++ b/mysql-test/suite/rpl/t/rpl_semi_sync_fail_over.test @@ -83,7 +83,7 @@ SHOW VARIABLES LIKE 'gtid_slave_pos'; --connection server_1 --sync_with_master ---eval SELECT COUNT(*) = $rows_so_far as 'true' FROM t1 +--eval SELECT COUNT(*) 'must be $rows_so_far' FROM t1 --echo # ... the gtid states on the slave: SHOW VARIABLES LIKE 'gtid_slave_pos'; SHOW VARIABLES LIKE 'gtid_binlog_pos'; @@ -134,7 +134,7 @@ SHOW VARIABLES LIKE 'gtid_slave_pos'; --connection server_2 --sync_with_master ---eval SELECT COUNT(*) = $rows_so_far as 'true' FROM t1 +--eval SELECT COUNT(*) 'must be $rows_so_far as' FROM t1 --echo # ... the gtid states on the slave: SHOW VARIABLES LIKE 'gtid_slave_pos'; SHOW VARIABLES LIKE 'gtid_binlog_pos'; @@ -185,7 +185,7 @@ SHOW VARIABLES LIKE 'gtid_slave_pos'; --connection server_1 --source include/sync_with_master_gtid.inc ---eval SELECT COUNT(*) = $rows_so_far as 'true' FROM t1 +--eval SELECT COUNT(*) 'must be $rows_so_far' FROM t1 --echo # ... the gtid states on the slave: SHOW VARIABLES LIKE 'gtid_slave_pos'; SHOW VARIABLES LIKE 'gtid_binlog_pos'; From e83d92ee5e0e071e77d7fd0f73964a6bf8948124 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 21 Apr 2024 18:28:15 +0200 Subject: [PATCH 159/159] sporadic failures of rpl.rpl_semi_sync_fail_over in the $case=2 - it's wrong to kill after the first binlog EOF, because that might happen between INSERT(4) and INSERT(5). So, wait for the slave to acknowledge INSERT(5) before killing the master, that is, both connection threads must pass repl_semisync_master.wait_after_sync() --- mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result | 6 ++++-- mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc | 6 ++++-- sql/sql_repl.cc | 6 ------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result b/mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result index 96150209af9..49fdb485c50 100644 --- a/mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result +++ b/mysql-test/suite/rpl/r/rpl_semi_sync_fail_over.result @@ -117,13 +117,15 @@ connection server_2; #================================================================= connect conn_client,127.0.0.1,root,,test,$SERVER_MYPORT_2,; SET DEBUG_SYNC= "commit_before_get_LOCK_commit_ordered SIGNAL con1_ready WAIT_FOR con1_go"; +SET DEBUG_SYNC= "commit_after_release_LOCK_after_binlog_sync WAIT_FOR con1_go1"; SET STATEMENT server_id=1 FOR INSERT INTO t1 VALUES (4, REPEAT("x", 4100)); connect conn_client_2,127.0.0.1,root,,test,$SERVER_MYPORT_2,; SET DEBUG_SYNC= "now WAIT_FOR con1_ready"; -SET GLOBAL debug_dbug="d,Notify_binlog_EOF"; +SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL con1_go"; +SET DEBUG_SYNC= "commit_before_get_LOCK_commit_ordered SIGNAL con2_ready"; INSERT INTO t1 VALUES (5, REPEAT("x", 4100)); connection server_2; -SET DEBUG_SYNC= "now WAIT_FOR eof_reached"; +SET DEBUG_SYNC= "now WAIT_FOR con2_ready"; # Kill the server connection server_1; include/wait_for_slave_param.inc [Slave_SQL_Running_State] diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc b/mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc index 5454600edf7..bb705d390ac 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc +++ b/mysql-test/suite/rpl/t/rpl_semi_sync_crash.inc @@ -34,14 +34,16 @@ if ($case == 1) if ($case == 2) { SET DEBUG_SYNC= "commit_before_get_LOCK_commit_ordered SIGNAL con1_ready WAIT_FOR con1_go"; + SET DEBUG_SYNC= "commit_after_release_LOCK_after_binlog_sync WAIT_FOR con1_go1"; --send_eval $query_to_crash --connect (conn_client_2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) # use the same signal with $query_to_crash SET DEBUG_SYNC= "now WAIT_FOR con1_ready"; - SET GLOBAL debug_dbug="d,Notify_binlog_EOF"; + SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL con1_go"; + SET DEBUG_SYNC= "commit_before_get_LOCK_commit_ordered SIGNAL con2_ready"; --send_eval $query2_to_crash --connection server_$server_to_crash - SET DEBUG_SYNC= "now WAIT_FOR eof_reached"; + SET DEBUG_SYNC= "now WAIT_FOR con2_ready"; --source include/kill_mysqld.inc } diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 6cfb10f6bee..f96f7ac6d21 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -2828,12 +2828,6 @@ static int send_one_binlog_file(binlog_send_info *info, */ if (send_events(info, log, linfo, end_pos)) return 1; - DBUG_EXECUTE_IF("Notify_binlog_EOF", - { - const char act[]= "now signal eof_reached"; - DBUG_ASSERT(!debug_sync_set_action(current_thd, - STRING_WITH_LEN(act))); - };); } return 1;