From 5d856760fb3941b4a36cc484e28c500236c45ac1 Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Thu, 23 Apr 2020 04:49:24 +0300 Subject: [PATCH 01/12] MDEV-22349 MTR re-bootstrap modifies environment variable MYSQLD_BOOTSTRAP_CMD --- mysql-test/mysql-test-run.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index fc152b232cad6..80abc0fbb824b 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -3167,7 +3167,8 @@ sub mysql_install_db { # ---------------------------------------------------------------------- # export MYSQLD_BOOTSTRAP_CMD variable containing /mysqld # ---------------------------------------------------------------------- - $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args); + $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args) + unless defined $ENV{'MYSQLD_BOOTSTRAP_CMD'}; # Extra options can come not only from the command line, but also # from option files or combinations. We want them on a command line From 9f19dbe0c3f6bc3ee68c336869c186dd820107c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 23 Apr 2020 19:33:55 +0300 Subject: [PATCH 02/12] MDEV-22358 Assertion srv_undo_sources || ... in row_prebuilt_free() row_prebuilt_free(): Do not attempt to drop orphan indexes that might have been left behind by a failed ADD UNIQUE INDEX. This avoids the execution of unwanted transactions during shutdown. --- mysql-test/suite/innodb_fts/r/innodb_fts_misc.result | 7 ++++++- mysql-test/suite/innodb_fts/t/innodb_fts_misc.test | 8 +++++++- storage/innobase/row/row0mysql.cc | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/innodb_fts/r/innodb_fts_misc.result b/mysql-test/suite/innodb_fts/r/innodb_fts_misc.result index 8c3c3b5be6894..8074260952a2b 100644 --- a/mysql-test/suite/innodb_fts/r/innodb_fts_misc.result +++ b/mysql-test/suite/innodb_fts/r/innodb_fts_misc.result @@ -740,6 +740,11 @@ FULLTEXT(f2), FOREIGN KEY(f1) REFERENCES mdev20987_1(f1))ENGINE=InnoDB; INSERT INTO mdev20987_1 VALUES(1); INSERT INTO mdev20987_2 VALUES(1, 'mariadb'); +CREATE TABLE mdev22358 (a INT, b TEXT, FULLTEXT KEY ftidx (b)) ENGINE=InnoDB; +ALTER TABLE mdev22358 DROP KEY ftidx; +INSERT INTO mdev22358 (a) VALUES (2),(2); +ALTER TABLE mdev22358 ADD UNIQUE KEY uidx (a), ADD FULLTEXT KEY ftidx (b); +ERROR 23000: Duplicate entry '2' for key 'uidx' SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( @@ -747,7 +752,7 @@ t2 CREATE TABLE `t2` ( PRIMARY KEY (`FTS_DOC_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 DELETE FROM t1 WHERE MATCH(char_column) AGAINST ('bbb'); -DROP TABLE t1, t2, mdev20987_2, mdev20987_1; +DROP TABLE t1, t2, mdev20987_2, mdev20987_1, mdev22358; "----------Test28---------" create table `fts_test`(`a` text,fulltext key(`a`))engine=innodb; set session autocommit=0; diff --git a/mysql-test/suite/innodb_fts/t/innodb_fts_misc.test b/mysql-test/suite/innodb_fts/t/innodb_fts_misc.test index 5b11a418dab13..d1c6063d524f5 100644 --- a/mysql-test/suite/innodb_fts/t/innodb_fts_misc.test +++ b/mysql-test/suite/innodb_fts/t/innodb_fts_misc.test @@ -672,10 +672,16 @@ CREATE TABLE mdev20987_2(f1 INT NOT NULL, f2 CHAR(100), FOREIGN KEY(f1) REFERENCES mdev20987_1(f1))ENGINE=InnoDB; INSERT INTO mdev20987_1 VALUES(1); INSERT INTO mdev20987_2 VALUES(1, 'mariadb'); + +CREATE TABLE mdev22358 (a INT, b TEXT, FULLTEXT KEY ftidx (b)) ENGINE=InnoDB; +ALTER TABLE mdev22358 DROP KEY ftidx; +INSERT INTO mdev22358 (a) VALUES (2),(2); +--error ER_DUP_ENTRY +ALTER TABLE mdev22358 ADD UNIQUE KEY uidx (a), ADD FULLTEXT KEY ftidx (b); --source include/restart_mysqld.inc SHOW CREATE TABLE t2; DELETE FROM t1 WHERE MATCH(char_column) AGAINST ('bbb'); -DROP TABLE t1, t2, mdev20987_2, mdev20987_1; +DROP TABLE t1, t2, mdev20987_2, mdev20987_1, mdev22358; --echo "----------Test28---------" create table `fts_test`(`a` text,fulltext key(`a`))engine=innodb; diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index c708842b04d26..ac44e32c326ca 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -1033,7 +1033,7 @@ row_prebuilt_free( rtr_clean_rtr_info(prebuilt->rtr_info, true); } if (prebuilt->table) { - dict_table_close(prebuilt->table, dict_locked, TRUE); + dict_table_close(prebuilt->table, dict_locked, FALSE); } mem_heap_free(prebuilt->heap); From 57ec41d6ea5d9384b45d026b70b3fd97ddd2861b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 24 Apr 2020 10:42:08 +0300 Subject: [PATCH 03/12] Cleanup: Remove a constant parameter row_vers_vc_matches_cluster(): Remove the parameter in_purge, which was always passed as in_purge=true. This parameter became constant in mysql/mysql-server@1dec14d346ac55fe72989dccb071f84b3b0d3bd6 and it always was constant in MariaDB starting from the introduction of the function in commit 2e814d4702d71a04388386a9f591d14a35980bfe (MariaDB 10.2.2). --- storage/innobase/row/row0vers.cc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/storage/innobase/row/row0vers.cc b/storage/innobase/row/row0vers.cc index 3a4b560670fa3..b3d0e93b73281 100644 --- a/storage/innobase/row/row0vers.cc +++ b/storage/innobase/row/row0vers.cc @@ -619,7 +619,6 @@ row_vers_build_cur_vrow_low( /** Check a virtual column value index secondary virtual index matches that of current cluster index record, which is recreated from information stored in undo log -@param[in] in_purge called by purge thread @param[in] rec record in the clustered index @param[in] icentry the index entry built from a cluster row @param[in] clust_index cluster index @@ -635,7 +634,6 @@ stored in undo log static bool row_vers_vc_matches_cluster( - bool in_purge, const rec_t* rec, const dtuple_t* icentry, dict_index_t* clust_index, @@ -696,12 +694,6 @@ row_vers_vc_matches_cluster( version = rec; - /* If this is called by purge thread, set TRX_UNDO_PREV_IN_PURGE - bit to search the undo log until we hit the current undo log with - roll_ptr */ - ulint status = (in_purge ? TRX_UNDO_PREV_IN_PURGE : 0) - | TRX_UNDO_GET_OLD_V_VALUE; - while (n_cmp_v_col < n_fields - n_non_v_col) { heap2 = heap; heap = mem_heap_create(1024); @@ -709,11 +701,12 @@ row_vers_vc_matches_cluster( version, clust_index, clust_offsets); ut_ad(cur_roll_ptr != 0); - ut_ad(in_purge == (roll_ptr != 0)); + ut_ad(roll_ptr != 0); trx_undo_prev_version_build( rec, mtr, version, clust_index, clust_offsets, - heap, &prev_version, NULL, vrow, status); + heap, &prev_version, NULL, vrow, + TRX_UNDO_PREV_IN_PURGE | TRX_UNDO_GET_OLD_V_VALUE); if (heap2) { mem_heap_free(heap2); @@ -997,7 +990,7 @@ row_vers_old_has_index_entry( secondary indexes.) */ if (entry && row_vers_vc_matches_cluster( - also_curr, rec, entry, + rec, entry, clust_index, clust_offsets, index, ientry, roll_ptr, trx_id, NULL, &vrow, mtr)) { From da7564edcf239fe7bc612efed97cc7b6fa89320b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 24 Apr 2020 10:46:33 +0300 Subject: [PATCH 04/12] Cleanup: Make row_upd_store_row() static --- storage/innobase/include/row0upd.h | 12 +----------- storage/innobase/row/row0upd.cc | 1 + 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/storage/innobase/include/row0upd.h b/storage/innobase/include/row0upd.h index e08c9dd6b4838..cca86590f7421 100644 --- a/storage/innobase/include/row0upd.h +++ b/storage/innobase/include/row0upd.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2018, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, MariaDB Corporation. +Copyright (c) 2018, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -371,16 +371,6 @@ row_upd_changes_some_index_ord_field_binary( /*========================================*/ const dict_table_t* table, /*!< in: table */ const upd_t* update);/*!< in: update vector for the row */ -/** Stores to the heap the row on which the node->pcur is positioned. -@param[in] node row update node -@param[in] thd mysql thread handle -@param[in,out] mysql_table NULL, or mysql table object when - user thread invokes dml */ -void -row_upd_store_row( - upd_node_t* node, - THD* thd, - TABLE* mysql_table); /***********************************************************//** Updates a row in a table. This is a high-level function used in SQL execution graphs. diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index fd7d622aa6916..943e31d99fea6 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -2206,6 +2206,7 @@ row_upd_store_v_row( @param[in] thd mysql thread handle @param[in,out] mysql_table NULL, or mysql table object when user thread invokes dml */ +static void row_upd_store_row( upd_node_t* node, From 2c5067b6890974d0df335a833ed7a4e4c6ced183 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Tue, 7 Apr 2020 13:14:41 +0300 Subject: [PATCH 05/12] cleanup THR_KEY_mysys read TLS with my_thread_var write TLS with set_mysys_var() my_thread_var is no longer __attribute__ ((const)): this attribute is simply incorrect here. Read gcc manual for more information. sql/threadpool_generic.cc fails with that attribute. --- include/my_pthread.h | 3 ++- mysys/my_thr_init.c | 14 +++++++------- sql/threadpool_common.cc | 11 +++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/my_pthread.h b/include/my_pthread.h index 72647b6c9f7c6..f369b765edda4 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -729,13 +729,14 @@ struct st_my_thread_var #endif }; -extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const)); +struct st_my_thread_var *_my_thread_var(void); extern void **my_thread_var_dbug(void); extern safe_mutex_t **my_thread_var_mutex_in_use(void); extern uint my_thread_end_wait_time; extern my_bool safe_mutex_deadlock_detector; #define my_thread_var (_my_thread_var()) #define my_errno my_thread_var->thr_errno +int set_mysys_var(struct st_my_thread_var *mysys_var); /* Keep track of shutdown,signal, and main threads so that my_end() will not report errors with them diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 8e38bd7c826d8..5686dabf35ddc 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -141,7 +141,7 @@ void my_thread_global_reinit(void) my_thread_destroy_internal_mutex(); my_thread_init_internal_mutex(); - tmp= my_pthread_getspecific(struct st_my_thread_var*, THR_KEY_mysys); + tmp= my_thread_var; DBUG_ASSERT(tmp); my_thread_destory_thr_mutex(tmp); @@ -279,7 +279,7 @@ my_bool my_thread_init(void) fprintf(stderr,"my_thread_init(): pthread_self: %p\n", pthread_self()); #endif - if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys)) + if (my_thread_var) { #ifdef EXTRA_DEBUG_THREADS fprintf(stderr,"my_thread_init() called more than once in thread 0x%lx\n", @@ -297,7 +297,7 @@ my_bool my_thread_init(void) error= 1; goto end; } - pthread_setspecific(THR_KEY_mysys,tmp); + set_mysys_var(tmp); tmp->pthread_self= pthread_self(); my_thread_init_thr_mutex(tmp); @@ -334,7 +334,7 @@ my_bool my_thread_init(void) void my_thread_end(void) { struct st_my_thread_var *tmp; - tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); + tmp= my_thread_var; #ifdef EXTRA_DEBUG_THREADS fprintf(stderr,"my_thread_end(): tmp: %p pthread_self: %p thread_id: %ld\n", @@ -357,7 +357,7 @@ void my_thread_end(void) as the key is used by DBUG. */ DBUG_POP(); - pthread_setspecific(THR_KEY_mysys,0); + set_mysys_var(NULL); if (tmp && tmp->init) { @@ -441,7 +441,7 @@ extern void **my_thread_var_dbug() struct st_my_thread_var *tmp; if (!my_thread_global_init_done) return NULL; - tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); + tmp= my_thread_var; return tmp && tmp->init ? &tmp->dbug : 0; } #endif /* DBUG_OFF */ @@ -453,7 +453,7 @@ safe_mutex_t **my_thread_var_mutex_in_use() struct st_my_thread_var *tmp; if (!my_thread_global_init_done) return NULL; - tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); + tmp= my_thread_var; return tmp ? &tmp->mutex_in_use : 0; } diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 0a374147e0763..b0438770aae6c 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -45,7 +45,6 @@ static void threadpool_remove_connection(THD *thd); static int threadpool_process_request(THD *thd); static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data); -extern "C" pthread_key(struct st_my_thread_var*, THR_KEY_mysys); extern bool do_command(THD*); static inline TP_connection *get_TP_connection(THD *thd) @@ -87,7 +86,7 @@ struct Worker_thread_context #ifdef HAVE_PSI_THREAD_INTERFACE psi_thread = PSI_THREAD_CALL(get_thread)(); #endif - mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); + mysys_var= my_thread_var; } void restore() @@ -95,7 +94,7 @@ struct Worker_thread_context #ifdef HAVE_PSI_THREAD_INTERFACE PSI_THREAD_CALL(set_thread)(psi_thread); #endif - pthread_setspecific(THR_KEY_mysys,mysys_var); + set_mysys_var(mysys_var); pthread_setspecific(THR_THD, 0); } }; @@ -141,7 +140,7 @@ static inline void set_thd_idle(THD *thd) */ static void thread_attach(THD* thd) { - pthread_setspecific(THR_KEY_mysys,thd->mysys_var); + set_mysys_var(thd->mysys_var); thd->thread_stack=(char*)&thd; thd->store_globals(); #ifdef HAVE_PSI_THREAD_INTERFACE @@ -228,9 +227,9 @@ static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data) Store them in THD. */ - pthread_setspecific(THR_KEY_mysys, 0); + set_mysys_var(NULL); my_thread_init(); - st_my_thread_var* mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); + st_my_thread_var* mysys_var= my_thread_var; if (!mysys_var ||!(thd= connect->create_thd(NULL))) { /* Out of memory? */ From d28ee189b794d3ceebd4a108da5653a1e38279e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 27 Apr 2020 09:36:31 +0300 Subject: [PATCH 06/12] MDEV-22271: Follow-up fix of --embedded Since commit 7198c6ab2dc8f8286f6732824ab985a76ebaaddc the ./mtr --embedded tests would fail to start innodb_plugin because of an undefined reference to the symbol wsrep_log(). Let us define a stub for that function. The embedded server is never built WITH_WSREP, but there are no separate storage engine builds for the embedded server. Hence, by default, the dynamic InnoDB storage engine plugin would be built WITH_WSREP and it would fail to load into the embedded server library due to a reference to the undefined symbol. --- sql/mysqld.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 4580da89f16cb..e2cc73903850a 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2015, Oracle and/or its affiliates. - Copyright (c) 2008, 2018, MariaDB + Copyright (c) 2008, 2020, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1814,6 +1814,15 @@ static void close_server_sock() #endif } +#else /* EMBEDDED LIBRARY */ +# ifndef _WIN32 +/* Unfortunately, ha_innodb.so is by default built WITH_WSREP, and it +will be used for both the normal and the embedded server, while the +embedded server library is never built WITH_WSREP. We must define this +symbol in the embedded library, so that loading a dynamic InnoDB storage +engine plugin will work in the embedded server library. */ +void wsrep_log(void (*)(const char *, ...), const char *, ...) {} +# endif #endif /*EMBEDDED_LIBRARY*/ From 6a3fc1101cd8cfc8ae755f81a22d16cd98c03210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 27 Apr 2020 09:40:10 +0300 Subject: [PATCH 07/12] Aria: Avoid unused variables in embedded server --- storage/maria/ha_maria.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 5f73a1dc1afd9..6355781e19c8e 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -296,7 +296,7 @@ static MYSQL_SYSVAR_BOOL(encrypt_tables, maria_encrypt_tables, PLUGIN_VAR_OPCMDA "and not FIXED/DYNAMIC)", 0, 0, 0); -#ifdef HAVE_PSI_INTERFACE +#if defined HAVE_PSI_INTERFACE && !defined EMBEDDED_LIBRARY static PSI_mutex_info all_aria_mutexes[]= { From 758fbec6e3dd5f640c6e2eb1a78675e369540adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 13 Mar 2020 08:37:22 +0200 Subject: [PATCH 08/12] Fix clang 10 warnings _ma_fetch_keypage(): Correct an assertion that used to always hold. Thanks to clang -Wint-in-bool-context for flagging this. double_to_datetime_with_warn(): Suppress -Wimplicit-int-float-conversion by adding a cast. LONGLONG_MAX converted to double will actually be LONGLONG_MAX+1. --- sql/sql_time.cc | 4 ++-- storage/maria/ma_page.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 6d94de047e8ff..421eb79c7a3b7 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. - Copyright (c) 2009, 2013 Monty Program Ab. + Copyright (c) 2009, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -402,7 +402,7 @@ bool double_to_datetime_with_warn(double value, MYSQL_TIME *ltime, if (neg) value= -value; - if (value > LONGLONG_MAX) + if (value > static_cast(LONGLONG_MAX)) value= static_cast(LONGLONG_MAX); longlong nr= static_cast(floor(value)); diff --git a/storage/maria/ma_page.c b/storage/maria/ma_page.c index 7067421b51aa5..e1d41d1a1d818 100644 --- a/storage/maria/ma_page.c +++ b/storage/maria/ma_page.c @@ -1,4 +1,5 @@ /* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + Copyright (c) 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -112,7 +113,7 @@ my_bool _ma_fetch_keypage(MARIA_PAGE *page, MARIA_HA *info, if (lock != PAGECACHE_LOCK_LEFT_UNLOCKED) { - DBUG_ASSERT(lock == PAGECACHE_LOCK_WRITE || PAGECACHE_LOCK_READ); + DBUG_ASSERT(lock == PAGECACHE_LOCK_WRITE || lock == PAGECACHE_LOCK_READ); page_link.unlock= (lock == PAGECACHE_LOCK_WRITE ? PAGECACHE_LOCK_WRITE_UNLOCK : PAGECACHE_LOCK_READ_UNLOCK); From 6be05ceb05609b1aa7382776b4e27ad134808eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 27 Apr 2020 09:40:51 +0300 Subject: [PATCH 09/12] MDEV-22203: WSREP_ON is unnecessarily expensive to evaluate This is a backport of the applicable part of commit 93475aff8de80a0ef53cbee924bcb70de6e86f2c and commit 2c39f69d34e64a5cf94720e82e78c0ee91bd4649 from 10.4. Before 10.4 and Galera 4, WSREP_ON is a macro that points to a global Boolean variable, so it is not that expensive to evaluate, but we will add an unlikely() hint around it. WSREP_ON_NEW: Remove. This macro was introduced in commit c863159c320008676aff978a7cdde5732678f975 when reverting WSREP_ON to its previous definition. We replace some use of WSREP_ON with WSREP(thd), like it was done in 93475aff8de80a0ef53cbee924bcb70de6e86f2c. Note: the macro WSREP() in 10.1 is equivalent to WSREP_NNULL() in 10.4. Item_func_rand::seed_random(): Avoid invoking current_thd when WSREP is not enabled. --- mysql-test/suite/galera/t/MW-86-wait1.test | 1 + sql/item_func.cc | 23 +++++++++++----------- sql/log.cc | 9 +++++---- sql/log_event.cc | 8 ++++---- sql/mysqld.cc | 2 ++ sql/slave.cc | 8 +++++--- sql/sql_base.cc | 4 ++-- sql/sql_parse.cc | 8 ++++---- sql/sql_table.cc | 4 ++-- sql/wsrep_mysqld.h | 8 +------- 10 files changed, 38 insertions(+), 37 deletions(-) diff --git a/mysql-test/suite/galera/t/MW-86-wait1.test b/mysql-test/suite/galera/t/MW-86-wait1.test index 40a7882829b80..a7476b74e6893 100644 --- a/mysql-test/suite/galera/t/MW-86-wait1.test +++ b/mysql-test/suite/galera/t/MW-86-wait1.test @@ -5,6 +5,7 @@ # --source include/galera_cluster.inc --source include/have_binlog_format_row.inc +--source include/have_debug.inc --source include/have_debug_sync.inc --connection node_2 diff --git a/sql/item_func.cc b/sql/item_func.cc index 302ec58a70827..8407dc881befd 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2015, Oracle and/or its affiliates. - Copyright (c) 2009, 2017, MariaDB + Copyright (c) 2009, 2020, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -2650,19 +2650,20 @@ void Item_func_rand::seed_random(Item *arg) TODO: do not do reinit 'rand' for every execute of PS/SP if args[0] is a constant. */ - uint32 tmp; + uint32 tmp= (uint32) arg->val_int(); #ifdef WITH_WSREP - THD *thd= current_thd; - if (WSREP(thd)) + if (WSREP_ON) { - if (thd->wsrep_exec_mode==REPL_RECV) - tmp= thd->wsrep_rand; - else - tmp= thd->wsrep_rand= (uint32) arg->val_int(); - } - else + THD *thd= current_thd; + if (thd->variables.wsrep_on) + { + if (thd->wsrep_exec_mode==REPL_RECV) + tmp= thd->wsrep_rand; + else + thd->wsrep_rand= tmp; + } + } #endif /* WITH_WSREP */ - tmp= (uint32) arg->val_int(); my_rnd_init(rand, (uint32) (tmp*0x10001L+55555555L), (uint32) (tmp*0x10000001L)); diff --git a/sql/log.cc b/sql/log.cc index 0efef6d1e2930..076dd36a21930 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1791,7 +1791,7 @@ binlog_commit_flush_stmt_cache(THD *thd, bool all, #ifdef WITH_WSREP if (thd->wsrep_mysql_replicated > 0) { - DBUG_ASSERT(WSREP_ON); + DBUG_ASSERT(WSREP(thd)); WSREP_DEBUG("avoiding binlog_commit_flush_trx_cache: %d", thd->wsrep_mysql_replicated); return 0; @@ -6612,14 +6612,15 @@ int MYSQL_BIN_LOG::rotate(bool force_rotate, bool* check_purge) int error= 0; DBUG_ENTER("MYSQL_BIN_LOG::rotate"); - if (wsrep_to_isolation) +#ifdef WITH_WSREP + if (WSREP_ON && wsrep_to_isolation) { - DBUG_ASSERT(WSREP_ON); *check_purge= false; - WSREP_DEBUG("avoiding binlog rotate due to TO isolation: %d", + WSREP_DEBUG("avoiding binlog rotate due to TO isolation: %d", wsrep_to_isolation); DBUG_RETURN(0); } +#endif /* WITH_WSREP */ //todo: fix the macro def and restore safe_mutex_assert_owner(&LOCK_log); *check_purge= false; diff --git a/sql/log_event.cc b/sql/log_event.cc index d731c39d9c598..bb3465ae9f0cc 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1,6 +1,6 @@ /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. - Copyright (c) 2009, 2019, MariaDB + Copyright (c) 2009, 2020, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -4770,7 +4770,7 @@ Query_log_event::do_shall_skip(rpl_group_info *rgi) } } #ifdef WITH_WSREP - else if (WSREP_ON && wsrep_mysql_replication_bundle && opt_slave_domain_parallel_threads == 0 && + else if (WSREP(thd) && wsrep_mysql_replication_bundle && opt_slave_domain_parallel_threads == 0 && thd->wsrep_mysql_replicated > 0 && (is_begin() || is_commit())) { @@ -4784,7 +4784,7 @@ Query_log_event::do_shall_skip(rpl_group_info *rgi) thd->wsrep_mysql_replicated = 0; } } -#endif +#endif /* WITH_WSREP */ DBUG_RETURN(Log_event::do_shall_skip(rgi)); } @@ -7755,7 +7755,7 @@ Xid_log_event::do_shall_skip(rpl_group_info *rgi) DBUG_RETURN(Log_event::EVENT_SKIP_COUNT); } #ifdef WITH_WSREP - else if (wsrep_mysql_replication_bundle && WSREP_ON && + else if (WSREP(thd) && wsrep_mysql_replication_bundle && opt_slave_domain_parallel_threads == 0) { if (++thd->wsrep_mysql_replicated < (int)wsrep_mysql_replication_bundle) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e2cc73903850a..ff3faaa92bcd8 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5781,8 +5781,10 @@ int mysqld_main(int argc, char **argv) set_user(mysqld_user, user_info); } +#ifdef WITH_WSREP if (WSREP_ON && wsrep_check_opts()) global_system_variables.wsrep_on= 0; +#endif if (opt_bin_log && !global_system_variables.server_id) { diff --git a/sql/slave.cc b/sql/slave.cc index cbfc3fd841352..26fabc2cc5281 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2017, Oracle and/or its affiliates. - Copyright (c) 2009, 2017, MariaDB Corporation + Copyright (c) 2009, 2020, MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -4998,8 +4998,10 @@ pthread_handler_t handle_slave_sql(void *arg) if (!sql_slave_killed(serial_rgi)) { slave_output_error_info(serial_rgi, thd); - if (WSREP_ON && rli->last_error().number == ER_UNKNOWN_COM_ERROR) + if (WSREP(thd) && rli->last_error().number == ER_UNKNOWN_COM_ERROR) + { wsrep_node_dropped= TRUE; + } } goto err; } @@ -5131,7 +5133,7 @@ pthread_handler_t handle_slave_sql(void *arg) If slave stopped due to node going non primary, we set global flag to trigger automatic restart of slave when node joins back to cluster. */ - if (WSREP_ON && wsrep_node_dropped && wsrep_restart_slave) + if (WSREP(thd) && wsrep_node_dropped && wsrep_restart_slave) { if (wsrep_ready_get()) { diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 1c4e7600d87b1..1dbed8c55d153 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2016, Oracle and/or its affiliates. - Copyright (c) 2010, 2016, MariaDB + Copyright (c) 2010, 2020, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -4784,7 +4784,7 @@ bool open_tables(THD *thd, const DDL_options_st &options, } } - if (WSREP_ON && + if (WSREP(thd) && wsrep_replicate_myisam && (*start) && (*start)->table && diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e5626ccbd7c52..d19cbf5ad9bee 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2017, Oracle and/or its affiliates. - Copyright (c) 2008, 2019, MariaDB + Copyright (c) 2008, 2020, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1493,7 +1493,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (parser_state.init(thd, thd->query(), thd->query_length())) break; - if (WSREP_ON) + if (WSREP(thd)) wsrep_mysql_parse(thd, thd->query(), thd->query_length(), &parser_state); else mysql_parse(thd, thd->query(), thd->query_length(), &parser_state); @@ -1574,13 +1574,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd, */ statistic_increment(thd->status_var.questions, &LOCK_status); - if(!WSREP(thd)) + if (!WSREP(thd)) thd->set_time(); /* Reset the query start time. */ parser_state.reset(beginning_of_next_stmt, length); /* TODO: set thd->lex->sql_command to SQLCOM_END here */ - if (WSREP_ON) + if (WSREP(thd)) wsrep_mysql_parse(thd, beginning_of_next_stmt, length, &parser_state); else mysql_parse(thd, beginning_of_next_stmt, length, &parser_state); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index e694c52e2722d..ef6a8c018433b 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1,6 +1,6 @@ /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. - Copyright (c) 2010, 2019, MariaDB + Copyright (c) 2010, 2020, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -5338,7 +5338,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, DBUG_ENTER("mysql_create_like_table"); #ifdef WITH_WSREP - if (WSREP_ON && !thd->wsrep_applier && + if (WSREP(thd) && !thd->wsrep_applier && wsrep_create_like_table(thd, table, src_table, create_info)) DBUG_RETURN(res); #endif diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index a5ec69268d465..1531abe78f8f6 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -179,13 +179,7 @@ extern void wsrep_prepend_PATH (const char* path); /* Other global variables */ extern wsrep_seqno_t wsrep_locked_seqno; -#define WSREP_ON \ - (global_system_variables.wsrep_on) - -#define WSREP_ON_NEW \ - ((global_system_variables.wsrep_on) && \ - wsrep_provider && \ - strcmp(wsrep_provider, WSREP_NONE)) +#define WSREP_ON unlikely(global_system_variables.wsrep_on) #define WSREP(thd) \ (WSREP_ON && thd->variables.wsrep_on) From f462fbac61445558a7b8929cabace8a9c480d961 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 21 Apr 2020 22:57:54 +0200 Subject: [PATCH 10/12] MDEV-22078 MariaDB-compat missing from MariaDB 10.4 CentOS 8 Yum Repo Backport INSALL_SYMLINK cmake macro from 10.3. It'll make libmysqlclient_r.* symlinks to link to the actual shared library file, not to another symlink. As a bonus it'll fix cmake warning about deprecated LOCATION property --- cmake/install_macros.cmake | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cmake/install_macros.cmake b/cmake/install_macros.cmake index 0c05b06208f7f..bb89a57ab1186 100644 --- a/cmake/install_macros.cmake +++ b/cmake/install_macros.cmake @@ -162,17 +162,13 @@ ENDFUNCTION() # and extension will be the same as for target file. MACRO(INSTALL_SYMLINK linkname target destination component) IF(UNIX) - GET_TARGET_PROPERTY(location ${target} LOCATION) - GET_FILENAME_COMPONENT(path ${location} PATH) - GET_FILENAME_COMPONENT(name ${location} NAME) - SET(output ${path}/${linkname}) + SET(output ${CMAKE_CURRENT_BINARY_DIR}/${linkname}) ADD_CUSTOM_COMMAND( OUTPUT ${output} - COMMAND ${CMAKE_COMMAND} ARGS -E remove -f ${output} + COMMAND ${CMAKE_COMMAND} ARGS -E remove -f ${linkname} COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink - ${name} + $ ${linkname} - WORKING_DIRECTORY ${path} DEPENDS ${target} ) From dd4124c22430dd2f245afbf9a20cfea303de3320 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 22 Apr 2020 13:21:43 +0200 Subject: [PATCH 11/12] MDEV-22271 Excessive stack memory usage due to WSREP_LOG fix embedded innodb_plugin tests followup for 7198c6ab2dc --- sql/mysqld.cc | 9 --------- sql/wsrep_dummy.cc | 4 ++++ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ff3faaa92bcd8..594f50b72f233 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1814,15 +1814,6 @@ static void close_server_sock() #endif } -#else /* EMBEDDED LIBRARY */ -# ifndef _WIN32 -/* Unfortunately, ha_innodb.so is by default built WITH_WSREP, and it -will be used for both the normal and the embedded server, while the -embedded server library is never built WITH_WSREP. We must define this -symbol in the embedded library, so that loading a dynamic InnoDB storage -engine plugin will work in the embedded server library. */ -void wsrep_log(void (*)(const char *, ...), const char *, ...) {} -# endif #endif /*EMBEDDED_LIBRARY*/ diff --git a/sql/wsrep_dummy.cc b/sql/wsrep_dummy.cc index 43cea8bad426c..364ef2d3e7a8a 100644 --- a/sql/wsrep_dummy.cc +++ b/sql/wsrep_dummy.cc @@ -141,3 +141,7 @@ void wsrep_unlock_rollback() void wsrep_set_data_home_dir(const char *) { } + +void wsrep_log(void (*)(const char *, ...), const char *, ...) +{ +} From edbdfc2f995eb47ba49235195aca00888aeacbc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 27 Apr 2020 11:18:11 +0300 Subject: [PATCH 12/12] MDEV-7962 wsrep_on() takes 0.14% in OLTP RO The function wsrep_on() was being called rather frequently in InnoDB and XtraDB. Let us cache it in trx_t and invoke trx_t::is_wsrep() instead. innobase_trx_init(): Cache trx->wsrep = wsrep_on(thd). ha_innobase::write_row(): Replace many repeated calls to current_thd, and test the cheapest condition first. --- storage/innobase/handler/ha_innodb.cc | 111 +++++++++-------------- storage/innobase/include/lock0lock.h | 5 +- storage/innobase/include/trx0trx.h | 14 ++- storage/innobase/lock/lock0lock.cc | 13 ++- storage/innobase/lock/lock0wait.cc | 7 +- storage/innobase/row/row0ins.cc | 4 +- storage/innobase/row/row0mysql.cc | 2 +- storage/innobase/row/row0upd.cc | 4 +- storage/innobase/srv/srv0conc.cc | 11 +-- storage/innobase/trx/trx0trx.cc | 8 +- storage/xtradb/handler/ha_innodb.cc | 126 +++++++++++--------------- storage/xtradb/include/lock0lock.h | 3 +- storage/xtradb/include/trx0trx.h | 14 ++- storage/xtradb/lock/lock0lock.cc | 13 ++- storage/xtradb/lock/lock0wait.cc | 7 +- storage/xtradb/row/row0ins.cc | 4 +- storage/xtradb/row/row0upd.cc | 4 +- storage/xtradb/srv/srv0conc.cc | 11 +-- storage/xtradb/trx/trx0roll.cc | 11 +-- storage/xtradb/trx/trx0trx.cc | 8 +- 20 files changed, 160 insertions(+), 220 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 4de2cdbeaecce..f9bad3a128c0a 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -4,7 +4,7 @@ Copyright (c) 2000, 2019, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. Copyright (c) 2012, Facebook Inc. -Copyright (c) 2013, 2019, MariaDB Corporation. +Copyright (c) 2013, 2020, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -1671,8 +1671,7 @@ innobase_srv_conc_enter_innodb( trx_t* trx) /*!< in: transaction handle */ { #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; #endif /* WITH_WSREP */ if (srv_thread_concurrency) { if (trx->n_tickets_to_enter_innodb > 0) { @@ -1710,8 +1709,7 @@ innobase_srv_conc_exit_innodb( ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch)); #endif /* UNIV_SYNC_DEBUG */ #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; #endif /* WITH_WSREP */ /* This is to avoid making an unnecessary function call. */ @@ -2638,6 +2636,9 @@ innobase_trx_init( trx->check_unique_secondary = !thd_test_options( thd, OPTION_RELAXED_UNIQUE_CHECKS); +#ifdef WITH_WSREP + trx->wsrep = wsrep_on(thd); +#endif DBUG_VOID_RETURN; } @@ -4185,19 +4186,17 @@ innobase_commit_low( trx_t* trx) /*!< in: transaction handle */ { #ifdef WITH_WSREP - THD* thd = (THD*)trx->mysql_thd; const char* tmp = 0; - if (thd && wsrep_on(thd)) { + if (trx->is_wsrep()) { #ifdef WSREP_PROC_INFO char info[64]; info[sizeof(info) - 1] = '\0'; snprintf(info, sizeof(info) - 1, "innobase_commit_low():trx_commit_for_mysql(%lld)", - (long long) wsrep_thd_trx_seqno(thd)); - tmp = thd_proc_info(thd, info); - + (long long) wsrep_thd_trx_seqno(trx->mysql_thd)); + tmp = thd_proc_info(trx->mysql_thd, info); #else - tmp = thd_proc_info(thd, "innobase_commit_low()"); + tmp = thd_proc_info(trx->mysql_thd, "innobase_commit_low()"); #endif /* WSREP_PROC_INFO */ } #endif /* WITH_WSREP */ @@ -4206,7 +4205,7 @@ innobase_commit_low( trx_commit_for_mysql(trx); } #ifdef WITH_WSREP - if (thd && wsrep_on(thd)) { thd_proc_info(thd, tmp); } + if (trx->is_wsrep()) { thd_proc_info(trx->mysql_thd, tmp); } #endif /* WITH_WSREP */ } @@ -8151,19 +8150,19 @@ ha_innobase::write_row( sql_command = thd_sql_command(user_thd); - if ((sql_command == SQLCOM_ALTER_TABLE - || sql_command == SQLCOM_OPTIMIZE - || sql_command == SQLCOM_CREATE_INDEX + if (num_write_row >= 10000 + && (sql_command == SQLCOM_ALTER_TABLE + || sql_command == SQLCOM_OPTIMIZE + || sql_command == SQLCOM_CREATE_INDEX #ifdef WITH_WSREP - || (wsrep_on(user_thd) && wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && - !thd_test_options( - user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + || (sql_command == SQLCOM_LOAD && + trx->is_wsrep() && wsrep_load_data_splitting && + !thd_test_options( + user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) #endif /* WITH_WSREP */ - || sql_command == SQLCOM_DROP_INDEX) - && num_write_row >= 10000) { + || sql_command == SQLCOM_DROP_INDEX)) { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && sql_command == SQLCOM_LOAD) { + if (sql_command == SQLCOM_LOAD && trx->is_wsrep()) { WSREP_DEBUG("forced trx split for LOAD: %s", wsrep_thd_query(user_thd)); } @@ -8202,9 +8201,8 @@ ha_innobase::write_row( ; } else if (src_table == prebuilt->table) { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && - wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && + if (sql_command == SQLCOM_LOAD && trx->is_wsrep() && + wsrep_load_data_splitting && !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { @@ -8234,9 +8232,8 @@ ha_innobase::write_row( prebuilt->sql_stat_start = TRUE; } else { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && - wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && + if (sql_command == SQLCOM_LOAD && trx->is_wsrep() && + wsrep_load_data_splitting && !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { @@ -8377,21 +8374,19 @@ ha_innobase::write_row( prebuilt->autoinc_offset, prebuilt->autoinc_increment); - if (wsrep_on(current_thd) && + if (trx->is_wsrep() && auto_inc_inserted && wsrep_drupal_282555_workaround && - wsrep_thd_retry_counter(current_thd) == 0 && - !thd_test_options(current_thd, + wsrep_thd_retry_counter(user_thd) == 0 && + !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { WSREP_DEBUG( "retrying insert: %s", - (*wsrep_thd_query(current_thd)) ? - wsrep_thd_query(current_thd) : - (char *)"void"); + wsrep_thd_query(user_thd)); error= DB_SUCCESS; wsrep_thd_set_conflict_state( - current_thd, MUST_ABORT); + user_thd, MUST_ABORT); innobase_srv_conc_exit_innodb(prebuilt->trx); /* jump straight to func exit over * later wsrep hooks */ @@ -8429,7 +8424,7 @@ ha_innobase::write_row( prebuilt autoinc values don't get properly assigned. Fetch values from server side. */ - if (wsrep_on(user_thd) && + if (trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == REPL_RECV) { wsrep_thd_auto_increment_variables( @@ -8478,8 +8473,7 @@ ha_innobase::write_row( user_thd); #ifdef WITH_WSREP - if (!error_result - && wsrep_on(user_thd) + if (!error_result && trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && !wsrep_consistency_check(user_thd) && !wsrep_thd_ignore_table(user_thd)) { @@ -8487,10 +8481,9 @@ ha_innobase::write_row( NULL)) { DBUG_PRINT("wsrep", ("row key failed")); error_result = HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + goto func_exit; } } -wsrep_error: #endif /* WITH_WSREP */ if (error_result == HA_FTS_INVALID_DOCID) { @@ -8973,7 +8966,7 @@ ha_innobase::update_row( prebuilt autoinc values don't get properly assigned. Fetch values from server side. */ - if (wsrep_on(user_thd) && + if (trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == REPL_RECV) { wsrep_thd_auto_increment_variables( @@ -9018,9 +9011,8 @@ ha_innobase::update_row( innobase_active_small(); #ifdef WITH_WSREP - if (error == DB_SUCCESS && + if (error == DB_SUCCESS && trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && - wsrep_on(user_thd) && !wsrep_thd_ignore_table(user_thd)) { DBUG_PRINT("wsrep", ("update row key")); @@ -9029,14 +9021,11 @@ ha_innobase::update_row( new_row)) { WSREP_DEBUG("WSREP: UPDATE_ROW_KEY FAILED"); DBUG_PRINT("wsrep", ("row key failed")); - err = HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } } -wsrep_error: #endif /* WITH_WSREP */ - DBUG_RETURN(err); } @@ -9085,19 +9074,16 @@ ha_innobase::delete_row( innobase_active_small(); #ifdef WITH_WSREP - if (error == DB_SUCCESS && + if (error == DB_SUCCESS && trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && - wsrep_on(user_thd) && !wsrep_thd_ignore_table(user_thd)) { if (wsrep_append_keys(user_thd, WSREP_KEY_EXCLUSIVE, record, NULL)) { DBUG_PRINT("wsrep", ("delete fail")); - error = (dberr_t) HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } } -wsrep_error: #endif /* WITH_WSREP */ DBUG_RETURN(convert_error_code_to_mysql( error, prebuilt->table->flags, user_thd)); @@ -10370,8 +10356,7 @@ wsrep_append_foreign_key( int cache_key_len; bool const copy = true; - if (!wsrep_on(trx->mysql_thd) || - wsrep_thd_exec_mode(thd) != LOCAL_STATE) + if (!trx->is_wsrep() || wsrep_thd_exec_mode(thd) != LOCAL_STATE) return DB_SUCCESS; if (!thd || !foreign || @@ -14921,12 +14906,11 @@ ha_innobase::external_lock( THD* thd, /*!< in: handle to the user thread */ int lock_type) /*!< in: lock type */ { - trx_t* trx; - DBUG_ENTER("ha_innobase::external_lock"); DBUG_PRINT("enter",("lock_type: %d", lock_type)); update_thd(thd); + trx_t* trx = prebuilt->trx; /* Statement based binlogging does not work in isolation level READ UNCOMMITTED and READ COMMITTED since the necessary @@ -14940,22 +14924,19 @@ ha_innobase::external_lock( && thd_binlog_format(thd) == BINLOG_FORMAT_STMT && thd_binlog_filter_ok(thd) && thd_sqlcom_can_generate_row_events(thd)) { - bool skip = 0; + bool skip = false; +#ifdef WITH_WSREP + skip = trx->is_wsrep() + && wsrep_thd_exec_mode(thd) != LOCAL_STATE; +#endif /* WITH_WSREP */ /* used by test case */ DBUG_EXECUTE_IF("no_innodb_binlog_errors", skip = true;); if (!skip) { -#ifdef WITH_WSREP - if (!wsrep_on(thd) || wsrep_thd_exec_mode(thd) == LOCAL_STATE) - { -#endif /* WITH_WSREP */ my_error(ER_BINLOG_STMT_MODE_AND_ROW_ENGINE, MYF(0), " InnoDB is limited to row-logging when " "transaction isolation level is " "READ COMMITTED or READ UNCOMMITTED."); DBUG_RETURN(HA_ERR_LOGGING_IMPOSSIBLE); -#ifdef WITH_WSREP - } -#endif /* WITH_WSREP */ } } @@ -14986,8 +14967,6 @@ ha_innobase::external_lock( } - trx = prebuilt->trx; - prebuilt->sql_stat_start = TRUE; prebuilt->hint_need_to_fetch_extra_cols = 0; diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h index 2628cdfc461c6..d1ad4c403d45f 100644 --- a/storage/innobase/include/lock0lock.h +++ b/storage/innobase/include/lock0lock.h @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1008,10 +1009,6 @@ std::string lock_get_info( const lock_t*); -/*******************************************************************//** -@return whether wsrep_on is true on trx->mysql_thd*/ -#define wsrep_on_trx(trx) ((trx)->mysql_thd && wsrep_on((trx)->mysql_thd)) - #endif /* WITH_WSREP */ #ifndef UNIV_NONINL #include "lock0lock.ic" diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index 0291140a982fb..9aa3daea4e1ef 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2015, 2019, MariaDB Corporation. +Copyright (c) 2015, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -769,15 +769,21 @@ struct trx_t{ ro_trx_list the first time they try to acquire a lock ie. by default we treat all read-only transactions as non-locking. */ trx_state_t state; - trx_lock_t lock; /*!< Information about the transaction locks and state. Protected by trx->mutex or lock_sys->mutex or both */ - ulint is_recovered; /*!< 0=normal transaction, - 1=recovered, must be rolled back, + bool is_recovered; /*!< false=normal transaction, + true=recovered, must be rolled back, protected by trx_sys->mutex when trx->in_rw_trx_list holds */ +#ifdef WITH_WSREP + /** whether wsrep_on(mysql_thd) held at the start of transaction */ + bool wsrep; + bool is_wsrep() const { return UNIV_UNLIKELY(wsrep); } +#else /* WITH_WSREP */ + bool is_wsrep() const { return false; } +#endif /* WITH_WSREP */ /* These fields are not protected by any mutex. */ const char* op_info; /*!< English text describing the diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 0fade62e7aa02..0c4e40067d1fd 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2014, 2019, MariaDB Corporation. +Copyright (c) 2014, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1759,7 +1759,7 @@ wsrep_kill_victim( ut_ad(trx_mutex_own(lock->trx)); /* quit for native mysql */ - if (!wsrep_on(trx->mysql_thd)) return; + if (!trx->is_wsrep()) return; my_bool bf_this = wsrep_thd_is_BF(trx->mysql_thd, FALSE); my_bool bf_other = wsrep_thd_is_BF(lock->trx->mysql_thd, TRUE); @@ -1845,7 +1845,7 @@ lock_rec_other_has_conflicting( #ifdef WITH_WSREP if (lock_rec_has_to_wait(TRUE, trx, mode, lock, is_supremum)) { - if (wsrep_on_trx(trx)) { + if (trx->is_wsrep()) { trx_mutex_enter(lock->trx); /* Below function will roll back either trx or lock->trx depending on priority of the @@ -2179,8 +2179,7 @@ lock_rec_create( ut_ad(index->table->n_ref_count > 0 || !index->table->can_be_evicted); #ifdef WITH_WSREP - if (c_lock && - wsrep_on_trx(trx) && + if (c_lock && trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { lock_t *hash = (lock_t *)c_lock->hash; lock_t *prev = NULL; @@ -4973,7 +4972,7 @@ lock_table_create( UT_LIST_ADD_LAST(trx_locks, trx->lock.trx_locks, lock); #ifdef WITH_WSREP - if (c_lock && wsrep_on_trx(trx)) { + if (c_lock && trx->is_wsrep()) { if (wsrep_thd_is_wsrep(trx->mysql_thd) && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { UT_LIST_INSERT_AFTER( @@ -5212,7 +5211,7 @@ lock_table_enqueue_waiting( /* Enqueue the lock request that will wait to be granted */ #ifdef WITH_WSREP - if (trx->lock.was_chosen_as_deadlock_victim && wsrep_on_trx(trx)) { + if (trx->lock.was_chosen_as_deadlock_victim && trx->is_wsrep()) { return(DB_DEADLOCK); } diff --git a/storage/innobase/lock/lock0wait.cc b/storage/innobase/lock/lock0wait.cc index ca697ab8be5f7..8f39c555c6af2 100644 --- a/storage/innobase/lock/lock0wait.cc +++ b/storage/innobase/lock/lock0wait.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2014, 2019, MariaDB Corporation. +Copyright (c) 2014, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -200,8 +200,7 @@ wsrep_is_BF_lock_timeout( const trx_t* trx, bool locked = true) { - if (wsrep_on_trx(trx) - && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { fprintf(stderr, "WSREP: BF lock wait long for trx " TRX_ID_FMT "\n", trx->id); srv_print_innodb_monitor = TRUE; srv_print_innodb_lock_monitor = TRUE; @@ -390,7 +389,7 @@ lock_wait_suspend_thread( if (lock_wait_timeout < 100000000 && wait_time > (double) lock_wait_timeout) { #ifdef WITH_WSREP - if (!wsrep_on_trx(trx) || + if (!trx->is_wsrep() || (!wsrep_is_BF_lock_timeout(trx) && trx->error_state != DB_DEADLOCK)) { #endif /* WITH_WSREP */ diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 4a4c5112f883e..ecbfd03ec932c 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1639,7 +1639,7 @@ row_ins_check_foreign_constraint( if (check_ref) { err = DB_SUCCESS; #ifdef WITH_WSREP - if (!wsrep_on(trx->mysql_thd)) { + if (!trx->is_wsrep()) { goto end_scan; } enum wsrep_key_type key_type; diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 7df9629294aff..999e8d882ecf7 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -1125,7 +1125,7 @@ row_update_statistics_if_needed( && dict_stats_auto_recalc_is_enabled(table)) { #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { WSREP_DEBUG("Avoiding background statistics" " calculation for table %s", diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index 435eb065d7abb..6bb97e917bbbb 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, 2019, MariaDB Corporation. +Copyright (c) 2018, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1811,7 +1811,7 @@ row_upd_store_row( inline bool wsrep_must_process_fk(const upd_node_t* node, const trx_t* trx) { - if (!wsrep_on_trx(trx)) { + if (!trx->is_wsrep()) { return false; } return que_node_get_type(node->common.parent) != QUE_NODE_UPDATE diff --git a/storage/innobase/srv/srv0conc.cc b/storage/innobase/srv/srv0conc.cc index 8a1ece92ba4a3..bf57c308acf97 100644 --- a/storage/innobase/srv/srv0conc.cc +++ b/storage/innobase/srv/srv0conc.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2011, 2012, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, MariaDB Corporation. All Rights Reserved. +Copyright (c) 2017, 2020, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -213,8 +213,7 @@ srv_conc_enter_innodb_with_atomics( for (;;) { ulint sleep_in_us; #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_trx_is_aborting(trx->mysql_thd)) { + if (trx->is_wsrep() && wsrep_trx_is_aborting(trx->mysql_thd)) { if (wsrep_debug) fprintf(stderr, "srv_conc_enter due to MUST_ABORT"); @@ -421,8 +420,7 @@ srv_conc_enter_innodb_without_atomics( return; } #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_thd_is_brute_force(trx->mysql_thd)) { + if (trx->is_wsrep() && wsrep_thd_is_brute_force(trx->mysql_thd)) { srv_conc_force_enter_innodb(trx); return; } @@ -504,8 +502,7 @@ srv_conc_enter_innodb_without_atomics( srv_conc.n_waiting++; #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_trx_is_aborting(trx->mysql_thd)) { + if (trx->is_wsrep() && wsrep_trx_is_aborting(trx->mysql_thd)) { os_fast_mutex_unlock(&srv_conc_mutex); if (wsrep_debug) fprintf(stderr, "srv_conc_enter due to MUST_ABORT"); diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index 76d501aad5309..53c5d1ca82d0e 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2015, 2019, MariaDB Corporation. +Copyright (c) 2015, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1331,11 +1331,7 @@ trx_commit_in_memory( ut_ad(!trx->in_ro_trx_list); ut_ad(!trx->in_rw_trx_list); -#ifdef WITH_WSREP - if (trx->mysql_thd && wsrep_on(trx->mysql_thd)) { - trx->lock.was_chosen_as_deadlock_victim = FALSE; - } -#endif + trx->lock.was_chosen_as_deadlock_victim = FALSE; trx->dict_operation = TRX_DICT_OP_NONE; trx->error_state = DB_SUCCESS; diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 2aafb1a44eee4..2ec16280eb645 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -5,7 +5,7 @@ Copyright (c) 2013, 2018, MariaDB Corporation. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. Copyright (c) 2012, Facebook Inc. -Copyright (c) 2013, 2019, MariaDB Corporation. +Copyright (c) 2013, 2020, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -1934,8 +1934,7 @@ innobase_srv_conc_enter_innodb( trx_t* trx) /*!< in: transaction handle */ { #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; #endif /* WITH_WSREP */ if (srv_thread_concurrency) { if (trx->n_tickets_to_enter_innodb > 0) { @@ -1973,8 +1972,7 @@ innobase_srv_conc_exit_innodb( ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch)); #endif /* UNIV_SYNC_DEBUG */ #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; #endif /* WITH_WSREP */ /* This is to avoid making an unnecessary function call. */ @@ -2950,6 +2948,9 @@ innobase_trx_init( trx->check_unique_secondary = !thd_test_options( thd, OPTION_RELAXED_UNIQUE_CHECKS); +#ifdef WITH_WSREP + trx->wsrep = wsrep_on(thd); +#endif /* Transaction on start caches the fake_changes state and uses it for complete transaction lifetime. @@ -4676,19 +4677,17 @@ innobase_commit_low( trx_t* trx) /*!< in: transaction handle */ { #ifdef WITH_WSREP - THD* thd = (THD*)trx->mysql_thd; const char* tmp = 0; - if (thd && wsrep_on(thd)) { + if (trx->is_wsrep()) { #ifdef WSREP_PROC_INFO char info[64]; info[sizeof(info) - 1] = '\0'; snprintf(info, sizeof(info) - 1, "innobase_commit_low():trx_commit_for_mysql(%lld)", - (long long) wsrep_thd_trx_seqno(thd)); - tmp = thd_proc_info(thd, info); - + (long long) wsrep_thd_trx_seqno(trx->mysql_thd)); + tmp = thd_proc_info(trx->mysql_thd, info); #else - tmp = thd_proc_info(thd, "innobase_commit_low()"); + tmp = thd_proc_info(trx->mysql_thd, "innobase_commit_low()"); #endif /* WSREP_PROC_INFO */ } #endif /* WITH_WSREP */ @@ -4697,7 +4696,7 @@ innobase_commit_low( trx_commit_for_mysql(trx); } #ifdef WITH_WSREP - if (thd && wsrep_on(thd)) { thd_proc_info(thd, tmp); } + if (trx->is_wsrep()) { thd_proc_info(trx->mysql_thd, tmp); } #endif /* WITH_WSREP */ } @@ -8713,19 +8712,19 @@ ha_innobase::write_row( sql_command = thd_sql_command(user_thd); - if ((sql_command == SQLCOM_ALTER_TABLE - || sql_command == SQLCOM_OPTIMIZE - || sql_command == SQLCOM_CREATE_INDEX + if (num_write_row >= 10000 + && (sql_command == SQLCOM_ALTER_TABLE + || sql_command == SQLCOM_OPTIMIZE + || sql_command == SQLCOM_CREATE_INDEX #ifdef WITH_WSREP - || (wsrep_on(user_thd) && wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && - !thd_test_options( - user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + || (sql_command == SQLCOM_LOAD && + trx->is_wsrep() && wsrep_load_data_splitting && + !thd_test_options( + user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) #endif /* WITH_WSREP */ - || sql_command == SQLCOM_DROP_INDEX) - && num_write_row >= 10000) { + || sql_command == SQLCOM_DROP_INDEX)) { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && sql_command == SQLCOM_LOAD) { + if (sql_command == SQLCOM_LOAD && trx->is_wsrep()) { WSREP_DEBUG("forced trx split for LOAD: %s", wsrep_thd_query(user_thd)); } @@ -8764,9 +8763,8 @@ ha_innobase::write_row( ; } else if (src_table == prebuilt->table) { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && - wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && + if (sql_command == SQLCOM_LOAD && trx->is_wsrep() && + wsrep_load_data_splitting && !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { @@ -8796,9 +8794,8 @@ ha_innobase::write_row( prebuilt->sql_stat_start = TRUE; } else { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && - wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && + if (sql_command == SQLCOM_LOAD && trx->is_wsrep() && + wsrep_load_data_splitting && !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { @@ -8943,21 +8940,19 @@ ha_innobase::write_row( prebuilt->autoinc_offset, prebuilt->autoinc_increment); - if (wsrep_on(current_thd) && + if (trx->is_wsrep() && auto_inc_inserted && wsrep_drupal_282555_workaround && - wsrep_thd_retry_counter(current_thd) == 0 && - !thd_test_options(current_thd, + wsrep_thd_retry_counter(user_thd) == 0 && + !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { WSREP_DEBUG( "retrying insert: %s", - (*wsrep_thd_query(current_thd)) ? - wsrep_thd_query(current_thd) : - (char *)"void"); + wsrep_thd_query(user_thd)); error= DB_SUCCESS; wsrep_thd_set_conflict_state( - current_thd, MUST_ABORT); + user_thd, MUST_ABORT); innobase_srv_conc_exit_innodb(prebuilt->trx); /* jump straight to func exit over * later wsrep hooks */ @@ -8995,7 +8990,7 @@ ha_innobase::write_row( prebuilt autoinc values don't get properly assigned. Fetch values from server side. */ - if (wsrep_on(user_thd) && + if (trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == REPL_RECV) { wsrep_thd_auto_increment_variables( @@ -9044,18 +9039,16 @@ ha_innobase::write_row( user_thd); #ifdef WITH_WSREP - if (!error_result - && wsrep_on(user_thd) - && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE + if (!error_result && trx->is_wsrep() + && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && !wsrep_consistency_check(user_thd) && !wsrep_thd_ignore_table(user_thd)) { if (wsrep_append_keys(user_thd, WSREP_KEY_EXCLUSIVE, record, NULL)) { DBUG_PRINT("wsrep", ("row key failed")); error_result = HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + goto func_exit; } } -wsrep_error: #endif /* WITH_WSREP */ if (error_result == HA_FTS_INVALID_DOCID) { @@ -9536,7 +9529,7 @@ ha_innobase::update_row( prebuilt autoinc values don't get properly assigned. Fetch values from server side. */ - if (wsrep_on(user_thd) && + if (trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == REPL_RECV) { wsrep_thd_auto_increment_variables( @@ -9581,9 +9574,8 @@ ha_innobase::update_row( innobase_active_small(); #ifdef WITH_WSREP - if (error == DB_SUCCESS && + if (error == DB_SUCCESS && trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && - wsrep_on(user_thd) && !wsrep_thd_ignore_table(user_thd)) { DBUG_PRINT("wsrep", ("update row key")); @@ -9592,11 +9584,9 @@ ha_innobase::update_row( new_row)) { WSREP_DEBUG("WSREP: UPDATE_ROW_KEY FAILED"); DBUG_PRINT("wsrep", ("row key failed")); - err = HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } } -wsrep_error: #endif /* WITH_WSREP */ DBUG_RETURN(err); @@ -9643,25 +9633,20 @@ ha_innobase::delete_row( /* Tell the InnoDB server that there might be work for utility threads: */ - innobase_active_small(); #ifdef WITH_WSREP - if (error == DB_SUCCESS && + if (error == DB_SUCCESS && trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && - wsrep_on(user_thd) && !wsrep_thd_ignore_table(user_thd)) { if (wsrep_append_keys(user_thd, WSREP_KEY_EXCLUSIVE, record, - NULL)) { + NULL)) { DBUG_PRINT("wsrep", ("delete fail")); - error = (dberr_t) HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } } -wsrep_error: #endif /* WITH_WSREP */ - DBUG_RETURN(convert_error_code_to_mysql( error, prebuilt->table->flags, user_thd)); } @@ -10917,8 +10902,7 @@ wsrep_append_foreign_key( int cache_key_len; bool const copy = true; - if (!wsrep_on(trx->mysql_thd) || - wsrep_thd_exec_mode(thd) != LOCAL_STATE) + if (!trx->is_wsrep() || wsrep_thd_exec_mode(thd) != LOCAL_STATE) return DB_SUCCESS; if (!thd || !foreign || @@ -15541,12 +15525,11 @@ ha_innobase::external_lock( THD* thd, /*!< in: handle to the user thread */ int lock_type) /*!< in: lock type */ { - trx_t* trx; - DBUG_ENTER("ha_innobase::external_lock"); DBUG_PRINT("enter",("lock_type: %d", lock_type)); update_thd(thd); + trx_t* trx = prebuilt->trx; /* Statement based binlogging does not work in isolation level READ UNCOMMITTED and READ COMMITTED since the necessary @@ -15560,22 +15543,19 @@ ha_innobase::external_lock( && thd_binlog_format(thd) == BINLOG_FORMAT_STMT && thd_binlog_filter_ok(thd) && thd_sqlcom_can_generate_row_events(thd)) { - bool skip = 0; + bool skip = false; +#ifdef WITH_WSREP + skip = trx->is_wsrep() + && wsrep_thd_exec_mode(thd) != LOCAL_STATE; +#endif /* WITH_WSREP */ /* used by test case */ DBUG_EXECUTE_IF("no_innodb_binlog_errors", skip = true;); if (!skip) { -#ifdef WITH_WSREP - if (!wsrep_on(thd) || wsrep_thd_exec_mode(thd) == LOCAL_STATE) - { -#endif /* WITH_WSREP */ - my_error(ER_BINLOG_STMT_MODE_AND_ROW_ENGINE, MYF(0), - " InnoDB is limited to row-logging when " - "transaction isolation level is " - "READ COMMITTED or READ UNCOMMITTED."); - DBUG_RETURN(HA_ERR_LOGGING_IMPOSSIBLE); -#ifdef WITH_WSREP - } -#endif /* WITH_WSREP */ + my_error(ER_BINLOG_STMT_MODE_AND_ROW_ENGINE, MYF(0), + " InnoDB is limited to row-logging when " + "transaction isolation level is " + "READ COMMITTED or READ UNCOMMITTED."); + DBUG_RETURN(HA_ERR_LOGGING_IMPOSSIBLE); } } @@ -15606,8 +15586,6 @@ ha_innobase::external_lock( } - trx = prebuilt->trx; - prebuilt->sql_stat_start = TRUE; prebuilt->hint_need_to_fetch_extra_cols = 0; diff --git a/storage/xtradb/include/lock0lock.h b/storage/xtradb/include/lock0lock.h index 878a42ea81bb2..a6b6e08b68bf1 100644 --- a/storage/xtradb/include/lock0lock.h +++ b/storage/xtradb/include/lock0lock.h @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1013,8 +1014,6 @@ std::string lock_get_info( const lock_t*); -#define wsrep_on_trx(trx) ((trx)->mysql_thd && wsrep_on((trx)->mysql_thd)) - #ifndef UNIV_NONINL #include "lock0lock.ic" #endif diff --git a/storage/xtradb/include/trx0trx.h b/storage/xtradb/include/trx0trx.h index 448b242912659..5fed8d68e50da 100644 --- a/storage/xtradb/include/trx0trx.h +++ b/storage/xtradb/include/trx0trx.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2015, 2019, MariaDB Corporation. +Copyright (c) 2015, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -818,15 +818,21 @@ struct trx_t{ ro_trx_list the first time they try to acquire a lock ie. by default we treat all read-only transactions as non-locking. */ trx_state_t state; - trx_lock_t lock; /*!< Information about the transaction locks and state. Protected by trx->mutex or lock_sys->mutex or both */ - ulint is_recovered; /*!< 0=normal transaction, - 1=recovered, must be rolled back, + bool is_recovered; /*!< false=normal transaction, + true=recovered, must be rolled back, protected by trx_sys->mutex when trx->in_rw_trx_list holds */ +#ifdef WITH_WSREP + /** whether wsrep_on(mysql_thd) held at the start of transaction */ + bool wsrep; + bool is_wsrep() const { return UNIV_UNLIKELY(wsrep); } +#else /* WITH_WSREP */ + bool is_wsrep() const { return false; } +#endif /* WITH_WSREP */ /* These fields are not protected by any mutex. */ const char* op_info; /*!< English text describing the diff --git a/storage/xtradb/lock/lock0lock.cc b/storage/xtradb/lock/lock0lock.cc index c110c83cbe704..4d40111ac2090 100644 --- a/storage/xtradb/lock/lock0lock.cc +++ b/storage/xtradb/lock/lock0lock.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2014, 2019, MariaDB Corporation. +Copyright (c) 2014, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1770,7 +1770,7 @@ wsrep_kill_victim( ut_ad(trx_mutex_own(lock->trx)); /* quit for native mysql */ - if (!wsrep_on(trx->mysql_thd)) return; + if (!trx->is_wsrep()) return; my_bool bf_this = wsrep_thd_is_BF(trx->mysql_thd, FALSE); my_bool bf_other = wsrep_thd_is_BF(lock->trx->mysql_thd, TRUE); @@ -1856,7 +1856,7 @@ lock_rec_other_has_conflicting( #ifdef WITH_WSREP if (lock_rec_has_to_wait(TRUE, trx, mode, lock, is_supremum)) { - if (wsrep_on_trx(trx)) { + if (trx->is_wsrep()) { trx_mutex_enter(lock->trx); /* Below function will roll back either trx or lock->trx depending on priority of the @@ -2318,8 +2318,7 @@ lock_rec_create( ut_ad(index->table->n_ref_count > 0 || !index->table->can_be_evicted); #ifdef WITH_WSREP - if (c_lock && - wsrep_on_trx(trx) && + if (c_lock && trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { lock_t *hash = (lock_t *)c_lock->hash; lock_t *prev = NULL; @@ -5009,7 +5008,7 @@ lock_table_create( UT_LIST_ADD_LAST(trx_locks, trx->lock.trx_locks, lock); #ifdef WITH_WSREP - if (c_lock && wsrep_on_trx(trx)) { + if (c_lock && trx->is_wsrep()) { if (wsrep_thd_is_wsrep(trx->mysql_thd) && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { UT_LIST_INSERT_AFTER( @@ -5248,7 +5247,7 @@ lock_table_enqueue_waiting( /* Enqueue the lock request that will wait to be granted */ #ifdef WITH_WSREP - if (trx->lock.was_chosen_as_deadlock_victim && wsrep_on_trx(trx)) { + if (trx->lock.was_chosen_as_deadlock_victim && trx->is_wsrep()) { return(DB_DEADLOCK); } diff --git a/storage/xtradb/lock/lock0wait.cc b/storage/xtradb/lock/lock0wait.cc index fe43ef3cc73d0..70ade1191d750 100644 --- a/storage/xtradb/lock/lock0wait.cc +++ b/storage/xtradb/lock/lock0wait.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2014, 2019, MariaDB Corporation. +Copyright (c) 2014, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -255,8 +255,7 @@ wsrep_is_BF_lock_timeout( const trx_t* trx, bool locked = true) { - if (wsrep_on_trx(trx) - && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) { fprintf(stderr, "WSREP: BF lock wait long for trx " TRX_ID_FMT "\n", trx->id); srv_print_innodb_monitor = TRUE; srv_print_innodb_lock_monitor = TRUE; @@ -447,7 +446,7 @@ lock_wait_suspend_thread( if (lock_wait_timeout < 100000000 && wait_time > (double) lock_wait_timeout) { #ifdef WITH_WSREP - if (!wsrep_on_trx(trx) || + if (!trx->is_wsrep() || (!wsrep_is_BF_lock_timeout(trx) && trx->error_state != DB_DEADLOCK)) { #endif /* WITH_WSREP */ diff --git a/storage/xtradb/row/row0ins.cc b/storage/xtradb/row/row0ins.cc index 50da7fb40adc9..f7371d6b83e9d 100644 --- a/storage/xtradb/row/row0ins.cc +++ b/storage/xtradb/row/row0ins.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2018, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1651,7 +1651,7 @@ row_ins_check_foreign_constraint( if (check_ref) { err = DB_SUCCESS; #ifdef WITH_WSREP - if (!wsrep_on(trx->mysql_thd)) { + if (!trx->is_wsrep()) { goto end_scan; } enum wsrep_key_type key_type; diff --git a/storage/xtradb/row/row0upd.cc b/storage/xtradb/row/row0upd.cc index 6324c1d71a1f5..a5e5988113d43 100644 --- a/storage/xtradb/row/row0upd.cc +++ b/storage/xtradb/row/row0upd.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, 2019, MariaDB Corporation. +Copyright (c) 2018, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1814,7 +1814,7 @@ row_upd_store_row( inline bool wsrep_must_process_fk(const upd_node_t* node, const trx_t* trx) { - if (!wsrep_on_trx(trx)) { + if (!trx->is_wsrep()) { return false; } return que_node_get_type(node->common.parent) != QUE_NODE_UPDATE diff --git a/storage/xtradb/srv/srv0conc.cc b/storage/xtradb/srv/srv0conc.cc index 3433d968eb288..d2ededc3894f6 100644 --- a/storage/xtradb/srv/srv0conc.cc +++ b/storage/xtradb/srv/srv0conc.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2011, 2012, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, MariaDB Corporation. All Rights Reserved. +Copyright (c) 2017, 2020, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -218,8 +218,7 @@ srv_conc_enter_innodb_with_atomics( for (;;) { ulint sleep_in_us; #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_trx_is_aborting(trx->mysql_thd)) { + if (trx->is_wsrep() && wsrep_trx_is_aborting(trx->mysql_thd)) { if (wsrep_debug) fprintf(stderr, "srv_conc_enter due to MUST_ABORT"); @@ -430,8 +429,7 @@ srv_conc_enter_innodb_without_atomics( return; } #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_thd_is_brute_force(trx->mysql_thd)) { + if (trx->is_wsrep() && wsrep_thd_is_brute_force(trx->mysql_thd)) { srv_conc_force_enter_innodb(trx); return; } @@ -514,8 +512,7 @@ srv_conc_enter_innodb_without_atomics( srv_conc.n_waiting++; #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_trx_is_aborting(trx->mysql_thd)) { + if (trx->is_wsrep() && wsrep_trx_is_aborting(trx->mysql_thd)) { os_fast_mutex_unlock(&srv_conc_mutex); if (wsrep_debug) fprintf(stderr, "srv_conc_enter due to MUST_ABORT"); diff --git a/storage/xtradb/trx/trx0roll.cc b/storage/xtradb/trx/trx0roll.cc index 97f08d1fa0cd0..7624d92a83180 100644 --- a/storage/xtradb/trx/trx0roll.cc +++ b/storage/xtradb/trx/trx0roll.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2016, 2019, MariaDB Corporation. +Copyright (c) 2016, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -379,8 +379,7 @@ trx_rollback_to_savepoint_for_mysql_low( trx->op_info = ""; #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - trx->lock.was_chosen_as_deadlock_victim) { + if (trx->is_wsrep()) { trx->lock.was_chosen_as_deadlock_victim = FALSE; } #endif @@ -1083,12 +1082,6 @@ trx_roll_try_truncate( if (trx->update_undo) { trx_undo_truncate_end(trx, trx->update_undo, limit); } - -#ifdef WITH_WSREP_OUT - if (wsrep_on(trx->mysql_thd)) { - trx->lock.was_chosen_as_deadlock_victim = FALSE; - } -#endif /* WITH_WSREP */ } /***********************************************************************//** diff --git a/storage/xtradb/trx/trx0trx.cc b/storage/xtradb/trx/trx0trx.cc index a65132cf57270..bfbd15d62a2a7 100644 --- a/storage/xtradb/trx/trx0trx.cc +++ b/storage/xtradb/trx/trx0trx.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2015, 2019, MariaDB Corporation. +Copyright (c) 2015, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1555,11 +1555,7 @@ trx_commit_in_memory( ut_ad(!trx->in_ro_trx_list); ut_ad(!trx->in_rw_trx_list); -#ifdef WITH_WSREP - if (trx->mysql_thd && wsrep_on(trx->mysql_thd)) { - trx->lock.was_chosen_as_deadlock_victim = FALSE; - } -#endif + trx->lock.was_chosen_as_deadlock_victim = FALSE; trx->dict_operation = TRX_DICT_OP_NONE; trx->error_state = DB_SUCCESS;