Skip to content

Commit 8795f3b

Browse files
committed
MDEV-38202: make init_rpl_role visible at runtime
Problem: The --init-rpl-role option can be set in the .cnf file or command line to configure the server replication role at startup (MASTER or SLAVE), but there was no way to check this value at runtime. This made it hard to for investigation issues because we can't know which role the server was started with. Solution: I added a new read-only status variable init_rpl_role that captures the value of rpl_status right after startup and keeps it unchanged. ex usage: SHOW STATUS LIKE 'init_rpl_role'; SHOW GLOBAL STATUS LIKE 'init_rpl_role';
1 parent 9fc925d commit 8795f3b

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# MDEV-38202: add init_rpl_role in output of "show variables"
3+
#
4+
# it should show SLAVE as it is set in opt file
5+
SHOW STATUS LIKE 'init_rpl_role';
6+
Variable_name Value
7+
Init_rpl_role SLAVE
8+
SHOW GLOBAL STATUS LIKE 'init_rpl_role';
9+
Variable_name Value
10+
Init_rpl_role SLAVE
11+
Init_rpl_role is: SLAVE
12+
# End of 13.0 tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--init-rpl-role=SLAVE
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--echo #
2+
--echo # MDEV-38202: add init_rpl_role in output of "show variables"
3+
--echo #
4+
--source include/not_embedded.inc
5+
6+
--echo # it should show SLAVE as it is set in opt file
7+
SHOW STATUS LIKE 'init_rpl_role';
8+
SHOW GLOBAL STATUS LIKE 'init_rpl_role';
9+
10+
let $init_role= query_get_value(SHOW STATUS LIKE 'Init_rpl_role', Value, 1);
11+
--echo Init_rpl_role is: $init_role
12+
13+
if (`SELECT strcmp("SLAVE", "$init_role") != 0`)
14+
{
15+
--die init_rpl_role should be SLAVE
16+
}
17+
18+
--echo # End of 13.0 tests

sql/mysqld.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7315,6 +7315,13 @@ static int show_rpl_status(THD *, SHOW_VAR *var, void *, system_status_var *,
73157315
return 0;
73167316
}
73177317

7318+
static int show_init_rpl_role(THD *, SHOW_VAR *var, void *, system_status_var *,
7319+
enum_var_type)
7320+
{
7321+
var->type= SHOW_CHAR;
7322+
var->value= const_cast<char*>(rpl_role_type[init_rpl_role_val]);
7323+
return 0;
7324+
}
73187325
static int show_slave_running(THD *thd, SHOW_VAR *var, void *buff,
73197326
system_status_var *, enum_var_type)
73207327
{
@@ -7979,6 +7986,7 @@ SHOW_VAR status_vars[]= {
79797986
{"Questions", (char*) offsetof(STATUS_VAR, questions), SHOW_LONG_STATUS},
79807987
#ifdef HAVE_REPLICATION
79817988
{"Rpl_status", (char*) &show_rpl_status, SHOW_SIMPLE_FUNC},
7989+
{"Init_rpl_role", (char*) &show_init_rpl_role, SHOW_SIMPLE_FUNC},
79827990
#endif
79837991
{"Select_full_join", (char*) offsetof(STATUS_VAR, select_full_join_count_), SHOW_LONG_STATUS},
79847992
{"Select_full_range_join", (char*) offsetof(STATUS_VAR, select_full_range_join_count_), SHOW_LONG_STATUS},
@@ -9141,6 +9149,7 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
91419149
flush_time= 0;
91429150

91439151
#ifdef HAVE_REPLICATION
9152+
init_rpl_role_val = rpl_status;
91449153
if (init_slave_skip_errors(opt_slave_skip_errors))
91459154
return 1;
91469155
if (init_slave_transaction_retry_errors(opt_slave_transaction_retry_errors))

sql/repl_failsafe.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct Slave_info
5252

5353
Atomic_counter<uint32_t> binlog_dump_thread_count;
5454
ulong rpl_status=RPL_NULL;
55+
ulong init_rpl_role_val= 0;
5556
mysql_mutex_t LOCK_rpl_status;
5657

5758
const char *rpl_role_type[] = {"MASTER","SLAVE",NullS};

sql/repl_failsafe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef enum {RPL_AUTH_MASTER=0,RPL_IDLE_SLAVE,RPL_ACTIVE_SLAVE,
2929
RPL_ANY /* wild card used by change_rpl_status */ } RPL_STATUS;
3030
extern ulong rpl_status;
3131

32+
extern ulong init_rpl_role_val;
3233
extern mysql_mutex_t LOCK_rpl_status;
3334
extern mysql_cond_t COND_rpl_status;
3435
extern TYPELIB rpl_role_typelib;

0 commit comments

Comments
 (0)