From c79051e5871a61034f37eb26f9199c1c3380bc61 Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Tue, 3 Mar 2020 16:50:48 +0200 Subject: MDEV-22271 Excessive stack memory usage due to WSREP_LOG - Made WSREP_LOG a function and moved the body out of header. - Reduced the stack allocated buffer size and implemented reprint into dynamically allocated buffer if stack buffer is not large enough to hold the message. --- sql/wsrep_mysqld.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'sql/wsrep_mysqld.h') diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index a5da8e3bc44..8623c83cb14 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -242,13 +242,9 @@ extern wsrep_seqno_t wsrep_locked_seqno; ((wsrep_forced_binlog_format != BINLOG_FORMAT_UNSPEC) ? \ wsrep_forced_binlog_format : my_format) -// prefix all messages with "WSREP" -#define WSREP_LOG(fun, ...) \ - do { \ - char msg[1024]= {'\0'}; \ - snprintf(msg, sizeof(msg) - 1, ## __VA_ARGS__); \ - fun("WSREP: %s", msg); \ - } while(0) +/* A wrapper function for MySQL log functions. The call will prefix + the log message with WSREP and forward the result buffer to fun. */ +void WSREP_LOG(void (*fun)(const char* fmt, ...), const char* fmt, ...); #define WSREP_DEBUG(...) \ if (wsrep_debug) WSREP_LOG(sql_print_information, ##__VA_ARGS__) -- cgit v1.2.1 From 93475aff8de80a0ef53cbee924bcb70de6e86f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 21 Apr 2020 13:46:05 +0300 Subject: MDEV-22203: WSREP_ON is unnecessarily expensive to evaluate Replaced WSREP_ON macro by single global variable WSREP_ON that is then updated at server statup and on wsrep_on and wsrep_provider update functions. --- sql/wsrep_mysqld.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'sql/wsrep_mysqld.h') diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 8623c83cb14..434956ee53f 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -18,6 +18,8 @@ #include +extern my_bool WSREP_ON; + #ifdef WITH_WSREP #include @@ -213,15 +215,11 @@ 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) && \ - wsrep_provider && \ - strcmp(wsrep_provider, WSREP_NONE)) /* use xxxxxx_NNULL macros when thd pointer is guaranteed to be non-null to * avoid compiler warnings (GCC 6 and later) */ -#define WSREP_NNULL(thd) \ - (WSREP_ON && thd->variables.wsrep_on) + +#define WSREP_NNULL(thd) (WSREP_ON && thd->variables.wsrep_on) #define WSREP(thd) \ (thd && WSREP_NNULL(thd)) @@ -484,7 +482,6 @@ enum wsrep::streaming_context::fragment_unit wsrep_fragment_unit(ulong unit); #define WSREP(T) (0) #define WSREP_NNULL(T) (0) -#define WSREP_ON (0) #define WSREP_EMULATE_BINLOG(thd) (0) #define WSREP_EMULATE_BINLOG_NNULL(thd) (0) #define WSREP_BINLOG_FORMAT(my_format) ((ulong)my_format) -- cgit v1.2.1 From 2c39f69d34e64a5cf94720e82e78c0ee91bd4649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 24 Apr 2020 15:25:39 +0300 Subject: 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. --- sql/wsrep_mysqld.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sql/wsrep_mysqld.h') 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 -extern my_bool WSREP_ON; - #ifdef WITH_WSREP +extern bool WSREP_ON_; #include #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) -- cgit v1.2.1