Skip to content

Commit 6be05ce

Browse files
committed
MDEV-22203: WSREP_ON is unnecessarily expensive to evaluate
This is a backport of the applicable part of commit 93475af and commit 2c39f69 from 10.4. Before 10.4 and Galera 4, WSREP_ON is a macro that points to a global Boolean variable, so it is not that expensive to evaluate, but we will add an unlikely() hint around it. WSREP_ON_NEW: Remove. This macro was introduced in commit c863159 when reverting WSREP_ON to its previous definition. We replace some use of WSREP_ON with WSREP(thd), like it was done in 93475af. Note: the macro WSREP() in 10.1 is equivalent to WSREP_NNULL() in 10.4. Item_func_rand::seed_random(): Avoid invoking current_thd when WSREP is not enabled.
1 parent 758fbec commit 6be05ce

File tree

10 files changed

+38
-37
lines changed

10 files changed

+38
-37
lines changed

mysql-test/suite/galera/t/MW-86-wait1.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
--source include/galera_cluster.inc
77
--source include/have_binlog_format_row.inc
8+
--source include/have_debug.inc
89
--source include/have_debug_sync.inc
910

1011
--connection node_2

sql/item_func.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
2-
Copyright (c) 2009, 2017, MariaDB
2+
Copyright (c) 2009, 2020, MariaDB
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -2650,19 +2650,20 @@ void Item_func_rand::seed_random(Item *arg)
26502650
TODO: do not do reinit 'rand' for every execute of PS/SP if
26512651
args[0] is a constant.
26522652
*/
2653-
uint32 tmp;
2653+
uint32 tmp= (uint32) arg->val_int();
26542654
#ifdef WITH_WSREP
2655-
THD *thd= current_thd;
2656-
if (WSREP(thd))
2655+
if (WSREP_ON)
26572656
{
2658-
if (thd->wsrep_exec_mode==REPL_RECV)
2659-
tmp= thd->wsrep_rand;
2660-
else
2661-
tmp= thd->wsrep_rand= (uint32) arg->val_int();
2662-
}
2663-
else
2657+
THD *thd= current_thd;
2658+
if (thd->variables.wsrep_on)
2659+
{
2660+
if (thd->wsrep_exec_mode==REPL_RECV)
2661+
tmp= thd->wsrep_rand;
2662+
else
2663+
thd->wsrep_rand= tmp;
2664+
}
2665+
}
26642666
#endif /* WITH_WSREP */
2665-
tmp= (uint32) arg->val_int();
26662667

26672668
my_rnd_init(rand, (uint32) (tmp*0x10001L+55555555L),
26682669
(uint32) (tmp*0x10000001L));

sql/log.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,7 @@ binlog_commit_flush_stmt_cache(THD *thd, bool all,
17911791
#ifdef WITH_WSREP
17921792
if (thd->wsrep_mysql_replicated > 0)
17931793
{
1794-
DBUG_ASSERT(WSREP_ON);
1794+
DBUG_ASSERT(WSREP(thd));
17951795
WSREP_DEBUG("avoiding binlog_commit_flush_trx_cache: %d",
17961796
thd->wsrep_mysql_replicated);
17971797
return 0;
@@ -6612,14 +6612,15 @@ int MYSQL_BIN_LOG::rotate(bool force_rotate, bool* check_purge)
66126612
int error= 0;
66136613
DBUG_ENTER("MYSQL_BIN_LOG::rotate");
66146614

6615-
if (wsrep_to_isolation)
6615+
#ifdef WITH_WSREP
6616+
if (WSREP_ON && wsrep_to_isolation)
66166617
{
6617-
DBUG_ASSERT(WSREP_ON);
66186618
*check_purge= false;
6619-
WSREP_DEBUG("avoiding binlog rotate due to TO isolation: %d",
6619+
WSREP_DEBUG("avoiding binlog rotate due to TO isolation: %d",
66206620
wsrep_to_isolation);
66216621
DBUG_RETURN(0);
66226622
}
6623+
#endif /* WITH_WSREP */
66236624

66246625
//todo: fix the macro def and restore safe_mutex_assert_owner(&LOCK_log);
66256626
*check_purge= false;

sql/log_event.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Copyright (c) 2000, 2019, Oracle and/or its affiliates.
3-
Copyright (c) 2009, 2019, MariaDB
3+
Copyright (c) 2009, 2020, MariaDB
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -4770,7 +4770,7 @@ Query_log_event::do_shall_skip(rpl_group_info *rgi)
47704770
}
47714771
}
47724772
#ifdef WITH_WSREP
4773-
else if (WSREP_ON && wsrep_mysql_replication_bundle && opt_slave_domain_parallel_threads == 0 &&
4773+
else if (WSREP(thd) && wsrep_mysql_replication_bundle && opt_slave_domain_parallel_threads == 0 &&
47744774
thd->wsrep_mysql_replicated > 0 &&
47754775
(is_begin() || is_commit()))
47764776
{
@@ -4784,7 +4784,7 @@ Query_log_event::do_shall_skip(rpl_group_info *rgi)
47844784
thd->wsrep_mysql_replicated = 0;
47854785
}
47864786
}
4787-
#endif
4787+
#endif /* WITH_WSREP */
47884788
DBUG_RETURN(Log_event::do_shall_skip(rgi));
47894789
}
47904790

