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.
This commit is contained in:
Marko Mäkelä 2020-04-27 09:40:51 +03:00
parent 758fbec6e3
commit 6be05ceb05
10 changed files with 38 additions and 37 deletions

View File

@ -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

View File

@ -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
if (WSREP_ON)
{
THD *thd= current_thd;
if (WSREP(thd))
if (thd->variables.wsrep_on)
{
if (thd->wsrep_exec_mode==REPL_RECV)
tmp= thd->wsrep_rand;
else
tmp= thd->wsrep_rand= (uint32) arg->val_int();
thd->wsrep_rand= tmp;
}
}
else
#endif /* WITH_WSREP */
tmp= (uint32) arg->val_int();
my_rnd_init(rand, (uint32) (tmp*0x10001L+55555555L),
(uint32) (tmp*0x10000001L));

View File

@ -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_to_isolation);
DBUG_RETURN(0);
}
#endif /* WITH_WSREP */
//todo: fix the macro def and restore safe_mutex_assert_owner(&LOCK_log);
*check_purge= false;

View File

@ -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)

View File

@ -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)
{

View File

@ -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,9 +4998,11 @@ 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 @@ err_during_init:
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())
{

View File

@ -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 @@ restart:
}
}
if (WSREP_ON &&
if (WSREP(thd) &&
wsrep_replicate_myisam &&
(*start) &&
(*start)->table &&

View File

@ -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);
@ -1580,7 +1580,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
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);

View File

@ -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

View File

@ -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)