Skip to content

Commit

Permalink
MDEV-7962 wsrep_on() takes 0.14% in OLTP RO
Browse files Browse the repository at this point in the history
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 conditions thd && WSREP_ON before
calling the function.

Global_read_lock: Use WSREP_NNULL(thd) instead of wsrep_on(thd)
because we not only know the definition of THD but also that
the pointer is not null.

wsrep_open(): Use WSREP(thd) instead of wsrep_on(thd).

InnoDB: Replace thd && wsrep_on(thd) with wsrep_on(thd), now that
the condition has been merged to the definition of the macro
wsrep_on().
  • Loading branch information
dr-m committed Apr 24, 2020
1 parent 2c39f69 commit edd38b5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/mysql/service_wsrep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ON && wsrep_service->wsrep_on_func(X)
#define wsrep_on(thd) (thd) && WSREP_ON && wsrep_service->wsrep_on_func(thd)
#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)
Expand Down
13 changes: 9 additions & 4 deletions sql/lock.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (c) 2000, 2011, Oracle and/or its affiliates.
Copyright (c) 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 @@ -1102,13 +1103,15 @@ void Global_read_lock::unlock_global_read_lock(THD *thd)
{
Wsrep_server_state& server_state= Wsrep_server_state::instance();
if (server_state.state() == Wsrep_server_state::s_donor ||
(wsrep_on(thd) && server_state.state() != Wsrep_server_state::s_synced))
(WSREP_NNULL(thd) &&
server_state.state() != Wsrep_server_state::s_synced))
{
/* TODO: maybe redundant here?: */
wsrep_locked_seqno= WSREP_SEQNO_UNDEFINED;
server_state.resume();
}
else if (wsrep_on(thd) && server_state.state() == Wsrep_server_state::s_synced)
else if (WSREP_NNULL(thd) &&
server_state.state() == Wsrep_server_state::s_synced)
{
server_state.resume_and_resync();
}
Expand Down Expand Up @@ -1164,11 +1167,13 @@ bool Global_read_lock::make_global_read_lock_block_commit(THD *thd)
Wsrep_server_state& server_state= Wsrep_server_state::instance();
wsrep::seqno paused_seqno;
if (server_state.state() == Wsrep_server_state::s_donor ||
(wsrep_on(thd) && server_state.state() != Wsrep_server_state::s_synced))
(WSREP_NNULL(thd) &&
server_state.state() != Wsrep_server_state::s_synced))
{
paused_seqno= server_state.pause();
}
else if (wsrep_on(thd) && server_state.state() == Wsrep_server_state::s_synced)
else if (WSREP_NNULL(thd) &&
server_state.state() == Wsrep_server_state::s_synced)
{
paused_seqno= server_state.desync_and_pause();
}
Expand Down
2 changes: 1 addition & 1 deletion sql/wsrep_trans_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static inline void wsrep_after_apply(THD* thd)
static inline void wsrep_open(THD* thd)
{
DBUG_ENTER("wsrep_open");
if (wsrep_on(thd))
if (WSREP(thd))
{
thd->wsrep_cs().open(wsrep::client_id(thd->thread_id));
thd->wsrep_cs().debug_log_level(wsrep_debug);
Expand Down
3 changes: 1 addition & 2 deletions storage/innobase/dict/dict0stats_bg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ void dict_stats_update_if_needed_func(dict_table_t* table)
generated row locks and allow BF thread
lock waits to be enqueued at head of waiting
queue. */
if (thd
&& wsrep_on(thd)
if (wsrep_on(thd)
&& !wsrep_thd_is_applying(thd)
&& wsrep_thd_is_BF(thd, 0)) {
WSREP_DEBUG("Avoiding background statistics"
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4366,7 +4366,7 @@ innobase_commit_low(
#ifdef WITH_WSREP
THD* thd = (THD*)trx->mysql_thd;
const char* tmp = 0;
if (thd && wsrep_on(thd)) {
if (wsrep_on(thd)) {
#ifdef WSREP_PROC_INFO
char info[64];
info[sizeof(info) - 1] = '\0';
Expand All @@ -4386,7 +4386,7 @@ innobase_commit_low(
}
trx->will_lock = 0;
#ifdef WITH_WSREP
if (thd && wsrep_on(thd)) { thd_proc_info(thd, tmp); }
if (wsrep_on(thd)) { thd_proc_info(thd, tmp); }
#endif /* WITH_WSREP */
}

Expand Down

0 comments on commit edd38b5

Please sign in to comment.