MDEV-22203: WSREP_ON is unnecessarily expensive WITH_WSREP=OFF

If the server is compiled WITH_WSREP=OFF, we should avoid evaluating
conditions on a global variable that is constant.

WSREP_ON_: Renamed from WSREP_ON. Defined only WITH_WSREP=ON.

WSREP_ON: Defined as unlikely(WSREP_ON_).

wsrep_on(): Defined as WSREP_ON && wsrep_service->wsrep_on_func().

The reason why we have wsrep_on() at all is that the macro WSREP(thd)
depends on the definition of THD, and that is intentionally an opaque
data type for InnoDB. So, we cannot avoid invoking wsrep_on(), but
we can evaluate the less expensive condition WSREP_ON before calling
the function.
This commit is contained in:
Marko Mäkelä 2020-04-24 15:25:39 +03:00
parent 93475aff8d
commit 2c39f69d34
7 changed files with 22 additions and 23 deletions

View File

@ -13,7 +13,7 @@ enum Wsrep_service_key_type
#else #else
/* Copyright (c) 2015 MariaDB Corporation Ab /* Copyright (c) 2015, 2020, MariaDB Corporation Ab
2018 Codership Oy <info@codership.com> 2018 Codership Oy <info@codership.com>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@ -97,7 +97,7 @@ extern struct wsrep_service_st {
#define wsrep_is_wsrep_xid(X) wsrep_service->wsrep_is_wsrep_xid_func(X) #define wsrep_is_wsrep_xid(X) wsrep_service->wsrep_is_wsrep_xid_func(X)
#define wsrep_xid_seqno(X) wsrep_service->wsrep_xid_seqno_func(X) #define wsrep_xid_seqno(X) wsrep_service->wsrep_xid_seqno_func(X)
#define wsrep_xid_uuid(X) wsrep_service->wsrep_xid_uuid_func(X) #define wsrep_xid_uuid(X) wsrep_service->wsrep_xid_uuid_func(X)
#define wsrep_on(X) wsrep_service->wsrep_on_func(X) #define wsrep_on(X) WSREP_ON && wsrep_service->wsrep_on_func(X)
#define wsrep_prepare_key_for_innodb(A,B,C,D,E,F,G) wsrep_service->wsrep_prepare_key_for_innodb_func(A,B,C,D,E,F,G) #define wsrep_prepare_key_for_innodb(A,B,C,D,E,F,G) wsrep_service->wsrep_prepare_key_for_innodb_func(A,B,C,D,E,F,G)
#define wsrep_thd_LOCK(T) wsrep_service->wsrep_thd_LOCK_func(T) #define wsrep_thd_LOCK(T) wsrep_service->wsrep_thd_LOCK_func(T)
#define wsrep_thd_UNLOCK(T) wsrep_service->wsrep_thd_UNLOCK_func(T) #define wsrep_thd_UNLOCK(T) wsrep_service->wsrep_thd_UNLOCK_func(T)

View File

@ -1136,7 +1136,13 @@ PSI_file_key key_file_binlog_state;
PSI_statement_info stmt_info_new_packet; PSI_statement_info stmt_info_new_packet;
#endif #endif
my_bool WSREP_ON= false; #ifdef WITH_WSREP
/** Whether the Galera write-set replication is enabled. A cached copy of
global_system_variables.wsrep_on && wsrep_provider &&
strcmp(wsrep_provider, WSREP_NONE)
*/
bool WSREP_ON_;
#endif /* WITH_WSREP */
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
void net_before_header_psi(struct st_net *net, void *thd, size_t /* unused: count */) void net_before_header_psi(struct st_net *net, void *thd, size_t /* unused: count */)
@ -5719,14 +5725,12 @@ int mysqld_main(int argc, char **argv)
} }
#ifdef WITH_WSREP #ifdef WITH_WSREP
WSREP_ON= (global_system_variables.wsrep_on && WSREP_ON_= (global_system_variables.wsrep_on &&
wsrep_provider && wsrep_provider &&
strcmp(wsrep_provider, WSREP_NONE)); strcmp(wsrep_provider, WSREP_NONE));
#else
WSREP_ON= false;
#endif
if (WSREP_ON && wsrep_check_opts()) unireg_abort(1); if (WSREP_ON && wsrep_check_opts()) unireg_abort(1);
#endif
/* /*
The subsequent calls may take a long time : e.g. innodb log read. The subsequent calls may take a long time : e.g. innodb log read.

View File

@ -770,10 +770,7 @@ int wsrep_init()
global_system_variables.wsrep_on= 1; global_system_variables.wsrep_on= 1;
if (wsrep_provider && strcmp(wsrep_provider, WSREP_NONE)) WSREP_ON_= wsrep_provider && strcmp(wsrep_provider, WSREP_NONE);
WSREP_ON= true;
else
WSREP_ON= false;
if (wsrep_gtid_mode && opt_bin_log && !opt_log_slave_updates) if (wsrep_gtid_mode && opt_bin_log && !opt_log_slave_updates)
{ {

View File

@ -18,9 +18,8 @@
#include <wsrep.h> #include <wsrep.h>
extern my_bool WSREP_ON;
#ifdef WITH_WSREP #ifdef WITH_WSREP
extern bool WSREP_ON_;
#include <mysql/plugin.h> #include <mysql/plugin.h>
#include "mysql/service_wsrep.h" #include "mysql/service_wsrep.h"
@ -215,6 +214,7 @@ extern void wsrep_prepend_PATH (const char* path);
/* Other global variables */ /* Other global variables */
extern wsrep_seqno_t wsrep_locked_seqno; extern wsrep_seqno_t wsrep_locked_seqno;
#define WSREP_ON unlikely(WSREP_ON_)
/* use xxxxxx_NNULL macros when thd pointer is guaranteed to be non-null to /* use xxxxxx_NNULL macros when thd pointer is guaranteed to be non-null to
* avoid compiler warnings (GCC 6 and later) */ * avoid compiler warnings (GCC 6 and later) */
@ -480,6 +480,7 @@ enum wsrep::streaming_context::fragment_unit wsrep_fragment_unit(ulong unit);
/* These macros are needed to compile MariaDB without WSREP support /* These macros are needed to compile MariaDB without WSREP support
* (e.g. embedded) */ * (e.g. embedded) */
#define WSREP_ON false
#define WSREP(T) (0) #define WSREP(T) (0)
#define WSREP_NNULL(T) (0) #define WSREP_NNULL(T) (0)
#define WSREP_EMULATE_BINLOG(thd) (0) #define WSREP_EMULATE_BINLOG(thd) (0)

