Skip to content

Commit 37a4765

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 37a4765

10 files changed

+65
-4
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';

mysql-test/main/mysqld--help.result

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,10 @@ The following specify which files/extra groups are read (specified before remain
465465
(unless the user has SUPER privilege)
466466
--init-file=name Read SQL commands from this file at startup
467467
--init-rpl-role=name
468-
Set the replication role. One of: MASTER, SLAVE
468+
The replication role the server was started with. Can be
469+
set in the cnf file to help recover special semi-sync
470+
replication situations. Possible values are MASTER and
471+
SLAVE
469472
--init-slave=name Command(s) that are executed by a slave server each time
470473
the SQL thread starts
471474
--interactive-timeout=#
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+
# Verify that it's a global scope only.
12+
SELECT @@session.init_rpl_role;
13+
ERROR HY000: Variable 'init_rpl_role' is a GLOBAL variable
14+
# Verify 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 the server was started with. Can be set in the cnf file to help recover special semi-sync replication situations. Possible 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 REQUIRED
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
--echo # Verify that it's a global scope only.
11+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
12+
SELECT @@session.init_rpl_role;
13+
14+
--echo # Verify it's read-only.
15+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
16+
SET @@GLOBAL.init_rpl_role = 'MASTER';
17+
18+
--echo # End of 13.0 tests

sql/mysqld.cc

Lines changed: 1 addition & 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},
@@ -9141,6 +9138,7 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
91419138
flush_time= 0;
91429139

91439140
#ifdef HAVE_REPLICATION
9141+
rpl_status= init_rpl_role_val;
91449142
if (init_slave_skip_errors(opt_slave_skip_errors))
91459143
return 1;
91469144
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;

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 starts with. "
1513+
"Can be set 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)