Skip to content

Commit

Permalink
MDEV-22203: WSREP_ON is unnecessarily expensive to evaluate
Browse files Browse the repository at this point in the history
This is a backport of the applicable part of
commit 93475af and
commit 2c39f69
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 c863159
when reverting WSREP_ON to its previous definition.

We replace some use of WSREP_ON with WSREP(thd), like it was done
in 93475af. 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.
  • Loading branch information
dr-m committed Apr 27, 2020
1 parent 758fbec commit 6be05ce
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 37 deletions.
1 change: 1 addition & 0 deletions mysql-test/suite/galera/t/MW-86-wait1.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions sql/item_func.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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));
Expand Down
9 changes: 5 additions & 4 deletions sql/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()))
{
Expand All @@ -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));
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 5 additions & 3 deletions sql/slave.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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())
{
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 &&
Expand Down
8 changes: 4 additions & 4 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions sql/wsrep_mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6be05ce

Please sign in to comment.