@@ -7755,7 +7755,7 @@ Xid_log_event::do_shall_skip(rpl_group_info *rgi)
77557755
DBUG_RETURN(Log_event::EVENT_SKIP_COUNT);
77567756
}
77577757
#ifdef WITH_WSREP
7758-
else if (wsrep_mysql_replication_bundle && WSREP_ON &&
7758+
else if (WSREP(thd) && wsrep_mysql_replication_bundle &&
77597759
opt_slave_domain_parallel_threads == 0)
77607760
{
77617761
if (++thd->wsrep_mysql_replicated < (int)wsrep_mysql_replication_bundle)

sql/mysqld.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5781,8 +5781,10 @@ int mysqld_main(int argc, char **argv)
57815781
set_user(mysqld_user, user_info);
57825782
}
57835783

5784+
#ifdef WITH_WSREP
57845785
if (WSREP_ON && wsrep_check_opts())
57855786
global_system_variables.wsrep_on= 0;
5787+
#endif
57865788

57875789
if (opt_bin_log && !global_system_variables.server_id)
57885790
{

sql/slave.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates.
2-
Copyright (c) 2009, 2017, MariaDB Corporation
2+
Copyright (c) 2009, 2020, MariaDB Corporation
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -4998,8 +4998,10 @@ pthread_handler_t handle_slave_sql(void *arg)
49984998
if (!sql_slave_killed(serial_rgi))
49994999
{
50005000
slave_output_error_info(serial_rgi, thd);
5001-
if (WSREP_ON && rli->last_error().number == ER_UNKNOWN_COM_ERROR)
5001+
if (WSREP(thd) && rli->last_error().number == ER_UNKNOWN_COM_ERROR)
5002+
{
50025003
wsrep_node_dropped= TRUE;
5004+
}
50035005
}
50045006
goto err;
50055007
}
@@ -5131,7 +5133,7 @@ pthread_handler_t handle_slave_sql(void *arg)
51315133
If slave stopped due to node going non primary, we set global flag to
51325134
trigger automatic restart of slave when node joins back to cluster.
51335135
*/
5134-
if (WSREP_ON && wsrep_node_dropped && wsrep_restart_slave)
5136+
if (WSREP(thd) && wsrep_node_dropped && wsrep_restart_slave)
51355137
{
51365138
if (wsrep_ready_get())
51375139
{

sql/sql_base.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
2-
Copyright (c) 2010, 2016, MariaDB
2+
Copyright (c) 2010, 2020, MariaDB
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -4784,7 +4784,7 @@ bool open_tables(THD *thd, const DDL_options_st &options,
47844784
}
47854785
}
47864786

4787-
if (WSREP_ON &&
4787+
if (WSREP(thd) &&
47884788
wsrep_replicate_myisam &&
47894789
(*start) &&
47904790
(*start)->table &&

sql/sql_parse.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates.
2-
Copyright (c) 2008, 2019, MariaDB
2+
Copyright (c) 2008, 2020, MariaDB
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -1493,7 +1493,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
14931493
if (parser_state.init(thd, thd->query(), thd->query_length()))
14941494
break;
14951495

1496-
if (WSREP_ON)
1496+
if (WSREP(thd))
14971497
wsrep_mysql_parse(thd, thd->query(), thd->query_length(), &parser_state);
14981498
else
14991499
mysql_parse(thd, thd->query(), thd->query_length(), &parser_state);
@@ -1574,13 +1574,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
15741574
*/
15751575
statistic_increment(thd->status_var.questions, &LOCK_status);
15761576

1577-
if(!WSREP(thd))
1577+
if (!WSREP(thd))
15781578
thd->set_time(); /* Reset the query start time. */
15791579

15801580
parser_state.reset(beginning_of_next_stmt, length);
15811581
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
15821582

1583-
if (WSREP_ON)
1583+
if (WSREP(thd))
15841584
wsrep_mysql_parse(thd, beginning_of_next_stmt, length, &parser_state);
15851585
else
15861586
mysql_parse(thd, beginning_of_next_stmt, length, &parser_state);

sql/sql_table.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Copyright (c) 2000, 2019, Oracle and/or its affiliates.
3-
Copyright (c) 2010, 2019, MariaDB
3+
Copyright (c) 2010, 2020, MariaDB
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -5338,7 +5338,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
53385338
DBUG_ENTER("mysql_create_like_table");
53395339

53405340
#ifdef WITH_WSREP
5341-
if (WSREP_ON && !thd->wsrep_applier &&
5341+
if (WSREP(thd) && !thd->wsrep_applier &&
53425342
wsrep_create_like_table(thd, table, src_table, create_info))
53435343
DBUG_RETURN(res);
53445344
#endif

sql/wsrep_mysqld.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,7 @@ extern void wsrep_prepend_PATH (const char* path);
179179
/* Other global variables */
180180
extern wsrep_seqno_t wsrep_locked_seqno;
181181

182-
#define WSREP_ON \
183-
(global_system_variables.wsrep_on)
184-
185-
#define WSREP_ON_NEW \
186-
((global_system_variables.wsrep_on) && \
187-
wsrep_provider && \
188-
strcmp(wsrep_provider, WSREP_NONE))
182+
#define WSREP_ON unlikely(global_system_variables.wsrep_on)
189183

190184
#define WSREP(thd) \
191185
(WSREP_ON && thd->variables.wsrep_on)

0 commit comments

Comments
 (0)