From 694d91da8969cc9ef8af9b7f9b59947faa82508f Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 9 Dec 2024 08:54:17 +0100 Subject: [PATCH 01/22] MDEV-35604: SIGSEGV in filter_query_type | log_statement_ex / auditing Take into account that filter_query_type can get empty query after skip_set_statement run on incorrect query. --- .../suite/plugins/r/server_audit_pwd_mask.result | 9 +++++++++ .../suite/plugins/t/server_audit_pwd_mask.test | 16 ++++++++++++++++ plugin/server_audit/server_audit.c | 2 ++ 3 files changed, 27 insertions(+) diff --git a/mysql-test/suite/plugins/r/server_audit_pwd_mask.result b/mysql-test/suite/plugins/r/server_audit_pwd_mask.result index ce90230f1ea..8068bbcf4d8 100644 --- a/mysql-test/suite/plugins/r/server_audit_pwd_mask.result +++ b/mysql-test/suite/plugins/r/server_audit_pwd_mask.result @@ -30,4 +30,13 @@ DROP USER u2; set global server_audit_logging=off; UNINSTALL PLUGIN ed25519; UNINSTALL PLUGIN server_audit; +# +# MDEV-35604: SIGSEGV in filter_query_type | log_statement_ex / auditing +# +INSTALL PLUGIN server_audit SONAME 'server_audit'; +SET GLOBAL server_audit_logging=ON; +SET STATEMENT max_error_count=1 SELECT 1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT 1' at line 1 +SET GLOBAL server_audit_logging=OFF; +UNINSTALL SONAME 'server_audit'; # end of 10.5 tests diff --git a/mysql-test/suite/plugins/t/server_audit_pwd_mask.test b/mysql-test/suite/plugins/t/server_audit_pwd_mask.test index b393e22d11e..fe660795ab3 100644 --- a/mysql-test/suite/plugins/t/server_audit_pwd_mask.test +++ b/mysql-test/suite/plugins/t/server_audit_pwd_mask.test @@ -56,4 +56,20 @@ UNINSTALL PLUGIN ed25519; UNINSTALL PLUGIN server_audit; --enable_warnings +--echo # +--echo # MDEV-35604: SIGSEGV in filter_query_type | log_statement_ex / auditing +--echo # + +INSTALL PLUGIN server_audit SONAME 'server_audit'; +SET GLOBAL server_audit_logging=ON; + +--ERROR ER_PARSE_ERROR +SET STATEMENT max_error_count=1 SELECT 1; + +# Cleanup +SET GLOBAL server_audit_logging=OFF; +--disable_warnings +UNINSTALL SONAME 'server_audit'; +--enable_warnings + --echo # end of 10.5 tests diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index 0f1a53183a3..8b49f354f47 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -1765,6 +1765,8 @@ static int filter_query_type(const char *query, struct sa_keyword *kwd) char fword[MAX_KEYWORD + 1], nword[MAX_KEYWORD + 1]; int len, nlen= 0; const struct sa_keyword *l_keywords; + if (!query) + return SQLCOM_NOTHING; while (*query && (is_space(*query) || *query == '(' || *query == '/')) { From d92d271648db812f89071594b8178145e10e2b83 Mon Sep 17 00:00:00 2001 From: Dave Gosselin Date: Mon, 15 Apr 2024 15:17:30 -0400 Subject: [PATCH 02/22] MDEV-35583 Tests failing on macOS These tests rely on THR_KEY_mysys but it is not initialized. On Linux, the corresponding thread variable is null, but on macOS it has a nonzero value. In all cases, initialize the variable explicitly by calling MY_INIT and my_end appropriately. --- unittest/mysys/dynstring-t.c | 5 ++++- unittest/sql/my_json_writer-t.cc | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/unittest/mysys/dynstring-t.c b/unittest/mysys/dynstring-t.c index 194d435dfff..32a6b2a50e3 100644 --- a/unittest/mysys/dynstring-t.c +++ b/unittest/mysys/dynstring-t.c @@ -26,8 +26,10 @@ static void check(const char *res) str1.length= 0; } -int main(void) +int main(int argc, char** argv) { + MY_INIT(argv[0]); + plan(23); IF_WIN(skip_all("Test of POSIX shell escaping rules, not for CMD.EXE\n"), ); @@ -69,6 +71,7 @@ int main(void) dynstr_free(&str1); + my_end(MY_CHECK_ERROR); return exit_status(); } diff --git a/unittest/sql/my_json_writer-t.cc b/unittest/sql/my_json_writer-t.cc index 6398a589c33..5b295980b53 100644 --- a/unittest/sql/my_json_writer-t.cc +++ b/unittest/sql/my_json_writer-t.cc @@ -51,6 +51,8 @@ public: int main(int args, char **argv) { + MY_INIT(argv[0]); + plan(NO_PLAN); diag("Testing Json_writer checks"); @@ -123,6 +125,7 @@ int main(int args, char **argv) diag("Done"); + my_end(MY_CHECK_ERROR); return exit_status(); } From bf7cfa2535618bfe9962c725555680e799fdcd18 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 5 Dec 2024 15:31:40 +1100 Subject: [PATCH 03/22] MDEV-35574 remove obsolete pthread_exit calls Threads can normally exit without a explicit pthread_exit call. There seem to date to old glibc bugs, many around 2.2.5. The semi related bug was https://bugs.mysql.com/bug.php?id=82886. To improve safety in the signal handlers DBUG_* code was removed. These where also needed to avoid some MSAN unresolved stack issues. This is effectively a backport of 2719cc4925c032f483edb0e61c0f487e0c429ae6. --- client/mysqlimport.c | 1 - client/mysqltest.cc | 1 - mysys/thr_alarm.c | 3 +-- mysys/thr_timer.c | 3 +-- plugin/feedback/sender_thread.cc | 1 - sql/mysqld.cc | 7 +------ storage/mroonga/vendor/groonga/src/groonga_benchmark.c | 7 +------ tests/thread_test.c | 1 - unittest/mysys/stack_allocation-t.c | 1 - unittest/sql/my_apc-t.cc | 1 - 10 files changed, 4 insertions(+), 22 deletions(-) diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 405eda8cc10..687fd8c2061 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -631,7 +631,6 @@ error: pthread_cond_signal(&count_threshhold); pthread_mutex_unlock(&counter_mutex); mysql_thread_end(); - pthread_exit(0); return 0; } diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 71025814fcf..becb411947f 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -991,7 +991,6 @@ end_thread: cn->mysql= 0; cn->query_done= 1; mysql_thread_end(); - pthread_exit(0); DBUG_RETURN(0); } diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index af22e7cc45c..6a3bc153462 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -566,8 +566,7 @@ static void *alarm_handler(void *arg __attribute__((unused))) alarm_thread_running= 0; mysql_cond_signal(&COND_alarm); mysql_mutex_unlock(&LOCK_alarm); - pthread_exit(0); - return 0; /* Impossible */ + return 0; } #endif /* USE_ALARM_THREAD */ #endif diff --git a/mysys/thr_timer.c b/mysys/thr_timer.c index 00fc74cdf77..6e9e5a421e0 100644 --- a/mysys/thr_timer.c +++ b/mysys/thr_timer.c @@ -330,8 +330,7 @@ static void *timer_handler(void *arg __attribute__((unused))) } mysql_mutex_unlock(&LOCK_timer); my_thread_end(); - pthread_exit(0); - return 0; /* Impossible */ + return 0; } diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index 68aaa4c5dc7..453f367c289 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -290,7 +290,6 @@ pthread_handler_t background_thread(void *arg __attribute__((unused))) } my_thread_end(); - pthread_exit(0); return 0; } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index dd2d9df4c1c..a9fa24c2064 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2948,7 +2948,6 @@ pthread_handler_t signal_hand(void *) sigset_t set; int sig; my_thread_init(); // Init new thread - DBUG_ENTER("signal_hand"); signal_thread_in_use= 1; /* @@ -3014,7 +3013,6 @@ pthread_handler_t signal_hand(void *) /* switch to the old log message processing */ logger.set_handlers(global_system_variables.sql_log_slow ? LOG_FILE:LOG_NONE, opt_log ? LOG_FILE:LOG_NONE); - DBUG_PRINT("info",("Got signal: %d abort_loop: %d",sig,abort_loop)); break_connect_loop(); DBUG_ASSERT(abort_loop); @@ -3050,12 +3048,9 @@ pthread_handler_t signal_hand(void *) break; /* purecov: tested */ } } - DBUG_PRINT("quit", ("signal_handler: calling my_thread_end()")); my_thread_end(); - DBUG_LEAVE; // Must match DBUG_ENTER() signal_thread_in_use= 0; - pthread_exit(0); // Safety - return(0); /* purecov: deadcode */ + return nullptr; } static void check_data_home(const char *path) diff --git a/storage/mroonga/vendor/groonga/src/groonga_benchmark.c b/storage/mroonga/vendor/groonga/src/groonga_benchmark.c index 267bb278764..a4918137d4f 100644 --- a/storage/mroonga/vendor/groonga/src/groonga_benchmark.c +++ b/storage/mroonga/vendor/groonga/src/groonga_benchmark.c @@ -271,12 +271,7 @@ error_exit_in_thread(intptr_t code) CRITICAL_SECTION_ENTER(grntest_cs); grntest_stop_flag = 1; CRITICAL_SECTION_LEAVE(grntest_cs); -#ifdef WIN32 - _endthreadex(code); -#else - pthread_exit((void *)code); -#endif /* WIN32 */ - return 0; + return code; } diff --git a/tests/thread_test.c b/tests/thread_test.c index d0c33b47b9c..a26e69bdf75 100644 --- a/tests/thread_test.c +++ b/tests/thread_test.c @@ -70,7 +70,6 @@ end: thread_count--; pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */ pthread_mutex_unlock(&LOCK_thread_count); - pthread_exit(0); return 0; } diff --git a/unittest/mysys/stack_allocation-t.c b/unittest/mysys/stack_allocation-t.c index 2b044c80f42..23b75a8f148 100644 --- a/unittest/mysys/stack_allocation-t.c +++ b/unittest/mysys/stack_allocation-t.c @@ -91,7 +91,6 @@ pthread_handler_t thread_stack_check(void *arg __attribute__((unused))) test_stack_detection(1, STACK_ALLOC_SMALL_BLOCK_SIZE-1); test_stack_detection(2, STACK_ALLOC_SMALL_BLOCK_SIZE+1); my_thread_end(); - pthread_exit(0); return 0; } diff --git a/unittest/sql/my_apc-t.cc b/unittest/sql/my_apc-t.cc index 8fb9181377a..c91a5015b6e 100644 --- a/unittest/sql/my_apc-t.cc +++ b/unittest/sql/my_apc-t.cc @@ -108,7 +108,6 @@ void *test_apc_service_thread(void *ptr) apc_target.destroy(); mysql_mutex_destroy(&target_mutex); my_thread_end(); - pthread_exit(0); return NULL; } From 807e4f320fe5e4531fbc178552b8c30f09a7d2df Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 10 Dec 2024 18:00:37 +1100 Subject: [PATCH 04/22] Change my_umask{,_dir} to mode_t and remove os_innodb_umask MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit os_innodb_umask was of the incorrect type resulting in warnings in clang-19. The correct type is mode_t. As os_innodb_umask was set during innnodb_init from my_umask, corrected the type there along with its companion my_umask_dir. Because of this, the defaults mask values in innodb never had an effect. The resulting change allow found signed differences in my_create{,_nosymlink}, open_nosymlinks: mysys/my_create.c:47:20: error: operand of ?: changes signedness from ‘int’ to ‘mode_t’ {aka ‘unsigned int’} due to unsignedness of other operand [-Werror=sign-compare] 47 | CreateFlags ? CreateFlags : my_umask); Ref: clang-19 warnings: [55/123] Building CXX object storage/innobase/CMakeFiles/innobase.dir/os/os0file.cc.o storage/innobase/os/os0file.cc:1075:46: warning: implicit conversion loses integer precision: 'ulint' (aka 'unsigned long') to 'mode_t' (aka 'unsigned int') [-Wshorten-64-to-32] 1075 | file = open(name, create_flag | O_CLOEXEC, os_innodb_umask); | ~~~~ ^~~~~~~~~~~~~~~ storage/innobase/os/os0file.cc:1249:46: warning: implicit conversion loses integer precision: 'ulint' (aka 'unsigned long') to 'mode_t' (aka 'unsigned int') [-Wshorten-64-to-32] 1249 | file = open(name, create_flag | O_CLOEXEC, os_innodb_umask); | ~~~~ ^~~~~~~~~~~~~~~ storage/innobase/os/os0file.cc:1381:45: warning: implicit conversion loses integer precision: 'ulint' (aka 'unsigned long') to 'mode_t' (aka 'unsigned int') [-Wshorten-64-to-32] 1381 | file = open(name, create_flag | O_CLOEXEC, os_innodb_umask); | ~~~~ ^~~~~~~~~~~~~~~ --- include/my_sys.h | 10 +++++----- mysys/my_create.c | 4 ++-- mysys/my_init.c | 8 ++++---- mysys/my_open.c | 2 +- mysys/my_static.c | 2 +- mysys/my_symlink2.c | 2 +- storage/innobase/handler/ha_innodb.cc | 2 -- storage/innobase/include/os0file.h | 5 ----- storage/innobase/os/os0file.cc | 28 +++------------------------ 9 files changed, 17 insertions(+), 46 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index d1a0394086c..856640a3a90 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -246,9 +246,9 @@ extern void (*my_sigtstp_cleanup)(void), /* Executed before jump to shell */ (*my_sigtstp_restart)(void); /* Executed when coming from shell */ -extern MYSQL_PLUGIN_IMPORT int my_umask; /* Default creation mask */ -extern int my_umask_dir, - my_recived_signals, /* Signals we have got */ +extern MYSQL_PLUGIN_IMPORT mode_t my_umask; /* Default creation mask */ +extern mode_t my_umask_dir; +extern int my_recived_signals, /* Signals we have got */ my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */ my_dont_interrupt; /* call remember_intr when set */ extern MYSQL_PLUGIN_IMPORT my_bool my_use_symdir; @@ -609,7 +609,7 @@ extern File my_open(const char *FileName,int Flags,myf MyFlags); extern File my_register_filename(File fd, const char *FileName, enum file_type type_of_file, uint error_message_number, myf MyFlags); -extern File my_create(const char *FileName,int CreateFlags, +extern File my_create(const char *FileName, mode_t CreateFlags, int AccessFlags, myf MyFlags); extern int my_close(File Filedes,myf MyFlags); extern int my_mkdir(const char *dir, int Flags, myf MyFlags); @@ -617,7 +617,7 @@ extern int my_readlink(char *to, const char *filename, myf MyFlags); extern int my_is_symlink(const char *filename); extern int my_realpath(char *to, const char *filename, myf MyFlags); extern File my_create_with_symlink(const char *linkname, const char *filename, - int createflags, int access_flags, + mode_t createflags, int access_flags, myf MyFlags); extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags); extern int my_symlink(const char *content, const char *linkname, myf MyFlags); diff --git a/mysys/my_create.c b/mysys/my_create.c index 6fb817da8df..32cc73a53c4 100644 --- a/mysys/my_create.c +++ b/mysys/my_create.c @@ -33,12 +33,12 @@ */ -File my_create(const char *FileName, int CreateFlags, int access_flags, +File my_create(const char *FileName, mode_t CreateFlags, int access_flags, myf MyFlags) { int fd; DBUG_ENTER("my_create"); - DBUG_PRINT("my",("Name: '%s' CreateFlags: %d AccessFlags: %d MyFlags: %lu", + DBUG_PRINT("my",("Name: '%s' CreateFlags: %u AccessFlags: %d MyFlags: %lu", FileName, CreateFlags, access_flags, MyFlags)); #if defined(_WIN32) fd= my_win_open(FileName, access_flags | O_CREAT); diff --git a/mysys/my_init.c b/mysys/my_init.c index 2b420da03be..fcb3ccfdf31 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -45,7 +45,7 @@ uint mysys_usage_id= 0; /* Incremented for each my_init() */ ulonglong my_thread_stack_size= (sizeof(void*) <= 4)? 65536: ((256-16)*1024); -static ulong atoi_octal(const char *str) +static mode_t atoi_octal(const char *str) { long int tmp; while (*str && my_isspace(&my_charset_latin1, *str)) @@ -53,7 +53,7 @@ static ulong atoi_octal(const char *str) str2int(str, (*str == '0' ? 8 : 10), /* Octalt or decimalt */ 0, INT_MAX, &tmp); - return (ulong) tmp; + return (mode_t) tmp; } MYSQL_FILE *mysql_stdin= NULL; @@ -82,10 +82,10 @@ my_bool my_init(void) /* Default creation of new files */ if ((str= getenv("UMASK")) != 0) - my_umask= (int) (atoi_octal(str) | 0600); + my_umask= atoi_octal(str) | 0600; /* Default creation of new dir's */ if ((str= getenv("UMASK_DIR")) != 0) - my_umask_dir= (int) (atoi_octal(str) | 0700); + my_umask_dir= atoi_octal(str) | 0700; init_glob_errs(); diff --git a/mysys/my_open.c b/mysys/my_open.c index 8b5f4f9435e..c39539342d9 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -20,7 +20,7 @@ #include "my_atomic.h" CREATE_NOSYMLINK_FUNCTION( - open_nosymlinks(const char *pathname, int flags, int mode), + open_nosymlinks(const char *pathname, int flags, mode_t mode), openat(dfd, filename, O_NOFOLLOW | flags, mode), open(pathname, O_NOFOLLOW | flags, mode) ); diff --git a/mysys/my_static.c b/mysys/my_static.c index 6c09ab8d94b..1e54c4c93b2 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -63,7 +63,7 @@ char curr_dir[FN_REFLEN]= {0}, home_dir_buff[FN_REFLEN]= {0}; ulong my_stream_opened=0,my_tmp_file_created=0; ulong my_file_total_opened= 0; -int my_umask=0664, my_umask_dir=0777; +mode_t my_umask=0664, my_umask_dir=0777; myf my_global_flags= 0; #ifndef DBUG_OFF diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c index 0b580ecd32f..d9b31e3dfaf 100644 --- a/mysys/my_symlink2.c +++ b/mysys/my_symlink2.c @@ -26,7 +26,7 @@ #include File my_create_with_symlink(const char *linkname, const char *filename, - int createflags, int access_flags, myf MyFlags) + mode_t createflags, int access_flags, myf MyFlags) { File file; int tmp_errno; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 68d486b9457..ad0f894f924 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -4024,8 +4024,6 @@ static int innodb_init(void* p) test_filename)); #endif /* DBUG_OFF */ - os_file_set_umask(my_umask); - /* Setup the memory alloc/free tracing mechanisms before calling any functions that could possibly allocate memory. */ ut_new_boot(); diff --git a/storage/innobase/include/os0file.h b/storage/innobase/include/os0file.h index 43320515fbd..e3dc5d16c8e 100644 --- a/storage/innobase/include/os0file.h +++ b/storage/innobase/include/os0file.h @@ -1135,11 +1135,6 @@ os_file_get_status( bool check_rw_perm, bool read_only); -/** Set the file create umask -@param[in] umask The umask to use for file creation. */ -void -os_file_set_umask(ulint umask); - #ifdef _WIN32 /** diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index f33797305dc..012f23b3b8d 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -140,18 +140,6 @@ static io_slots *write_slots; /** Number of retries for partial I/O's */ constexpr ulint NUM_RETRIES_ON_PARTIAL_IO = 10; -/* This specifies the file permissions InnoDB uses when it creates files in -Unix; the value of os_innodb_umask is initialized in ha_innodb.cc to -my_umask */ - -#ifndef _WIN32 -/** Umask for creating files */ -static ulint os_innodb_umask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; -#else -/** Umask for creating files */ -static ulint os_innodb_umask = 0; -#endif /* _WIN32 */ - Atomic_counter os_n_file_reads; static ulint os_bytes_read_since_printout; ulint os_n_file_writes; @@ -1072,7 +1060,7 @@ os_file_create_simple_func( bool retry; do { - file = open(name, create_flag | O_CLOEXEC, os_innodb_umask); + file = open(name, create_flag | O_CLOEXEC, my_umask); if (file == -1) { *success = false; @@ -1246,7 +1234,7 @@ os_file_create_func( bool retry; do { - file = open(name, create_flag | O_CLOEXEC, os_innodb_umask); + file = open(name, create_flag | O_CLOEXEC, my_umask); if (file == -1) { const char* operation; @@ -1378,7 +1366,7 @@ os_file_create_simple_no_error_handling_func( return(OS_FILE_CLOSED); } - file = open(name, create_flag | O_CLOEXEC, os_innodb_umask); + file = open(name, create_flag | O_CLOEXEC, my_umask); *success = (file != -1); @@ -3861,16 +3849,6 @@ os_aio_refresh_stats() os_last_printout = time(NULL); } - -/** -Set the file create umask -@param[in] umask The umask to use for file creation. */ -void -os_file_set_umask(ulint umask) -{ - os_innodb_umask = umask; -} - #ifdef _WIN32 /* Checks whether physical drive is on SSD.*/ From bfe7c8ff0ae2c18b38ee823d95d64e6ab60356af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 11 Dec 2024 14:44:42 +0200 Subject: [PATCH 05/22] MDEV-35494 fil_space_t::fil_space_t() may be unsafe with GCC -flifetime-dse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fil_space_t::create(): Instead of invoking the default fil_space_t constructor on a zero-filled buffer, allocate an uninitialized buffer and invoke an explicitly defined constructor on it. Also, specify initializer expressions for all constant data members, so that all of them will be initialized in the constructor. fil_space_t::being_imported: Replaces part of fil_space_t::purpose. fil_space_t::is_being_imported(), fil_space_t::is_temporary(): Replaces fil_space_t::purpose. fil_space_t::id: Changed the type from ulint to uint32_t to reduce incompatibility with later branches that include commit ca501ffb04246dcaa1f1d433d916d8436e30602e (MDEV-26195). fil_space_t::try_to_close(): Do not attempt to close files that are in an I/O bound phase of ALTER TABLE…IMPORT TABLESPACE. log_file_op, first_page_init: recv_spaces_t: Use uint32_t for the tablespace id. Reviewed by: Debarun Banerjee --- extra/mariabackup/xtrabackup.cc | 50 ++--- storage/innobase/buf/buf0buf.cc | 5 +- storage/innobase/buf/buf0dblwr.cc | 3 +- storage/innobase/buf/buf0flu.cc | 20 +- storage/innobase/dict/dict0load.cc | 10 +- storage/innobase/dict/dict0mem.cc | 3 - storage/innobase/fil/fil0crypt.cc | 12 +- storage/innobase/fil/fil0fil.cc | 285 ++++++++++----------------- storage/innobase/fsp/fsp0fsp.cc | 11 +- storage/innobase/fsp/fsp0space.cc | 6 +- storage/innobase/fsp/fsp0sysspace.cc | 6 +- storage/innobase/handler/i_s.cc | 7 +- storage/innobase/ibuf/ibuf0ibuf.cc | 11 +- storage/innobase/include/fil0fil.h | 189 +++++++++--------- storage/innobase/include/log0recv.h | 8 +- storage/innobase/log/log0recv.cc | 20 +- storage/innobase/mtr/mtr0mtr.cc | 6 +- storage/innobase/os/os0file.cc | 14 +- storage/innobase/row/row0import.cc | 11 +- storage/innobase/srv/srv0start.cc | 6 +- storage/innobase/trx/trx0sys.cc | 3 +- 21 files changed, 310 insertions(+), 376 deletions(-) diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index d7860627717..8aeeb7d7e9f 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -730,13 +730,15 @@ datafiles_iter_next(datafiles_iter_t *it) fil_system.space_list.begin() : std::next(it->space); - while (it->space != fil_system.space_list.end() && - (it->space->purpose != FIL_TYPE_TABLESPACE || - UT_LIST_GET_LEN(it->space->chain) == 0)) + while (it->space != fil_system.space_list.end() + && UT_LIST_GET_LEN(it->space->chain) == 0) ++it->space; if (it->space == fil_system.space_list.end()) goto end; + ut_ad(!it->space->is_temporary()); + ut_ad(!it->space->is_being_imported()); + it->node = UT_LIST_GET_FIRST(it->space->chain); end: @@ -907,7 +909,7 @@ err: @param[in] len length of name, in bytes @param[in] new_name new file name (NULL if not rename) @param[in] new_len length of new_name, in bytes (0 if NULL) */ -static void backup_file_op(ulint space_id, int type, +static void backup_file_op(uint32_t space_id, int type, const byte* name, ulint len, const byte* new_name, ulint new_len) { @@ -923,7 +925,8 @@ static void backup_file_op(ulint space_id, int type, std::string space_name = filename_to_spacename(name, len); ddl_tracker.id_to_name[space_id] = space_name; ddl_tracker.delete_defer(space_id, space_name); - msg("DDL tracking : create %zu \"%.*s\"", space_id, int(len), name); + msg("DDL tracking : create %" PRIu32 " \"%.*s\"", + space_id, int(len), name); } break; case FILE_MODIFY: @@ -939,7 +942,7 @@ static void backup_file_op(ulint space_id, int type, ddl_tracker.id_to_name[space_id] = new_space_name; ddl_tracker.rename_defer(space_id, old_space_name, new_space_name); - msg("DDL tracking : rename %zu \"%.*s\",\"%.*s\"", + msg("DDL tracking : rename %" PRIu32 " \"%.*s\",\"%.*s\"", space_id, int(len), name, int(new_len), new_name); } break; @@ -947,7 +950,8 @@ static void backup_file_op(ulint space_id, int type, ddl_tracker.drops.insert(space_id); ddl_tracker.delete_defer( space_id, filename_to_spacename(name, len)); - msg("DDL tracking : delete %zu \"%.*s\"", space_id, int(len), name); + msg("DDL tracking : delete %" PRIu32 " \"%.*s\"", + space_id, int(len), name); break; default: ut_ad(0); @@ -966,21 +970,22 @@ static void backup_file_op(ulint space_id, int type, We will abort backup in this case. */ -static void backup_file_op_fail(ulint space_id, int type, +static void backup_file_op_fail(uint32_t space_id, int type, const byte* name, ulint len, const byte* new_name, ulint new_len) { bool fail = false; switch(type) { case FILE_CREATE: - msg("DDL tracking : create %zu \"%.*s\"", space_id, int(len), name); + msg("DDL tracking : create %" PRIu32 " \"%.*s\"", + space_id, int(len), name); fail = !check_if_skip_table( filename_to_spacename(name, len).c_str()); break; case FILE_MODIFY: break; case FILE_RENAME: - msg("DDL tracking : rename %zu \"%.*s\",\"%.*s\"", + msg("DDL tracking : rename %" PRIu32 " \"%.*s\",\"%.*s\"", space_id, int(len), name, int(new_len), new_name); fail = !check_if_skip_table( filename_to_spacename(name, len).c_str()) @@ -990,7 +995,8 @@ static void backup_file_op_fail(ulint space_id, int type, case FILE_DELETE: fail = !check_if_skip_table( filename_to_spacename(name, len).c_str()); - msg("DDL tracking : delete %zu \"%.*s\"", space_id, int(len), name); + msg("DDL tracking : delete %" PRIu32 " \"%.*s\"", + space_id, int(len), name); break; default: ut_ad(0); @@ -1011,7 +1017,7 @@ static void backup_undo_trunc(uint32_t space_id) /* Function to store the space id of page0 INIT_PAGE @param space_id space id which has page0 init page */ -static void backup_first_page_op(ulint space_id) +static void backup_first_page_op(uint32_t space_id) { first_page_init_ids.insert(space_id); } @@ -3532,8 +3538,8 @@ static void xb_load_single_table_tablespace(const char *dirname, if (err == DB_SUCCESS && file->space_id() != SRV_TMP_SPACE_ID) { mysql_mutex_lock(&fil_system.mutex); space = fil_space_t::create( - file->space_id(), file->flags(), - FIL_TYPE_TABLESPACE, nullptr/* TODO: crypt_data */, + uint32_t(file->space_id()), file->flags(), false, + nullptr/* TODO: crypt_data */, FIL_ENCRYPTION_DEFAULT, file->handle() != OS_FILE_CLOSED); ut_ad(space); @@ -4998,8 +5004,8 @@ void CorruptedPages::backup_fix_ddl(ds_ctxt *ds_data, ds_ctxt *ds_meta) iter != ddl_tracker.tables_in_backup.end(); iter++) { - const std::string name = iter->second; - ulint id = iter->first; + uint32_t id = iter->first; + const std::string &name = iter->second; if (ddl_tracker.drops.find(id) != ddl_tracker.drops.end()) { dropped_tables.insert(name); @@ -5025,8 +5031,8 @@ void CorruptedPages::backup_fix_ddl(ds_ctxt *ds_data, ds_ctxt *ds_meta) iter != ddl_tracker.id_to_name.end(); iter++) { - ulint id = iter->first; - std::string name = iter->second; + uint32_t id = iter->first; + const std::string &name = iter->second; if (ddl_tracker.tables_in_backup.find(id) != ddl_tracker.tables_in_backup.end()) { /* already processed above */ @@ -5322,8 +5328,8 @@ exit: char tmpname[FN_REFLEN]; - snprintf(tmpname, FN_REFLEN, "%s/xtrabackup_tmp_#" ULINTPF, - dbname, fil_space->id); + snprintf(tmpname, FN_REFLEN, "%s/xtrabackup_tmp_#%" + PRIu32, dbname, fil_space->id); msg("mariabackup: Renaming %s to %s.ibd", fil_space->chain.start->name, tmpname); @@ -5378,8 +5384,8 @@ exit: ut_ad(fil_space_t::physical_size(flags) == info.page_size); mysql_mutex_lock(&fil_system.mutex); - fil_space_t* space = fil_space_t::create(info.space_id, flags, - FIL_TYPE_TABLESPACE, 0, + fil_space_t* space = fil_space_t::create(uint32_t(info.space_id), + flags, false, 0, FIL_ENCRYPTION_DEFAULT, true); mysql_mutex_unlock(&fil_system.mutex); if (space) { diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index ae604f0826c..4cc3cdf38c4 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -3643,8 +3643,7 @@ static dberr_t buf_page_check_corrupt(buf_page_t *bpage, const bool seems_encrypted = !node.space->full_crc32() && key_version && node.space->crypt_data && node.space->crypt_data->type != CRYPT_SCHEME_UNENCRYPTED; - ut_ad(node.space->purpose != FIL_TYPE_TEMPORARY || - node.space->full_crc32()); + ut_ad(!node.space->is_temporary() || node.space->full_crc32()); /* If traditional checksums match, we assume that page is not anymore encrypted. */ @@ -3652,7 +3651,7 @@ static dberr_t buf_page_check_corrupt(buf_page_t *bpage, && !buf_is_zeroes(span(dst_frame, node.space->physical_size())) && (key_version || node.space->is_compressed() - || node.space->purpose == FIL_TYPE_TEMPORARY)) { + || node.space->is_temporary())) { if (buf_page_full_crc32_is_corrupted( bpage->id().space(), dst_frame, node.space->is_compressed())) { diff --git a/storage/innobase/buf/buf0dblwr.cc b/storage/innobase/buf/buf0dblwr.cc index 31036bf978d..0060ee29fd9 100644 --- a/storage/innobase/buf/buf0dblwr.cc +++ b/storage/innobase/buf/buf0dblwr.cc @@ -750,7 +750,8 @@ void buf_dblwr_t::add_to_batch(const IORequest &request, size_t size) ut_ad(request.bpage); ut_ad(request.bpage->in_file()); ut_ad(request.node); - ut_ad(request.node->space->purpose == FIL_TYPE_TABLESPACE); + ut_ad(!request.node->space->is_temporary()); + ut_ad(!request.node->space->is_being_imported()); ut_ad(request.node->space->id == request.bpage->id().space()); ut_ad(request.node->space->referenced()); ut_ad(!srv_read_only_mode); diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index a513f2499f6..024866f4f75 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -639,7 +639,7 @@ static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s, fil_space_crypt_t *crypt_data= space->crypt_data; bool encrypted, page_compressed; - if (space->purpose == FIL_TYPE_TEMPORARY) + if (space->is_temporary()) { ut_ad(!crypt_data); encrypted= innodb_encrypt_temporary_tables; @@ -685,13 +685,13 @@ static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s, if (!page_compressed) { not_compressed: - d= space->purpose == FIL_TYPE_TEMPORARY + d= space->is_temporary() ? buf_tmp_page_encrypt(page_no, s, d) : fil_space_encrypt(space, page_no, s, d); } else { - ut_ad(space->purpose != FIL_TYPE_TEMPORARY); + ut_ad(!space->is_temporary()); /* First we compress the page content */ buf_tmp_reserve_compression_buf(*slot); byte *tmp= (*slot)->comp_buf; @@ -768,8 +768,7 @@ bool buf_page_t::flush(fil_space_t *space) mysql_mutex_assert_not_owner(&buf_pool.flush_list_mutex); ut_ad(in_file()); ut_ad(in_LRU_list); - ut_ad((space->purpose == FIL_TYPE_TEMPORARY) == - (space == fil_system.temp_space)); + ut_ad((space->is_temporary()) == (space == fil_system.temp_space)); ut_ad(space->referenced()); const auto s= state(); @@ -779,12 +778,12 @@ bool buf_page_t::flush(fil_space_t *space) (FIL_PAGE_LSN + (zip.data ? zip.data : frame))); ut_ad(lsn ? lsn >= oldest_modification() || oldest_modification() == 2 - : space->purpose != FIL_TYPE_TABLESPACE); + : (space->is_temporary() || space->is_being_imported())); if (s < UNFIXED) { ut_a(s >= FREED); - if (UNIV_LIKELY(space->purpose == FIL_TYPE_TABLESPACE)) + if (!space->is_temporary() && !space->is_being_imported()) { freed: if (lsn > log_sys.get_flushed_lsn()) @@ -800,7 +799,8 @@ bool buf_page_t::flush(fil_space_t *space) if (UNIV_UNLIKELY(lsn < space->get_create_lsn())) { - ut_ad(space->purpose == FIL_TYPE_TABLESPACE); + ut_ad(!space->is_temporary()); + ut_ad(!space->is_being_imported()); goto freed; } @@ -884,7 +884,7 @@ bool buf_page_t::flush(fil_space_t *space) if ((s & LRU_MASK) == REINIT || !space->use_doublewrite()) { - if (UNIV_LIKELY(space->purpose == FIL_TYPE_TABLESPACE) && + if (!space->is_temporary() && !space->is_being_imported() && lsn > log_sys.get_flushed_lsn()) log_write_up_to(lsn, true); space->io(IORequest{type, this, slot}, physical_offset(), size, @@ -1735,7 +1735,7 @@ done: if (acquired) space->release(); - if (space->purpose == FIL_TYPE_IMPORT) + if (space->is_being_imported()) os_aio_wait_until_no_pending_writes(true); else buf_dblwr.flush_buffered_writes(); diff --git a/storage/innobase/dict/dict0load.cc b/storage/innobase/dict/dict0load.cc index e9efc10f994..917c4d51ee9 100644 --- a/storage/innobase/dict/dict0load.cc +++ b/storage/innobase/dict/dict0load.cc @@ -972,8 +972,10 @@ void dict_check_tablespaces_and_store_max_id(const std::set *spaces) const bool not_dropped{!rec_get_deleted_flag(rec, 0)}; /* Check that the .ibd file exists. */ - if (fil_ibd_open(not_dropped, FIL_TYPE_TABLESPACE, - space_id, dict_tf_to_fsp_flags(flags), + if (fil_ibd_open(space_id, dict_tf_to_fsp_flags(flags), + not_dropped + ? fil_space_t::VALIDATE_NOTHING + : fil_space_t::MAYBE_MISSING, name, filepath)) { } else if (!not_dropped) { } else if (srv_operation == SRV_OPERATION_NORMAL @@ -2291,8 +2293,8 @@ dict_load_tablespace( } table->space = fil_ibd_open( - 2, FIL_TYPE_TABLESPACE, table->space_id, - dict_tf_to_fsp_flags(table->flags), + table->space_id, dict_tf_to_fsp_flags(table->flags), + fil_space_t::VALIDATE_SPACE_ID, {table->name.m_name, strlen(table->name.m_name)}, filepath); if (!table->space) { diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 59189d3e053..9de43abbb17 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -136,9 +136,6 @@ dict_table_t *dict_table_t::create(const span &name, ulint n_cols, ulint n_v_cols, ulint flags, ulint flags2) { - ut_ad(!space || space->purpose == FIL_TYPE_TABLESPACE || - space->purpose == FIL_TYPE_TEMPORARY || - space->purpose == FIL_TYPE_IMPORT); ut_a(dict_tf2_is_valid(flags, flags2)); ut_a(!(flags2 & DICT_TF2_UNUSED_BIT_MASK)); diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index ddfa6440680..842f79569d9 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -1067,7 +1067,8 @@ default_encrypt_list only when default encrypt */ static bool fil_crypt_must_remove(const fil_space_t &space) { - ut_ad(space.purpose == FIL_TYPE_TABLESPACE); + ut_ad(!space.is_temporary()); + ut_ad(!space.is_being_imported()); fil_space_crypt_t *crypt_data = space.crypt_data; mysql_mutex_assert_owner(&fil_system.mutex); const ulong encrypt_tables= srv_encrypt_tables; @@ -1103,7 +1104,8 @@ fil_crypt_space_needs_rotation( fil_space_t* space = &*state->space; ut_ad(space->referenced()); - ut_ad(space->purpose == FIL_TYPE_TABLESPACE); + ut_ad(!space->is_temporary()); + ut_ad(!space->is_being_imported()); fil_space_crypt_t *crypt_data = space->crypt_data; @@ -1455,7 +1457,7 @@ space_list_t::iterator fil_space_t::next(space_list_t::iterator space, for (; space != fil_system.space_list.end(); ++space) { - if (space->purpose != FIL_TYPE_TABLESPACE) + if (space->is_temporary() || space->is_being_imported()) continue; const uint32_t n= space->acquire_low(); if (UNIV_LIKELY(!(n & (STOPPING | CLOSING)))) @@ -2137,9 +2139,9 @@ static void fil_crypt_default_encrypt_tables_fill() mysql_mutex_assert_owner(&fil_system.mutex); for (fil_space_t& space : fil_system.space_list) { - if (space.purpose != FIL_TYPE_TABLESPACE - || space.is_in_default_encrypt + if (space.is_in_default_encrypt || UT_LIST_GET_LEN(space.chain) == 0 + || space.is_temporary() || space.is_being_imported() || !space.acquire_if_not_stopped()) { continue; } diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index a682fd533e9..1f72c2bbd1f 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -81,17 +81,10 @@ bool fil_space_t::try_to_close(fil_space_t *ignore_space, bool print_info) mysql_mutex_assert_owner(&fil_system.mutex); for (fil_space_t &space : fil_system.space_list) { - if (&space == ignore_space) + if (&space == ignore_space || space.is_being_imported() || + !fil_is_user_tablespace_id(space.id)) continue; - switch (space.purpose) { - case FIL_TYPE_TEMPORARY: - continue; - case FIL_TYPE_IMPORT: - break; - case FIL_TYPE_TABLESPACE: - if (!fil_is_user_tablespace_id(space.id)) - continue; - } + ut_ad(!space.is_temporary()); /* We are using an approximation of LRU replacement policy. In fil_node_open_file_low(), newly opened files are moved to the end @@ -432,7 +425,7 @@ static bool fil_node_open_file(fil_node_t *node, const byte *page, bool no_lsn) srv_operation == SRV_OPERATION_BACKUP || srv_operation == SRV_OPERATION_RESTORE || srv_operation == SRV_OPERATION_RESTORE_DELTA); - ut_ad(node->space->purpose != FIL_TYPE_TEMPORARY); + ut_ad(!node->space->is_temporary()); ut_ad(node->space->referenced()); const auto old_time= fil_system.n_open_exceeded_time; @@ -493,7 +486,7 @@ void fil_node_t::prepare_to_close_or_detach() srv_operation == SRV_OPERATION_RESTORE_DELTA); ut_a(is_open()); ut_a(!being_extended); - ut_a(space->is_ready_to_close() || space->purpose == FIL_TYPE_TEMPORARY || + ut_a(space->is_ready_to_close() || space->is_temporary() || srv_fast_shutdown == 2 || !srv_was_started); ut_a(fil_system.n_open > 0); @@ -650,14 +643,13 @@ fil_space_extend_must_retry( mysql_mutex_lock(&fil_system.mutex); break; default: - ut_ad(space->purpose == FIL_TYPE_TABLESPACE - || space->purpose == FIL_TYPE_IMPORT); - if (space->purpose == FIL_TYPE_TABLESPACE) { + ut_ad(!space->is_temporary()); + if (!space->is_being_imported()) { goto do_flush; } break; case SRV_TMP_SPACE_ID: - ut_ad(space->purpose == FIL_TYPE_TEMPORARY); + ut_ad(space->is_temporary()); srv_tmp_space.set_last_file_size(pages_in_MiB); break; } @@ -671,8 +663,7 @@ ATTRIBUTE_COLD bool fil_space_t::prepare_acquired() ut_ad(referenced()); mysql_mutex_assert_owner(&fil_system.mutex); fil_node_t *node= UT_LIST_GET_LAST(chain); - ut_ad(!id || purpose == FIL_TYPE_TEMPORARY || - node == UT_LIST_GET_FIRST(chain)); + ut_ad(!id || is_temporary() || node == UT_LIST_GET_FIRST(chain)); const bool is_open= node && (node->is_open() || fil_node_open_file(node, nullptr, false)); @@ -734,7 +725,7 @@ ATTRIBUTE_COLD bool fil_space_t::acquire_and_prepare() @return whether the tablespace is at least as big as requested */ bool fil_space_extend(fil_space_t *space, uint32_t size) { - ut_ad(!srv_read_only_mode || space->purpose == FIL_TYPE_TEMPORARY); + ut_ad(!srv_read_only_mode || space->is_temporary()); bool success= false; const bool acquired= space->acquire(); mysql_mutex_lock(&fil_system.mutex); @@ -942,111 +933,87 @@ fil_space_free( return(space != NULL); } -/** Create a tablespace in fil_system. -@param name tablespace name -@param id tablespace identifier -@param flags tablespace flags -@param purpose tablespace purpose -@param crypt_data encryption information -@param mode encryption mode -@param opened true if space files are opened -@return pointer to created tablespace, to be filled in with add() -@retval nullptr on failure (such as when the same tablespace exists) */ -fil_space_t *fil_space_t::create(ulint id, ulint flags, - fil_type_t purpose, - fil_space_crypt_t *crypt_data, - fil_encryption_t mode, - bool opened) +fil_space_t::fil_space_t(uint32_t id, ulint flags, bool being_imported, + fil_space_crypt_t *crypt_data) noexcept : + id(id), crypt_data(crypt_data), being_imported(being_imported), flags(flags) { - fil_space_t* space; + UT_LIST_INIT(chain, &fil_node_t::chain); +#ifndef SUX_LOCK_GENERIC + memset((void*) &latch, 0, sizeof latch); +#endif + latch.SRW_LOCK_INIT(fil_space_latch_key); +} - mysql_mutex_assert_owner(&fil_system.mutex); - ut_ad(fil_system.is_initialised()); - ut_ad(fil_space_t::is_valid_flags(flags & ~FSP_FLAGS_MEM_MASK, id)); - ut_ad(srv_page_size == UNIV_PAGE_SIZE_ORIG || flags != 0); +fil_space_t *fil_space_t::create(uint32_t id, ulint flags, + bool being_imported, + fil_space_crypt_t *crypt_data, + fil_encryption_t mode, + bool opened) noexcept +{ + mysql_mutex_assert_owner(&fil_system.mutex); + ut_ad(fil_system.is_initialised()); + ut_ad(fil_space_t::is_valid_flags(flags & ~FSP_FLAGS_MEM_MASK, id)); + ut_ad(srv_page_size == UNIV_PAGE_SIZE_ORIG || flags != 0); - DBUG_EXECUTE_IF("fil_space_create_failure", return(NULL);); + DBUG_EXECUTE_IF("fil_space_create_failure", return nullptr;); - fil_space_t** after = reinterpret_cast( - &fil_system.spaces.cell_get(id)->node); - for (; *after; after = &(*after)->hash) { - ut_a((*after)->id != id); - } + fil_space_t** after= fil_system.spaces.cell_get(id)->search + (&fil_space_t::hash, [id](const fil_space_t *space) + { return !space || space->id == id; }); + ut_a(!*after); + fil_space_t *space= new (ut_malloc_nokey(sizeof(*space))) + fil_space_t(id, flags, being_imported, crypt_data); + *after= space; - /* FIXME: if calloc() is defined as an inline function that calls - memset() or bzero(), then GCC 6 -flifetime-dse can optimize it away */ - *after = space = new (ut_zalloc_nokey(sizeof(*space))) fil_space_t; + if (crypt_data) + DBUG_PRINT("crypt", ("Tablespace %" PRIu32 " encryption %d key id %" PRIu32 + ":%s %s", + id, crypt_data->encryption, crypt_data->key_id, + fil_crypt_get_mode(crypt_data), + fil_crypt_get_type(crypt_data))); - space->id = id; + if (opened) + fil_system.add_opened_last_to_space_list(space); + else + fil_system.space_list.push_back(*space); - UT_LIST_INIT(space->chain, &fil_node_t::chain); + switch (id) { + case 0: + ut_ad(!fil_system.sys_space); + fil_system.sys_space= space; + break; + case SRV_TMP_SPACE_ID: + ut_ad(!fil_system.temp_space); + fil_system.temp_space= space; + return space; + default: + if (UNIV_LIKELY(id <= fil_system.max_assigned_id)) + break; + if (UNIV_UNLIKELY(srv_operation == SRV_OPERATION_BACKUP)) + break; + if (!fil_system.space_id_reuse_warned) + sql_print_warning("InnoDB: Allocated tablespace ID %" PRIu32 + ", old maximum was %" PRIu32, + id, fil_system.max_assigned_id); + fil_system.max_assigned_id = id; + } - space->purpose = purpose; - space->flags = flags; + if ((mode == FIL_ENCRYPTION_ON || + (mode == FIL_ENCRYPTION_OFF || srv_encrypt_tables)) && + !space->is_being_imported() && fil_crypt_must_default_encrypt()) + { + fil_system.default_encrypt_tables.push_back(*space); + space->is_in_default_encrypt= true; - space->crypt_data = crypt_data; - space->n_pending.store(CLOSING, std::memory_order_relaxed); + if (srv_n_fil_crypt_threads_started) + { + mysql_mutex_unlock(&fil_system.mutex); + fil_crypt_threads_signal(); + mysql_mutex_lock(&fil_system.mutex); + } + } - DBUG_LOG("tablespace", "Created metadata for " << id); - if (crypt_data) { - DBUG_LOG("crypt", - "Tablespace " << id - << " encryption " << crypt_data->encryption - << " key id " << crypt_data->key_id - << ":" << fil_crypt_get_mode(crypt_data) - << " " << fil_crypt_get_type(crypt_data)); - } - - space->latch.SRW_LOCK_INIT(fil_space_latch_key); - - if (opened) - fil_system.add_opened_last_to_space_list(space); - else - fil_system.space_list.push_back(*space); - - switch (id) { - case 0: - ut_ad(!fil_system.sys_space); - fil_system.sys_space = space; - break; - case SRV_TMP_SPACE_ID: - ut_ad(!fil_system.temp_space); - fil_system.temp_space = space; - break; - default: - ut_ad(purpose != FIL_TYPE_TEMPORARY); - if (UNIV_LIKELY(id <= fil_system.max_assigned_id)) { - break; - } - if (UNIV_UNLIKELY(srv_operation == SRV_OPERATION_BACKUP)) { - break; - } - if (!fil_system.space_id_reuse_warned) { - ib::warn() << "Allocated tablespace ID " << id - << ", old maximum was " - << fil_system.max_assigned_id; - } - - fil_system.max_assigned_id = id; - } - - const bool rotate = purpose == FIL_TYPE_TABLESPACE - && (mode == FIL_ENCRYPTION_ON || mode == FIL_ENCRYPTION_OFF - || srv_encrypt_tables) - && fil_crypt_must_default_encrypt(); - - if (rotate) { - fil_system.default_encrypt_tables.push_back(*space); - space->is_in_default_encrypt = true; - - if (srv_n_fil_crypt_threads_started) { - mysql_mutex_unlock(&fil_system.mutex); - fil_crypt_threads_signal(); - mysql_mutex_lock(&fil_system.mutex); - } - } - - return(space); + return space; } /*******************************************************************//** @@ -1580,6 +1547,7 @@ fil_name_write( fil_space_t *fil_space_t::drop(ulint id, pfs_os_file_t *detached_handle) { ut_a(!is_system_tablespace(id)); + ut_ad(id != SRV_TMP_SPACE_ID); mysql_mutex_lock(&fil_system.mutex); fil_space_t *space= fil_space_get_by_id(id); @@ -1622,7 +1590,7 @@ fil_space_t *fil_space_t::drop(ulint id, pfs_os_file_t *detached_handle) if (space->crypt_data) fil_space_crypt_close_tablespace(space); - if (space->purpose == FIL_TYPE_TABLESPACE) + if (!space->is_being_imported()) { /* Before deleting the file, persistently write a log record. */ mtr_t mtr; @@ -1635,8 +1603,6 @@ fil_space_t *fil_space_t::drop(ulint id, pfs_os_file_t *detached_handle) os_file_delete(innodb_data_file_key, space->chain.start->name); } - else - ut_ad(space->purpose == FIL_TYPE_IMPORT); if (char *cfg_name= fil_make_filepath(space->chain.start->name, fil_space_t::name_type{}, CFG, false)) @@ -1935,7 +1901,7 @@ fil_ibd_create( uint32_t size, fil_encryption_t mode, uint32_t key_id, - dberr_t* err) + dberr_t* err) noexcept { pfs_os_file_t file; bool success; @@ -2055,8 +2021,8 @@ err_exit: log_make_checkpoint();); mysql_mutex_lock(&fil_system.mutex); - if (fil_space_t* space = fil_space_t::create(space_id, flags, - FIL_TYPE_TABLESPACE, + if (fil_space_t* space = fil_space_t::create(uint32_t(space_id), + flags, false, crypt_data, mode, true)) { fil_node_t* node = space->add(path, file, size, false, true); node->find_metadata(IF_WIN(,true)); @@ -2078,51 +2044,17 @@ err_exit: goto err_exit; } -/** Try to open a single-table tablespace and optionally check that the -space id in it is correct. If this does not succeed, print an error message -to the .err log. This function is used to open a tablespace when we start -mysqld after the dictionary has been booted, and also in IMPORT TABLESPACE. - -NOTE that we assume this operation is used either at the database startup -or under the protection of dict_sys.latch, so that two users cannot -race here. This operation does not leave the file associated with the -tablespace open, but closes it after we have looked at the space id in it. - -If the validate boolean is set, we read the first page of the file and -check that the space id in the file is what we expect. We assume that -this function runs much faster if no check is made, since accessing the -file inode probably is much faster (the OS caches them) than accessing -the first page of the file. This boolean may be initially false, but if -a remote tablespace is found it will be changed to true. - -If the fix_dict boolean is set, then it is safe to use an internal SQL -statement to update the dictionary tables if they are incorrect. - -@param[in] validate 0=maybe missing, 1=do not validate, 2=validate -@param[in] purpose FIL_TYPE_TABLESPACE or FIL_TYPE_TEMPORARY -@param[in] id tablespace ID -@param[in] flags expected FSP_SPACE_FLAGS -@param[in] name table name -If file-per-table, it is the table name in the databasename/tablename format -@param[in] path_in expected filepath, usually read from dictionary -@param[out] err DB_SUCCESS or error code -@return tablespace -@retval NULL if the tablespace could not be opened */ -fil_space_t* -fil_ibd_open( - unsigned validate, - fil_type_t purpose, - ulint id, - ulint flags, - fil_space_t::name_type name, - const char* path_in, - dberr_t* err) +fil_space_t *fil_ibd_open(ulint id, ulint flags, + fil_space_t::validate validate, + fil_space_t::name_type name, + const char *path_in, dberr_t *err) noexcept { mysql_mutex_lock(&fil_system.mutex); fil_space_t* space = fil_space_get_by_id(id); mysql_mutex_unlock(&fil_system.mutex); if (space) { - if (validate > 1 && !srv_read_only_mode) { + if (validate == fil_space_t::VALIDATE_SPACE_ID + && !srv_read_only_mode) { fsp_flags_try_adjust(space, flags & ~FSP_FLAGS_MEM_MASK); } @@ -2148,8 +2080,8 @@ func_exit: ulint tablespaces_found = 0; ulint valid_tablespaces_found = 0; - df_default.init(flags); - df_remote.init(flags); + df_default.init(uint32_t(flags)); + df_remote.init(uint32_t(flags)); /* Discover the correct file by looking in three possible locations while avoiding unecessary effort. */ @@ -2178,7 +2110,7 @@ func_exit: /* Dict path is not the default path. Always validate remote files. If default is opened, it was moved. */ must_validate = true; - } else if (validate > 1) { + } else if (validate >= fil_space_t::VALIDATE_SPACE_ID) { must_validate = true; } @@ -2195,7 +2127,8 @@ func_exit: the first server startup. The tables ought to be dropped by drop_garbage_tables_after_restore() a little later. */ - const bool strict = validate && !tablespaces_found + const bool strict = (validate != fil_space_t::MAYBE_MISSING) + && !tablespaces_found && operation_not_for_export && !(srv_operation == SRV_OPERATION_NORMAL && srv_start_after_restore @@ -2326,7 +2259,9 @@ skip_validate: : NULL; mysql_mutex_lock(&fil_system.mutex); - space = fil_space_t::create(id, flags, purpose, crypt_data); + space = fil_space_t::create(uint32_t(id), flags, + validate == fil_space_t::VALIDATE_IMPORT, + crypt_data); if (!space) { mysql_mutex_unlock(&fil_system.mutex); goto error; @@ -2344,7 +2279,7 @@ skip_validate: df_remote.close(); df_default.close(); if (space->acquire()) { - if (purpose != FIL_TYPE_IMPORT) { + if (validate < fil_space_t::VALIDATE_IMPORT) { fsp_flags_try_adjust(space, flags & ~FSP_FLAGS_MEM_MASK); } @@ -2632,8 +2567,8 @@ tablespace_check: mysql_mutex_lock(&fil_system.mutex); - space = fil_space_t::create( - space_id, flags, FIL_TYPE_TABLESPACE, crypt_data); + space = fil_space_t::create(uint32_t(space_id), flags, false, + crypt_data); if (space == NULL) { mysql_mutex_unlock(&fil_system.mutex); @@ -2661,16 +2596,14 @@ void fsp_flags_try_adjust(fil_space_t* space, ulint flags) { ut_ad(!srv_read_only_mode); ut_ad(fil_space_t::is_valid_flags(flags, space->id)); + ut_ad(!space->is_being_imported()); + ut_ad(!space->is_temporary()); if (space->full_crc32() || fil_space_t::full_crc32(flags)) { return; } - if (!space->size && (space->purpose != FIL_TYPE_TABLESPACE - || !space->get_size())) { + if (!space->size || !space->get_size()) { return; } - /* This code is executed during server startup while no - connections are allowed. We do not need to protect against - DROP TABLE by fil_space_acquire(). */ mtr_t mtr; mtr.start(); if (buf_block_t* b = buf_page_get( @@ -2760,7 +2693,7 @@ inline void fil_node_t::complete_write() { mysql_mutex_assert_not_owner(&fil_system.mutex); - if (space->purpose != FIL_TYPE_TEMPORARY && + if (!space->is_temporary() && srv_file_flush_method != SRV_O_DIRECT_NO_FSYNC && space->set_needs_flush()) { @@ -3074,8 +3007,8 @@ fil_space_validate_for_mtr_commit( { mysql_mutex_assert_not_owner(&fil_system.mutex); ut_ad(space != NULL); - ut_ad(space->purpose == FIL_TYPE_TABLESPACE); ut_ad(!is_predefined_tablespace(space->id)); + ut_ad(!space->is_being_imported()); /* We are serving mtr_commit(). While there is an active mini-transaction, we should have !space->is_stopping(). This is @@ -3290,7 +3223,7 @@ fil_space_t::name_type fil_space_t::name() const if (!UT_LIST_GET_FIRST(chain) || srv_is_undo_tablespace(id)) return name_type{}; - ut_ad(purpose != FIL_TYPE_TEMPORARY); + ut_ad(!is_temporary()); ut_ad(UT_LIST_GET_LEN(chain) == 1); const char *path= UT_LIST_GET_FIRST(chain)->name; diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc index 3f94e8fb569..40bfca1388c 100644 --- a/storage/innobase/fsp/fsp0fsp.cc +++ b/storage/innobase/fsp/fsp0fsp.cc @@ -352,7 +352,7 @@ xdes_get_descriptor_with_space_hdr( ut_ad(limit == space->free_limit || (space->free_limit == 0 && (init_space - || space->purpose == FIL_TYPE_TEMPORARY + || space->is_temporary() || (srv_startup_is_before_trx_rollback_phase && (space->id == TRX_SYS_SPACE || srv_is_undo_tablespace(space->id)))))); @@ -490,14 +490,15 @@ void fil_space_t::modify_check(const mtr_t& mtr) const case MTR_LOG_NONE: /* These modes are only allowed within a non-bitmap page when there is a higher-level redo log record written. */ - ut_ad(purpose == FIL_TYPE_TABLESPACE || purpose == FIL_TYPE_TEMPORARY); + ut_ad(!is_being_imported()); break; case MTR_LOG_NO_REDO: - ut_ad(purpose == FIL_TYPE_TEMPORARY || purpose == FIL_TYPE_IMPORT); + ut_ad(is_temporary() || is_being_imported()); break; default: /* We may only write redo log for a persistent tablespace. */ - ut_ad(purpose == FIL_TYPE_TABLESPACE); + ut_ad(!is_temporary()); + ut_ad(!is_being_imported()); ut_ad(mtr.is_named_space(id)); } } @@ -857,7 +858,7 @@ fsp_fill_free_list( FIL_PAGE_TYPE_XDES); } - if (space->purpose != FIL_TYPE_TEMPORARY) + if (!space->is_temporary()) { buf_block_t *f= buf_LRU_get_free_block(false); buf_block_t *block= diff --git a/storage/innobase/fsp/fsp0space.cc b/storage/innobase/fsp/fsp0space.cc index 8c6344946a4..e72ddfef7ed 100644 --- a/storage/innobase/fsp/fsp0space.cc +++ b/storage/innobase/fsp/fsp0space.cc @@ -132,10 +132,8 @@ Tablespace::open_or_create(bool is_temp) mysql_mutex_lock(&fil_system.mutex); space = fil_space_t::create( - m_space_id, fsp_flags, - is_temp - ? FIL_TYPE_TEMPORARY : FIL_TYPE_TABLESPACE, - NULL); + uint32_t(m_space_id), fsp_flags, + false, nullptr); if (!space) { mysql_mutex_unlock(&fil_system.mutex); return DB_ERROR; diff --git a/storage/innobase/fsp/fsp0sysspace.cc b/storage/innobase/fsp/fsp0sysspace.cc index 2a60f60b43d..dbc5987b2e5 100644 --- a/storage/innobase/fsp/fsp0sysspace.cc +++ b/storage/innobase/fsp/fsp0sysspace.cc @@ -936,8 +936,7 @@ SysTablespace::open_or_create( } else if (is_temp) { ut_ad(space_id() == SRV_TMP_SPACE_ID); space = fil_space_t::create( - SRV_TMP_SPACE_ID, flags(), - FIL_TYPE_TEMPORARY, NULL); + SRV_TMP_SPACE_ID, flags(), false, nullptr); ut_ad(space == fil_system.temp_space); if (!space) { err = DB_ERROR; @@ -948,8 +947,7 @@ SysTablespace::open_or_create( } else { ut_ad(space_id() == TRX_SYS_SPACE); space = fil_space_t::create( - TRX_SYS_SPACE, it->flags(), - FIL_TYPE_TABLESPACE, NULL); + TRX_SYS_SPACE, it->flags(), false, nullptr); ut_ad(space == fil_system.sys_space); if (!space) { err = DB_ERROR; diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index 604ce85e93e..c38ff61b0e4 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -6562,7 +6562,8 @@ static int i_s_sys_tablespaces_fill_table(THD *thd, TABLE_LIST *tables, Item*) for (fil_space_t &space : fil_system.space_list) { - if (space.purpose == FIL_TYPE_TABLESPACE && !space.is_stopping() && + if (!space.is_temporary() && !space.is_being_imported() && + !space.is_stopping() && space.chain.start) { space.reacquire(); @@ -6734,7 +6735,7 @@ i_s_dict_fill_tablespaces_encryption( } else if (srv_is_undo_tablespace(space->id)) { char undo_name[sizeof "innodb_undo000"]; snprintf(undo_name, sizeof(undo_name), - "innodb_undo%03zu",space->id); + "innodb_undo%03" PRIu32, space->id); OK(fields[TABLESPACES_ENCRYPTION_NAME]->store( undo_name, strlen(undo_name), system_charset_info)); @@ -6802,7 +6803,7 @@ i_s_tablespaces_encryption_fill_table( fil_system.freeze_space_list++; for (fil_space_t& space : fil_system.space_list) { - if (space.purpose == FIL_TYPE_TABLESPACE + if (!space.is_temporary() && !space.is_being_imported() && !space.is_stopping()) { space.reacquire(); mysql_mutex_unlock(&fil_system.mutex); diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index 750df18dc8d..3e8f7888959 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -738,13 +738,15 @@ ibuf_set_free_bits_func( mtr.start(); const page_id_t id(block->page.id()); const fil_space_t *space= mtr.set_named_space_id(id.space()); + /* all callers of ibuf_update_free_bits_if_full() or ibuf_reset_free_bits() + check this */ + ut_ad(!space->is_temporary()); if (buf_block_t *bitmap_page= ibuf_bitmap_get_map_page(id, block->zip_size(), &mtr)) { - if (space->purpose != FIL_TYPE_TABLESPACE) + if (space->is_being_imported()) /* IndexPurge may invoke this */ mtr.set_log_mode(MTR_LOG_NO_REDO); - #ifdef UNIV_IBUF_DEBUG if (max_val != ULINT_UNDEFINED) { @@ -925,8 +927,7 @@ ibuf_page_low( return(false); } - compile_time_assert(IBUF_SPACE_ID == 0); - ut_ad(fil_system.sys_space->purpose == FIL_TYPE_TABLESPACE); + static_assert(IBUF_SPACE_ID == 0, "compatiblity"); #ifdef UNIV_DEBUG if (x_latch) { @@ -4498,7 +4499,7 @@ ibuf_print( dberr_t ibuf_check_bitmap_on_import(const trx_t* trx, fil_space_t* space) { ut_ad(trx->mysql_thd); - ut_ad(space->purpose == FIL_TYPE_IMPORT); + ut_ad(space->is_being_imported()); const unsigned zip_size = space->zip_size(); const unsigned physical_size = space->physical_size(); diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index 8e5357912d3..ff627e81eb2 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -100,16 +100,6 @@ class page_id_t; /** Structure containing encryption specification */ struct fil_space_crypt_t; -/** File types */ -enum fil_type_t { - /** temporary tablespace (temporary undo log or tables) */ - FIL_TYPE_TEMPORARY, - /** a tablespace that is being imported (no logging until finished) */ - FIL_TYPE_IMPORT, - /** persistent tablespace (for system, undo log or tables) */ - FIL_TYPE_TABLESPACE, -}; - struct fil_node_t; /** Structure to store first and last value of range */ @@ -344,42 +334,43 @@ struct fil_space_t final { #ifndef UNIV_INNOCHECKSUM friend fil_node_t; + + /** Constructor; see @fil_space_t::create() */ + inline explicit fil_space_t(uint32_t id, ulint flags, bool being_imported, + fil_space_crypt_t *crypt_data) noexcept; + ~fil_space_t() { ut_ad(!latch_owner); latch.destroy(); } - ulint id; /*!< space id */ + /** tablespace identifier */ + uint32_t id; /** fil_system.spaces chain node */ - fil_space_t *hash; - lsn_t max_lsn; - /*!< LSN of the most recent - fil_names_write_if_was_clean(). - Reset to 0 by fil_names_clear(). - Protected by log_sys.mutex. - If and only if this is nonzero, the - tablespace will be in named_spaces. */ - fil_type_t purpose;/*!< purpose */ - UT_LIST_BASE_NODE_T(fil_node_t) chain; - /*!< base node for the file chain */ - uint32_t size; /*!< tablespace file size in pages; - 0 if not known yet */ - uint32_t size_in_header; - /* FSP_SIZE in the tablespace header; - 0 if not known yet */ - uint32_t free_len; - /*!< length of the FSP_FREE list */ - uint32_t free_limit; - /*!< contents of FSP_FREE_LIMIT */ - uint32_t recv_size; - /*!< recovered tablespace size in pages; - 0 if no size change was read from the redo log, - or if the size change was implemented */ - uint32_t n_reserved_extents; - /*!< number of reserved free extents for - ongoing operations like B-tree page split */ + fil_space_t *hash= nullptr; + /** log_sys.get_lsn() of the most recent fil_names_write_if_was_clean(). + Reset to 0 by fil_names_clear(). Protected by log_sys.mutex. + If and only if this is nonzero, the tablespace will be in named_spaces. */ + lsn_t max_lsn= 0; + /** base node for the chain of data files; multiple entries are + only possible for is_temporary() or id==0 */ + UT_LIST_BASE_NODE_T(fil_node_t) chain; + /** tablespace size in pages; 0 if not determined yet */ + uint32_t size= 0; + /** FSP_SIZE in the tablespace header; 0 if not determined yet */ + uint32_t size_in_header= 0; + /** length of the FSP_FREE list */ + uint32_t free_len= 0; + /** contents of FSP_FREE_LIMIT */ + uint32_t free_limit= 0; + /** recovered tablespace size in pages; 0 if no size change was read + from the redo log, or if the size change was applied */ + uint32_t recv_size= 0; + /** number of reserved free extents for ongoing operations like + B-tree page split */ + uint32_t n_reserved_extents= 0; private: #ifdef UNIV_DEBUG fil_space_t *next_in_space_list(); @@ -390,10 +381,10 @@ private: #endif /** the committed size of the tablespace in pages */ - Atomic_relaxed committed_size; + Atomic_relaxed committed_size{0}; /** Number of pending operations on the file. The tablespace cannot be freed while (n_pending & PENDING) != 0. */ - std::atomic n_pending; + std::atomic n_pending{CLOSING}; /** Flag in n_pending that indicates that the tablespace is about to be deleted, and no further operations should be performed */ static constexpr uint32_t STOPPING_READS= 1U << 31; @@ -415,20 +406,23 @@ private: /** latch protecting all page allocation bitmap pages */ IF_DBUG(srw_lock_debug, srw_lock) latch; /** the thread that holds the exclusive latch, or 0 */ - pthread_t latch_owner; + pthread_t latch_owner= 0; public: /** MariaDB encryption data */ - fil_space_crypt_t *crypt_data; + fil_space_crypt_t *crypt_data= nullptr; /** Whether needs_flush(), or this is in fil_system.unflushed_spaces */ - bool is_in_unflushed_spaces; + bool is_in_unflushed_spaces= false; /** Whether this in fil_system.default_encrypt_tables (needs key rotation) */ - bool is_in_default_encrypt; + bool is_in_default_encrypt= false; private: + /** Whether the tablespace is being imported */ + bool being_imported= false; + /** Whether any corrupton of this tablespace has been reported */ - mutable std::atomic_flag is_corrupted; + mutable std::atomic_flag is_corrupted{false}; /** mutex to protect freed_ranges and last_freed_lsn */ std::mutex freed_range_mutex; @@ -437,11 +431,18 @@ private: range_set freed_ranges; /** LSN of freeing last page; protected by freed_range_mutex */ - lsn_t last_freed_lsn; + lsn_t last_freed_lsn= 0; /** LSN of undo tablespace creation or 0; protected by latch */ - lsn_t create_lsn; + lsn_t create_lsn= 0; public: + /** @return whether this is the temporary tablespace */ + bool is_temporary() const noexcept + { return UNIV_UNLIKELY(id == SRV_TMP_SPACE_ID); } + /** @return whether this tablespace is being imported */ + bool is_being_imported() const noexcept + { return UNIV_UNLIKELY(being_imported); } + /** @return whether doublewrite buffering is needed */ inline bool use_doublewrite() const; @@ -511,7 +512,7 @@ public: MY_ATTRIBUTE((nonnull)); /** Note that the tablespace has been imported. - Initially, purpose=FIL_TYPE_IMPORT so that no redo log is + Initially, purpose=IMPORT so that no redo log is written while the space ID is being updated in each page. */ inline void set_imported(); @@ -946,18 +947,18 @@ public: #ifndef UNIV_INNOCHECKSUM MY_ATTRIBUTE((warn_unused_result)) /** Create a tablespace in fil_system. - @param id tablespace identifier - @param flags tablespace flags - @param purpose tablespace purpose - @param crypt_data encryption information - @param mode encryption mode - @param opened true if space files are opened + @param id tablespace identifier + @param flags tablespace flags + @param being_imported whether this is IMPORT TABLESPACE + @param crypt_data encryption information + @param mode encryption mode + @param opened whether the tablespace files are open @return pointer to created tablespace, to be filled in with add() @retval nullptr on failure (such as when the same tablespace exists) */ - static fil_space_t *create(ulint id, ulint flags, - fil_type_t purpose, fil_space_crypt_t *crypt_data, + static fil_space_t *create(uint32_t id, ulint flags, bool being_imported, + fil_space_crypt_t *crypt_data, fil_encryption_t mode= FIL_ENCRYPTION_DEFAULT, - bool opened= false); + bool opened= false) noexcept; MY_ATTRIBUTE((warn_unused_result)) /** Acquire a tablespace reference. @@ -1079,6 +1080,18 @@ public: /** @return the tablespace name (databasename/tablename) */ name_type name() const; + /** How to validate tablespace files that are being opened */ + enum validate { + /** the file may be missing */ + MAYBE_MISSING= 0, + /** do not validate */ + VALIDATE_NOTHING, + /** validate the tablespace ID */ + VALIDATE_SPACE_ID, + /** opening a file for ALTER TABLE...IMPORT TABLESPACE */ + VALIDATE_IMPORT + }; + private: /** @return whether the file is usable for io() */ ATTRIBUTE_COLD bool prepare_acquired(); @@ -1163,8 +1176,8 @@ inline bool fil_space_t::use_doublewrite() const inline void fil_space_t::set_imported() { - ut_ad(purpose == FIL_TYPE_IMPORT); - purpose= FIL_TYPE_TABLESPACE; + ut_ad(being_imported); + being_imported= false; UT_LIST_GET_FIRST(chain)->find_metadata(); } @@ -1478,12 +1491,9 @@ public: ulint n_open; /** last time we noted n_open exceeding the limit; protected by mutex */ time_t n_open_exceeded_time; - ulint max_assigned_id;/*!< maximum space id in the existing - tables, or assigned during the time - mysqld has been up; at an InnoDB - startup we scan the data dictionary - and set here the maximum of the - space id's of the tables there */ + /** maximum space id in the existing tables; on InnoDB startup this is + initialized based on the data dictionary contents */ + ulint max_assigned_id; /** nonzero if fil_node_open_file_low() should avoid moving the tablespace to the end of space_list, for FIFO policy of try_to_close() */ ulint freeze_space_list; @@ -1588,7 +1598,7 @@ template inline void fil_space_t::flush() { mysql_mutex_assert_not_owner(&fil_system.mutex); ut_ad(!have_reference || (pending() & PENDING)); - ut_ad(purpose == FIL_TYPE_TABLESPACE || purpose == FIL_TYPE_IMPORT); + ut_ad(!is_temporary()); if (srv_file_flush_method == SRV_O_DIRECT_NO_FSYNC) { ut_ad(!is_in_unflushed_spaces); @@ -1729,7 +1739,7 @@ fil_ibd_create( uint32_t size, fil_encryption_t mode, uint32_t key_id, - dberr_t* err) + dberr_t* err) noexcept MY_ATTRIBUTE((nonnull, warn_unused_result)); /** Try to adjust FSP_SPACE_FLAGS if they differ from the expectations. @@ -1738,43 +1748,28 @@ fil_ibd_create( @param[in] flags desired tablespace flags */ void fsp_flags_try_adjust(fil_space_t* space, ulint flags); -/********************************************************************//** +/** Tries to open a single-table tablespace and optionally checks the space id is right in it. If does not succeed, prints an error message to the .err log. This function is used to open a tablespace when we start up mysqld, and also in IMPORT TABLESPACE. -NOTE that we assume this operation is used either at the database startup -or under the protection of dict_sys.latch, so that two users cannot -race here. This operation does not leave the file associated with the -tablespace open, but closes it after we have looked at the space id in it. -If the validate boolean is set, we read the first page of the file and -check that the space id in the file is what we expect. We assume that -this function runs much faster if no check is made, since accessing the -file inode probably is much faster (the OS caches them) than accessing -the first page of the file. This boolean may be initially false, but if -a remote tablespace is found it will be changed to true. +NOTE that we assume this operation is used either at the database +startup or under the protection of MDL, to prevent concurrent access +to the same tablespace. -@param[in] validate 0=maybe missing, 1=do not validate, 2=validate -@param[in] purpose FIL_TYPE_TABLESPACE or FIL_TYPE_TEMPORARY -@param[in] id tablespace ID -@param[in] flags expected FSP_SPACE_FLAGS -@param[in] name table name -If file-per-table, it is the table name in the databasename/tablename format -@param[in] path_in expected filepath, usually read from dictionary -@param[out] err DB_SUCCESS or error code +@param id tablespace identifier +@param flags expected FSP_SPACE_FLAGS +@param validate how to validate files +@param name the table name in databasename/tablename format +@param path_in expected filepath, usually read from dictionary +@param err DB_SUCCESS or error code @return tablespace -@retval NULL if the tablespace could not be opened */ -fil_space_t* -fil_ibd_open( - unsigned validate, - fil_type_t purpose, - ulint id, - ulint flags, - fil_space_t::name_type name, - const char* path_in, - dberr_t* err = NULL) - MY_ATTRIBUTE((warn_unused_result)); +@retval nullptr if the tablespace could not be opened */ +fil_space_t *fil_ibd_open(ulint id, ulint flags, + fil_space_t::validate validate, + fil_space_t::name_type name, + const char *path_in, dberr_t *err= nullptr) noexcept; enum fil_load_status { /** The tablespace file(s) were found and valid. */ diff --git a/storage/innobase/include/log0recv.h b/storage/innobase/include/log0recv.h index 773bd4c9f86..fb7028126c8 100644 --- a/storage/innobase/include/log0recv.h +++ b/storage/innobase/include/log0recv.h @@ -93,9 +93,9 @@ void recv_sys_justify_left_parsing_buf(); @param[in] len length of name, in bytes @param[in] new_name new file name (NULL if not rename) @param[in] new_len length of new_name, in bytes (0 if NULL) */ -extern void (*log_file_op)(ulint space_id, int type, - const byte* name, ulint len, - const byte* new_name, ulint new_len); +extern void (*log_file_op)(uint32_t space_id, int type, + const byte* name, size_t len, + const byte* new_name, size_t new_len); /** Report an operation which does undo log tablespace truncation during backup @@ -104,7 +104,7 @@ extern void (*undo_space_trunc)(uint32_t space_id); /** Report an operation which does INIT_PAGE for page0 during backup. @param space_id tablespace identifier */ -extern void (*first_page_init)(ulint space_id); +extern void (*first_page_init)(uint32_t space_id); /** Stored redo log record */ struct log_rec_t diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 2c9c93a42fa..cb408313279 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -598,10 +598,10 @@ struct file_name_t { /** Map of dirty tablespaces during recovery */ typedef std::map< - ulint, + uint32_t, file_name_t, std::less, - ut_allocator > > recv_spaces_t; + ut_allocator > > recv_spaces_t; static recv_spaces_t recv_spaces; @@ -820,8 +820,8 @@ processed: if (crypt_data && !fil_crypt_check(crypt_data, name.c_str())) return nullptr; mysql_mutex_lock(&fil_system.mutex); - fil_space_t *space= fil_space_t::create(it->first, flags, - FIL_TYPE_TABLESPACE, crypt_data); + fil_space_t *space= fil_space_t::create(it->first, flags, false, + crypt_data); ut_ad(space); const char *filename= name.c_str(); if (srv_operation == SRV_OPERATION_RESTORE) @@ -939,13 +939,13 @@ deferred_spaces; @param[in] len length of name, in bytes @param[in] new_name new file name (NULL if not rename) @param[in] new_len length of new_name, in bytes (0 if NULL) */ -void (*log_file_op)(ulint space_id, int type, - const byte* name, ulint len, - const byte* new_name, ulint new_len); +void (*log_file_op)(uint32_t space_id, int type, + const byte* name, size_t len, + const byte* new_name, size_t new_len); void (*undo_space_trunc)(uint32_t space_id); -void (*first_page_init)(ulint space_id); +void (*first_page_init)(uint32_t space_id); /** Information about initializing page contents during redo log processing. FIXME: Rely on recv_sys.pages! */ @@ -4203,7 +4203,7 @@ recv_validate_tablespace(bool rescan, bool& missing_tablespace) for (recv_sys_t::map::iterator p = recv_sys.pages.begin(); p != recv_sys.pages.end();) { ut_ad(!p->second.log.empty()); - const ulint space = p->first.space(); + const uint32_t space = p->first.space(); if (is_predefined_tablespace(space)) { next: p++; @@ -4213,7 +4213,7 @@ next: recv_spaces_t::iterator i = recv_spaces.find(space); ut_ad(i != recv_spaces.end()); - if (deferred_spaces.find(static_cast(space))) { + if (deferred_spaces.find(space)) { /* Skip redo logs belonging to incomplete tablespaces */ goto next; diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc index d6306f7b1c1..834bceaa8e2 100644 --- a/storage/innobase/mtr/mtr0mtr.cc +++ b/storage/innobase/mtr/mtr0mtr.cc @@ -488,8 +488,7 @@ mtr_t::x_lock_space(ulint space_id) } else { space = fil_space_get(space_id); ut_ad(m_log_mode != MTR_LOG_NO_REDO - || space->purpose == FIL_TYPE_TEMPORARY - || space->purpose == FIL_TYPE_IMPORT); + || space->is_temporary() || space->is_being_imported()); } ut_ad(space); @@ -502,9 +501,6 @@ mtr_t::x_lock_space(ulint space_id) @param space tablespace */ void mtr_t::x_lock_space(fil_space_t *space) { - ut_ad(space->purpose == FIL_TYPE_TEMPORARY || - space->purpose == FIL_TYPE_IMPORT || - space->purpose == FIL_TYPE_TABLESPACE); if (!memo_contains(*space)) { memo_push(space, MTR_MEMO_SPACE_X_LOCK); diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index b73fe21216b..25f47cb032d 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -3947,13 +3947,19 @@ void fil_node_t::find_metadata(IF_WIN(,bool create)) noexcept punch_hole= 2; else punch_hole= IF_WIN(, !create ||) os_is_sparse_file_supported(file); - if (space->purpose != FIL_TYPE_TABLESPACE) + /* For temporary tablespace or during IMPORT TABLESPACE, we + disable neighbour flushing and do not care about atomicity. */ + if (space->is_temporary()) { - /* For temporary tablespace or during IMPORT TABLESPACE, we - disable neighbour flushing and do not care about atomicity. */ on_ssd= true; atomic_write= true; - if (space->purpose == FIL_TYPE_TEMPORARY || !space->is_compressed()) + return; + } + if (space->is_being_imported()) + { + on_ssd= true; + atomic_write= true; + if (!space->is_compressed()) return; } #ifdef _WIN32 diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index 0be420147c0..a7557044056 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -4841,11 +4841,10 @@ import_error: we will not be writing any redo log for it before we have invoked fil_space_t::set_imported() to declare it a persistent tablespace. */ - ulint fsp_flags = dict_tf_to_fsp_flags(table->flags); - - table->space = fil_ibd_open( - 2, FIL_TYPE_IMPORT, table->space_id, - fsp_flags, name, filepath, &err); + table->space = fil_ibd_open(table->space_id, + dict_tf_to_fsp_flags(table->flags), + fil_space_t::VALIDATE_IMPORT, + name, filepath, &err); ut_ad((table->space == NULL) == (err != DB_SUCCESS)); DBUG_EXECUTE_IF("ib_import_open_tablespace_failure", @@ -4947,8 +4946,6 @@ import_error: } ib::info() << "Phase IV - Flush complete"; - /* Set tablespace purpose as FIL_TYPE_TABLESPACE, - so that rollback can go ahead smoothly */ table->space->set_imported(); err = lock_sys_tables(trx); diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 727a9f4d4fc..c3397c88336 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -575,9 +575,9 @@ err_exit: fil_set_max_space_id_if_bigger(space_id); mysql_mutex_lock(&fil_system.mutex); - fil_space_t *space= fil_space_t::create(space_id, fsp_flags, - FIL_TYPE_TABLESPACE, nullptr, - FIL_ENCRYPTION_DEFAULT, true); + fil_space_t *space= fil_space_t::create(uint32_t(space_id), + fsp_flags, false, nullptr, + FIL_ENCRYPTION_DEFAULT, true); ut_ad(space); fil_node_t *file= space->add(name, fh, 0, false, true); diff --git a/storage/innobase/trx/trx0sys.cc b/storage/innobase/trx/trx0sys.cc index 614e34e5a8a..df3755f6c10 100644 --- a/storage/innobase/trx/trx0sys.cc +++ b/storage/innobase/trx/trx0sys.cc @@ -238,7 +238,8 @@ static trx_rseg_t *trx_rseg_create(ulint space_id) if (fil_space_t *space= mtr.x_lock_space(space_id)) { - ut_ad(space->purpose == FIL_TYPE_TABLESPACE); + ut_ad(!space->is_temporary()); + ut_ad(!space->is_being_imported()); if (buf_block_t *sys_header= trx_sysf_get(&mtr)) { ulint rseg_id= trx_sys_rseg_find_free(sys_header); From 7bcd6c610a5c7f7dd0884172acb128de22782a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 11 Dec 2024 14:47:39 +0200 Subject: [PATCH 06/22] MDEV-35618 Bogus assertion failure 'recv_sys.scanned_lsn < max_lsn + 32 * 512U' during recovery buf_dblwr_t::recover(): Correct a debug assertion failure that had been added in commit bb47e575de2bdad06d04f74b65c2a22d07f83cc4 (MDEV-34830). The server may have been killed while a log write was in progress, and therefore recv_sys.scanned_lsn may be up to RECV_PARSING_BUF_SIZE bytes ahead of recv_sys.recovered_lsn. Thanks to Matthias Leich for providing "rr replay" traces and testing this. --- storage/innobase/buf/buf0dblwr.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/buf/buf0dblwr.cc b/storage/innobase/buf/buf0dblwr.cc index 0060ee29fd9..f53710caf1d 100644 --- a/storage/innobase/buf/buf0dblwr.cc +++ b/storage/innobase/buf/buf0dblwr.cc @@ -363,7 +363,7 @@ void buf_dblwr_t::recover() innodb_log_write_ahead_size. After MDEV-14425 eliminated OS_FILE_LOG_BLOCK_SIZE, these two LSN must be equal. */ ut_ad(recv_sys.scanned_lsn >= max_lsn); - ut_ad(recv_sys.scanned_lsn < max_lsn + 32 * OS_FILE_LOG_BLOCK_SIZE); + ut_ad(recv_sys.scanned_lsn < max_lsn + RECV_PARSING_BUF_SIZE); uint32_t page_no_dblwr= 0; byte *read_buf= static_cast(aligned_malloc(3 * srv_page_size, From ee287821e3980d4b08892757764f5d70c7dc2aa8 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 6 Dec 2024 11:34:58 +1100 Subject: [PATCH 07/22] MDEV-32561: WSREP FSM failure: (postfix) - enable galera.galera_sequences The MDEV is fixed, so enable the test case again. --- mysql-test/suite/galera/disabled.def | 1 - 1 file changed, 1 deletion(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index cbb42331792..5b92b282ece 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -10,6 +10,5 @@ # ############################################################################## -galera_sequences : MDEV-32561 WSREP FSM failure: no such a transition REPLICATING -> COMMITTED 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() From 7181ea56630d4e397f30b1073c3c806a2d59a530 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 6 Dec 2024 11:35:58 +1100 Subject: [PATCH 08/22] MDEV-33245 SIGSEGV in wsrep_check_sequence The segfault in wsrep_check_sequence is due to a null pointer deference on: db_type= thd->lex->create_info.db_type->db_type; Where create_info.db_type is null. This occured under a used_engine==true condition which is set in the calling function based on create_info.used_fields==HA_CREATE_USED_ENGINE. However the create_info.used_fields was a left over from the parsing of the previous failed CREATE TABLE where because of its failure, db_type wasn't populated. This is corrected by cleaning the create_info when we start to parse ALTER SEQUENCE statements. Other paths to wsrep_check_sequence is via CREATE SEQUENCE and CREATE TABLE LIKE which both initialize the create_info correctly. --- mysql-test/suite/galera/r/galera_sequences.result | 11 +++++++++++ mysql-test/suite/galera/t/galera_sequences.test | 15 +++++++++++++++ sql/sql_yacc.yy | 1 + 3 files changed, 27 insertions(+) diff --git a/mysql-test/suite/galera/r/galera_sequences.result b/mysql-test/suite/galera/r/galera_sequences.result index 1a5219c2d45..1f6b2bd6637 100644 --- a/mysql-test/suite/galera/r/galera_sequences.result +++ b/mysql-test/suite/galera/r/galera_sequences.result @@ -314,3 +314,14 @@ NEXTVAL(t) connection node_1; DROP TABLE t1; DROP SEQUENCE t; + +MDEV-33245 SIGSEGV in wsrep_check_sequence | Sql_cmd_alter_sequence::execute + +CREATE TABLE t (a INT) ENGINE=InnoDB; +INSERT INTO t VALUES (0); +CREATE TABLE t1 (c VARCHAR) ENGINE=InnoDB; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ENGINE=InnoDB' at line 1 +ALTER SEQUENCE IF EXISTS t MINVALUE=1; +ERROR 42000: This version of MariaDB doesn't yet support 'CACHE without INCREMENT BY 0 in Galera cluster' +DROP TABLE t; +End of 10.5 tests diff --git a/mysql-test/suite/galera/t/galera_sequences.test b/mysql-test/suite/galera/t/galera_sequences.test index 53417055d7d..75a31b224b9 100644 --- a/mysql-test/suite/galera/t/galera_sequences.test +++ b/mysql-test/suite/galera/t/galera_sequences.test @@ -341,3 +341,18 @@ SELECT NEXTVAL(t); --connection node_1 DROP TABLE t1; DROP SEQUENCE t; + +--echo +--echo MDEV-33245 SIGSEGV in wsrep_check_sequence | Sql_cmd_alter_sequence::execute +--echo + +CREATE TABLE t (a INT) ENGINE=InnoDB; +INSERT INTO t VALUES (0); + +--error ER_PARSE_ERROR +CREATE TABLE t1 (c VARCHAR) ENGINE=InnoDB; +--error ER_NOT_SUPPORTED_YET +ALTER SEQUENCE IF EXISTS t MINVALUE=1; + +DROP TABLE t; +--echo End of 10.5 tests diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9aab9f97fe0..7c2060d0b9d 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -7472,6 +7472,7 @@ alter: { LEX *lex= Lex; lex->sql_command= SQLCOM_ALTER_SEQUENCE; + lex->create_info.init(); DBUG_ASSERT(!lex->m_sql_cmd); if (Lex->main_select_push()) MYSQL_YYABORT; From 801587c821290e707884f425a2da22fd88d32cf9 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 10 Nov 2023 11:22:46 +1100 Subject: [PATCH 09/22] MDEV-32686: minimise crash information Provide bug url in addition to how to report the bug. Remove obsolete information like key_buffers and used connections as they haven't meaningfully added value to a bug report for quite a while. Remove information that comes from long fixed interfaces in glibc/kernel. Encourage the use of a full backtrace from the core with debug symbols. Lets be realistic about the error messages, its the users we are addressing not developers so wording around getting the information communicated is the key aspect. All the user readable text and instructions are in on place, as non-understandable is the end of the reading process for the user. Remove the duplicate printing of the query. Use my_progname rather than "mysqld" to reflex the program name. So the signal handler output is now in the form: 1. User instructions 2. Server Information 3. Stacktrace 4. connection/query/optimizer_switch 5. Core information and resource limits 6. Kernel information --- sql/signal_handler.cc | 122 ++++++------------------------------------ 1 file changed, 17 insertions(+), 105 deletions(-) diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 002a4c244d1..1200a5a1608 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -144,7 +144,6 @@ extern "C" sig_handler handle_fatal_signal(int sig) We will try and print the query at the end of the signal handler, in case we're wrong. */ - bool print_invalid_query_pointer= false; #endif if (segfaulted) @@ -173,57 +172,19 @@ extern "C" sig_handler handle_fatal_signal(int sig) goto end; } - my_safe_printf_stderr("[ERROR] mysqld got " SIGNAL_FMT " ;\n",sig); + my_safe_printf_stderr("[ERROR] %s got " SIGNAL_FMT " ;\n", my_progname, sig); my_safe_printf_stderr("%s", "Sorry, we probably made a mistake, and this is a bug.\n\n" "Your assistance in bug reporting will enable us to fix this for the next release.\n" - "To report this bug, see https://mariadb.com/kb/en/reporting-bugs\n\n"); - - my_safe_printf_stderr("%s", - "We will try our best to scrape up some info that will hopefully help\n" - "diagnose the problem, but since we have already crashed, \n" - "something is definitely wrong and this may fail.\n\n"); + "To report this bug, see https://mariadb.com/kb/en/reporting-bugs about how to report\n" + "a bug on https://jira.mariadb.org/.\n\n" + "Please include the information from the server start above, to the end of the\n" + "information below.\n\n"); set_server_version(server_version, sizeof(server_version)); - my_safe_printf_stderr("Server version: %s source revision: %s\n", - server_version, SOURCE_REVISION); - - if (dflt_key_cache) - my_safe_printf_stderr("key_buffer_size=%zu\n", - dflt_key_cache->key_cache_mem_size); - - my_safe_printf_stderr("read_buffer_size=%lu\n", - global_system_variables.read_buff_size); - - my_safe_printf_stderr("max_used_connections=%lu\n", - max_used_connections); - - if (thread_scheduler) - my_safe_printf_stderr("max_threads=%lu\n", - thread_scheduler->max_threads + - extra_max_connections); - - my_safe_printf_stderr("thread_count=%u\n", THD_count::value()); - - if (dflt_key_cache && thread_scheduler) - { - size_t used_mem= - (dflt_key_cache->key_cache_mem_size + - (global_system_variables.read_buff_size + - (size_t) global_system_variables.sortbuff_size) * - (thread_scheduler->max_threads + extra_max_connections) + - (max_connections + extra_max_connections) * sizeof(THD)) / 1024; - - my_safe_printf_stderr("It is possible that mysqld could use up to \n" - "key_buffer_size + " - "(read_buffer_size + sort_buffer_size)*max_threads = " - "%zu K bytes of memory\n", used_mem); - - my_safe_printf_stderr("%s", - "Hope that's ok; if not, decrease some variables in " - "the equation.\n\n"); - } + my_safe_printf_stderr("Server version: %s source revision: %s\n\n", + server_version, SOURCE_REVISION); #ifdef WITH_WSREP Wsrep_server_state::handle_fatal_signal(); @@ -234,12 +195,14 @@ extern "C" sig_handler handle_fatal_signal(int sig) if (opt_stack_trace) { - my_safe_printf_stderr("Thread pointer: %p\n", thd); my_safe_printf_stderr("%s", - "Attempting backtrace. You can use the following " - "information to find out\n" - "where mysqld died. If you see no messages after this, something went\n" - "terribly wrong...\n"); + "The information page at " + "https://mariadb.com/kb/en/how-to-produce-a-full-stack-trace-for-mariadbd/\n" + "contains instructions to obtain a better version of the backtrace below.\n" + "Following these instructions will help MariaDB developers provide a fix quicker.\n\n" + "Attempting backtrace. Include this in the bug report.\n" + "(note: Retrieving this information may fail)\n\n"); + my_safe_printf_stderr("Thread pointer: %p\n", thd); my_print_stacktrace(thd ? (uchar*) thd->thread_stack : NULL, (ulong)my_thread_stack_size, 0); } @@ -287,20 +250,12 @@ extern "C" sig_handler handle_fatal_signal(int sig) kreason= "KILL_WAIT_TIMEOUT"; break; } - my_safe_printf_stderr("%s", "\n" - "Trying to get some variables.\n" - "Some pointers may be invalid and cause the dump to abort.\n"); - - my_safe_printf_stderr("Query (%p): ", thd->query()); - if (my_safe_print_str(thd->query(), MY_MIN(65536U, thd->query_length()))) - { - // Query was found invalid. We will try to print it at the end. - print_invalid_query_pointer= true; - } my_safe_printf_stderr("\nConnection ID (thread ID): %lu\n", (ulong) thd->thread_id); - my_safe_printf_stderr("Status: %s\n\n", kreason); + my_safe_printf_stderr("Status: %s\n", kreason); + my_safe_printf_stderr("Query (%p): ", thd->query()); + my_safe_print_str(thd->query(), MY_MIN(65536U, thd->query_length())); my_safe_printf_stderr("%s", "Optimizer switch: "); ulonglong optsw= thd->variables.optimizer_switch; for (uint i= 0; optimizer_switch_names[i+1]; i++, optsw >>= 1) @@ -312,52 +267,9 @@ extern "C" sig_handler handle_fatal_signal(int sig) } my_safe_printf_stderr("%s", "\n\n"); } - my_safe_printf_stderr("%s", - "The manual page at " - "https://mariadb.com/kb/en/how-to-produce-a-full-stack-trace-for-mariadbd/ contains\n" - "information that should help you find out what is causing the crash.\n"); #endif /* HAVE_STACKTRACE */ -#ifdef HAVE_INITGROUPS - if (calling_initgroups) - { - my_safe_printf_stderr("%s", "\n" - "This crash occurred while the server was calling initgroups(). This is\n" - "often due to the use of a mysqld that is statically linked against \n" - "glibc and configured to use LDAP in /etc/nsswitch.conf.\n" - "You will need to either upgrade to a version of glibc that does not\n" - "have this problem (2.3.4 or later when used with nscd),\n" - "disable LDAP in your nsswitch.conf, or use a " - "mysqld that is not statically linked.\n"); - } -#endif - - if (locked_in_memory) - { - my_safe_printf_stderr("%s", "\n" - "The \"--memlock\" argument, which was enabled, " - "uses system calls that are\n" - "unreliable and unstable on some operating systems and " - "operating-system versions (notably, some versions of Linux).\n" - "This crash could be due to use of those buggy OS calls.\n" - "You should consider whether you really need the " - "\"--memlock\" parameter and/or consult the OS distributer about " - "\"mlockall\" bugs.\n"); - } - -#ifdef HAVE_STACKTRACE - if (print_invalid_query_pointer) - { - my_safe_printf_stderr( - "\nWe think the query pointer is invalid, but we will try " - "to print it anyway. \n" - "Query: "); - my_write_stderr(thd->query(), MY_MIN(65536U, thd->query_length())); - my_safe_printf_stderr("\n\n"); - } -#endif - output_core_info(); #ifdef HAVE_WRITE_CORE if (test_flags & TEST_CORE_ON_SIGNAL) From 965e65d6bb5649f6301e777637e06b17117a40cd Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 10 Nov 2023 11:59:06 +1100 Subject: [PATCH 10/22] MDEV-32686: Signal hander- minimise resource limit output. Most resource limit information is excessive, particularly limits that aren't limited. We restructure the output by considering the Linux format of /proc/limits which had its soft limits beginning at offset 26. "u"limited lines are skipped. Example output: Resource Limits (excludes unlimited resources): Limit Soft Limit Hard Limit Units Max stack size 8388608 unlimited bytes Max processes 127235 127235 processes Max open files 32198 32198 files Max locked memory 8388608 8388608 bytes Max pending signals 127235 127235 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 This is 8 lines less that what was before. The FreeBSD limits file was /proc/curproc/rlimit and a different format so a loss of non-Linux proc enabled OSes isn't expected. --- sql/signal_handler.cc | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 1200a5a1608..20dcbb4fa89 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -71,20 +71,40 @@ static inline void output_core_info() (int) len, buff); } #ifdef __FreeBSD__ - if ((fd= open("/proc/curproc/rlimit", O_RDONLY, MYF(0))) >= 0) + if ((fd= open("/proc/curproc/rlimit", O_RDONLY)) >= 0) #else - if ((fd= open("/proc/self/limits", O_RDONLY, MYF(0))) >= 0) + if ((fd= open("/proc/self/limits", O_RDONLY)) >= 0) #endif { - my_safe_printf_stderr("Resource Limits:\n"); - while ((len= read(fd, (uchar*)buff, sizeof(buff))) > 0) - { - my_write_stderr(buff, len); - } + char *endline= buff; + ssize_t remain_len= len= read(fd, buff, sizeof(buff)); close(fd); + my_safe_printf_stderr("Resource Limits (excludes unlimited resources):\n"); + /* first line, header */ + endline= (char *) memchr(buff, '\n', remain_len); + if (endline) + { + endline++; + remain_len= buff + len - endline; + my_safe_printf_stderr("%.*s", (int) (endline - buff), buff); + + while (remain_len > 27) + { + char *newendline= (char *) memchr(endline, '\n', remain_len); + if (!newendline) + break; + *newendline= '\0'; + newendline++; + if (endline[26] != 'u') /* skip unlimited limits */ + my_safe_printf_stderr("%s\n", endline); + + remain_len-= newendline - endline; + endline= newendline; + } + } } #ifdef __linux__ - if ((fd= open("/proc/sys/kernel/core_pattern", O_RDONLY, MYF(0))) >= 0) + if ((fd= open("/proc/sys/kernel/core_pattern", O_RDONLY)) >= 0) { len= read(fd, (uchar*)buff, sizeof(buff)); my_safe_printf_stderr("Core pattern: %.*s\n", (int) len, buff); From 9aa84cf57f13a7cd78f6b81b1ae9136254d2d2b7 Mon Sep 17 00:00:00 2001 From: Dave Gosselin Date: Thu, 5 Dec 2024 14:53:48 -0500 Subject: [PATCH 11/22] MDEV-35587 unit.innodb_sync leaks memory on mac unit.innodb_sync calls my_end to cleanup its memory --- storage/innobase/unittest/innodb_sync-t.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/innobase/unittest/innodb_sync-t.cc b/storage/innobase/unittest/innodb_sync-t.cc index 5ad726d8429..e12b5c25ba3 100644 --- a/storage/innobase/unittest/innodb_sync-t.cc +++ b/storage/innobase/unittest/innodb_sync-t.cc @@ -209,4 +209,7 @@ int main(int argc __attribute__((unused)), char **argv) ok(true, "sux_lock"); sux.free(); + + my_end(MY_CHECK_ERROR); + return exit_status(); } From 9a25f2a5bbc084df725538b8b3e9d2019cbacd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 12 Dec 2024 11:58:11 +0200 Subject: [PATCH 12/22] MDEV-35632: HandlerSocket uses deprecated auto_ptr Let us suppress the deprecation warnings more specifically. This fixes up commit d76f5774fe70c51577cfbfdddcbfb3309d51f06e --- plugin/handler_socket/CMakeLists.txt | 2 -- plugin/handler_socket/handlersocket/database.hpp | 5 +++++ plugin/handler_socket/libhsclient/hstcpcli.hpp | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin/handler_socket/CMakeLists.txt b/plugin/handler_socket/CMakeLists.txt index 5a1925b40e0..1510dc839a4 100644 --- a/plugin/handler_socket/CMakeLists.txt +++ b/plugin/handler_socket/CMakeLists.txt @@ -6,8 +6,6 @@ IF(WIN32 OR WITHOUT_SERVER) RETURN() ENDIF() -MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-deprecated-declarations") - INCLUDE_DIRECTORIES(libhsclient) # Handlersocket client library. We do not distribute it, diff --git a/plugin/handler_socket/handlersocket/database.hpp b/plugin/handler_socket/handlersocket/database.hpp index ed5d00800d9..9e2aadf7380 100644 --- a/plugin/handler_socket/handlersocket/database.hpp +++ b/plugin/handler_socket/handlersocket/database.hpp @@ -9,6 +9,11 @@ #ifndef DENA_DATABASE_HPP #define DENA_DATABASE_HPP +#ifdef __GNUC__ +/* auto_ptr is deprecated */ +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + #include #include #include diff --git a/plugin/handler_socket/libhsclient/hstcpcli.hpp b/plugin/handler_socket/libhsclient/hstcpcli.hpp index fa0d4db1742..d078bdfd533 100644 --- a/plugin/handler_socket/libhsclient/hstcpcli.hpp +++ b/plugin/handler_socket/libhsclient/hstcpcli.hpp @@ -19,6 +19,11 @@ #include "string_ref.hpp" #include "string_buffer.hpp" +#ifdef __GNUC__ +/* auto_ptr is deprecated */ +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + namespace dena { struct hstcpcli_filter { From 95fdfb733d28e8e0d558d9ddd4d648830c46189f Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Thu, 12 Dec 2024 12:36:42 +0100 Subject: [PATCH 13/22] In allocate_dynamic() fixed return value on error. The previous value probably was copied from alloc_dynamic() where it means number of elements. --- mysys/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysys/array.c b/mysys/array.c index 29527ab5145..11e44d463ab 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -248,7 +248,7 @@ my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements) if (!(new_ptr= (uchar *) my_malloc(array->m_psi_key, size * array->size_of_element, MYF(array->malloc_flags | MY_WME)))) - DBUG_RETURN(0); + DBUG_RETURN(TRUE); memcpy(new_ptr, array->buffer, array->elements * array->size_of_element); array->malloc_flags&= ~MY_INIT_BUFFER_USED; From ddd7d5d8e34c3edd7ebf4790eec2c4e4d9141e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 12 Dec 2024 18:02:00 +0200 Subject: [PATCH 14/22] MDEV-24035 Failing assertion: UT_LIST_GET_LEN(lock.trx_locks) == 0 causing disruption and replication failure Under unknown circumstances, the SQL layer may wrongly disregard an invocation of thd_mark_transaction_to_rollback() when an InnoDB transaction had been aborted (rolled back) due to one of the following errors: * HA_ERR_LOCK_DEADLOCK * HA_ERR_RECORD_CHANGED (if innodb_snapshot_isolation=ON) * HA_ERR_LOCK_WAIT_TIMEOUT (if innodb_rollback_on_timeout=ON) Such an error used to cause a crash of InnoDB during transaction commit. These changes aim to catch and report the error earlier, so that not only this crash can be avoided but also the original root cause be found and fixed more easily later. The idea of this fix is from Michael 'Monty' Widenius. HA_ERR_ROLLBACK: A new error code that will be translated into ER_ROLLBACK_ONLY, signalling that the current transaction has been aborted and the only allowed action is ROLLBACK. trx_t::state: Add TRX_STATE_ABORTED that is like TRX_STATE_NOT_STARTED, but noting that the transaction had been rolled back and aborted. trx_t::is_started(): Replaces trx_is_started(). ha_innobase: Check the transaction state in various places. Simplify the logic around SAVEPOINT. ha_innobase::is_valid_trx(): Replaces ha_innobase::is_read_only(). The InnoDB logic around transaction savepoints, commit, and rollback was unnecessarily complex and might have contributed to this inconsistency. So, we are simplifying that logic as well. trx_savept_t: Replace with const undo_no_t*. When we rollback to a savepoint, all we need to know is the number of undo log records that must survive. trx_named_savept_t, DB_NO_SAVEPOINT: Remove. We can store undo_no_t directly in the space allocated at innobase_hton->savepoint_offset. fts_trx_create(): Do not copy previous savepoints. fts_savepoint_rollback(): If a savepoint was not found, roll back everything after the default savepoint of fts_trx_create(). The test innodb_fts.savepoint is extended to cover this code. Reviewed by: Vladislav Lesin Tested by: Matthias Leich --- include/handler_ername.h | 4 +- include/my_base.h | 3 +- include/my_handler_errors.h | 3 +- .../include/innodb_rollback_on_timeout.inc | 4 + mysql-test/main/bug39022.test | 4 + mysql-test/main/innodb_mysql_lock.test | 4 + mysql-test/main/long_unique_bugs.test | 4 + mysql-test/main/partition_innodb_plugin.test | 3 + mysql-test/main/rowid_filter_innodb.test | 4 + mysql-test/main/xa.test | 5 +- .../suite/galera/r/galera_bf_kill.result | 2 + .../suite/galera/r/galera_bf_lock_wait.result | 2 + mysql-test/suite/galera/t/galera_bf_kill.test | 2 + .../suite/galera/t/galera_bf_lock_wait.test | 2 + .../suite/innodb/r/innodb-wl5522-debug.result | 2 +- mysql-test/suite/innodb/t/autoinc_debug.test | 4 + .../suite/innodb/t/deadlock_detect.test | 4 + .../innodb/t/deadlock_in_subqueries_join.test | 4 + .../suite/innodb/t/deadlock_victim_race.test | 4 + .../innodb/t/deadlock_wait_lock_race.test | 4 + .../innodb/t/deadlock_wait_thr_race.test | 4 + mysql-test/suite/innodb/t/foreign_key.test | 4 + mysql-test/suite/innodb/t/innodb-lock.test | 4 + .../suite/innodb/t/innodb_bug42419.test | 4 + .../suite/innodb/t/innodb_mysql_rbk.test | 4 + .../suite/innodb/t/innodb_trx_weight.test | 4 + .../suite/innodb/t/insert-before-delete.test | 4 + .../suite/innodb/t/lock_delete_updated.test | 4 + mysql-test/suite/innodb/t/lock_isolation.test | 4 + .../suite/innodb/t/lock_memory_debug.test | 3 + mysql-test/suite/innodb/t/mdev-14846.test | 4 + mysql-test/suite/innodb/t/row_lock.test | 4 + mysql-test/suite/innodb/t/stat_tables.test | 4 + .../suite/innodb_fts/r/savepoint.result | 24 + mysql-test/suite/innodb_fts/t/savepoint.test | 16 + .../innodb_zip/r/wl5522_debug_zip.result | 2 +- .../multi_source/gtid_ignore_duplicates.test | 3 + .../rpl/r/rpl_mark_optimize_tbl_ddl.result | 4 +- .../rpl/t/rpl_mark_optimize_tbl_ddl.test | 4 + .../rpl/t/rpl_parallel_deadlock_victim.test | 3 + .../rpl/t/rpl_parallel_deadlock_victim2.test | 4 + .../t/rpl_parallel_innodb_lock_conflict.test | 4 + .../suite/rpl/t/rpl_parallel_optimistic.test | 3 + .../t/rpl_parallel_optimistic_nobinlog.test | 4 + .../suite/rpl/t/rpl_parallel_xa_same_xid.test | 4 + .../suite/rpl/t/rpl_temporary_error2.test | 3 + mysql-test/suite/versioning/t/update.test | 4 + sql/handler.cc | 8 +- storage/innobase/buf/buf0buf.cc | 6 +- storage/innobase/fts/fts0fts.cc | 74 +- storage/innobase/handler/ha_innodb.cc | 930 +++++++++--------- storage/innobase/handler/ha_innodb.h | 18 +- storage/innobase/handler/handler0alter.cc | 8 +- storage/innobase/include/db0err.h | 2 - storage/innobase/include/fts0fts.h | 12 +- storage/innobase/include/row0mysql.h | 2 +- storage/innobase/include/trx0roll.h | 76 +- storage/innobase/include/trx0sys.h | 14 +- storage/innobase/include/trx0trx.h | 88 +- storage/innobase/include/trx0trx.inl | 2 + storage/innobase/include/trx0types.h | 10 +- storage/innobase/lock/lock0lock.cc | 26 +- storage/innobase/que/que0que.cc | 3 +- storage/innobase/row/row0mysql.cc | 16 +- storage/innobase/row/row0sel.cc | 5 +- storage/innobase/trx/trx0i_s.cc | 2 +- storage/innobase/trx/trx0roll.cc | 391 +------- storage/innobase/trx/trx0sys.cc | 26 + storage/innobase/trx/trx0trx.cc | 121 +-- storage/innobase/ut/ut0ut.cc | 2 - 70 files changed, 880 insertions(+), 1163 deletions(-) diff --git a/include/handler_ername.h b/include/handler_ername.h index e969daa7c77..32faa84b52d 100644 --- a/include/handler_ername.h +++ b/include/handler_ername.h @@ -78,5 +78,7 @@ { "HA_ERR_ABORTED_BY_USER", HA_ERR_ABORTED_BY_USER, "" }, { "HA_ERR_DISK_FULL", HA_ERR_DISK_FULL, "" }, { "HA_ERR_INCOMPATIBLE_DEFINITION", HA_ERR_INCOMPATIBLE_DEFINITION, "" }, -{ "HA_ERR_NO_ENCRYPTION", HA_ERR_NO_ENCRYPTION, "" }, { "HA_ERR_COMMIT_ERROR", HA_ERR_COMMIT_ERROR, "" }, +{ "HA_ERR_PARTITION_LIST", HA_ERR_PARTITION_LIST, ""}, +{ "HA_ERR_NO_ENCRYPTION", HA_ERR_NO_ENCRYPTION, ""}, +{ "HA_ERR_ROLLBACK", HA_ERR_ROLLBACK, "" }, diff --git a/include/my_base.h b/include/my_base.h index 44889c4ca96..2ae107c4799 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -535,7 +535,8 @@ enum ha_base_keytype { #define HA_ERR_COMMIT_ERROR 197 #define HA_ERR_PARTITION_LIST 198 #define HA_ERR_NO_ENCRYPTION 199 -#define HA_ERR_LAST 199 /* Copy of last error nr * */ +#define HA_ERR_ROLLBACK 200 /* Automatic rollback done */ +#define HA_ERR_LAST 200 /* Copy of last error nr * */ /* Number of different errors */ #define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1) diff --git a/include/my_handler_errors.h b/include/my_handler_errors.h index df414888907..4e96945e134 100644 --- a/include/my_handler_errors.h +++ b/include/my_handler_errors.h @@ -110,7 +110,8 @@ static const char *handler_error_messages[]= "Sequence values are conflicting", "Error during commit", "Cannot select partitions", - "Cannot initialize encryption. Check that all encryption parameters have been set" + "Cannot initialize encryption. Check that all encryption parameters have been set", + "Transaction was aborted", }; #endif /* MYSYS_MY_HANDLER_ERRORS_INCLUDED */ diff --git a/mysql-test/include/innodb_rollback_on_timeout.inc b/mysql-test/include/innodb_rollback_on_timeout.inc index d41e1f1ec9f..5fbdaa1c62a 100644 --- a/mysql-test/include/innodb_rollback_on_timeout.inc +++ b/mysql-test/include/innodb_rollback_on_timeout.inc @@ -2,6 +2,10 @@ # Bug #24200: Provide backwards compatibility mode for 4.x "rollback on # transaction timeout" # +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --disable_warnings drop table if exists t1; --enable_warnings diff --git a/mysql-test/main/bug39022.test b/mysql-test/main/bug39022.test index 211a40234b4..81dd6f14bed 100644 --- a/mysql-test/main/bug39022.test +++ b/mysql-test/main/bug39022.test @@ -2,6 +2,10 @@ -- source include/have_innodb.inc -- source include/not_binlog_format_row.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --echo # --echo # Bug #39022: Mysql randomly crashing in lock_sec_rec_cons_read_sees --echo # diff --git a/mysql-test/main/innodb_mysql_lock.test b/mysql-test/main/innodb_mysql_lock.test index 5ee688b1d6e..e61b2fde055 100644 --- a/mysql-test/main/innodb_mysql_lock.test +++ b/mysql-test/main/innodb_mysql_lock.test @@ -1,6 +1,10 @@ --source include/have_metadata_lock_info.inc -- source include/have_innodb.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + # Save the initial number of concurrent sessions. --source include/count_sessions.inc diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test index 2f85328bda3..78cf072ed8b 100644 --- a/mysql-test/main/long_unique_bugs.test +++ b/mysql-test/main/long_unique_bugs.test @@ -2,6 +2,10 @@ --source include/have_partition.inc --source include/have_sequence.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --echo # --echo # MDEV-18707 Server crash in my_hash_sort_bin, ASAN heap-use-after-free in Field::is_null, server hang, corrupted double-linked list --echo # diff --git a/mysql-test/main/partition_innodb_plugin.test b/mysql-test/main/partition_innodb_plugin.test index c24945152b3..2699ca2ca1a 100644 --- a/mysql-test/main/partition_innodb_plugin.test +++ b/mysql-test/main/partition_innodb_plugin.test @@ -5,6 +5,9 @@ let $MYSQLD_DATADIR= `SELECT @@datadir`; call mtr.add_suppression("InnoDB: Table .* does not exist in the InnoDB internal data dictionary .*"); call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log --echo # --echo # Bug#11766879/Bug#60106: DIFF BETWEEN # OF INDEXES IN MYSQL VS INNODB, diff --git a/mysql-test/main/rowid_filter_innodb.test b/mysql-test/main/rowid_filter_innodb.test index d82dccd0551..6b3f9c783e6 100644 --- a/mysql-test/main/rowid_filter_innodb.test +++ b/mysql-test/main/rowid_filter_innodb.test @@ -4,6 +4,10 @@ --source include/have_sequence.inc --source include/innodb_stable_estimates.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB'; SET @save_stats_persistent=@@GLOBAL.innodb_stats_persistent; diff --git a/mysql-test/main/xa.test b/mysql-test/main/xa.test index 77df6831355..a4c60ef316d 100644 --- a/mysql-test/main/xa.test +++ b/mysql-test/main/xa.test @@ -2,13 +2,16 @@ # WL#1756 # -- source include/have_innodb.inc - --source include/not_embedded.inc # Save the initial number of concurrent sessions --source include/count_sessions.inc call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --disable_warnings drop table if exists t1, t2; diff --git a/mysql-test/suite/galera/r/galera_bf_kill.result b/mysql-test/suite/galera/r/galera_bf_kill.result index 71b0366081b..e6ddf3fc3c5 100644 --- a/mysql-test/suite/galera/r/galera_bf_kill.result +++ b/mysql-test/suite/galera/r/galera_bf_kill.result @@ -1,10 +1,12 @@ connection node_2; connection node_1; connection node_2; +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); CREATE TABLE t1(a int not null primary key auto_increment,b int) engine=InnoDB; insert into t1 values (NULL,1); connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; connection node_2a; +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); begin; update t1 set a = 5; connection node_2; diff --git a/mysql-test/suite/galera/r/galera_bf_lock_wait.result b/mysql-test/suite/galera/r/galera_bf_lock_wait.result index 9e5cb2d9266..590fcea2997 100644 --- a/mysql-test/suite/galera/r/galera_bf_lock_wait.result +++ b/mysql-test/suite/galera/r/galera_bf_lock_wait.result @@ -1,8 +1,10 @@ connection node_2; connection node_1; connection node_2; +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); call mtr.add_suppression("WSREP: Trying to continue unpaused monitor"); connection node_1; +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); call mtr.add_suppression("WSREP: Trying to continue unpaused monitor"); CREATE TABLE t1 ENGINE=InnoDB select 1 as a, 1 as b union select 2, 2; ALTER TABLE t1 add primary key(a); diff --git a/mysql-test/suite/galera/t/galera_bf_kill.test b/mysql-test/suite/galera/t/galera_bf_kill.test index 1cb2e866cb4..4655a35fde5 100644 --- a/mysql-test/suite/galera/t/galera_bf_kill.test +++ b/mysql-test/suite/galera/t/galera_bf_kill.test @@ -7,11 +7,13 @@ # --connection node_2 +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); CREATE TABLE t1(a int not null primary key auto_increment,b int) engine=InnoDB; insert into t1 values (NULL,1); --connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 --connection node_2a +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); begin; update t1 set a = 5; diff --git a/mysql-test/suite/galera/t/galera_bf_lock_wait.test b/mysql-test/suite/galera/t/galera_bf_lock_wait.test index 8ef2fee78ed..78a460eda09 100644 --- a/mysql-test/suite/galera/t/galera_bf_lock_wait.test +++ b/mysql-test/suite/galera/t/galera_bf_lock_wait.test @@ -3,9 +3,11 @@ --source include/big_test.inc --connection node_2 +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); call mtr.add_suppression("WSREP: Trying to continue unpaused monitor"); --connection node_1 +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); call mtr.add_suppression("WSREP: Trying to continue unpaused monitor"); CREATE TABLE t1 ENGINE=InnoDB select 1 as a, 1 as b union select 2, 2; diff --git a/mysql-test/suite/innodb/r/innodb-wl5522-debug.result b/mysql-test/suite/innodb/r/innodb-wl5522-debug.result index 6b7bb9b9584..aa8a683620f 100644 --- a/mysql-test/suite/innodb/r/innodb-wl5522-debug.result +++ b/mysql-test/suite/innodb/r/innodb-wl5522-debug.result @@ -456,7 +456,7 @@ restore: t1 .ibd and .cfg files SET SESSION debug_dbug=@saved_debug_dbug; SET SESSION debug_dbug="+d,ib_import_open_tablespace_failure"; ALTER TABLE t1 IMPORT TABLESPACE; -ERROR HY000: Got error 42 'Tablespace not found' from ./test/t1.ibd +ERROR HY000: Got error 41 'Tablespace not found' from ./test/t1.ibd SET SESSION debug_dbug=@saved_debug_dbug; restore: t1 .ibd and .cfg files SET SESSION debug_dbug="+d,ib_import_check_bitmap_failure"; diff --git a/mysql-test/suite/innodb/t/autoinc_debug.test b/mysql-test/suite/innodb/t/autoinc_debug.test index d38a70b3376..f62cfd8afce 100644 --- a/mysql-test/suite/innodb/t/autoinc_debug.test +++ b/mysql-test/suite/innodb/t/autoinc_debug.test @@ -3,6 +3,10 @@ --source include/have_debug_sync.inc --source include/not_embedded.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + # Two parallel connection with autoinc column after restart. CREATE TABLE t1 (id INT AUTO_INCREMENT PRIMARY KEY)ENGINE=INNODB; diff --git a/mysql-test/suite/innodb/t/deadlock_detect.test b/mysql-test/suite/innodb/t/deadlock_detect.test index a84e6fc328f..39ea174a3ec 100644 --- a/mysql-test/suite/innodb/t/deadlock_detect.test +++ b/mysql-test/suite/innodb/t/deadlock_detect.test @@ -5,6 +5,10 @@ --source include/have_innodb.inc --source include/count_sessions.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + let $have_deadlock=`select @@GLOBAL.innodb_deadlock_detect`; connection default; diff --git a/mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test b/mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test index b3adfb3b02d..beded05198e 100644 --- a/mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test +++ b/mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test @@ -1,6 +1,10 @@ --source include/have_innodb.inc --source include/count_sessions.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + CREATE TABLE t1 ( pkey int NOT NULL PRIMARY KEY, c int diff --git a/mysql-test/suite/innodb/t/deadlock_victim_race.test b/mysql-test/suite/innodb/t/deadlock_victim_race.test index b9a442fc5b9..dac6be698fc 100644 --- a/mysql-test/suite/innodb/t/deadlock_victim_race.test +++ b/mysql-test/suite/innodb/t/deadlock_victim_race.test @@ -2,6 +2,10 @@ --source include/have_debug_sync.inc --source include/count_sessions.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --connect(cancel_purge,localhost,root,,) # Purge can cause deadlock in the test, requesting page's RW_X_LATCH for trx # ids reseting, after trx 2 acqured RW_S_LATCH and suspended in debug sync point diff --git a/mysql-test/suite/innodb/t/deadlock_wait_lock_race.test b/mysql-test/suite/innodb/t/deadlock_wait_lock_race.test index 79a62b098c9..27d02898b72 100644 --- a/mysql-test/suite/innodb/t/deadlock_wait_lock_race.test +++ b/mysql-test/suite/innodb/t/deadlock_wait_lock_race.test @@ -2,6 +2,10 @@ --source include/have_debug_sync.inc --source include/count_sessions.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + # Purge can cause deadlock in the test, requesting page's RW_X_LATCH for trx # ids reseting, after trx 2 acqured RW_S_LATCH and suspended in debug sync point # lock_trx_handle_wait_enter, waiting for upd_cont signal, which must be diff --git a/mysql-test/suite/innodb/t/deadlock_wait_thr_race.test b/mysql-test/suite/innodb/t/deadlock_wait_thr_race.test index 42576f35baf..318db88a470 100644 --- a/mysql-test/suite/innodb/t/deadlock_wait_thr_race.test +++ b/mysql-test/suite/innodb/t/deadlock_wait_thr_race.test @@ -2,6 +2,10 @@ --source include/have_debug_sync.inc --source include/count_sessions.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + # Purge can cause deadlock in the test, requesting page's RW_X_LATCH for trx # ids reseting, after trx 2 acqured RW_S_LATCH and suspended in debug sync point # lock_trx_handle_wait_enter, waiting for upd_cont signal, which must be diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index e793e261abd..506cca3245c 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -2,6 +2,10 @@ --source include/count_sessions.inc --source include/default_charset.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + SET GLOBAL innodb_stats_persistent = 0; --echo # diff --git a/mysql-test/suite/innodb/t/innodb-lock.test b/mysql-test/suite/innodb/t/innodb-lock.test index fbbb1035481..394681702c0 100644 --- a/mysql-test/suite/innodb/t/innodb-lock.test +++ b/mysql-test/suite/innodb/t/innodb-lock.test @@ -1,6 +1,10 @@ --source include/have_innodb.inc --source include/have_partition.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + # # Check and select innodb lock type # diff --git a/mysql-test/suite/innodb/t/innodb_bug42419.test b/mysql-test/suite/innodb/t/innodb_bug42419.test index ef350529604..2314a2b43ab 100644 --- a/mysql-test/suite/innodb/t/innodb_bug42419.test +++ b/mysql-test/suite/innodb/t/innodb_bug42419.test @@ -4,6 +4,10 @@ # Bug#42419 Server crash with "Pure virtual method called" on two concurrent connections # +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --source include/not_embedded.inc let $innodb_lock_wait_timeout= query_get_value(SHOW VARIABLES LIKE 'innodb_lock_wait_timeout%', Value, 1); diff --git a/mysql-test/suite/innodb/t/innodb_mysql_rbk.test b/mysql-test/suite/innodb/t/innodb_mysql_rbk.test index 85a9769732f..ffdfaf48ea6 100644 --- a/mysql-test/suite/innodb/t/innodb_mysql_rbk.test +++ b/mysql-test/suite/innodb/t/innodb_mysql_rbk.test @@ -1,5 +1,9 @@ --source include/have_innodb.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + # # Bug #41453: Assertion `m_status == DA_ERROR' failed in # Diagnostics_area::sql_errno diff --git a/mysql-test/suite/innodb/t/innodb_trx_weight.test b/mysql-test/suite/innodb/t/innodb_trx_weight.test index 819f05f331e..a8c29a1a8a8 100644 --- a/mysql-test/suite/innodb/t/innodb_trx_weight.test +++ b/mysql-test/suite/innodb/t/innodb_trx_weight.test @@ -6,6 +6,10 @@ # be heavier than ones that had not. # +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + -- source include/have_innodb.inc SET default_storage_engine=InnoDB; diff --git a/mysql-test/suite/innodb/t/insert-before-delete.test b/mysql-test/suite/innodb/t/insert-before-delete.test index 2547b94e5ea..1cadbf7c0c6 100644 --- a/mysql-test/suite/innodb/t/insert-before-delete.test +++ b/mysql-test/suite/innodb/t/insert-before-delete.test @@ -3,6 +3,10 @@ --source include/have_debug_sync.inc --source include/count_sessions.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --connect (pause_purge,localhost,root) START TRANSACTION WITH CONSISTENT SNAPSHOT; diff --git a/mysql-test/suite/innodb/t/lock_delete_updated.test b/mysql-test/suite/innodb/t/lock_delete_updated.test index 1f7b13144e4..8697ff595ab 100644 --- a/mysql-test/suite/innodb/t/lock_delete_updated.test +++ b/mysql-test/suite/innodb/t/lock_delete_updated.test @@ -3,6 +3,10 @@ --source include/have_debug.inc --source include/have_debug_sync.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t VALUES (3); diff --git a/mysql-test/suite/innodb/t/lock_isolation.test b/mysql-test/suite/innodb/t/lock_isolation.test index c9658c0a362..bac034a50e4 100644 --- a/mysql-test/suite/innodb/t/lock_isolation.test +++ b/mysql-test/suite/innodb/t/lock_isolation.test @@ -1,5 +1,9 @@ --source include/have_innodb.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --echo # --echo # MDEV-26642 Weird SELECT view when a record is --echo # modified to the same value by two transactions diff --git a/mysql-test/suite/innodb/t/lock_memory_debug.test b/mysql-test/suite/innodb/t/lock_memory_debug.test index 51e0e8fd57e..588356f7fa4 100644 --- a/mysql-test/suite/innodb/t/lock_memory_debug.test +++ b/mysql-test/suite/innodb/t/lock_memory_debug.test @@ -6,6 +6,9 @@ --echo # call mtr.add_suppression("\\[Warning\\] InnoDB: Over 67 percent of the buffer pool"); +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log CREATE TABLE t1 (col1 INT) ENGINE=InnoDB; INSERT INTO t1 VALUES (1),(2),(3),(4),(5); diff --git a/mysql-test/suite/innodb/t/mdev-14846.test b/mysql-test/suite/innodb/t/mdev-14846.test index e9698cc0594..75b634a0908 100644 --- a/mysql-test/suite/innodb/t/mdev-14846.test +++ b/mysql-test/suite/innodb/t/mdev-14846.test @@ -4,6 +4,10 @@ --source include/innodb_stable_estimates.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + CREATE TABLE t1 ( pk INT, f1 VARCHAR(10) NOT NULL, diff --git a/mysql-test/suite/innodb/t/row_lock.test b/mysql-test/suite/innodb/t/row_lock.test index 361bce461f7..2598189d0e2 100644 --- a/mysql-test/suite/innodb/t/row_lock.test +++ b/mysql-test/suite/innodb/t/row_lock.test @@ -4,6 +4,10 @@ # concurrent CREATE OR REPLACE and transactional UPDATE # +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --source include/have_innodb.inc CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB; diff --git a/mysql-test/suite/innodb/t/stat_tables.test b/mysql-test/suite/innodb/t/stat_tables.test index 602d05915a0..0aaabb26803 100644 --- a/mysql-test/suite/innodb/t/stat_tables.test +++ b/mysql-test/suite/innodb/t/stat_tables.test @@ -1,5 +1,9 @@ source include/have_innodb.inc; +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + # # MDEV-20354 All but last insert ignored in InnoDB tables when table locked # diff --git a/mysql-test/suite/innodb_fts/r/savepoint.result b/mysql-test/suite/innodb_fts/r/savepoint.result index 1abfc961d0a..b2d53c36fbe 100644 --- a/mysql-test/suite/innodb_fts/r/savepoint.result +++ b/mysql-test/suite/innodb_fts/r/savepoint.result @@ -249,9 +249,33 @@ id title 7 mysql TRUNCATE TABLE articles; INSERT INTO articles(id, title) VALUES(1, 'mysql'); +CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB; BEGIN; +INSERT INTO t SET a=1; +SAVEPOINT t; +INSERT INTO articles(id, title) VALUES(2, 'mysql'); +SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql'); +id title +1 mysql +ROLLBACK TO SAVEPOINT t; +SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql'); +id title +1 mysql +SELECT * FROM t; +a +1 +COMMIT; +SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql'); +id title +1 mysql +BEGIN; +INSERT INTO t SET a=2; INSERT INTO articles(id, title) VALUES(2, 'mysql'); ROLLBACK; +SELECT * FROM t; +a +1 +DROP TABLE t; INSERT INTO articles(id, title) VALUES(3, 'mysql'); SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql'); id title diff --git a/mysql-test/suite/innodb_fts/t/savepoint.test b/mysql-test/suite/innodb_fts/t/savepoint.test index 09ccb383bb9..ae83c23d20c 100644 --- a/mysql-test/suite/innodb_fts/t/savepoint.test +++ b/mysql-test/suite/innodb_fts/t/savepoint.test @@ -366,12 +366,28 @@ TRUNCATE TABLE articles; INSERT INTO articles(id, title) VALUES(1, 'mysql'); +CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB; BEGIN; +INSERT INTO t SET a=1; +SAVEPOINT t; +INSERT INTO articles(id, title) VALUES(2, 'mysql'); +SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql'); +ROLLBACK TO SAVEPOINT t; +SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql'); +SELECT * FROM t; +COMMIT; +SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql'); + +BEGIN; +INSERT INTO t SET a=2; INSERT INTO articles(id, title) VALUES(2, 'mysql'); ROLLBACK; +SELECT * FROM t; +DROP TABLE t; + INSERT INTO articles(id, title) VALUES(3, 'mysql'); SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql'); diff --git a/mysql-test/suite/innodb_zip/r/wl5522_debug_zip.result b/mysql-test/suite/innodb_zip/r/wl5522_debug_zip.result index 5ce6affeb0c..1f4d9e592ab 100644 --- a/mysql-test/suite/innodb_zip/r/wl5522_debug_zip.result +++ b/mysql-test/suite/innodb_zip/r/wl5522_debug_zip.result @@ -91,7 +91,7 @@ restore: t1 .ibd and .cfg files SET SESSION debug_dbug=@saved_debug_dbug; SET SESSION debug_dbug="+d,ib_import_open_tablespace_failure"; ALTER TABLE t1 IMPORT TABLESPACE; -ERROR HY000: Got error 42 'Tablespace not found' from ./test/t1.ibd +ERROR HY000: Got error 41 'Tablespace not found' from ./test/t1.ibd SET SESSION debug_dbug=@saved_debug_dbug; restore: t1 .ibd and .cfg files SET SESSION debug_dbug="+d,ib_import_check_bitmap_failure"; diff --git a/mysql-test/suite/multi_source/gtid_ignore_duplicates.test b/mysql-test/suite/multi_source/gtid_ignore_duplicates.test index cbc06920b41..634ff002cbc 100644 --- a/mysql-test/suite/multi_source/gtid_ignore_duplicates.test +++ b/mysql-test/suite/multi_source/gtid_ignore_duplicates.test @@ -2,6 +2,9 @@ --source include/have_innodb.inc --source include/have_debug.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log --echo *** Test all-to-all replication with --gtid-ignore-duplicates *** diff --git a/mysql-test/suite/rpl/r/rpl_mark_optimize_tbl_ddl.result b/mysql-test/suite/rpl/r/rpl_mark_optimize_tbl_ddl.result index 09edd28827b..6296196104b 100644 --- a/mysql-test/suite/rpl/r/rpl_mark_optimize_tbl_ddl.result +++ b/mysql-test/suite/rpl/r/rpl_mark_optimize_tbl_ddl.result @@ -36,9 +36,9 @@ Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK FLUSH LOGS; -FOUND 1 /GTID 0-1-8 ddl/ in mysqlbinlog.out FOUND 1 /GTID 0-1-9 ddl/ in mysqlbinlog.out FOUND 1 /GTID 0-1-10 ddl/ in mysqlbinlog.out +FOUND 1 /GTID 0-1-11 ddl/ in mysqlbinlog.out # # Clean up # @@ -63,9 +63,9 @@ ALTER TABLE t1 REPAIR PARTITION p0; Table Op Msg_type Msg_text test.t1 repair status OK FLUSH LOGS; -FOUND 1 /GTID 0-1-14 ddl/ in mysqlbinlog.out FOUND 1 /GTID 0-1-15 ddl/ in mysqlbinlog.out FOUND 1 /GTID 0-1-16 ddl/ in mysqlbinlog.out +FOUND 1 /GTID 0-1-17 ddl/ in mysqlbinlog.out # # Clean up # diff --git a/mysql-test/suite/rpl/t/rpl_mark_optimize_tbl_ddl.test b/mysql-test/suite/rpl/t/rpl_mark_optimize_tbl_ddl.test index 6d66e3fd088..4c9b57e4bda 100644 --- a/mysql-test/suite/rpl/t/rpl_mark_optimize_tbl_ddl.test +++ b/mysql-test/suite/rpl/t/rpl_mark_optimize_tbl_ddl.test @@ -22,6 +22,10 @@ --let $rpl_topology=1->2 --source include/rpl_init.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --connection server_1 FLUSH TABLES; ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; diff --git a/mysql-test/suite/rpl/t/rpl_parallel_deadlock_victim.test b/mysql-test/suite/rpl/t/rpl_parallel_deadlock_victim.test index ab634d2953e..c1876a43dca 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_deadlock_victim.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_deadlock_victim.test @@ -2,6 +2,9 @@ --source include/have_debug.inc --source include/master-slave.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log --echo MDEV-31655: Parallel replication deadlock victim preference code erroneously removed # The problem was that InnoDB would choose the wrong deadlock victim. diff --git a/mysql-test/suite/rpl/t/rpl_parallel_deadlock_victim2.test b/mysql-test/suite/rpl/t/rpl_parallel_deadlock_victim2.test index 522cec18bbc..68d5ad6a481 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_deadlock_victim2.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_deadlock_victim2.test @@ -3,6 +3,10 @@ --source include/have_debug.inc --source include/have_binlog_format_statement.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --connection master ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; CREATE TABLE t1(a INT) ENGINE=INNODB; diff --git a/mysql-test/suite/rpl/t/rpl_parallel_innodb_lock_conflict.test b/mysql-test/suite/rpl/t/rpl_parallel_innodb_lock_conflict.test index 90304937445..532eb58571c 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_innodb_lock_conflict.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_innodb_lock_conflict.test @@ -5,6 +5,10 @@ --source include/have_debug_sync.inc --source include/master-slave.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --connection server_2 SET sql_log_bin=0; CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends"); diff --git a/mysql-test/suite/rpl/t/rpl_parallel_optimistic.test b/mysql-test/suite/rpl/t/rpl_parallel_optimistic.test index 09da8c2df15..988221d4c18 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_optimistic.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_optimistic.test @@ -7,6 +7,9 @@ call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); call mtr.add_suppression("Can't find record in 't1'"); call mtr.add_suppression("Can't find record in 't2'"); +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log --connection server_1 ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; diff --git a/mysql-test/suite/rpl/t/rpl_parallel_optimistic_nobinlog.test b/mysql-test/suite/rpl/t/rpl_parallel_optimistic_nobinlog.test index ee0de499edf..0b7a76aa78b 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_optimistic_nobinlog.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_optimistic_nobinlog.test @@ -3,6 +3,10 @@ --let $rpl_topology=1->2 --source include/rpl_init.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --connection server_1 ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; CREATE TABLE t1 (a int PRIMARY KEY, b INT) ENGINE=InnoDB; diff --git a/mysql-test/suite/rpl/t/rpl_parallel_xa_same_xid.test b/mysql-test/suite/rpl/t/rpl_parallel_xa_same_xid.test index 888dd2f177b..17c404adef8 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_xa_same_xid.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_xa_same_xid.test @@ -9,6 +9,10 @@ --source include/have_perfschema.inc --source include/master-slave.inc +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + --let $xid_num = 19 --let $repeat = 17 --let $workers = 7 diff --git a/mysql-test/suite/rpl/t/rpl_temporary_error2.test b/mysql-test/suite/rpl/t/rpl_temporary_error2.test index 3537499d562..23a84a02760 100644 --- a/mysql-test/suite/rpl/t/rpl_temporary_error2.test +++ b/mysql-test/suite/rpl/t/rpl_temporary_error2.test @@ -2,6 +2,9 @@ --source include/master-slave.inc call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log --echo *** Provoke a deadlock on the slave, check that transaction retry succeeds. *** --connection master diff --git a/mysql-test/suite/versioning/t/update.test b/mysql-test/suite/versioning/t/update.test index e7a57b393ad..e3b07bfe47a 100644 --- a/mysql-test/suite/versioning/t/update.test +++ b/mysql-test/suite/versioning/t/update.test @@ -1,6 +1,10 @@ source suite/versioning/engines.inc; source suite/versioning/common.inc; +--disable_query_log +call mtr.add_suppression("InnoDB: Transaction was aborted due to "); +--enable_query_log + replace_result $sys_datatype_expl SYS_DATATYPE; eval create table t1( x int unsigned, diff --git a/sql/handler.cc b/sql/handler.cc index 09f5131626b..286f65db1ae 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -4676,6 +4676,12 @@ void handler::print_error(int error, myf errflag) case HA_ERR_PARTITION_LIST: my_error(ER_VERS_NOT_ALLOWED, errflag, table->s->db.str, table->s->table_name.str); DBUG_VOID_RETURN; + case HA_ERR_ROLLBACK: + /* Crash if we run with --debug-assert-on-error */ + DBUG_ASSERT(!debug_assert_if_crashed_table); + SET_FATAL_ERROR; + textno= ER_ROLLBACK_ONLY; + break; default: { /* The error was "unknown" to this function. @@ -4710,7 +4716,7 @@ void handler::print_error(int error, myf errflag) /* Ensure this becomes a true error */ errflag&= ~(ME_WARNING | ME_NOTE); if ((debug_assert_if_crashed_table || - global_system_variables.log_warnings > 1)) + global_system_variables.log_warnings > 1)) { /* Log error to log before we crash or if extended warnings are requested diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 4cc3cdf38c4..69e3032a2db 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -1541,7 +1541,7 @@ struct find_interesting_trx { void operator()(const trx_t &trx) { - if (trx.state == TRX_STATE_NOT_STARTED) + if (!trx.is_started()) return; if (trx.mysql_thd == nullptr) return; @@ -1550,12 +1550,12 @@ struct find_interesting_trx if (!found) { - ib::warn() << "The following trx might hold " + sql_print_warning("InnoDB: The following trx might hold " "the blocks in buffer pool to " "be withdrawn. Buffer pool " "resizing can complete only " "after all the transactions " - "below release the blocks."; + "below release the blocks."); found= true; } diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 4ff034e0e3c..df2cb568d4d 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -2211,7 +2211,7 @@ fts_savepoint_t* fts_savepoint_create( /*=================*/ ib_vector_t* savepoints, /*!< out: InnoDB transaction */ - const char* name, /*!< in: savepoint name */ + const void* name, /*!< in: savepoint */ mem_heap_t* heap) /*!< in: heap */ { fts_savepoint_t* savepoint; @@ -2220,11 +2220,7 @@ fts_savepoint_create( ib_vector_push(savepoints, NULL)); memset(savepoint, 0x0, sizeof(*savepoint)); - - if (name) { - savepoint->name = mem_heap_strdup(heap, name); - } - + savepoint->name = name; static_assert(!offsetof(fts_trx_table_t, table), "ABI"); savepoint->tables = rbt_create(sizeof(fts_trx_table_t*), fts_ptr2_cmp); @@ -2243,7 +2239,6 @@ fts_trx_create( fts_trx_t* ftt; ib_alloc_t* heap_alloc; mem_heap_t* heap = mem_heap_create(1024); - trx_named_savept_t* savep; ut_a(trx->fts_trx == NULL); @@ -2263,14 +2258,6 @@ fts_trx_create( fts_savepoint_create(ftt->savepoints, NULL, NULL); fts_savepoint_create(ftt->last_stmt, NULL, NULL); - /* Copy savepoints that already set before. */ - for (savep = UT_LIST_GET_FIRST(trx->trx_savepoints); - savep != NULL; - savep = UT_LIST_GET_NEXT(trx_savepoints, savep)) { - - fts_savepoint_take(ftt, savep->name); - } - return(ftt); } @@ -5410,7 +5397,7 @@ void fts_savepoint_take( /*===============*/ fts_trx_t* fts_trx, /*!< in: fts transaction */ - const char* name) /*!< in: savepoint name */ + const void* name) /*!< in: savepoint */ { mem_heap_t* heap; fts_savepoint_t* savepoint; @@ -5433,31 +5420,21 @@ fts_savepoint_take( } /*********************************************************************//** -Lookup a savepoint instance by name. -@return ULINT_UNDEFINED if not found */ -UNIV_INLINE +Lookup a savepoint instance. +@return 0 if not found */ +static ulint fts_savepoint_lookup( /*==================*/ ib_vector_t* savepoints, /*!< in: savepoints */ - const char* name) /*!< in: savepoint name */ + const void* name) /*!< in: savepoint */ { - ulint i; - - ut_a(ib_vector_size(savepoints) > 0); - - for (i = 1; i < ib_vector_size(savepoints); ++i) { - fts_savepoint_t* savepoint; - - savepoint = static_cast( - ib_vector_get(savepoints, i)); - - if (strcmp(name, savepoint->name) == 0) { - return(i); - } - } - - return(ULINT_UNDEFINED); + ut_a(ib_vector_size(savepoints) > 0); + for (ulint i= 1; i < ib_vector_size(savepoints); ++i) + if (name == static_cast + (ib_vector_get(savepoints, i))->name) + return i; + return 0; } /*********************************************************************//** @@ -5468,7 +5445,7 @@ void fts_savepoint_release( /*==================*/ trx_t* trx, /*!< in: transaction */ - const char* name) /*!< in: savepoint name */ + const void* name) /*!< in: savepoint name */ { ut_a(name != NULL); @@ -5476,10 +5453,7 @@ fts_savepoint_release( ut_a(ib_vector_size(savepoints) > 0); - ulint i = fts_savepoint_lookup(savepoints, name); - if (i != ULINT_UNDEFINED) { - ut_a(i >= 1); - + if (ulint i = fts_savepoint_lookup(savepoints, name)) { fts_savepoint_t* savepoint; savepoint = static_cast( ib_vector_get(savepoints, i)); @@ -5634,9 +5608,8 @@ void fts_savepoint_rollback( /*===================*/ trx_t* trx, /*!< in: transaction */ - const char* name) /*!< in: savepoint name */ + const void* name) /*!< in: savepoint */ { - ulint i; ib_vector_t* savepoints; ut_a(name != NULL); @@ -5645,16 +5618,19 @@ fts_savepoint_rollback( /* We pop all savepoints from the the top of the stack up to and including the instance that was found. */ - i = fts_savepoint_lookup(savepoints, name); + ulint i = fts_savepoint_lookup(savepoints, name); - if (i != ULINT_UNDEFINED) { + if (i == 0) { + /* fts_trx_create() must have been invoked after + this savepoint had been created, and we must roll back + everything. */ + i = 1; + } + + { fts_savepoint_t* savepoint; - ut_a(i > 0); - while (ib_vector_size(savepoints) > i) { - fts_savepoint_t* savepoint; - savepoint = static_cast( ib_vector_pop(savepoints)); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 4005b9345fa..ffed80b1341 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -1115,17 +1115,6 @@ static SHOW_VAR innodb_status_variables[]= { {NullS, NullS, SHOW_LONG} }; -/*****************************************************************//** -Frees a possible InnoDB trx object associated with the current THD. -@return 0 or error number */ -static -int -innobase_close_connection( -/*======================*/ - handlerton* hton, /*!< in/out: InnoDB handlerton */ - THD* thd); /*!< in: MySQL thread handle for - which to close the connection */ - /** Cancel any pending lock request associated with the current THD. @sa THD::awake() @sa ha_kill_query() */ static void innobase_kill_query(handlerton*, THD* thd, enum thd_kill_levels); @@ -1190,33 +1179,6 @@ innobase_rollback_to_savepoint_can_release_mdl( the user whose XA transaction should be rolled back to savepoint */ -/*****************************************************************//** -Sets a transaction savepoint. -@return always 0, that is, always succeeds */ -static -int -innobase_savepoint( -/*===============*/ - handlerton* hton, /*!< in/out: InnoDB handlerton */ - THD* thd, /*!< in: handle to the MySQL thread of - the user's XA transaction for which - we need to take a savepoint */ - void* savepoint); /*!< in: savepoint data */ - -/*****************************************************************//** -Release transaction savepoint name. -@return 0 if success, HA_ERR_NO_SAVEPOINT if no savepoint with the -given name */ -static -int -innobase_release_savepoint( -/*=======================*/ - handlerton* hton, /*!< in/out: handlerton for InnoDB */ - THD* thd, /*!< in: handle to the MySQL thread - of the user whose transaction's - savepoint should be released */ - void* savepoint); /*!< in: savepoint data */ - /** Request notification of log writes */ static void innodb_log_flush_request(void *cookie); @@ -2179,6 +2141,25 @@ static int innodb_ddl_recovery_done(handlerton*) return 0; } +/** Report an aborted transaction or statement. +@param thd execution context +@param all true=transaction, false=statement +@param err InnoDB error code */ +static void innodb_transaction_abort(THD *thd, bool all, dberr_t err) noexcept +{ + if (!thd) + return; + if (!all); + else if (trx_t *trx = thd_to_trx(thd)) + { + ut_ad(trx->state == TRX_STATE_NOT_STARTED); + trx->state= TRX_STATE_ABORTED; + sql_print_error("InnoDB: Transaction was aborted due to %s", + ut_strerr(err)); + } + thd_mark_transaction_to_rollback(thd, all); +} + /********************************************************************//** Converts an InnoDB error code to a MySQL error code and also tells to MySQL about a possible transaction rollback inside InnoDB caused by a lock wait @@ -2241,14 +2222,9 @@ convert_error_code_to_mysql( case DB_DEADLOCK: case DB_RECORD_CHANGED: - /* Since we rolled back the whole transaction, we must - tell it also to MySQL so that MySQL knows to empty the - cached binlog for this transaction */ - - if (thd != NULL) { - thd_mark_transaction_to_rollback(thd, 1); - } - + /* Since we rolled back the whole transaction, the + cached binlog must be emptied. */ + innodb_transaction_abort(thd, true, error); return error == DB_DEADLOCK ? HA_ERR_LOCK_DEADLOCK : HA_ERR_RECORD_CHANGED; @@ -2257,11 +2233,8 @@ convert_error_code_to_mysql( latest SQL statement in a lock wait timeout. Previously, we rolled back the whole transaction. */ - if (thd) { - thd_mark_transaction_to_rollback( - thd, innobase_rollback_on_timeout); - } - + innodb_transaction_abort(thd, innobase_rollback_on_timeout, + error); return(HA_ERR_LOCK_WAIT_TIMEOUT); case DB_NO_REFERENCED_ROW: @@ -2340,9 +2313,6 @@ convert_error_code_to_mysql( (ulong) DICT_MAX_FIELD_LEN_BY_FORMAT_FLAG(flags)); return(HA_ERR_INDEX_COL_TOO_LONG); - case DB_NO_SAVEPOINT: - return(HA_ERR_NO_SAVEPOINT); - case DB_LOCK_TABLE_FULL: /* Since we rolled back the whole transaction, we must tell it also to MySQL so that MySQL knows to empty the @@ -2928,7 +2898,7 @@ Gets the InnoDB transaction handle for a MySQL handler object, creates an InnoDB transaction struct if the corresponding MySQL thread struct still lacks one. @return InnoDB transaction handle */ -static inline +static trx_t* check_trx_exists( /*=============*/ @@ -2986,6 +2956,137 @@ trx_deregister_from_2pc( trx->active_commit_ordered= false; } +/** + Set a transaction savepoint. + + @param thd server thread descriptor + @param savepoint transaction savepoint storage area + + @retval 0 on success + @retval HA_ERR_NO_SAVEPOINT if the transaction is in an inconsistent state +*/ +static int innobase_savepoint(handlerton*, THD *thd, void *savepoint) noexcept +{ + DBUG_ENTER("innobase_savepoint"); + + /* In the autocommit mode there is no sense to set a savepoint + (unless we are in sub-statement), so SQL layer ensures that + this method is never called in such situation. */ + trx_t *trx= check_trx_exists(thd); + + /* Cannot happen outside of transaction */ + DBUG_ASSERT(trx_is_registered_for_2pc(trx)); + + switch (UNIV_EXPECT(trx->state, TRX_STATE_ACTIVE)) { + default: + ut_ad("invalid state" == 0); + DBUG_RETURN(HA_ERR_NO_SAVEPOINT); + case TRX_STATE_NOT_STARTED: + trx_start_if_not_started_xa(trx, false); + /* fall through */ + case TRX_STATE_ACTIVE: + const undo_no_t savept{trx->undo_no}; + *static_cast(savepoint)= savept; + trx->last_stmt_start= savept; + trx->end_bulk_insert(); + + if (trx->fts_trx) + fts_savepoint_take(trx->fts_trx, savepoint); + + DBUG_RETURN(0); + } +} + +/** + Releases a transaction savepoint. + + @param thd server thread descriptor + @param savepoint transaction savepoint to be released + + @return 0 always +*/ +static int innobase_release_savepoint(handlerton*, THD *thd, void *savepoint) + noexcept +{ + DBUG_ENTER("innobase_release_savepoint"); + trx_t *trx= check_trx_exists(thd); + ut_ad(trx->mysql_thd == thd); + if (trx->fts_trx) + fts_savepoint_release(trx, savepoint); + DBUG_RETURN(0); +} + +/** + Frees a possible InnoDB trx object associated with the current THD. + + @param thd server thread descriptor, which resources should be free'd + + @return 0 always +*/ +static int innobase_close_connection(handlerton *, THD *thd) noexcept +{ + if (auto trx= thd_to_trx(thd)) + { + thd_set_ha_data(thd, innodb_hton_ptr, nullptr); + switch (trx->state) { + case TRX_STATE_ABORTED: + trx->state= TRX_STATE_NOT_STARTED; + /* fall through */ + case TRX_STATE_NOT_STARTED: + ut_ad(!trx->id); + trx->will_lock= false; + break; + default: + ut_ad("invalid state" == 0); + return 0; + case TRX_STATE_PREPARED: + if (trx->has_logged_persistent()) + { + trx_disconnect_prepared(trx); + return 0; + } + /* fall through */ + case TRX_STATE_ACTIVE: + /* If we had reserved the auto-inc lock for some table (if + we come here to roll back the latest SQL statement) we + release it now before a possibly lengthy rollback */ + lock_unlock_table_autoinc(trx); + trx_rollback_for_mysql(trx); + } + trx_deregister_from_2pc(trx); + trx->free(); + DEBUG_SYNC(thd, "innobase_connection_closed"); + } + return 0; +} + +/** + XA ROLLBACK after XA PREPARE + + @param xid X/Open XA transaction identification + + @retval 0 if the transaction was found and rolled back + @retval XAER_NOTA if no such transaction exists + @retval XAER_RMFAIL if InnoDB is in read-only mode +*/ +static int innobase_rollback_by_xid(handlerton*, XID *xid) noexcept +{ + DBUG_EXECUTE_IF("innobase_xa_fail", return XAER_RMFAIL;); + if (high_level_read_only) + return XAER_RMFAIL; + if (trx_t *trx= trx_get_trx_by_xid(xid)) + { + ut_ad(trx->xid.is_null()); /* should have been cleared by the lookup */ + trx_deregister_from_2pc(trx); + THD* thd= trx->mysql_thd; + dberr_t err= trx_rollback_for_mysql(trx); + ut_ad(!trx->will_lock); + trx->free(); + return convert_error_code_to_mysql(err, 0, thd); + } + return XAER_NOTA; +} + /*********************************************************************//** Copy table flags from MySQL's HA_CREATE_INFO into an InnoDB table object. Those flags are stored in .frm file and end up in the MySQL table object, @@ -4190,7 +4291,7 @@ static int innodb_init(void* p) innodb_hton_ptr = innobase_hton; innobase_hton->db_type = DB_TYPE_INNODB; - innobase_hton->savepoint_offset = sizeof(trx_named_savept_t); + innobase_hton->savepoint_offset = sizeof(undo_no_t); innobase_hton->close_connection = innobase_close_connection; innobase_hton->kill_query = innobase_kill_query; innobase_hton->savepoint_set = innobase_savepoint; @@ -4409,12 +4510,7 @@ innobase_commit_low( tmp = thd_proc_info(trx->mysql_thd, "innobase_commit_low()"); } #endif /* WITH_WSREP */ - if (trx_is_started(trx)) { - trx_commit_for_mysql(trx); - } else { - trx->will_lock = false; - } - + trx_commit_for_mysql(trx); #ifdef WITH_WSREP if (is_wsrep) { thd_proc_info(trx->mysql_thd, tmp); @@ -4445,7 +4541,7 @@ innobase_start_trx_and_assign_read_view( /* The transaction should not be active yet, start it */ - ut_ad(!trx_is_started(trx)); + ut_ad(!trx->is_started()); trx_start_if_not_started_xa(trx, false); @@ -4468,7 +4564,7 @@ innobase_start_trx_and_assign_read_view( /* Set the MySQL flag to mark that there is an active transaction */ - innobase_register_trx(hton, current_thd, trx); + innobase_register_trx(hton, thd, trx); DBUG_RETURN(0); } @@ -4546,7 +4642,7 @@ innobase_commit_ordered( trx = check_trx_exists(thd); - if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) { + if (!trx_is_registered_for_2pc(trx) && trx->is_started()) { /* We cannot throw error here; instead we will catch this error again in innobase_commit() and report it from there. */ DBUG_VOID_RETURN; @@ -4563,6 +4659,23 @@ innobase_commit_ordered( DBUG_VOID_RETURN; } +/** Marks the latest SQL statement ended. */ +static void trx_mark_stmt_end(trx_t *trx) noexcept +{ + ut_d(const trx_state_t trx_state{trx->state}); + ut_ad(trx_state == TRX_STATE_ACTIVE || trx_state == TRX_STATE_NOT_STARTED); + if (trx->fts_trx) + fts_savepoint_laststmt_refresh(trx); + if (trx->is_bulk_insert()) + /* Allow a subsequent INSERT into an empty table + if !unique_checks && !foreign_key_checks. */; + else + { + trx->last_stmt_start= trx->undo_no; + trx->end_bulk_insert(); + } +} + /*****************************************************************//** Commits a transaction in an InnoDB database or marks an SQL statement ended. @@ -4590,20 +4703,36 @@ innobase_commit( ut_ad(!trx->dict_operation_lock_mode); ut_ad(!trx->dict_operation); - /* Transaction is deregistered only in a commit or a rollback. If - it is deregistered we know there cannot be resources to be freed - and we could return immediately. For the time being, we play safe - and do the cleanup though there should be nothing to clean up. */ - - if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) { - - sql_print_error("Transaction not registered for MariaDB 2PC," - " but transaction is active"); + switch (UNIV_EXPECT(trx->state, TRX_STATE_ACTIVE)) { + case TRX_STATE_ABORTED: + trx->state = TRX_STATE_NOT_STARTED; + /* fall through */ + case TRX_STATE_NOT_STARTED: + break; + default: + case TRX_STATE_COMMITTED_IN_MEMORY: + case TRX_STATE_PREPARED_RECOVERED: + ut_ad("invalid state" == 0); + /* fall through */ + case TRX_STATE_PREPARED: + ut_ad(commit_trx); + ut_ad(thd_test_options(thd, OPTION_NOT_AUTOCOMMIT + | OPTION_BEGIN)); + /* fall through */ + case TRX_STATE_ACTIVE: + /* Transaction is deregistered only in a commit or a + rollback. If it is deregistered we know there cannot + be resources to be freed and we could return + immediately. For the time being, we play safe and do + the cleanup though there should be nothing to clean + up. */ + if (!trx_is_registered_for_2pc(trx)) { + sql_print_error("Transaction not registered" + " for MariaDB 2PC," + " but transaction is active"); + } } - bool read_only = trx->read_only || trx->id == 0; - DBUG_PRINT("info", ("readonly: %d", read_only)); - if (commit_trx || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) { @@ -4631,19 +4760,8 @@ innobase_commit( } else { /* We just mark the SQL statement ended and do not do a transaction commit */ - - /* If we had reserved the auto-inc lock for some - table in this SQL statement we release it now */ - - if (!read_only) { - lock_unlock_table_autoinc(trx); - } - - /* Store the current undo_no of the transaction so that we - know where to roll back if we have to roll back the next - SQL statement */ - - trx_mark_sql_stat_end(trx); + lock_unlock_table_autoinc(trx); + trx_mark_stmt_end(trx); } /* Reset the number AUTO-INC rows required */ @@ -4662,7 +4780,7 @@ static int innobase_rollback( /*==============*/ - handlerton* hton, /*!< in: InnoDB handlerton */ + handlerton*, THD* thd, /*!< in: handle to the MySQL thread of the user whose transaction should be rolled back */ @@ -4670,74 +4788,79 @@ innobase_rollback( transaction FALSE - rollback the current statement only */ { - DBUG_ENTER("innobase_rollback"); - DBUG_ASSERT(hton == innodb_hton_ptr); - DBUG_PRINT("trans", ("aborting transaction")); + DBUG_ENTER("innobase_rollback"); + DBUG_PRINT("trans", ("aborting transaction")); - trx_t* trx = check_trx_exists(thd); + if (!rollback_trx) + rollback_trx= !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN); - ut_ad(!trx->dict_operation_lock_mode); - ut_ad(!trx->dict_operation); + trx_t *trx= check_trx_exists(thd); - /* Reset the number AUTO-INC rows required */ + ut_ad(trx->mysql_thd == thd); + ut_ad(!trx->is_recovered); + ut_ad(!trx->dict_operation_lock_mode); + ut_ad(!trx->dict_operation); - trx->n_autoinc_rows = 0; + /* Reset the number AUTO-INC rows required */ + trx->n_autoinc_rows= 0; + /* This is a statement level variable. */ + trx->fts_next_doc_id= 0; - /* If we had reserved the auto-inc lock for some table (if - we come here to roll back the latest SQL statement) we - release it now before a possibly lengthy rollback */ - lock_unlock_table_autoinc(trx); - - /* This is a statement level variable. */ - - trx->fts_next_doc_id = 0; - - dberr_t error; + const trx_state_t trx_state{trx->state}; + switch (UNIV_EXPECT(trx_state, TRX_STATE_ACTIVE)) { + case TRX_STATE_ABORTED: + if (rollback_trx) + trx->state= TRX_STATE_NOT_STARTED; + /* fall through */ + case TRX_STATE_NOT_STARTED: + ut_ad(!trx->id); + trx->will_lock= false; + if (rollback_trx) + trx_deregister_from_2pc(trx); + DBUG_RETURN(0); + default: + case TRX_STATE_COMMITTED_IN_MEMORY: + case TRX_STATE_PREPARED_RECOVERED: + ut_ad("invalid state" == 0); + /* fall through */ + case TRX_STATE_PREPARED: + ut_ad(rollback_trx); + /* fall through */ + case TRX_STATE_ACTIVE: + /* If we had reserved the auto-inc lock for some table (if + we come here to roll back the latest SQL statement) we + release it now before a possibly lengthy rollback */ + lock_unlock_table_autoinc(trx); #ifdef WITH_WSREP - /* If trx was assigned wsrep XID in prepare phase and the - trx is being rolled back due to BF abort, clear XID in order - to avoid writing it to rollback segment out of order. The XID - will be reassigned when the transaction is replayed. */ - if (trx->state != TRX_STATE_NOT_STARTED - && wsrep_is_wsrep_xid(&trx->xid)) { - trx->xid.null(); - } + /* If trx was assigned wsrep XID in prepare phase and the + trx is being rolled back due to BF abort, clear XID in order + to avoid writing it to rollback segment out of order. The XID + will be reassigned when the transaction is replayed. */ + if (rollback_trx || wsrep_is_wsrep_xid(&trx->xid)) + trx->xid.null(); #endif /* WITH_WSREP */ - if (rollback_trx - || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { - - error = trx_rollback_for_mysql(trx); - - trx_deregister_from_2pc(trx); - } else { - - error = trx_rollback_last_sql_stat_for_mysql(trx); - } - - DBUG_RETURN(convert_error_code_to_mysql(error, 0, trx->mysql_thd)); -} - -/*****************************************************************//** -Rolls back a transaction -@return 0 or error number */ -static -int -innobase_rollback_trx( -/*==================*/ - trx_t* trx) /*!< in: transaction */ -{ - DBUG_ENTER("innobase_rollback_trx"); - DBUG_PRINT("trans", ("aborting transaction")); - - /* If we had reserved the auto-inc lock for some table (if - we come here to roll back the latest SQL statement) we - release it now before a possibly lengthy rollback */ - lock_unlock_table_autoinc(trx); - trx_deregister_from_2pc(trx); - - DBUG_RETURN(convert_error_code_to_mysql(trx_rollback_for_mysql(trx), - 0, trx->mysql_thd)); + dberr_t error; + if (rollback_trx) + { + error= trx_rollback_for_mysql(trx); + trx_deregister_from_2pc(trx); + } + else + { + ut_a(trx_state == TRX_STATE_ACTIVE); + ut_ad(!trx->is_autocommit_non_locking() || trx->read_only); + error= trx->rollback(&trx->last_stmt_start); + if (trx->fts_trx) + { + fts_savepoint_rollback_last_stmt(trx); + fts_savepoint_laststmt_refresh(trx); + } + trx->last_stmt_start= trx->undo_no; + trx->end_bulk_insert(); + } + DBUG_RETURN(convert_error_code_to_mysql(error, 0, trx->mysql_thd)); + } } /** Invoke commit_checkpoint_notify_ha() on completed log flush requests. @@ -4874,34 +4997,43 @@ static int innobase_rollback_to_savepoint( /*===========================*/ - handlerton* hton, /*!< in: InnoDB handlerton */ + handlerton*, THD* thd, /*!< in: handle to the MySQL thread of the user whose transaction should be rolled back to savepoint */ void* savepoint) /*!< in: savepoint data */ { + DBUG_ENTER("innobase_rollback_to_savepoint"); + trx_t *trx= check_trx_exists(thd); - DBUG_ENTER("innobase_rollback_to_savepoint"); - DBUG_ASSERT(hton == innodb_hton_ptr); + /* We are reading trx->state without holding trx->mutex here, + because the savepoint rollback should be invoked for a running + active transaction that is associated with the current thread. */ + ut_ad(trx->mysql_thd); - trx_t* trx = check_trx_exists(thd); + if (UNIV_UNLIKELY(trx->state != TRX_STATE_ACTIVE)) + { + ut_ad("invalid state" == 0); + DBUG_RETURN(HA_ERR_NO_SAVEPOINT); + } - /* TODO: use provided savepoint data area to store savepoint data */ + const undo_no_t *savept= static_cast(savepoint); - char name[64]; + if (UNIV_UNLIKELY(*savept > trx->undo_no)) + /* row_mysql_handle_errors() should have invoked rollback during + a bulk insert into an empty table. */ + DBUG_RETURN(HA_ERR_NO_SAVEPOINT); - longlong2str(longlong(savepoint), name, 36); - - int64_t mysql_binlog_cache_pos; - - dberr_t error = trx_rollback_to_savepoint_for_mysql( - trx, name, &mysql_binlog_cache_pos); - - if (error == DB_SUCCESS && trx->fts_trx != NULL) { - fts_savepoint_rollback(trx, name); - } - - DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL)); + dberr_t error= trx->rollback(savept); + /* Store the position for rolling back the next SQL statement */ + if (trx->fts_trx) + { + fts_savepoint_laststmt_refresh(trx); + fts_savepoint_rollback(trx, savept); + } + trx->last_stmt_start= trx->undo_no; + trx->end_bulk_insert(); + DBUG_RETURN(convert_error_code_to_mysql(error, 0, nullptr)); } /*****************************************************************//** @@ -4934,106 +5066,6 @@ innobase_rollback_to_savepoint_can_release_mdl( DBUG_RETURN(false); } -/*****************************************************************//** -Release transaction savepoint name. -@return 0 if success, HA_ERR_NO_SAVEPOINT if no savepoint with the -given name */ -static -int -innobase_release_savepoint( -/*=======================*/ - handlerton* hton, /*!< in: handlerton for InnoDB */ - THD* thd, /*!< in: handle to the MySQL thread - of the user whose transaction's - savepoint should be released */ - void* savepoint) /*!< in: savepoint data */ -{ - dberr_t error; - trx_t* trx; - char name[64]; - - DBUG_ENTER("innobase_release_savepoint"); - DBUG_ASSERT(hton == innodb_hton_ptr); - - trx = check_trx_exists(thd); - - /* TODO: use provided savepoint data area to store savepoint data */ - - longlong2str(longlong(savepoint), name, 36); - - error = trx_release_savepoint_for_mysql(trx, name); - - if (error == DB_SUCCESS && trx->fts_trx != NULL) { - fts_savepoint_release(trx, name); - } - - DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL)); -} - -/*****************************************************************//** -Sets a transaction savepoint. -@return always 0, that is, always succeeds */ -static -int -innobase_savepoint( -/*===============*/ - handlerton* hton, /*!< in: handle to the InnoDB handlerton */ - THD* thd, /*!< in: handle to the MySQL thread */ - void* savepoint)/*!< in: savepoint data */ -{ - DBUG_ENTER("innobase_savepoint"); - DBUG_ASSERT(hton == innodb_hton_ptr); - - /* In the autocommit mode there is no sense to set a savepoint - (unless we are in sub-statement), so SQL layer ensures that - this method is never called in such situation. */ - - trx_t* trx = check_trx_exists(thd); - - /* Cannot happen outside of transaction */ - DBUG_ASSERT(trx_is_registered_for_2pc(trx)); - - /* TODO: use provided savepoint data area to store savepoint data */ - char name[64]; - - longlong2str(longlong(savepoint), name, 36); - - dberr_t error = trx_savepoint_for_mysql(trx, name, 0); - - if (error == DB_SUCCESS && trx->fts_trx != NULL) { - fts_savepoint_take(trx->fts_trx, name); - } - - DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL)); -} - - -/** - Frees a possible InnoDB trx object associated with the current THD. - - @param hton innobase handlerton - @param thd server thread descriptor, which resources should be free'd - - @return 0 always -*/ -static int innobase_close_connection(handlerton *hton, THD *thd) -{ - DBUG_ASSERT(hton == innodb_hton_ptr); - if (auto trx= thd_to_trx(thd)) - { - thd_set_ha_data(thd, innodb_hton_ptr, NULL); - if (trx->state == TRX_STATE_PREPARED && trx->has_logged_persistent()) - { - trx_disconnect_prepared(trx); - return 0; - } - innobase_rollback_trx(trx); - trx->free(); - DEBUG_SYNC(thd, "innobase_connection_closed"); - } - return 0; -} - /** Cancel any pending lock request associated with the current THD. @sa THD::awake() @sa ha_kill_query() */ static void innobase_kill_query(handlerton*, THD *thd, enum thd_kill_levels) @@ -7794,26 +7826,35 @@ ha_innobase::innobase_set_max_autoinc( return(error); } -/** @return whether the table is read-only */ -bool ha_innobase::is_read_only(bool altering_to_supported) const +int ha_innobase::is_valid_trx(bool altering_to_supported) const noexcept { ut_ad(m_prebuilt->trx == thd_to_trx(m_user_thd)); if (high_level_read_only) { ib_senderrf(m_user_thd, IB_LOG_LEVEL_WARN, ER_READ_ONLY_MODE); - return true; + return HA_ERR_TABLE_READONLY; } - if (altering_to_supported) - return false; + switch (UNIV_EXPECT(m_prebuilt->trx->state, TRX_STATE_ACTIVE)) { + default: + ut_ad("invalid state" == 0); + /* fall through */ + case TRX_STATE_ABORTED: + break; + case TRX_STATE_NOT_STARTED: + m_prebuilt->trx->will_lock= true; + /* fall through */ + case TRX_STATE_ACTIVE: + if (altering_to_supported || + !DICT_TF_GET_ZIP_SSIZE(m_prebuilt->table->flags) || + !innodb_read_only_compressed) + return 0; - if (!DICT_TF_GET_ZIP_SSIZE(m_prebuilt->table->flags) || - !innodb_read_only_compressed) - return false; - - ib_senderrf(m_user_thd, IB_LOG_LEVEL_WARN, ER_UNSUPPORTED_COMPRESSED_TABLE); - return true; + ib_senderrf(m_user_thd, IB_LOG_LEVEL_WARN, ER_UNSUPPORTED_COMPRESSED_TABLE); + return HA_ERR_TABLE_READONLY; + } + return HA_ERR_ROLLBACK; } /********************************************************************//** @@ -7839,12 +7880,8 @@ ha_innobase::write_row( trx_t* trx = thd_to_trx(m_user_thd); /* Validation checks before we commence write_row operation. */ - if (is_read_only()) { - DBUG_RETURN(HA_ERR_TABLE_READONLY); - } - - if (!trx_is_started(trx)) { - trx->will_lock = true; + if (int err = is_valid_trx()) { + DBUG_RETURN(err); } ins_mode_t vers_set_fields; @@ -8613,10 +8650,8 @@ ha_innobase::update_row( DBUG_ENTER("ha_innobase::update_row"); - if (is_read_only()) { - DBUG_RETURN(HA_ERR_TABLE_READONLY); - } else if (!trx_is_started(trx)) { - trx->will_lock = true; + if (int err = is_valid_trx()) { + DBUG_RETURN(err); } if (m_upd_buf == NULL) { @@ -8734,7 +8769,8 @@ func_exit: if (error == DB_SUCCESS && /* For sequences, InnoDB transaction may not have been started yet. Check THD-level wsrep state in that case. */ - (trx->is_wsrep() || (!trx_is_started(trx) && wsrep_on(m_user_thd))) + (trx->is_wsrep() + || (trx->state == TRX_STATE_NOT_STARTED && wsrep_on(m_user_thd))) && wsrep_thd_is_local(m_user_thd) && !wsrep_thd_ignore_table(m_user_thd) && (thd_sql_command(m_user_thd) != SQLCOM_CREATE_TABLE) @@ -8778,12 +8814,9 @@ ha_innobase::delete_row( DBUG_ENTER("ha_innobase::delete_row"); - if (is_read_only()) { - DBUG_RETURN(HA_ERR_TABLE_READONLY); - } else if (!trx_is_started(trx)) { - trx->will_lock = true; + if (int err = is_valid_trx()) { + DBUG_RETURN(err); } - if (!m_prebuilt->upd_node) { row_get_prebuilt_update_vector(m_prebuilt); } @@ -9060,10 +9093,15 @@ ha_innobase::index_read( DBUG_RETURN(HA_ERR_KEY_NOT_FOUND); } + const trx_state_t trx_state{m_prebuilt->trx->state}; + if (trx_state == TRX_STATE_ABORTED) { + DBUG_RETURN(HA_ERR_ROLLBACK); + } + /* For R-Tree index, we will always place the page lock to pages being searched */ if (index->is_spatial() && !m_prebuilt->trx->will_lock) { - if (trx_is_started(m_prebuilt->trx)) { + if (trx_state != TRX_STATE_NOT_STARTED) { DBUG_RETURN(HA_ERR_READ_ONLY_TRANSACTION); } else { m_prebuilt->trx->will_lock = true; @@ -9344,6 +9382,17 @@ ha_innobase::general_fetch( ut_ad(trx == thd_to_trx(m_user_thd)); + switch (UNIV_EXPECT(trx->state, TRX_STATE_ACTIVE)) { + default: + ut_ad("invalid state" == 0); + /* fall through */ + case TRX_STATE_ABORTED: + DBUG_RETURN(HA_ERR_ROLLBACK); + case TRX_STATE_ACTIVE: + case TRX_STATE_NOT_STARTED: + break; + } + if (m_prebuilt->table->is_readable()) { } else if (m_prebuilt->table->corrupted) { DBUG_RETURN(HA_ERR_CRASHED); @@ -9596,9 +9645,7 @@ ha_innobase::rnd_pos( Initialize FT index scan @return 0 or error number */ -int -ha_innobase::ft_init() -/*==================*/ +int ha_innobase::ft_init() { DBUG_ENTER("ft_init"); @@ -9608,9 +9655,14 @@ ha_innobase::ft_init() This is because the FTS implementation can acquire locks behind the scenes. This has not been verified but it is safer to treat them as regular read only transactions for now. */ - - if (!trx_is_started(trx)) { + switch (trx->state) { + default: + DBUG_RETURN(HA_ERR_ROLLBACK); + case TRX_STATE_ACTIVE: + break; + case TRX_STATE_NOT_STARTED: trx->will_lock = true; + break; } DBUG_RETURN(rnd_init(false)); @@ -9644,11 +9696,9 @@ ha_innobase::ft_init_ext( out.write(key->ptr(), key->length()); } - if (flags & FT_BOOL) { - ib::info() << "BOOL search"; - } else { - ib::info() << "NL search"; - } + sql_print_information((flags & FT_BOOL) + ? "InnoDB: BOOL search" + : "InnoDB: NL search"); } /* Multi byte character sets like utf32 and utf16 are not @@ -9673,8 +9723,17 @@ ha_innobase::ft_init_ext( the scenes. This has not been verified but it is safer to treat them as regular read only transactions for now. */ - if (!trx_is_started(trx)) { + switch (trx->state) { + default: + ut_ad("invalid state" == 0); + my_printf_error(HA_ERR_ROLLBACK, "Invalid tansaction state", + ME_ERROR_LOG); + return nullptr; + case TRX_STATE_ACTIVE: + break; + case TRX_STATE_NOT_STARTED: trx->will_lock = true; + break; } dict_table_t* ft_table = m_prebuilt->table; @@ -13354,12 +13413,8 @@ ha_innobase::discard_or_import_tablespace( DBUG_ENTER("ha_innobase::discard_or_import_tablespace"); - ut_a(m_prebuilt->trx != NULL); - ut_a(m_prebuilt->trx->magic_n == TRX_MAGIC_N); - ut_a(m_prebuilt->trx == thd_to_trx(ha_thd())); - - if (is_read_only()) { - DBUG_RETURN(HA_ERR_TABLE_READONLY); + if (int err = is_valid_trx()) { + DBUG_RETURN(err); } if (m_prebuilt->table->is_temporary()) { @@ -13907,8 +13962,8 @@ int ha_innobase::truncate() } #endif - if (is_read_only()) - DBUG_RETURN(HA_ERR_TABLE_READONLY); + if (int err= is_valid_trx()) + DBUG_RETURN(err); HA_CREATE_INFO info; dict_table_t *ib_table= m_prebuilt->table; @@ -15940,6 +15995,16 @@ ha_innobase::start_stmt( trx = m_prebuilt->trx; + switch (trx->state) { + default: + DBUG_RETURN(HA_ERR_ROLLBACK); + case TRX_STATE_ACTIVE: + break; + case TRX_STATE_NOT_STARTED: + trx->will_lock = true; + break; + } + /* Reset the AUTOINC statement level counter for multi-row INSERTs. */ trx->n_autoinc_rows = 0; @@ -15963,7 +16028,7 @@ ha_innobase::start_stmt( break; } trx->bulk_insert = false; - trx->last_sql_stat_start.least_undo_no = trx->undo_no; + trx->last_stmt_start = trx->undo_no; } m_prebuilt->sql_stat_start = TRUE; @@ -16021,10 +16086,6 @@ ha_innobase::start_stmt( innobase_register_trx(ht, thd, trx); - if (!trx_is_started(trx)) { - trx->will_lock = true; - } - DBUG_RETURN(0); } @@ -16076,6 +16137,28 @@ ha_innobase::external_lock( trx_t* trx = m_prebuilt->trx; ut_ad(m_prebuilt->table); + const bool not_autocommit = thd_test_options(thd, OPTION_NOT_AUTOCOMMIT + | OPTION_BEGIN); + bool not_started = false; + switch (trx->state) { + default: + case TRX_STATE_PREPARED: + ut_ad("invalid state" == 0); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + case TRX_STATE_ABORTED: + if (lock_type != F_UNLCK && not_autocommit) { + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + /* Reset the state if the transaction had been aborted. */ + trx->state = TRX_STATE_NOT_STARTED; + /* fall through */ + case TRX_STATE_NOT_STARTED: + not_started = true; + break; + case TRX_STATE_ACTIVE: + break; + } + /* Statement based binlogging does not work in isolation level READ UNCOMMITTED and READ COMMITTED since the necessary locks cannot be taken. In this case, we print an @@ -16151,7 +16234,7 @@ ha_innobase::external_lock( break; } trx->bulk_insert = false; - trx->last_sql_stat_start.least_undo_no = trx->undo_no; + trx->last_stmt_start = trx->undo_no; } switch (m_prebuilt->table->quiesce) { @@ -16197,25 +16280,47 @@ ha_innobase::external_lock( break; } - if (lock_type == F_WRLCK) { + switch (lock_type) { + case F_UNLCK: + DEBUG_SYNC_C("ha_innobase_end_statement"); + m_mysql_has_locked = false; + if (--trx->n_mysql_tables_in_use) { + break; + } + + /* If the lock count drops to zero we know that the + current SQL statement has ended */ + trx->mysql_n_tables_locked = 0; + m_prebuilt->used_in_HANDLER = FALSE; + + if (!not_autocommit) { + if (!not_started) { + innobase_commit(ht, thd, TRUE); + } + } else if (trx->isolation_level <= TRX_ISO_READ_COMMITTED) { + trx->read_view.close(); + } + break; + case F_WRLCK: /* If this is a SELECT, then it is in UPDATE TABLE ... or SELECT ... FOR UPDATE */ m_prebuilt->select_lock_type = LOCK_X; m_prebuilt->stored_select_lock_type = LOCK_X; - } - - if (lock_type != F_UNLCK) { - /* MySQL is setting a new table lock */ - + goto set_lock; + case F_RDLCK: + /* Ensure that trx->lock.trx_locks is empty for read-only + autocommit transactions */ + ut_ad(not_autocommit || trx->n_mysql_tables_in_use + || UT_LIST_GET_LEN(trx->lock.trx_locks) == 0); +set_lock: *trx->detailed_error = 0; innobase_register_trx(ht, thd, trx); - if (trx->isolation_level == TRX_ISO_SERIALIZABLE - && m_prebuilt->select_lock_type == LOCK_NONE - && thd_test_options( - thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { + if (not_autocommit + && trx->isolation_level == TRX_ISO_SERIALIZABLE + && m_prebuilt->select_lock_type == LOCK_NONE) { /* To get serializable execution, we let InnoDB conceptually add 'LOCK IN SHARE MODE' to all SELECTs @@ -16263,42 +16368,12 @@ ha_innobase::external_lock( trx->n_mysql_tables_in_use++; m_mysql_has_locked = true; - if (!trx_is_started(trx) + if (not_started && (m_prebuilt->select_lock_type != LOCK_NONE || m_prebuilt->stored_select_lock_type != LOCK_NONE)) { trx->will_lock = true; } - - DBUG_RETURN(0); - } - - DEBUG_SYNC_C("ha_innobase_end_statement"); - - /* MySQL is releasing a table lock */ - - trx->n_mysql_tables_in_use--; - m_mysql_has_locked = false; - - /* If the MySQL lock count drops to zero we know that the current SQL - statement has ended */ - - if (trx->n_mysql_tables_in_use == 0) { - - trx->mysql_n_tables_locked = 0; - m_prebuilt->used_in_HANDLER = FALSE; - - if (!thd_test_options( - thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { - - if (trx_is_started(trx)) { - - innobase_commit(ht, thd, TRUE); - } - - } else if (trx->isolation_level <= TRX_ISO_READ_COMMITTED) { - trx->read_view.close(); - } } DBUG_RETURN(0); @@ -16639,14 +16714,6 @@ ha_innobase::store_lock( } m_prebuilt->skip_locked= (lock_type == TL_WRITE_SKIP_LOCKED || lock_type == TL_READ_SKIP_LOCKED); - - if (!trx_is_started(trx) - && (m_prebuilt->select_lock_type != LOCK_NONE - || m_prebuilt->stored_select_lock_type != LOCK_NONE)) { - - trx->will_lock = true; - } - return(to); } @@ -17120,7 +17187,7 @@ static int innobase_xa_prepare( /*================*/ - handlerton* hton, /*!< in: InnoDB handlerton */ + handlerton*, THD* thd, /*!< in: handle to the MySQL thread of the user whose XA transaction should be prepared */ @@ -17128,62 +17195,30 @@ innobase_xa_prepare( false - the current SQL statement ended */ { - trx_t* trx = check_trx_exists(thd); + trx_t *trx= check_trx_exists(thd); + ut_ad(trx_is_registered_for_2pc(trx)); + if (!prepare_trx) + prepare_trx= !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN); - DBUG_ASSERT(hton == innodb_hton_ptr); - - thd_get_xid(thd, &reinterpret_cast(trx->xid)); - - if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) { - - sql_print_error("Transaction not registered for MariaDB 2PC," - " but transaction is active"); - } - - if (prepare_trx - || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) { - - /* We were instructed to prepare the whole transaction, or - this is an SQL statement end and autocommit is on */ - - ut_ad(trx_is_registered_for_2pc(trx)); - - trx_prepare_for_mysql(trx); - } else { - /* We just mark the SQL statement ended and do not do a - transaction prepare */ - - /* If we had reserved the auto-inc lock for some - table in this SQL statement we release it now */ - - lock_unlock_table_autoinc(trx); - - /* Store the current undo_no of the transaction so that we - know where to roll back if we have to roll back the next - SQL statement */ - - trx_mark_sql_stat_end(trx); - } - - if (thd_sql_command(thd) != SQLCOM_XA_PREPARE - && (prepare_trx - || !thd_test_options( - thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) { - - /* For mysqlbackup to work the order of transactions in binlog - and InnoDB must be the same. Consider the situation - - thread1> prepare; write to binlog; ... - - thread2> prepare; write to binlog; commit - thread1> ... commit - - The server guarantees that writes to the binary log - and commits are in the same order, so we do not have - to handle this case. */ - } - - return(0); + switch (UNIV_EXPECT(trx->state, TRX_STATE_ACTIVE)) { + default: + ut_ad("invalid state" == 0); + return HA_ERR_GENERIC; + case TRX_STATE_NOT_STARTED: + if (prepare_trx) + trx_start_if_not_started_xa(trx, false);; + /* fall through */ + case TRX_STATE_ACTIVE: + thd_get_xid(thd, &reinterpret_cast(trx->xid)); + if (prepare_trx) + trx_prepare_for_mysql(trx); + else + { + lock_unlock_table_autoinc(trx); + trx_mark_stmt_end(trx); + } + return 0; + } } /*******************************************************************//** @@ -17193,12 +17228,10 @@ static int innobase_xa_recover( /*================*/ - handlerton* hton, /*!< in: InnoDB handlerton */ + handlerton*, XID* xid_list,/*!< in/out: prepared transactions */ uint len) /*!< in: number of slots in xid_list */ { - DBUG_ASSERT(hton == innodb_hton_ptr); - if (len == 0 || xid_list == NULL) { return(0); @@ -17241,43 +17274,6 @@ innobase_commit_by_xid( } } -/** This function is used to rollback one X/Open XA distributed transaction -which is in the prepared state - -@param[in] hton InnoDB handlerton -@param[in] xid X/Open XA transaction identification - -@return 0 or error number */ -int innobase_rollback_by_xid(handlerton* hton, XID* xid) -{ - DBUG_ASSERT(hton == innodb_hton_ptr); - - DBUG_EXECUTE_IF("innobase_xa_fail", - return XAER_RMFAIL;); - - if (high_level_read_only) { - return(XAER_RMFAIL); - } - - if (trx_t* trx = trx_get_trx_by_xid(xid)) { -#ifdef WITH_WSREP - /* If a wsrep transaction is being rolled back during - the recovery, we must clear the xid in order to avoid - writing serialisation history for rolled back transaction. */ - if (wsrep_is_wsrep_xid(&trx->xid)) { - trx->xid.null(); - } -#endif /* WITH_WSREP */ - int ret = innobase_rollback_trx(trx); - ut_ad(!trx->will_lock); - trx->free(); - - return(ret); - } else { - return(XAER_NOTA); - } -} - bool ha_innobase::check_if_incompatible_data( /*====================================*/ diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 671acc3b3ca..534936f8fae 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -465,8 +465,13 @@ protected: @see build_template() */ void reset_template(); - /** @return whether the table is read-only */ - bool is_read_only(bool altering_to_supported= false) const; + /** Check the transaction is valid. + @param altering_to_supported whether an ALTER TABLE is being run + to something else than ROW_FORMAT=COMPRESSED + @retval 0 if the transaction is valid for the current operation + @retval HA_ERR_TABLE_READONLY if the table is read-only + @retval HA_ERR_ROLLBACK if the transaction has been aborted */ + int is_valid_trx(bool altering_to_supported= false) const noexcept; inline void update_thd(THD* thd); void update_thd(); @@ -937,12 +942,3 @@ ib_push_frm_error( @return true if index column length exceeds limit */ MY_ATTRIBUTE((warn_unused_result)) bool too_big_key_part_length(size_t max_field_len, const KEY& key); - -/** This function is used to rollback one X/Open XA distributed transaction -which is in the prepared state - -@param[in] hton InnoDB handlerton -@param[in] xid X/Open XA transaction identification - -@return 0 or error number */ -int innobase_rollback_by_xid(handlerton* hton, XID* xid); diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index c164956d9a0..ff427297375 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -2249,7 +2249,7 @@ ha_innobase::check_if_supported_inplace_alter( table->s->table_name.str); } - if (is_read_only(!high_level_read_only + if (is_valid_trx(!high_level_read_only && (ha_alter_info->handler_flags & ALTER_OPTIONS) && ha_alter_info->create_info->key_block_size == 0 && ha_alter_info->create_info->row_type @@ -9154,7 +9154,7 @@ inline bool rollback_inplace_alter_table(Alter_inplace_info *ha_alter_info, /* If we have not started a transaction yet, (almost) nothing has been or needs to be done. */ dict_sys.lock(SRW_LOCK_CALL); - else if (ctx->trx->state == TRX_STATE_NOT_STARTED) + else if (!ctx->trx->is_started()) goto free_and_exit; else if (ctx->new_table) { @@ -11382,7 +11382,7 @@ lock_fail: to remove the newly created table or index from data dictionary and table cache in rollback_inplace_alter_table() */ - if (trx->state == TRX_STATE_NOT_STARTED) { + if (!trx->is_started()) { trx_start_for_ddl(trx); } @@ -11549,7 +11549,7 @@ err_index: purge_sys.resume_FTS(); } - if (trx->state == TRX_STATE_NOT_STARTED) { + if (!trx->is_started()) { /* Transaction may have been rolled back due to a lock wait timeout, deadlock, or a KILL statement. So restart the diff --git a/storage/innobase/include/db0err.h b/storage/innobase/include/db0err.h index 960ec3905eb..921cc977e2e 100644 --- a/storage/innobase/include/db0err.h +++ b/storage/innobase/include/db0err.h @@ -68,8 +68,6 @@ enum dberr_t { noticed */ DB_CANNOT_DROP_CONSTRAINT, /*!< dropping a foreign key constraint from a table failed */ - DB_NO_SAVEPOINT, /*!< no savepoint exists with the given - name */ DB_TABLESPACE_EXISTS, /*!< we cannot create a new single-table tablespace because a file of the same name already exists */ diff --git a/storage/innobase/include/fts0fts.h b/storage/innobase/include/fts0fts.h index 1d2b409be01..810bfe6966b 100644 --- a/storage/innobase/include/fts0fts.h +++ b/storage/innobase/include/fts0fts.h @@ -201,9 +201,9 @@ struct fts_trx_t { /** Information required for transaction savepoint handling. */ struct fts_savepoint_t { - char* name; /*!< First entry is always NULL, the - default instance. Otherwise the name - of the savepoint */ + const void* name; /*!< First entry is always NULL, the + default instance. Otherwise the + savepoint */ ib_rbt_t* tables; /*!< Modified FTS tables */ }; @@ -666,7 +666,7 @@ void fts_savepoint_take( /*===============*/ fts_trx_t* fts_trx, /*!< in: fts transaction */ - const char* name); /*!< in: savepoint name */ + const void* name); /*!< in: savepoint */ /**********************************************************************//** Refresh last statement savepoint. */ @@ -681,7 +681,7 @@ void fts_savepoint_release( /*==================*/ trx_t* trx, /*!< in: transaction */ - const char* name); /*!< in: savepoint name */ + const void* name); /*!< in: savepoint */ /** Clear cache. @param[in,out] cache fts cache */ @@ -702,7 +702,7 @@ void fts_savepoint_rollback( /*===================*/ trx_t* trx, /*!< in: transaction */ - const char* name); /*!< in: savepoint name */ + const void* name); /*!< in: savepoint */ /*********************************************************************//** Rollback to and including savepoint indentified by name. */ diff --git a/storage/innobase/include/row0mysql.h b/storage/innobase/include/row0mysql.h index 878d9c9f1a2..8cbeed7d297 100644 --- a/storage/innobase/include/row0mysql.h +++ b/storage/innobase/include/row0mysql.h @@ -172,7 +172,7 @@ row_mysql_handle_errors( during the function entry */ trx_t* trx, /*!< in: transaction */ que_thr_t* thr, /*!< in: query thread, or NULL */ - trx_savept_t* savept) /*!< in: savepoint, or NULL */ + const undo_no_t*savept) /*!< in: pointer to savepoint, or nullptr */ MY_ATTRIBUTE((nonnull(1,2))); /********************************************************************//** Create a prebuilt struct for a MySQL table handle. diff --git a/storage/innobase/include/trx0roll.h b/storage/innobase/include/trx0roll.h index 9ef9ebe93b2..dd21597b270 100644 --- a/storage/innobase/include/trx0roll.h +++ b/storage/innobase/include/trx0roll.h @@ -74,62 +74,6 @@ trx_rollback_for_mysql( /*===================*/ trx_t* trx) /*!< in/out: transaction */ MY_ATTRIBUTE((nonnull)); -/*******************************************************************//** -Rollback the latest SQL statement for MySQL. -@return error code or DB_SUCCESS */ -dberr_t -trx_rollback_last_sql_stat_for_mysql( -/*=================================*/ - trx_t* trx) /*!< in/out: transaction */ - MY_ATTRIBUTE((nonnull)); -/*******************************************************************//** -Rolls back a transaction back to a named savepoint. Modifications after the -savepoint are undone but InnoDB does NOT release the corresponding locks -which are stored in memory. If a lock is 'implicit', that is, a new inserted -row holds a lock where the lock information is carried by the trx id stored in -the row, these locks are naturally released in the rollback. Savepoints which -were set after this savepoint are deleted. -@return if no savepoint of the name found then DB_NO_SAVEPOINT, -otherwise DB_SUCCESS */ -dberr_t -trx_rollback_to_savepoint_for_mysql( -/*================================*/ - trx_t* trx, /*!< in: transaction handle */ - const char* savepoint_name, /*!< in: savepoint name */ - int64_t* mysql_binlog_cache_pos) /*!< out: the MySQL binlog cache - position corresponding to this - savepoint; MySQL needs this - information to remove the - binlog entries of the queries - executed after the savepoint */ - MY_ATTRIBUTE((nonnull, warn_unused_result)); -/*******************************************************************//** -Creates a named savepoint. If the transaction is not yet started, starts it. -If there is already a savepoint of the same name, this call erases that old -savepoint and replaces it with a new. Savepoints are deleted in a transaction -commit or rollback. -@return always DB_SUCCESS */ -dberr_t -trx_savepoint_for_mysql( -/*====================*/ - trx_t* trx, /*!< in: transaction handle */ - const char* savepoint_name, /*!< in: savepoint name */ - int64_t binlog_cache_pos) /*!< in: MySQL binlog cache - position corresponding to this - connection at the time of the - savepoint */ - MY_ATTRIBUTE((nonnull)); -/*******************************************************************//** -Releases a named savepoint. Savepoints which -were set after this savepoint are deleted. -@return if no savepoint of the name found then DB_NO_SAVEPOINT, -otherwise DB_SUCCESS */ -dberr_t -trx_release_savepoint_for_mysql( -/*============================*/ - trx_t* trx, /*!< in: transaction handle */ - const char* savepoint_name) /*!< in: savepoint name */ - MY_ATTRIBUTE((nonnull, warn_unused_result)); /** Rollback node states */ enum roll_node_state { @@ -144,25 +88,9 @@ enum roll_node_state { struct roll_node_t{ que_common_t common; /*!< node type: QUE_NODE_ROLLBACK */ enum roll_node_state state; /*!< node execution state */ - const trx_savept_t* savept; /*!< savepoint to which to - roll back, in the case of a - partial rollback */ + undo_no_t savept; /*!< savepoint to which to + roll back; 0=entire transaction */ que_thr_t* undo_thr;/*!< undo query graph */ }; -/** A savepoint set with SQL's "SAVEPOINT savepoint_id" command */ -struct trx_named_savept_t{ - char* name; /*!< savepoint name */ - trx_savept_t savept; /*!< the undo number corresponding to - the savepoint */ - int64_t mysql_binlog_cache_pos; - /*!< the MySQL binlog cache position - corresponding to this savepoint, not - defined if the MySQL binlogging is not - enabled */ - UT_LIST_NODE_T(trx_named_savept_t) - trx_savepoints; /*!< the list of savepoints of a - transaction */ -}; - #endif diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index f76bdea33a4..f411e8420a9 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -495,19 +495,7 @@ class rw_trx_hash_t #ifdef UNIV_DEBUG - static void validate_element(trx_t *trx) - { - ut_ad(!trx->read_only || !trx->rsegs.m_redo.rseg); - ut_ad(!trx->is_autocommit_non_locking()); - /* trx->state can be anything except TRX_STATE_NOT_STARTED */ - ut_d(bool acquire_trx_mutex = !trx->mutex_is_owner()); - ut_d(if (acquire_trx_mutex) trx->mutex_lock()); - ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE) || - trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY) || - trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED) || - trx_state_eq(trx, TRX_STATE_PREPARED)); - ut_d(if (acquire_trx_mutex) trx->mutex_unlock()); - } + static void validate_element(trx_t *trx); struct debug_iterator_arg diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index 79d5b7be5da..e55c6f506ce 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -149,19 +149,15 @@ void trx_start_for_ddl_low(trx_t *trx); ut_ad((t)->start_file == 0); \ (t)->start_line = __LINE__; \ (t)->start_file = __FILE__; \ + t->state= TRX_STATE_NOT_STARTED; \ trx_start_for_ddl_low(t); \ } while (0) #else # define trx_start_for_ddl(t) trx_start_for_ddl_low(t) #endif /* UNIV_DEBUG */ -/**********************************************************************//** -Does the transaction commit for MySQL. -@return DB_SUCCESS or error number */ -dberr_t -trx_commit_for_mysql( -/*=================*/ - trx_t* trx); /*!< in/out: transaction */ +/** Commit a transaction */ +void trx_commit_for_mysql(trx_t *trx) noexcept; /** XA PREPARE a transaction. @param[in,out] trx transaction to prepare */ void trx_prepare_for_mysql(trx_t* trx); @@ -184,12 +180,6 @@ trx_t* trx_get_trx_by_xid(const XID* xid); /** Durably write log until trx->commit_lsn (if trx_t::commit_in_memory() was invoked with flush_log_later=true). */ void trx_commit_complete_for_mysql(trx_t *trx); -/**********************************************************************//** -Marks the latest SQL statement ended. */ -void -trx_mark_sql_stat_end( -/*==================*/ - trx_t* trx); /*!< in: trx handle */ /****************************************************************//** Prepares a transaction for commit/rollback. */ void @@ -663,6 +653,7 @@ public: Possible states: TRX_STATE_NOT_STARTED + TRX_STATE_ABORTED TRX_STATE_ACTIVE TRX_STATE_PREPARED TRX_STATE_PREPARED_RECOVERED (special case of TRX_STATE_PREPARED) @@ -672,6 +663,8 @@ public: Regular transactions: * NOT_STARTED -> ACTIVE -> COMMITTED -> NOT_STARTED + * NOT_STARTED -> ABORTED (when thd_mark_transaction_to_rollback() is called) + * ABORTED -> NOT_STARTED (acknowledging the rollback of a transaction) Auto-commit non-locking read-only: * NOT_STARTED -> ACTIVE -> NOT_STARTED @@ -708,16 +701,18 @@ public: do we remove it from the read-only list and put it on the read-write list. During this switch we assign it a rollback segment. - When a transaction is NOT_STARTED, it can be in trx_list. It cannot be - in rw_trx_hash. + When a transaction is NOT_STARTED or ABORTED, it can be in trx_list. + It cannot be in rw_trx_hash. - ACTIVE->PREPARED->COMMITTED is only possible when trx is in rw_trx_hash. - The transition ACTIVE->PREPARED is protected by trx->mutex. + ACTIVE->PREPARED->COMMITTED and ACTIVE->COMMITTED is only possible when + trx is in rw_trx_hash. These transitions are protected by trx_t::mutex. - ACTIVE->COMMITTED is possible when the transaction is in - rw_trx_hash. + COMMITTED->NOT_STARTED is possible when trx_t::mutex is being held. + The transaction would already have been removed from rw_trx_hash by + trx_sys_t::deregister_rw() on the transition to COMMITTED. - Transitions to COMMITTED are protected by trx_t::mutex. */ + Transitions between NOT_STARTED and ABORTED can be performed at any time by + the thread that is associated with the transaction. */ Atomic_relaxed state; /** The locks of the transaction. Protected by lock_sys.latch @@ -733,6 +728,14 @@ public: bool is_wsrep() const { return false; } #endif /* WITH_WSREP */ + /** @return whether the transaction has been started */ + bool is_started() const noexcept + { + static_assert(TRX_STATE_NOT_STARTED == 0, ""); + static_assert(TRX_STATE_ABORTED == 1, ""); + return state > TRX_STATE_ABORTED; + } + /** Consistent read view of the transaction */ ReadView read_view; @@ -839,10 +842,6 @@ public: it is a stored procedure with a COMMIT WORK statement, for instance */ /*------------------------------*/ - UT_LIST_BASE_NODE_T(trx_named_savept_t) - trx_savepoints; /*!< savepoints set with SAVEPOINT ..., - oldest first */ - /*------------------------------*/ undo_no_t undo_no; /*!< next undo log record number to assign; since the undo log is private for a transaction, this @@ -850,7 +849,7 @@ public: with no gaps; thus it represents the number of modified/inserted rows in a transaction */ - trx_savept_t last_sql_stat_start; + undo_no_t last_stmt_start; /*!< undo_no when the last sql statement was started: in case of an error, trx is rolled back down to this number */ @@ -949,16 +948,17 @@ public: void evict_table(table_id_t table_id, bool reset_only= false); /** Initiate rollback. - @param savept savepoint to which to roll back + @param savept pointer to savepoint; nullptr=entire transaction @return error code or DB_SUCCESS */ - dberr_t rollback(trx_savept_t *savept= nullptr); + dberr_t rollback(const undo_no_t *savept= nullptr) noexcept; /** Roll back an active transaction. - @param savept savepoint to which to roll back */ - inline void rollback_low(trx_savept_t *savept= nullptr); + @param savept pointer to savepoint; nullptr=entire transaction + @return error code or DB_SUCCESS */ + dberr_t rollback_low(const undo_no_t *savept= nullptr) noexcept; /** Finish rollback. @return whether the rollback was completed normally @retval false if the rollback was aborted by shutdown */ - inline bool rollback_finish(); + bool rollback_finish() noexcept; private: /** Apply any changes to tables for which online DDL is in progress. */ ATTRIBUTE_COLD void apply_log(); @@ -968,9 +968,10 @@ private: @param mtr mini-transaction (if there are any persistent modifications) */ inline void commit_in_memory(const mtr_t *mtr); /** Write log for committing the transaction. */ - void commit_persist(); - /** Clean up the transaction after commit_in_memory() */ - void commit_cleanup(); + void commit_persist() noexcept; + /** Clean up the transaction after commit_in_memory() + @return false (always) */ + bool commit_cleanup() noexcept; /** Commit the transaction in a mini-transaction. @param mtr mini-transaction (if there are any persistent modifications) */ void commit_low(mtr_t *mtr= nullptr); @@ -985,7 +986,7 @@ private: inline void write_serialisation_history(mtr_t *mtr); public: /** Commit the transaction. */ - void commit(); + void commit() noexcept; /** Try to drop a persistent table. @param table persistent table @@ -1005,16 +1006,6 @@ public: void commit(std::vector &deleted); - /** Discard all savepoints */ - void savepoints_discard() - { savepoints_discard(UT_LIST_GET_FIRST(trx_savepoints)); } - - - /** Discard all savepoints starting from a particular savepoint. - @param savept first savepoint to discard */ - void savepoints_discard(trx_named_savept_t *savept); - - bool is_referenced() const { return (skip_lock_inheritance_and_n_ref & ~(1U << 31)) > 0; @@ -1128,15 +1119,6 @@ private: trx_rseg_t *assign_temp_rseg(); }; -/** -Check if transaction is started. -@param[in] trx Transaction whose state we need to check -@reutrn true if transaction is in state started */ -inline bool trx_is_started(const trx_t* trx) -{ - return trx->state != TRX_STATE_NOT_STARTED; -} - /* Transaction isolation levels (trx->isolation_level) */ #define TRX_ISO_READ_UNCOMMITTED 0 /* dirty read: non-locking SELECTs are performed so that diff --git a/storage/innobase/include/trx0trx.inl b/storage/innobase/include/trx0trx.inl index b063c920e2f..317f1f5cd0d 100644 --- a/storage/innobase/include/trx0trx.inl +++ b/storage/innobase/include/trx0trx.inl @@ -67,6 +67,8 @@ trx_state_eq( && thd_get_error_number(trx->mysql_thd))); return(true); + case TRX_STATE_ABORTED: + break; } ut_error; #endif /* UNIV_DEBUG */ diff --git a/storage/innobase/include/trx0types.h b/storage/innobase/include/trx0types.h index 86e1f67bc02..d0a3c1d7892 100644 --- a/storage/innobase/include/trx0types.h +++ b/storage/innobase/include/trx0types.h @@ -52,6 +52,8 @@ constexpr uint innodb_purge_batch_size_MAX= 5000; /** Transaction states (trx_t::state) */ enum trx_state_t { TRX_STATE_NOT_STARTED, + /** The transaction was aborted (rolled back) due to an error */ + TRX_STATE_ABORTED, TRX_STATE_ACTIVE, /** XA PREPARE has been executed; only XA COMMIT or XA ROLLBACK @@ -59,6 +61,7 @@ enum trx_state_t { TRX_STATE_PREPARED, /** XA PREPARE transaction that was returned to ha_recover() */ TRX_STATE_PREPARED_RECOVERED, + /** The transaction has been committed (or completely rolled back) */ TRX_STATE_COMMITTED_IN_MEMORY }; @@ -76,8 +79,6 @@ struct trx_undo_t; struct roll_node_t; /** Commit command node in a query graph */ struct commit_node_t; -/** SAVEPOINT command node in a query graph */ -struct trx_named_savept_t; /* @} */ /** Row identifier (DB_ROW_ID, DATA_ROW_ID) */ @@ -89,11 +90,6 @@ typedef ib_id_t roll_ptr_t; /** Undo number */ typedef ib_id_t undo_no_t; -/** Transaction savepoint */ -struct trx_savept_t{ - undo_no_t least_undo_no; /*!< least undo number to undo */ -}; - /** File objects */ /* @{ */ /** Undo segment header */ diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 2392d67bb04..1795852ec94 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -6692,23 +6692,19 @@ lock_unlock_table_autoinc( /*======================*/ trx_t* trx) /*!< in/out: transaction */ { - lock_sys.assert_unlocked(); - ut_ad(!trx->mutex_is_owner()); - ut_ad(!trx->lock.wait_lock); + /* This function is invoked for a running transaction by the thread + that is serving the transaction. Therefore it is not necessary to + hold trx->mutex here. */ - /* This can be invoked on NOT_STARTED, ACTIVE, PREPARED, - but not COMMITTED transactions. */ + lock_sys.assert_unlocked(); + ut_ad(!trx->mutex_is_owner()); + ut_ad(!trx->lock.wait_lock); + ut_d(trx_state_t trx_state{trx->state}); + ut_ad(trx_state == TRX_STATE_ACTIVE || trx_state == TRX_STATE_PREPARED || + trx_state == TRX_STATE_NOT_STARTED); - ut_ad(trx_state_eq(trx, TRX_STATE_NOT_STARTED) - || !trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY)); - - /* This function is invoked for a running transaction by the - thread that is serving the transaction. Therefore it is not - necessary to hold trx->mutex here. */ - - if (lock_trx_holds_autoinc_locks(trx)) { - lock_release_autoinc_locks(trx); - } + if (lock_trx_holds_autoinc_locks(trx)) + lock_release_autoinc_locks(trx); } /** Handle a pending lock wait (DB_LOCK_WAIT) in a semi-consistent read diff --git a/storage/innobase/que/que0que.cc b/storage/innobase/que/que0que.cc index 5e1e0686c97..81d93505d70 100644 --- a/storage/innobase/que/que0que.cc +++ b/storage/innobase/que/que0que.cc @@ -514,8 +514,7 @@ que_thr_step( for_step(thr); } else if (type == QUE_NODE_PROC) { if (thr->prev_node == que_node_get_parent(node)) { - trx->last_sql_stat_start.least_undo_no - = trx->undo_no; + trx->last_stmt_start = trx->undo_no; } proc_step(thr); diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 30d186b4863..bb3b03aef14 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -625,7 +625,7 @@ row_mysql_handle_errors( function */ trx_t* trx, /*!< in: transaction */ que_thr_t* thr, /*!< in: query thread, or NULL */ - trx_savept_t* savept) /*!< in: savepoint, or NULL */ + const undo_no_t*savept) /*!< in: pointer to savepoint, or nullptr */ { dberr_t err; @@ -681,8 +681,7 @@ handle_new_error: } /* MariaDB will roll back the entire transaction. */ trx->bulk_insert = false; - trx->last_sql_stat_start.least_undo_no = 0; - trx->savepoints_discard(); + trx->last_stmt_start = 0; break; case DB_LOCK_WAIT: err = lock_wait(thr); @@ -700,7 +699,6 @@ handle_new_error: rollback: /* Roll back the whole transaction; this resolution was added to version 3.23.43 */ - trx->rollback(); break; @@ -1137,7 +1135,7 @@ row_lock_table_autoinc_for_mysql( trx->error_state = err; } while (err != DB_SUCCESS - && row_mysql_handle_errors(&err, trx, thr, NULL)); + && row_mysql_handle_errors(&err, trx, thr, nullptr)); trx->op_info = ""; @@ -1179,7 +1177,7 @@ row_lock_table(row_prebuilt_t* prebuilt) prebuilt->select_lock_type), thr); trx->error_state = err; } while (err != DB_SUCCESS - && row_mysql_handle_errors(&err, trx, thr, NULL)); + && row_mysql_handle_errors(&err, trx, thr, nullptr)); trx->op_info = ""; @@ -1218,7 +1216,6 @@ row_insert_for_mysql( row_prebuilt_t* prebuilt, ins_mode_t ins_mode) { - trx_savept_t savept; que_thr_t* thr; dberr_t err; ibool was_lock_wait; @@ -1272,7 +1269,7 @@ row_insert_for_mysql( roll back to the start of the transaction. For correctness, it would suffice to roll back to the start of the first insert into this empty table, but we will keep it simple and efficient. */ - savept.least_undo_no = trx->bulk_insert ? 0 : trx->undo_no; + const undo_no_t savept{trx->bulk_insert ? 0 : trx->undo_no}; thr = que_fork_get_first_thr(prebuilt->ins_graph); @@ -1586,7 +1583,6 @@ init_fts_doc_id_for_ref( dberr_t row_update_for_mysql(row_prebuilt_t* prebuilt) { - trx_savept_t savept; dberr_t err; que_thr_t* thr; dict_index_t* clust_index; @@ -1643,7 +1639,7 @@ row_update_for_mysql(row_prebuilt_t* prebuilt) generated for the table: MySQL does not know anything about the row id used as the clustered index key */ - savept.least_undo_no = trx->undo_no; + undo_no_t savept = trx->undo_no; thr = que_fork_get_first_thr(prebuilt->upd_graph); diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index a6340ccbc08..38b79af8da4 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -1208,8 +1208,7 @@ re_scan: mtr->commit(); trx->error_state = err; thr->lock_state = QUE_THR_LOCK_ROW; - if (row_mysql_handle_errors( - &err, trx, thr, NULL)) { + if (row_mysql_handle_errors(&err, trx, thr, 0)) { thr->lock_state = QUE_THR_LOCK_NOLOCK; mtr->start(); @@ -5873,7 +5872,7 @@ lock_table_wait: trx->error_state = err; thr->lock_state = QUE_THR_LOCK_ROW; - if (row_mysql_handle_errors(&err, trx, thr, NULL)) { + if (row_mysql_handle_errors(&err, trx, thr, nullptr)) { /* It was a lock wait, and it ended */ thr->lock_state = QUE_THR_LOCK_NOLOCK; diff --git a/storage/innobase/trx/trx0i_s.cc b/storage/innobase/trx/trx0i_s.cc index 4a661c51183..c1784b94bb1 100644 --- a/storage/innobase/trx/trx0i_s.cc +++ b/storage/innobase/trx/trx0i_s.cc @@ -1054,7 +1054,7 @@ static void fetch_data_into_cache(trx_i_s_cache_t *cache) &trx != (purge_sys.query ? purge_sys.query->trx : nullptr)) { trx.mutex_lock(); - if (trx.state != TRX_STATE_NOT_STARTED) + if (trx.is_started()) fetch_data_into_cache_low(cache, &trx); trx.mutex_unlock(); } diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc index d1baab9e684..a59a07b35a9 100644 --- a/storage/innobase/trx/trx0roll.cc +++ b/storage/innobase/trx/trx0roll.cc @@ -43,6 +43,7 @@ Created 3/26/1996 Heikki Tuuri #include "trx0sys.h" #include "trx0trx.h" #include "trx0undo.h" +#include "log.h" #ifdef UNIV_PFS_THREAD mysql_pfs_key_t trx_rollback_clean_thread_key; @@ -54,10 +55,7 @@ bool trx_rollback_is_active; /** In crash recovery, the current trx to be rolled back; NULL otherwise */ const trx_t* trx_roll_crash_recv_trx; -/** Finish transaction rollback. -@return whether the rollback was completed normally -@retval false if the rollback was aborted by shutdown */ -inline bool trx_t::rollback_finish() +bool trx_t::rollback_finish() noexcept { mod_tables.clear(); apply_online_log= false; @@ -85,34 +83,28 @@ inline bool trx_t::rollback_finish() undo= nullptr; } commit_low(); - commit_cleanup(); - return false; + return commit_cleanup(); } -/** Roll back an active transaction. */ -inline void trx_t::rollback_low(trx_savept_t *savept) +dberr_t trx_t::rollback_low(const undo_no_t *savept) noexcept { + op_info= "rollback"; mem_heap_t *heap= mem_heap_create(512); roll_node_t *roll_node= roll_node_create(heap); - roll_node->savept= savept; + + roll_node->savept= savept ? *savept : 0; ut_ad(!in_rollback); #ifdef UNIV_DEBUG + if (savept) { - const auto s= state; - ut_ad(s == TRX_STATE_ACTIVE || - s == TRX_STATE_PREPARED || - s == TRX_STATE_PREPARED_RECOVERED); - if (savept) - { - ut_ad(s == TRX_STATE_ACTIVE); - ut_ad(mysql_thd); - ut_ad(!is_recovered); - } + ut_ad(state == TRX_STATE_ACTIVE); + ut_ad(mysql_thd); + ut_ad(!is_recovered); } #endif - error_state = DB_SUCCESS; + error_state= DB_SUCCESS; if (has_logged()) { @@ -139,7 +131,7 @@ inline void trx_t::rollback_low(trx_savept_t *savept) victim. Galera transaction abort can be invoked during partial rollback. */ ut_ad(!(lock.was_chosen_as_deadlock_victim & 1)); ut_a(error_state == DB_SUCCESS); - const undo_no_t limit= savept->least_undo_no; + const undo_no_t limit{*savept}; apply_online_log= false; for (trx_mod_tables_t::iterator i= mod_tables.begin(); i != mod_tables.end(); ) @@ -155,49 +147,34 @@ inline void trx_t::rollback_low(trx_savept_t *savept) } mem_heap_free(heap); + op_info= ""; + return error_state; } -/** Initiate rollback. -@param savept savepoint -@return error code or DB_SUCCESS */ -dberr_t trx_t::rollback(trx_savept_t *savept) +dberr_t trx_t::rollback(const undo_no_t *savept) noexcept { ut_ad(!mutex_is_owner()); - if (state == TRX_STATE_NOT_STARTED) - { + switch (state) { + case TRX_STATE_ABORTED: + ut_ad(!savept); + state= TRX_STATE_NOT_STARTED; + /* fall through */ + case TRX_STATE_NOT_STARTED: error_state= DB_SUCCESS; return DB_SUCCESS; + case TRX_STATE_PREPARED: + case TRX_STATE_PREPARED_RECOVERED: + case TRX_STATE_COMMITTED_IN_MEMORY: + ut_ad("invalid state" == 0); + /* fall through */ + case TRX_STATE_ACTIVE: + break; } - ut_ad(state == TRX_STATE_ACTIVE); #ifdef WITH_WSREP if (!savept && is_wsrep() && wsrep_thd_is_SR(mysql_thd)) wsrep_handle_SR_rollback(nullptr, mysql_thd); #endif /* WITH_WSREP */ - rollback_low(savept); - return error_state; -} - -/*******************************************************************//** -Rollback a transaction used in MySQL. -@return error code or DB_SUCCESS */ -static -dberr_t -trx_rollback_for_mysql_low( -/*=======================*/ - trx_t* trx) /*!< in/out: transaction */ -{ - trx->op_info = "rollback"; - - /* If we are doing the XA recovery of prepared transactions, - then the transaction object does not have an InnoDB session - object, and we set a dummy session that we use for all MySQL - transactions. */ - - trx->rollback_low(); - - trx->op_info = ""; - - return(trx->error_state); + return rollback_low(savept); } /** Rollback a transaction used in MySQL @@ -211,6 +188,9 @@ dberr_t trx_rollback_for_mysql(trx_t* trx) that is associated with the current thread. */ switch (trx->state) { + case TRX_STATE_ABORTED: + trx->state = TRX_STATE_NOT_STARTED; + /* fall through */ case TRX_STATE_NOT_STARTED: trx->will_lock = false; ut_ad(trx->mysql_thd); @@ -222,13 +202,13 @@ dberr_t trx_rollback_for_mysql(trx_t* trx) ut_ad(!trx->is_wsrep()); trx->lock.was_chosen_as_deadlock_victim= false; #endif + ut_a(UT_LIST_GET_LEN(trx->lock.trx_locks) == 0); return(DB_SUCCESS); - case TRX_STATE_ACTIVE: ut_ad(trx->mysql_thd); ut_ad(!trx->is_recovered); ut_ad(!trx->is_autocommit_non_locking() || trx->read_only); - return(trx_rollback_for_mysql_low(trx)); + return trx->rollback_low(); case TRX_STATE_PREPARED: case TRX_STATE_PREPARED_RECOVERED: @@ -266,7 +246,7 @@ dberr_t trx_rollback_for_mysql(trx_t* trx) mtr.commit(); ut_ad(mtr.commit_lsn() > 0); } - return(trx_rollback_for_mysql_low(trx)); + return trx->rollback_low(); case TRX_STATE_COMMITTED_IN_MEMORY: ut_ad(!trx->is_autocommit_non_locking()); @@ -277,296 +257,6 @@ dberr_t trx_rollback_for_mysql(trx_t* trx) return(DB_CORRUPTION); } -/*******************************************************************//** -Rollback the latest SQL statement for MySQL. -@return error code or DB_SUCCESS */ -dberr_t -trx_rollback_last_sql_stat_for_mysql( -/*=================================*/ - trx_t* trx) /*!< in/out: transaction */ -{ - dberr_t err; - - /* We are reading trx->state without holding trx->mutex - here, because the statement rollback should be invoked for a - running active MySQL transaction that is associated with the - current thread. */ - ut_ad(trx->mysql_thd); - - switch (trx->state) { - case TRX_STATE_NOT_STARTED: - return(DB_SUCCESS); - - case TRX_STATE_ACTIVE: - ut_ad(trx->mysql_thd); - ut_ad(!trx->is_recovered); - ut_ad(!trx->is_autocommit_non_locking() || trx->read_only); - - trx->op_info = "rollback of SQL statement"; - - err = trx->rollback(&trx->last_sql_stat_start); - - if (trx->fts_trx != NULL) { - fts_savepoint_rollback_last_stmt(trx); - fts_savepoint_laststmt_refresh(trx); - } - - trx->last_sql_stat_start.least_undo_no = trx->undo_no; - trx->end_bulk_insert(); - - trx->op_info = ""; - - return(err); - - case TRX_STATE_PREPARED: - case TRX_STATE_PREPARED_RECOVERED: - case TRX_STATE_COMMITTED_IN_MEMORY: - /* The statement rollback is only allowed on an ACTIVE - transaction, not a PREPARED or COMMITTED one. */ - break; - } - - ut_error; - return(DB_CORRUPTION); -} - -/*******************************************************************//** -Search for a savepoint using name. -@return savepoint if found else NULL */ -static -trx_named_savept_t* -trx_savepoint_find( -/*===============*/ - trx_t* trx, /*!< in: transaction */ - const char* name) /*!< in: savepoint name */ -{ - trx_named_savept_t* savep; - - for (savep = UT_LIST_GET_FIRST(trx->trx_savepoints); - savep != NULL; - savep = UT_LIST_GET_NEXT(trx_savepoints, savep)) { - if (!strcmp(savep->name, name)) { - return(savep); - } - } - - return(NULL); -} - -/*******************************************************************//** -Frees a single savepoint struct. */ -static -void -trx_roll_savepoint_free( -/*=====================*/ - trx_t* trx, /*!< in: transaction handle */ - trx_named_savept_t* savep) /*!< in: savepoint to free */ -{ - UT_LIST_REMOVE(trx->trx_savepoints, savep); - - ut_free(savep->name); - ut_free(savep); -} - -/** Discard all savepoints starting from a particular savepoint. -@param savept first savepoint to discard */ -void trx_t::savepoints_discard(trx_named_savept_t *savept) -{ - while (savept) - { - auto next= UT_LIST_GET_NEXT(trx_savepoints, savept); - trx_roll_savepoint_free(this, savept); - savept= next; - } -} - -/*******************************************************************//** -Rolls back a transaction back to a named savepoint. Modifications after the -savepoint are undone but InnoDB does NOT release the corresponding locks -which are stored in memory. If a lock is 'implicit', that is, a new inserted -row holds a lock where the lock information is carried by the trx id stored in -the row, these locks are naturally released in the rollback. Savepoints which -were set after this savepoint are deleted. -@return if no savepoint of the name found then DB_NO_SAVEPOINT, -otherwise DB_SUCCESS */ -static MY_ATTRIBUTE((nonnull, warn_unused_result)) -dberr_t -trx_rollback_to_savepoint_for_mysql_low( -/*====================================*/ - trx_t* trx, /*!< in/out: transaction */ - trx_named_savept_t* savep, /*!< in/out: savepoint */ - int64_t* mysql_binlog_cache_pos) - /*!< out: the MySQL binlog - cache position corresponding - to this savepoint; MySQL needs - this information to remove the - binlog entries of the queries - executed after the savepoint */ -{ - dberr_t err; - - ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE)); - ut_ad(trx->mysql_thd); - - /* Free all savepoints strictly later than savep. */ - - trx->savepoints_discard(UT_LIST_GET_NEXT(trx_savepoints, savep)); - - *mysql_binlog_cache_pos = savep->mysql_binlog_cache_pos; - - trx->op_info = "rollback to a savepoint"; - - err = trx->rollback(&savep->savept); - - /* Store the current undo_no of the transaction so that - we know where to roll back if we have to roll back the - next SQL statement: */ - - trx_mark_sql_stat_end(trx); - - trx->op_info = ""; - return(err); -} - -/*******************************************************************//** -Rolls back a transaction back to a named savepoint. Modifications after the -savepoint are undone but InnoDB does NOT release the corresponding locks -which are stored in memory. If a lock is 'implicit', that is, a new inserted -row holds a lock where the lock information is carried by the trx id stored in -the row, these locks are naturally released in the rollback. Savepoints which -were set after this savepoint are deleted. -@return if no savepoint of the name found then DB_NO_SAVEPOINT, -otherwise DB_SUCCESS */ -dberr_t -trx_rollback_to_savepoint_for_mysql( -/*================================*/ - trx_t* trx, /*!< in: transaction handle */ - const char* savepoint_name, /*!< in: savepoint name */ - int64_t* mysql_binlog_cache_pos) /*!< out: the MySQL binlog cache - position corresponding to this - savepoint; MySQL needs this - information to remove the - binlog entries of the queries - executed after the savepoint */ -{ - trx_named_savept_t* savep; - - /* We are reading trx->state without holding trx->mutex - here, because the savepoint rollback should be invoked for a - running active MySQL transaction that is associated with the - current thread. */ - ut_ad(trx->mysql_thd); - - savep = trx_savepoint_find(trx, savepoint_name); - - if (savep == NULL) { - return(DB_NO_SAVEPOINT); - } - - switch (trx->state) { - case TRX_STATE_NOT_STARTED: - ib::error() << "Transaction has a savepoint " - << savep->name - << " though it is not started"; - return(DB_ERROR); - - case TRX_STATE_ACTIVE: - - return(trx_rollback_to_savepoint_for_mysql_low( - trx, savep, mysql_binlog_cache_pos)); - - case TRX_STATE_PREPARED: - case TRX_STATE_PREPARED_RECOVERED: - case TRX_STATE_COMMITTED_IN_MEMORY: - /* The savepoint rollback is only allowed on an ACTIVE - transaction, not a PREPARED or COMMITTED one. */ - break; - } - - ut_error; - return(DB_CORRUPTION); -} - -/*******************************************************************//** -Creates a named savepoint. If the transaction is not yet started, starts it. -If there is already a savepoint of the same name, this call erases that old -savepoint and replaces it with a new. Savepoints are deleted in a transaction -commit or rollback. -@return always DB_SUCCESS */ -dberr_t -trx_savepoint_for_mysql( -/*====================*/ - trx_t* trx, /*!< in: transaction handle */ - const char* savepoint_name, /*!< in: savepoint name */ - int64_t binlog_cache_pos) /*!< in: MySQL binlog cache - position corresponding to this - connection at the time of the - savepoint */ -{ - trx_named_savept_t* savep; - - trx_start_if_not_started_xa(trx, false); - - savep = trx_savepoint_find(trx, savepoint_name); - - if (savep) { - /* There is a savepoint with the same name: free that */ - - UT_LIST_REMOVE(trx->trx_savepoints, savep); - - ut_free(savep->name); - ut_free(savep); - } - - /* Create a new savepoint and add it as the last in the list */ - - savep = static_cast( - ut_malloc_nokey(sizeof(*savep))); - - savep->name = mem_strdup(savepoint_name); - - savep->savept.least_undo_no = trx->undo_no; - trx->last_sql_stat_start.least_undo_no = trx->undo_no; - - savep->mysql_binlog_cache_pos = binlog_cache_pos; - - UT_LIST_ADD_LAST(trx->trx_savepoints, savep); - - trx->end_bulk_insert(); - - return(DB_SUCCESS); -} - -/*******************************************************************//** -Releases only the named savepoint. Savepoints which were set after this -savepoint are left as is. -@return if no savepoint of the name found then DB_NO_SAVEPOINT, -otherwise DB_SUCCESS */ -dberr_t -trx_release_savepoint_for_mysql( -/*============================*/ - trx_t* trx, /*!< in: transaction handle */ - const char* savepoint_name) /*!< in: savepoint name */ -{ - trx_named_savept_t* savep; - - ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE, true) - || trx_state_eq(trx, TRX_STATE_PREPARED, true)); - ut_ad(trx->mysql_thd); - - savep = trx_savepoint_find(trx, savepoint_name); - - if (savep != NULL) { - trx_roll_savepoint_free(trx, savep); - return DB_SUCCESS; - } else if (trx->last_sql_stat_start.least_undo_no == 0) { - /* Bulk insert could have discarded savepoints */ - return DB_SUCCESS; - } - - return DB_NO_SAVEPOINT; -} - /*******************************************************************//** Roll back an active transaction. */ static @@ -618,7 +308,9 @@ trx_rollback_active( if (UNIV_UNLIKELY(!trx->rollback_finish())) { ut_ad(!dictionary_locked); } else { - ib::info() << "Rolled back recovered transaction " << trx_id; + sql_print_information( + "InnoDB: Rolled back recovered transaction " + TRX_ID_FMT, trx_id); } if (dictionary_locked) { @@ -904,7 +596,6 @@ trx_rollback_step( if (node->state == ROLL_NODE_SEND) { trx_t* trx; - ib_id_t roll_limit; trx = thr_get_trx(thr); @@ -912,13 +603,11 @@ trx_rollback_step( ut_a(node->undo_thr == NULL); - roll_limit = node->savept ? node->savept->least_undo_no : 0; - trx->mutex_lock(); trx_commit_or_rollback_prepare(trx); - node->undo_thr = trx_rollback_start(trx, roll_limit); + node->undo_thr = trx_rollback_start(trx, node->savept); trx->mutex_unlock(); } else { diff --git a/storage/innobase/trx/trx0sys.cc b/storage/innobase/trx/trx0sys.cc index df3755f6c10..68c3e79a3d1 100644 --- a/storage/innobase/trx/trx0sys.cc +++ b/storage/innobase/trx/trx0sys.cc @@ -47,6 +47,31 @@ trx_sys_t trx_sys; #ifdef UNIV_DEBUG /* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */ uint trx_rseg_n_slots_debug = 0; + +void rw_trx_hash_t::validate_element(trx_t *trx) +{ + ut_ad(!trx->read_only || !trx->rsegs.m_redo.rseg); + ut_ad(!trx->is_autocommit_non_locking()); + ut_d(bool acquire_trx_mutex= !trx->mutex_is_owner()); + ut_d(if (acquire_trx_mutex) trx->mutex_lock()); + switch (trx->state) { + case TRX_STATE_NOT_STARTED: + case TRX_STATE_ABORTED: + ut_error; + case TRX_STATE_PREPARED: + case TRX_STATE_PREPARED_RECOVERED: + case TRX_STATE_COMMITTED_IN_MEMORY: + ut_ad(!trx->is_autocommit_non_locking()); + break; + case TRX_STATE_ACTIVE: + if (!trx->is_autocommit_non_locking()) + break; + ut_ad(!trx->is_recovered); + ut_ad(trx->read_only); + ut_ad(trx->mysql_thd); + } + ut_d(if (acquire_trx_mutex) trx->mutex_unlock()); +} #endif /** Display the MySQL binlog offset info if it is present in the trx @@ -364,6 +389,7 @@ size_t trx_sys_t::any_active_transactions(size_t *prepared) trx_sys.trx_list.for_each([&](const trx_t &trx) { switch (trx.state) { case TRX_STATE_NOT_STARTED: + case TRX_STATE_ABORTED: break; case TRX_STATE_ACTIVE: if (!trx.id) diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index baa2694c179..94ed416eb60 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -144,7 +144,7 @@ trx_init( trx->magic_n = TRX_MAGIC_N; - trx->last_sql_stat_start.least_undo_no = 0; + trx->last_stmt_start = 0; ut_ad(!trx->read_view.is_open()); @@ -192,10 +192,6 @@ struct TrxFactory { UT_LIST_INIT(trx->lock.evicted_tables, &dict_table_t::table_LRU); - UT_LIST_INIT( - trx->trx_savepoints, - &trx_named_savept_t::trx_savepoints); - trx->mutex_init(); } @@ -437,9 +433,8 @@ void trx_t::free() MEM_NOACCESS(&error_info, sizeof error_info); MEM_NOACCESS(&error_key_num, sizeof error_key_num); MEM_NOACCESS(&graph, sizeof graph); - MEM_NOACCESS(&trx_savepoints, sizeof trx_savepoints); MEM_NOACCESS(&undo_no, sizeof undo_no); - MEM_NOACCESS(&last_sql_stat_start, sizeof last_sql_stat_start); + MEM_NOACCESS(&last_stmt_start, sizeof last_stmt_start); MEM_NOACCESS(&rsegs, sizeof rsegs); MEM_NOACCESS(&roll_limit, sizeof roll_limit); MEM_NOACCESS(&in_rollback, sizeof in_rollback); @@ -467,9 +462,10 @@ void trx_t::free() /** Transition to committed state, to release implicit locks. */ TRANSACTIONAL_INLINE inline void trx_t::commit_state() { - ut_ad(state == TRX_STATE_PREPARED - || state == TRX_STATE_PREPARED_RECOVERED - || state == TRX_STATE_ACTIVE); + ut_d(auto trx_state{state}); + ut_ad(trx_state == TRX_STATE_PREPARED || + trx_state == TRX_STATE_PREPARED_RECOVERED || + trx_state == TRX_STATE_ACTIVE); /* This makes the transaction committed in memory and makes its changes to data visible to other transactions. NOTE that there is a small discrepancy from the strict formal visibility rules here: a @@ -1490,8 +1486,6 @@ TRANSACTIONAL_INLINE inline void trx_t::commit_in_memory(const mtr_t *mtr) } } - savepoints_discard(); - if (fts_trx) trx_finalize_for_fts(this, undo_no != 0); @@ -1510,7 +1504,7 @@ TRANSACTIONAL_INLINE inline void trx_t::commit_in_memory(const mtr_t *mtr) lock.was_chosen_as_deadlock_victim= false; } -void trx_t::commit_cleanup() +bool trx_t::commit_cleanup() noexcept { ut_ad(!dict_operation); ut_ad(!was_dict_operation); @@ -1527,6 +1521,7 @@ void trx_t::commit_cleanup() mutex.wr_unlock(); ut_a(error_state == DB_SUCCESS); + return false; } /** Commit the transaction in a mini-transaction. @@ -1591,7 +1586,7 @@ TRANSACTIONAL_TARGET void trx_t::commit_low(mtr_t *mtr) } -void trx_t::commit_persist() +void trx_t::commit_persist() noexcept { mtr_t *mtr= nullptr; mtr_t local_mtr; @@ -1605,7 +1600,7 @@ void trx_t::commit_persist() } -void trx_t::commit() +void trx_t::commit() noexcept { ut_ad(!was_dict_operation); ut_d(was_dict_operation= dict_operation); @@ -1641,6 +1636,7 @@ trx_commit_or_rollback_prepare( return; case TRX_STATE_COMMITTED_IN_MEMORY: + case TRX_STATE_ABORTED: break; } @@ -1708,33 +1704,26 @@ trx_commit_step( return(thr); } -/**********************************************************************//** -Does the transaction commit for MySQL. -@return DB_SUCCESS or error number */ -dberr_t -trx_commit_for_mysql( -/*=================*/ - trx_t* trx) /*!< in/out: transaction */ +void trx_commit_for_mysql(trx_t *trx) noexcept { - /* Because we do not do the commit by sending an Innobase - sig to the transaction, we must here make sure that trx has been - started. */ - - switch (trx->state) { - case TRX_STATE_NOT_STARTED: - return DB_SUCCESS; - case TRX_STATE_ACTIVE: - case TRX_STATE_PREPARED: - case TRX_STATE_PREPARED_RECOVERED: - trx->op_info = "committing"; - trx->commit(); - trx->op_info = ""; - return(DB_SUCCESS); - case TRX_STATE_COMMITTED_IN_MEMORY: - break; - } - ut_error; - return(DB_CORRUPTION); + switch (trx->state) { + case TRX_STATE_ABORTED: + trx->state= TRX_STATE_NOT_STARTED; + /* fall through */ + case TRX_STATE_NOT_STARTED: + trx->will_lock= false; + break; + case TRX_STATE_ACTIVE: + case TRX_STATE_PREPARED: + case TRX_STATE_PREPARED_RECOVERED: + trx->op_info= "committing"; + trx->commit(); + trx->op_info= ""; + break; + case TRX_STATE_COMMITTED_IN_MEMORY: + ut_error; + break; + } } /** Durably write log until trx->commit_lsn @@ -1754,42 +1743,6 @@ void trx_commit_complete_for_mysql(trx_t *trx) trx_flush_log_if_needed(lsn, trx); } -/**********************************************************************//** -Marks the latest SQL statement ended. */ -void -trx_mark_sql_stat_end( -/*==================*/ - trx_t* trx) /*!< in: trx handle */ -{ - ut_a(trx); - - switch (trx->state) { - case TRX_STATE_PREPARED: - case TRX_STATE_PREPARED_RECOVERED: - case TRX_STATE_COMMITTED_IN_MEMORY: - break; - case TRX_STATE_NOT_STARTED: - trx->undo_no = 0; - /* fall through */ - case TRX_STATE_ACTIVE: - if (trx->fts_trx != NULL) { - fts_savepoint_laststmt_refresh(trx); - } - - if (trx->is_bulk_insert()) { - /* Allow a subsequent INSERT into an empty table - if !unique_checks && !foreign_key_checks. */ - return; - } - - trx->last_sql_stat_start.least_undo_no = trx->undo_no; - trx->end_bulk_insert(); - return; - } - - ut_error; -} - /**********************************************************************//** Prints info about a transaction. */ void @@ -1815,9 +1768,16 @@ trx_print_low( fprintf(f, "TRANSACTION (%p)", trx); } + THD* thd = trx->mysql_thd; + switch (trx->state) { case TRX_STATE_NOT_STARTED: fputs(", not started", f); + thd = nullptr; + goto state_ok; + case TRX_STATE_ABORTED: + fputs(", forced rollback done", f); + thd = nullptr; goto state_ok; case TRX_STATE_ACTIVE: fprintf(f, ", ACTIVE %lu sec", @@ -1883,9 +1843,8 @@ state_ok: putc('\n', f); } - if (trx->state != TRX_STATE_NOT_STARTED && trx->mysql_thd != NULL) { - innobase_mysql_print_thd( - f, trx->mysql_thd, static_cast(max_query_len)); + if (thd) { + innobase_mysql_print_thd(f, thd, uint(max_query_len)); } } @@ -2201,6 +2160,7 @@ trx_start_if_not_started_xa_low( bool read_write) /*!< in: true if read write transaction */ { switch (trx->state) { + case TRX_STATE_ABORTED: case TRX_STATE_NOT_STARTED: trx_start_low(trx, read_write); return; @@ -2244,6 +2204,7 @@ trx_start_if_not_started_low( } return; + case TRX_STATE_ABORTED: case TRX_STATE_PREPARED: case TRX_STATE_PREPARED_RECOVERED: case TRX_STATE_COMMITTED_IN_MEMORY: diff --git a/storage/innobase/ut/ut0ut.cc b/storage/innobase/ut/ut0ut.cc index 3cdc49c4b32..55ace7b12f6 100644 --- a/storage/innobase/ut/ut0ut.cc +++ b/storage/innobase/ut/ut0ut.cc @@ -340,8 +340,6 @@ ut_strerr( return("Data structure corruption"); case DB_CANNOT_DROP_CONSTRAINT: return("Cannot drop constraint"); - case DB_NO_SAVEPOINT: - return("No such savepoint"); case DB_TABLESPACE_EXISTS: return("Tablespace already exists"); case DB_TABLESPACE_DELETED: From ab9182470dd4f0ddeb28ae7dfa11979e83f9abe3 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 20 Nov 2024 13:46:43 +0400 Subject: [PATCH 15/22] MDEV-31366 Assertion `thd->start_time' failed in bool LOGGER::slow_log_print(THD*, const char*, size_t, ulonglong) Fixing a wrong DBUG_ASSERT. thd->start_time and thd->start_time_sec_part cannot be 0 at the same time. But thd->start_time can be 0 when thd->start_time_sec_part is not 0, e.g. after: SET timestamp=0.99; --- mysql-test/main/log_slow.result | 17 +++++++++++++++++ mysql-test/main/log_slow.test | 15 +++++++++++++++ sql/log.cc | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/log_slow.result b/mysql-test/main/log_slow.result index 81ef7f9af72..131542075a1 100644 --- a/mysql-test/main/log_slow.result +++ b/mysql-test/main/log_slow.result @@ -207,4 +207,21 @@ use `a b`; SET timestamp=1234567890; select count(*) from mysql.global_priv where length(priv)>2 +# +# MDEV-31366 Assertion `thd->start_time' failed in bool LOGGER::slow_log_print(THD*, const char*, size_t, ulonglong) +# +TRUNCATE mysql.slow_log; +SET global log_output='TABLE'; +SET timestamp=0.99; +SET long_query_time=0.00001; +SELECT SLEEP(0.1); +SLEEP(0.1) +0 +SELECT COUNT(*)>0 AS c1 FROM mysql.slow_log; +c1 +1 +SET global log_output=default; +SET timestamp=default; +SET long_query_time=default; +TRUNCATE mysql.slow_log; # End of 10.5 tests diff --git a/mysql-test/main/log_slow.test b/mysql-test/main/log_slow.test index 1f33cff9f25..8fb7fd1826b 100644 --- a/mysql-test/main/log_slow.test +++ b/mysql-test/main/log_slow.test @@ -221,4 +221,19 @@ let SEARCH_PATTERN= use \`a\n.*2; let SEARCH_OUTPUT=matches; source include/search_pattern_in_file.inc; +--echo # +--echo # MDEV-31366 Assertion `thd->start_time' failed in bool LOGGER::slow_log_print(THD*, const char*, size_t, ulonglong) +--echo # + +TRUNCATE mysql.slow_log; +SET global log_output='TABLE'; +SET timestamp=0.99; +SET long_query_time=0.00001; +SELECT SLEEP(0.1); +SELECT COUNT(*)>0 AS c1 FROM mysql.slow_log; +SET global log_output=default; +SET timestamp=default; +SET long_query_time=default; +TRUNCATE mysql.slow_log; + --echo # End of 10.5 tests diff --git a/sql/log.cc b/sql/log.cc index a0f865dc7e0..32a1436f9a6 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1330,7 +1330,7 @@ bool LOGGER::slow_log_print(THD *thd, const char *query, size_t query_length, user_host_buff); DBUG_ASSERT(thd->start_utime); - DBUG_ASSERT(thd->start_time); + DBUG_ASSERT(thd->start_time || thd->start_time_sec_part); query_utime= (current_utime - thd->start_utime); lock_utime= (thd->utime_after_lock - thd->start_utime); my_hrtime_t current_time= { hrtime_from_time(thd->start_time) + From 6dcd9de2a993409ce31df2a9eb0898e83436daff Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 30 Jul 2024 13:20:39 +1000 Subject: [PATCH 16/22] MDEV-34669: ER_NEED_REPREPARE on SELECT DEFAULT(name) FROM table1_containing_sequence A prepared SELECT statement because of CF_REEXECUTION_FRAGILE needs to check the table is the same definition as previously otherwise a re-prepare of the statement can occur. When running many 'SELECT DEFAULT(name) FROM table1_containing_sequence' in parallel the TABLE_LIST::is_the_same_definition may be called when m_table_ref_type is TABLE_REF_NULL because it hasn't been checked yet. In this case populate the TABLE_LIST with the values determined by the TABLE_SHARE and allow the execution to continue. As a result of this, the main.ps_ddl test doesn't need to reprepare as the defination hasn't changed. This is another case where TABLE_LIST::is_the_same_definition is called when m_table_ref_type is TABLE_REF_NULL, but that doesn't mean that the defination is different. --- mysql-test/main/ps_ddl.result | 2 +- mysql-test/main/ps_ddl.test | 2 +- sql/table.cc | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/ps_ddl.result b/mysql-test/main/ps_ddl.result index ace2682b637..e91e5c47351 100644 --- a/mysql-test/main/ps_ddl.result +++ b/mysql-test/main/ps_ddl.result @@ -2037,7 +2037,7 @@ SUCCESS execute stmt; Warnings: Note 1050 Table 't2' already exists -call p_verify_reprepare_count(1); +call p_verify_reprepare_count(0); SUCCESS select * from t2; diff --git a/mysql-test/main/ps_ddl.test b/mysql-test/main/ps_ddl.test index 21f2b715e86..bbcba398fe7 100644 --- a/mysql-test/main/ps_ddl.test +++ b/mysql-test/main/ps_ddl.test @@ -1680,7 +1680,7 @@ drop table t2; execute stmt; call p_verify_reprepare_count(0); execute stmt; -call p_verify_reprepare_count(1); +call p_verify_reprepare_count(0); select * from t2; execute stmt; call p_verify_reprepare_count(0); diff --git a/sql/table.cc b/sql/table.cc index b333cd040f6..1333cbff397 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -9727,7 +9727,14 @@ bool TABLE_LIST::is_the_same_definition(THD* thd, TABLE_SHARE *s) tabledef_version.length= 0; } else + { set_tabledef_version(s); + if (m_table_ref_type == TABLE_REF_NULL) + { + set_table_ref_id(s); + return TRUE; + } + } return FALSE; } From 71a9b3bf1636d27e3f314469588c82df0c99f33a Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Tue, 10 Dec 2024 17:16:53 +0100 Subject: [PATCH 17/22] galera sst scripts: fix for error hangling code Fixed some issues in the script code, mainly related to handling situations when a failure occurs: 1) the signal handler in the mariadb-backup SST script was using an uninitialized variable when trying to kill a hung streaming process; 2) inaccurate error messages were being logged sometime; 3) after completing SST, temporary or old (extra) files could remain in database directories. --- scripts/wsrep_sst_common.sh | 2 +- scripts/wsrep_sst_mariabackup.sh | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/wsrep_sst_common.sh b/scripts/wsrep_sst_common.sh index f9e563c2a95..2921dde8503 100644 --- a/scripts/wsrep_sst_common.sh +++ b/scripts/wsrep_sst_common.sh @@ -1556,7 +1556,7 @@ cleanup_pid() fi done elif ps -p $pid >/dev/null 2>&1; then - wsrep_log_warning "Unable to kill PID=$pid ($pid_file)" + wsrep_log_warning "Unable to kill PID=$pid${pid_file:+ ($pid_file)}" return 1 fi fi diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index d32a24da547..cfae27d388c 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -676,24 +676,25 @@ cleanup_at_exit() [ "$(pwd)" != "$OLD_PWD" ] && cd "$OLD_PWD" - if [ $estatus -ne 0 ]; then - wsrep_log_error "Removing $MAGIC_FILE file due to signal" + if [ "$WSREP_SST_OPT_ROLE" = 'donor' -o $estatus -ne 0 ]; then + if [ $estatus -ne 0 ]; then + wsrep_log_error "Removing $MAGIC_FILE file due to signal" + fi [ -f "$MAGIC_FILE" ] && rm -f "$MAGIC_FILE" || : [ -f "$DONOR_MAGIC_FILE" ] && rm -f "$DONOR_MAGIC_FILE" || : + [ -f "$DATA/$IST_FILE" ] && rm -f "$DATA/$IST_FILE" || : fi if [ "$WSREP_SST_OPT_ROLE" = 'joiner' ]; then if [ -n "$BACKUP_PID" ]; then if ps -p $BACKUP_PID >/dev/null 2>&1; then wsrep_log_error \ - "mariadb-backup process is still running. Killing..." - cleanup_pid $CHECK_PID + "SST streaming process is still running. Killing..." + cleanup_pid $BACKUP_PID fi fi wsrep_log_info "Removing the sst_in_progress file" wsrep_cleanup_progress_file - else - [ -f "$DATA/$IST_FILE" ] && rm -f "$DATA/$IST_FILE" || : fi if [ -n "$progress" -a -p "$progress" ]; then @@ -1346,6 +1347,7 @@ else # joiner [ -f "$DATA/xtrabackup_checkpoints" ] && rm -f "$DATA/xtrabackup_checkpoints" [ -f "$DATA/xtrabackup_info" ] && rm -f "$DATA/xtrabackup_info" [ -f "$DATA/xtrabackup_slave_info" ] && rm -f "$DATA/xtrabackup_slave_info" + [ -f "$DATA/xtrabackup_binlog_info" ] && rm -f "$DATA/xtrabackup_binlog_info" [ -f "$DATA/xtrabackup_binlog_pos_innodb" ] && rm -f "$DATA/xtrabackup_binlog_pos_innodb" TDATA="$DATA" From b52f88edf8b4660311c47fc0ffe05675ac06a5a9 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 12 Dec 2024 10:15:26 +0100 Subject: [PATCH 18/22] MDEV-35387: wsrep_sst_rsync crash if aria_log_dir_path is defined This commit fixes some functions in wsrep_sst_common to ensure that now and in the future return codes from a number of helper functions will be zero on success. --- scripts/wsrep_sst_common.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/wsrep_sst_common.sh b/scripts/wsrep_sst_common.sh index 2921dde8503..ff4befa6680 100644 --- a/scripts/wsrep_sst_common.sh +++ b/scripts/wsrep_sst_common.sh @@ -1117,7 +1117,7 @@ get_openssl() { # If the OPENSSL_BINARY variable is already defined, just return: if [ -n "${OPENSSL_BINARY+x}" ]; then - return + return 0 fi # Let's look for openssl: OPENSSL_BINARY=$(commandex 'openssl') @@ -1863,6 +1863,8 @@ create_dirs() cd "$OLD_PWD" [ $simplify -ne 0 -a "$ar_log_dir" = "$DATA_DIR" ] && ar_log_dir="" fi + + return 0 } wait_previous_sst() From 3e34e4c161477bd56d0cf2fff377051253500880 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 12 Dec 2024 10:56:36 +0100 Subject: [PATCH 19/22] MDEV-34820: wsrep_sst_mariabackup get_footprint() portability and accuracy fix Added get_footprint() implementation for FreeBSD (and for other non-Linux systems), and added "apparent file size" mode for Linux to take into account the real file size (without compression) when used with filesystems like ZFS. --- scripts/wsrep_sst_mariabackup.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index cfae27d388c..e50704b7cdc 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -439,17 +439,30 @@ get_transfer() get_footprint() { cd "$DATA_DIR" - local payload_data=$(find $findopt . \ - -regex '.*undo[0-9]+$\|.*\.ibd$\|.*\.MYI$\|.*\.MYD$\|.*ibdata1$' \ - -type f -print0 | du --files0-from=- --block-size=1 -c -s | \ - awk 'END { print $1 }') + local payload_data + if [ "$OS" = 'Linux' ]; then + payload_data=$(find $findopt . \ + -regex '.*undo[0-9]+$\|.*\.ibd$\|.*\.MYI$\|.*\.MYD$\|.*ibdata1$' \ + -type f -print0 | du --files0-from=- --bytes -c -s | \ + awk 'END { print $1 }') + else + payload_data=$(find $findopt . \ + -regex '.*undo[0-9]+$|.*\.ibd$|.*\.MYI$\.*\.MYD$|.*ibdata1$' \ + -type f -print0 | xargs -0 stat -f '%z' | \ + awk '{ sum += $1 } END { print sum }') + fi local payload_undo=0 if [ -n "$ib_undo_dir" -a "$ib_undo_dir" != '.' -a \ "$ib_undo_dir" != "$DATA_DIR" -a -d "$ib_undo_dir" ] then cd "$ib_undo_dir" - payload_undo=$(find . -regex '.*undo[0-9]+$' -type f -print0 | \ - du --files0-from=- --block-size=1 -c -s | awk 'END { print $1 }') + if [ "$OS" = 'Linux' ]; then + payload_undo=$(find . -regex '.*undo[0-9]+$' -type f -print0 | \ + du --files0-from=- --bytes -c -s | awk 'END { print $1 }') + else + payload_undo=$(find . -regex '.*undo[0-9]+$' -type f -print0 | \ + xargs -0 stat -f '%z' | awk '{ sum += $1 } END { print sum }') + fi fi cd "$OLD_PWD" From 1097164d3feaade13171cd8b70ce5310b7df6f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 13 Dec 2024 11:41:47 +0200 Subject: [PATCH 20/22] MDEV-35619 Assertion failure in row_purge_del_mark_error trx_sys_t::find_same_or_older_in_purge(): Correct a mistake that was made in commit 19acb0257eec0956e3a0dd3b11bbb701fa7ea648 (MDEV-35508) and make the caching logic correspond to the one in trx_sys_t::find_same_or_older(). In the more common code path for 64-bit systems, the condition !hot was inadvertently inverted, making us wrongly skip calls to find_same_or_older_low() when the transaction may still be active. Furthermore, the call should have been to find_same_or_older_low() and not the wrapper find_same_or_older(). --- storage/innobase/include/trx0sys.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index f411e8420a9..3ae2e0b5305 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -971,18 +971,23 @@ public: Our IA-32 target is not "i386" but at least "i686", that is, at least Pentium MMX, which has a 64-bit data bus and 64-bit XMM registers. */ + bool hot= false; trx->mutex_lock(); trx_id_t &max_inactive_id= trx->max_inactive_id; - const bool hot{max_inactive_id < id && find_same_or_older(trx, id)}; + if (max_inactive_id >= id); + else if (!find_same_or_older_low(trx, id)) + max_inactive_id= id; + else + hot= true; #else Atomic_relaxed &max_inactive_id= trx->max_inactive_id_atomic; if (max_inactive_id >= id) return false; trx->mutex_lock(); - const bool hot{find_same_or_older(trx, id)}; -#endif - if (hot) + const bool hot{find_same_or_older_low(trx, id)}; + if (!hot) max_inactive_id= id; +#endif trx->mutex_unlock(); return hot; } From c7698a0b709fe1ee15002333675383a2fd49ab29 Mon Sep 17 00:00:00 2001 From: mariadb-DebarunBanerjee Date: Wed, 11 Dec 2024 18:36:15 +0530 Subject: [PATCH 21/22] MDEV-35626 Race condition between buf_page_create_low() and read completion This regression is introduced in 10.6 by following commit. commit 35d477dd1dff464bd80dff9efe83884ce1c38e4c MDEV-34453 Trying to read 16384 bytes at 70368744161280 The page state could change after being buffer-fixed and needs to be read again after locking the page. --- storage/innobase/buf/buf0buf.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 69e3032a2db..c6adcb675f7 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -3322,6 +3322,8 @@ retry: ut_ad(!bpage->is_io_fixed(state)); ut_ad(bpage->buf_fix_count(state)); } + else + state= bpage->state(); ut_ad(state >= buf_page_t::FREED); ut_ad(state < buf_page_t::READ_FIX); From c982a143fccdc198b0ffb2177582b33a52dec5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 16 Dec 2024 13:23:13 +0200 Subject: [PATCH 22/22] MDEV-35494 fixup: Always initialize latch It turns out that init() always checks in debug builds that some fields of the latch had been filled with zero. --- storage/innobase/fil/fil0fil.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 1f72c2bbd1f..6403485ab3d 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -938,9 +938,7 @@ fil_space_t::fil_space_t(uint32_t id, ulint flags, bool being_imported, id(id), crypt_data(crypt_data), being_imported(being_imported), flags(flags) { UT_LIST_INIT(chain, &fil_node_t::chain); -#ifndef SUX_LOCK_GENERIC memset((void*) &latch, 0, sizeof latch); -#endif latch.SRW_LOCK_INIT(fil_space_latch_key); }