View File

@ -88,13 +88,10 @@ static bool refresh_provider_options()
} }
} }
static void wsrep_set_wsrep_on(void) static void wsrep_set_wsrep_on()
{ {
if (global_system_variables.wsrep_on && wsrep_provider && WSREP_ON_= global_system_variables.wsrep_on && wsrep_provider &&
strcmp(wsrep_provider, WSREP_NONE)) strcmp(wsrep_provider, WSREP_NONE);
WSREP_ON= true;
else
WSREP_ON= false;
} }
/* This is intentionally declared as a weak global symbol, so that /* This is intentionally declared as a weak global symbol, so that

View File

@ -1,7 +1,7 @@
/***************************************************************************** /*****************************************************************************
Copyright (c) 2012, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, 2017, 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 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 the terms of the GNU General Public License as published by the Free Software
@ -180,8 +180,8 @@ void dict_stats_update_if_needed_func(dict_table_t* table)
lock waits to be enqueued at head of waiting lock waits to be enqueued at head of waiting
queue. */ queue. */
if (thd if (thd
&& !wsrep_thd_is_applying(thd)
&& wsrep_on(thd) && wsrep_on(thd)
&& !wsrep_thd_is_applying(thd)
&& wsrep_thd_is_BF(thd, 0)) { && wsrep_thd_is_BF(thd, 0)) {
WSREP_DEBUG("Avoiding background statistics" WSREP_DEBUG("Avoiding background statistics"
" calculation for table %s.", " calculation for table %s.",

View File

@ -1,7 +1,7 @@
/***************************************************************************** /*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. 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 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 the terms of the GNU General Public License as published by the Free Software
@ -1046,7 +1046,7 @@ lock_get_info(
/*******************************************************************//** /*******************************************************************//**
@return whether wsrep_on is true on trx->mysql_thd*/ @return whether wsrep_on is true on trx->mysql_thd*/
#define wsrep_on_trx(trx) ((trx)->mysql_thd && wsrep_on((trx)->mysql_thd)) #define wsrep_on_trx(trx) wsrep_on((trx)->mysql_thd)
#endif /* WITH_WSREP */ #endif /* WITH_WSREP */