summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-04-24 15:25:39 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-04-24 15:25:39 +0300
commit2c39f69d34e64a5cf94720e82e78c0ee91bd4649 (patch)
tree5592450d8d717529c7e9d1e27ef534a821793946
parent93475aff8de80a0ef53cbee924bcb70de6e86f2c (diff)
downloadmariadb-git-2c39f69d34e64a5cf94720e82e78c0ee91bd4649.tar.gz
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.
-rw-r--r--include/mysql/service_wsrep.h4
-rw-r--r--sql/mysqld.cc14
-rw-r--r--sql/wsrep_mysqld.cc5
-rw-r--r--sql/wsrep_mysqld.h5
-rw-r--r--sql/wsrep_var.cc9
-rw-r--r--storage/innobase/dict/dict0stats_bg.cc4
-rw-r--r--storage/innobase/include/lock0lock.h4
7 files changed, 22 insertions, 23 deletions
diff --git a/include/mysql/service_wsrep.h b/include/mysql/service_wsrep.h
index 2f6b2be32a6..61a829f3043 100644
--- a/include/mysql/service_wsrep.h
+++ b/include/mysql/service_wsrep.h
@@ -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)
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 830f9bc61b2..e71e15a3dfc 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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.
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc
index c1a289cf685..14be333c107 100644
--- a/sql/wsrep_mysqld.cc
+++ b/sql/wsrep_mysqld.cc
@@ -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)
{
diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h
index 434956ee53f..d4420d9da7a 100644
--- a/sql/wsrep_mysqld.h
+++ b/sql/wsrep_mysqld.h
@@ -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)
diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc
index a484f8bf113..64362d1c9e2 100644
--- a/sql/wsrep_var.cc
+++ b/sql/wsrep_var.cc
@@ -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
diff --git a/storage/innobase/dict/dict0stats_bg.cc b/storage/innobase/dict/dict0stats_bg.cc
index 2985b6faf35..df877c36aae 100644
--- a/storage/innobase/dict/dict0stats_bg.cc
+++ b/storage/innobase/dict/dict0stats_bg.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
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.",
diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h
index 11000620e8c..29e2aacaf5c 100644
--- a/storage/innobase/include/lock0lock.h
+++ b/storage/innobase/include/lock0lock.h
@@ -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
@@ -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 */