Skip to content

MDEV-38202: make init_rpl_role visible at runtime#4904

Open
Mahmoud-kh1 wants to merge 1 commit intoMariaDB:mainfrom
Mahmoud-kh1:init_rpl_role
Open

MDEV-38202: make init_rpl_role visible at runtime#4904
Mahmoud-kh1 wants to merge 1 commit intoMariaDB:mainfrom
Mahmoud-kh1:init_rpl_role

Conversation

@Mahmoud-kh1
Copy link
Copy Markdown

@Mahmoud-kh1 Mahmoud-kh1 commented Apr 4, 2026

This PR adds a new feature to see the server’s initial replication role at runtime.

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.

Reason
Previously, init_rpl_role could be set in the cnf file but was not visible in runtime which will be helpful for investigating issues as it will allow us to see with which value mariadb was started.

Tests :
Added basic tests to verify that init_rpl_role is correctly set at startup and displayed properly.

@Mahmoud-kh1 Mahmoud-kh1 force-pushed the init_rpl_role branch 6 times, most recently from f6f6a30 to 029860e Compare April 4, 2026 17:30
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Apr 6, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! This is a preliminary review.

Please, in addition to the notes below:

  • add a commit message to your commit explaining what it is that you do
  • update the Jira with a complete description of what the new variable is (data type, validity period, purpose), when and how it can be set, etc. : helps documenting it.
  • Make sure that there are no failing buildbot hosts.


--echo # it should show in INFORMATION_SCHEMA.GLOBAL_VARIABLES
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME = 'init_rpl_role'; No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always terminate the last line with a new line.

We also customarily add a --echo # End of MA.MI tests at the end: helps conflict resolution when merging up and down.

sql/sys_vars.cc Outdated
NOT_IN_BINLOG, ON_CHECK(check_init_string));

#ifdef HAVE_REPLICATION
static Sys_var_enum Sys_init_rpl_role(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to leave that to the final reviewer. But: is there any specific reason this should be a system variable?
It's read only at runtime and not settable via the command line/config file at startup. So, in essence, you can only read it. So why not make this a status variable?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just make it system variable to support this syntax
SELECT @@global.init_rpl_role;
SELECT @@init_rpl_role;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, why? what's better about this syntax compared to SHOW GLOBAL STATUS LIKE 'init_rpl_role' ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it will be just a nice bonus :) , I will turn it to status variable as you suggested.

Copy link
Copy Markdown
Contributor

@ParadoxV5 ParadoxV5 Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumbled upon the System & Status Variables Guide.

In general, I believe this should be a system variable, as it’s associated with a mode configuration rather than a status report.

In theory, it is possible to make --init-rpl-role mutable during runtime for recovering complex Semi-Sync networks/situations.
But in practice, --init-rpl-role doesn’t scale. (see also MDEV-34878)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I've requested that this is a status variable for the following reasons:

  • I've assumed that a value will never be assigned directly to it.
  • Status variables are more light-weight than system variables: less locking needed etc.
  • I personally find a non-settable system variable to be an abomination and a gotcha: why would you put something non-settable in a settable variables namespace?

This said, it's your review and your codebase. So feel free to ignore the above or not.

sql/sys_vars.cc Outdated
"The replication role that the server was started with. "
"Possible values are MASTER and SLAVE",
READ_ONLY GLOBAL_VAR(init_rpl_role_val), NO_CMD_LINE,
rpl_role_type, DEFAULT(RPL_AUTH_MASTER));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need a default here? You're going to always set it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see rp_status has it as default value so I follow it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I implied is that you will never see this default value. So you might just as well put 0 here.

@gkodinov gkodinov self-assigned this Apr 7, 2026
@Mahmoud-kh1 Mahmoud-kh1 force-pushed the init_rpl_role branch 3 times, most recently from 1979739 to 8795f3b Compare April 7, 2026 12:17
@Mahmoud-kh1 Mahmoud-kh1 changed the title MDEV-38202: add init_rpl_role in SHOW VARIABLES MDEV-38202: make init_rpl_role visible at runtime Apr 7, 2026
@Mahmoud-kh1 Mahmoud-kh1 requested a review from gkodinov April 7, 2026 12:51
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making it a status variable!

Some cleanups below. And then it's ready.

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';
sql/sys_vars.cc Outdated
NOT_IN_BINLOG, ON_CHECK(check_init_string));

#ifdef HAVE_REPLICATION
static Sys_var_enum Sys_init_rpl_role(
Copy link
Copy Markdown
Contributor

@ParadoxV5 ParadoxV5 Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumbled upon the System & Status Variables Guide.

In general, I believe this should be a system variable, as it’s associated with a mode configuration rather than a status report.

In theory, it is possible to make --init-rpl-role mutable during runtime for recovering complex Semi-Sync networks/situations.
But in practice, --init-rpl-role doesn’t scale. (see also MDEV-34878)

@ParadoxV5 ParadoxV5 self-assigned this Apr 7, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for your work. Please stay tuned for the final review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants