Skip to content

Commit 98393ff

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 98393ff

File tree

9 files changed

+63
-3
lines changed

9 files changed

+63
-3
lines changed

mysql-test/main/information_schema.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,7 @@ drop table if exists t1;drop table if exists t1;
19391939
drop table if exists t1;drop table if exists t1;
19401940
drop table if exists t1;drop table if exists t1;
19411941
INIT_FILE
1942+
INIT_RPL_ROLE MASTER
19421943
INIT_SLAVE
19431944
set global init_connect="";
19441945
create table t0 select * from information_schema.global_status where VARIABLE_NAME='COM_SELECT';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
SELECT @@global.init_rpl_role;
6+
@@global.init_rpl_role
7+
SLAVE
8+
SHOW GLOBAL VARIABLES LIKE 'init_rpl_role';
9+
Variable_name Value
10+
init_rpl_role SLAVE
11+
# it's a global scope only
12+
SELECT @@session.init_rpl_role;
13+
ERROR HY000: Variable 'init_rpl_role' is a GLOBAL variable
14+
# it's read-only
15+
SET @@GLOBAL.init_rpl_role = 'MASTER';
16+
ERROR HY000: Variable 'init_rpl_role' is a read only variable
17+
# End of 13.0 tests

mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,16 @@ NUMERIC_BLOCK_SIZE NULL
15821582
ENUM_VALUE_LIST NULL
15831583
READ_ONLY YES
15841584
COMMAND_LINE_ARGUMENT REQUIRED
1585+
VARIABLE_NAME INIT_RPL_ROLE
1586+
VARIABLE_SCOPE GLOBAL
1587+
VARIABLE_TYPE ENUM
1588+
VARIABLE_COMMENT The replication role that the server was started withPossible values are MASTER and SLAVE
1589+
NUMERIC_MIN_VALUE NULL
1590+
NUMERIC_MAX_VALUE NULL
1591+
NUMERIC_BLOCK_SIZE NULL
1592+
ENUM_VALUE_LIST MASTER,SLAVE
1593+
READ_ONLY YES
1594+
COMMAND_LINE_ARGUMENT NULL
15851595
VARIABLE_NAME INIT_SLAVE
15861596
VARIABLE_SCOPE GLOBAL
15871597
VARIABLE_TYPE VARCHAR
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--init-rpl-role=SLAVE
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--source include/not_embedded.inc
2+
--echo #
3+
--echo # MDEV-38202: add init_rpl_role in output of "show variables"
4+
--echo #
5+
6+
--echo # it should show SLAVE as it is set in opt file
7+
SELECT @@global.init_rpl_role;
8+
SHOW GLOBAL VARIABLES LIKE 'init_rpl_role';
9+
10+
11+
--echo # it's a global scope only
12+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
13+
SELECT @@session.init_rpl_role;
14+
15+
16+
--echo # it's read-only
17+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
18+
SET @@GLOBAL.init_rpl_role = 'MASTER';
19+
20+
21+
--echo # End of 13.0 tests

sql/mysqld.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7086,9 +7086,6 @@ struct my_option my_long_options[]=
70867086
"which is whether to validate the master's certificate in TLS replication",
70877087
&master_ssl_verify_server_cert, nullptr, nullptr, GET_BOOL, NO_ARG,
70887088
master_ssl_verify_server_cert, 0, 0, nullptr, 0, nullptr},
7089-
{"init-rpl-role", 0, "Set the replication role",
7090-
&rpl_status, &rpl_status, &rpl_role_typelib,
7091-
GET_ENUM, REQUIRED_ARG, RPL_AUTH_MASTER, 0, 0, 0, 0, 0},
70927089
#endif /* HAVE_REPLICATION */
70937090
{"memlock", 0, "Lock mariadbd process in memory", &locked_in_memory,
70947091
&locked_in_memory, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},

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;

sql/sys_vars.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include "semisync_master.h"
6868
#include "semisync_slave.h"
6969
#include <ssl_compat.h>
70+
#include "repl_failsafe.h"
7071
#ifdef WITH_WSREP
7172
#include "wsrep_mysqld.h"
7273
#endif
@@ -1505,6 +1506,16 @@ Sys_init_slave(
15051506
DEFAULT(""), &PLock_sys_init_slave,
15061507
NOT_IN_BINLOG, ON_CHECK(check_init_string));
15071508

1509+
#ifdef HAVE_REPLICATION
1510+
static Sys_var_enum Sys_init_rpl_role(
1511+
"init_rpl_role",
1512+
"The replication role the server was started with. "
1513+
"Can be set in the cnf file to help recover "
1514+
"special semi-sync replication situations. "
1515+
"Possible values are MASTER and SLAVE",
1516+
READ_ONLY GLOBAL_VAR(init_rpl_role_val), CMD_LINE(REQUIRED_ARG),
1517+
rpl_role_type, DEFAULT(RPL_AUTH_MASTER));
1518+
#endif
15081519
static Sys_var_ulong Sys_interactive_timeout(
15091520
"interactive_timeout",
15101521
"The number of seconds the server waits for activity on an interactive "

0 commit comments

Comments
 (0)