Skip to content

Commit 029860e

Browse files
committed
MDEV-38202: add init_rpl_role in SHOW VARIABLES by introducing a read-only sys_var set at server startup
1 parent 9fc925d commit 029860e

File tree

9 files changed

+59
-0
lines changed

9 files changed

+59
-0
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
# as we want to see the intial value only it should be read-only
12+
SET GLOBAL init_rpl_role = 'MASTER';
13+
ERROR HY000: Variable 'init_rpl_role' is a read only variable
14+
# it should show in INFORMATION_SCHEMA.GLOBAL_VARIABLES
15+
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
16+
WHERE VARIABLE_NAME = 'init_rpl_role';
17+
VARIABLE_NAME VARIABLE_VALUE
18+
INIT_RPL_ROLE SLAVE

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 with. 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 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--echo #
2+
--echo # MDEV-38202: add init_rpl_role in output of "show variables"
3+
--echo #
4+
5+
--echo # it should show SLAVE as it is set in opt file
6+
SELECT @@global.init_rpl_role;
7+
8+
SHOW GLOBAL VARIABLES LIKE 'init_rpl_role';
9+
10+
--echo # as we want to see the intial value only it should be read-only
11+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
12+
SET GLOBAL init_rpl_role = 'MASTER';
13+
14+
15+
--echo # it should show in INFORMATION_SCHEMA.GLOBAL_VARIABLES
16+
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
17+
WHERE VARIABLE_NAME = 'init_rpl_role';

sql/mysqld.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9141,6 +9141,7 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
91419141
flush_time= 0;
91429142

91439143
#ifdef HAVE_REPLICATION
9144+
init_rpl_role_val = rpl_status;
91449145
if (init_slave_skip_errors(opt_slave_skip_errors))
91459146
return 1;
91469147
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= RPL_AUTH_MASTER;
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: 9 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,14 @@ 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 that the server was started with. "
1513+
"Possible values are MASTER and SLAVE",
1514+
READ_ONLY GLOBAL_VAR(init_rpl_role_val), NO_CMD_LINE,
1515+
rpl_role_type, DEFAULT(RPL_AUTH_MASTER));
1516+
#endif
15081517
static Sys_var_ulong Sys_interactive_timeout(
15091518
"interactive_timeout",
15101519
"The number of seconds the server waits for activity on an interactive "

0 commit comments

Comments
 (0)