Commit 2c39f69d authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 93475aff
......@@ -13,7 +13,7 @@ enum Wsrep_service_key_type
#else
/* Copyright (c) 2015 MariaDB Corporation Ab
/* Copyright (c) 2015, 2020, MariaDB Corporation Ab
2018 Codership Oy <info@codership.com>
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_xid_seqno(X) wsrep_service->wsrep_xid_seqno_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_thd_LOCK(T) wsrep_service->wsrep_thd_LOCK_func(T)
#define wsrep_thd_UNLOCK(T) wsrep_service->wsrep_thd_UNLOCK_func(T)
......
......@@ -1136,7 +1136,13 @@ PSI_file_key key_file_binlog_state;
PSI_statement_info stmt_info_new_packet;
#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
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
WSREP_ON= (global_system_variables.wsrep_on &&
WSREP_ON_= (global_system_variables.wsrep_on &&
wsrep_provider &&
strcmp(wsrep_provider, WSREP_NONE));
#else
WSREP_ON= false;
#endif
if (WSREP_ON && wsrep_check_opts()) unireg_abort(1);
#endif
/*
The subsequent calls may take a long time : e.g. innodb log read.
......
......@@ -770,10 +770,7 @@ int wsrep_init()
global_system_variables.wsrep_on= 1;
if (wsrep_provider && strcmp(wsrep_provider, WSREP_NONE))
WSREP_ON= true;
else
WSREP_ON= false;
WSREP_ON_= wsrep_provider && strcmp(wsrep_provider, WSREP_NONE);
if (wsrep_gtid_mode && opt_bin_log && !opt_log_slave_updates)
{
......
......@@ -18,9 +18,8 @@
#include <wsrep.h>
extern my_bool WSREP_ON;
#ifdef WITH_WSREP
extern bool WSREP_ON_;
#include <mysql/plugin.h>
#include "mysql/service_wsrep.h"
......@@ -215,6 +214,7 @@ extern void wsrep_prepend_PATH (const char* path);
/* Other global variables */
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
* 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
* (e.g. embedded) */
#define WSREP_ON false
#define WSREP(T) (0)
#define WSREP_NNULL(T) (0)
#define WSREP_EMULATE_BINLOG(thd) (0)
......
......@@ -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 &&
strcmp(wsrep_provider, WSREP_NONE))
WSREP_ON= true;
else
WSREP_ON= false;
WSREP_ON_= global_system_variables.wsrep_on && wsrep_provider &&
strcmp(wsrep_provider, WSREP_NONE);
}
/* This is intentionally declared as a weak global symbol, so that
......
/*****************************************************************************
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
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
queue. */
if (thd
&& !wsrep_thd_is_applying(thd)
&& wsrep_on(thd)
&& !wsrep_thd_is_applying(thd)
&& wsrep_thd_is_BF(thd, 0)) {
WSREP_DEBUG("Avoiding background statistics"
" calculation for table %s.",
......
/*****************************************************************************
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
......@@ -1046,7 +1046,7 @@ lock_get_info(
/*******************************************************************//**
@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 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment