Skip to content

Commit

Permalink
Replace master-reboot-down-after-period with primary-reboot-down-afte…
Browse files Browse the repository at this point in the history
…r-period in sentinel.conf (#647)

Update sentinel.conf config parameter,

From:

SENTINEL master-reboot-down-after-period mymaster 0

To:

SENTINEL primary-reboot-down-after-period myprimary 0

But we still keep the backward compatibility, clients could use SENTINEL
master-reboot-down-after-period mymaster 0 OR
SENTINEL primary-reboot-down-after-period myprimary 0

---------

Signed-off-by: hwware <[email protected]>
  • Loading branch information
hwware authored Jul 15, 2024
1 parent dd4bd50 commit 1a8bd04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
10 changes: 5 additions & 5 deletions sentinel.conf
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ SENTINEL resolve-hostnames no
#
SENTINEL announce-hostnames no

# When master_reboot_down_after_period is set to 0, Sentinel does not fail over
# when receiving a -LOADING response from a master. This was the only supported
# behavior before version 7.0.
# When primary-reboot-down-after-period is set to 0, Sentinel does not fail over
# when receiving a -LOADING response from a primary. This was the only supported
# behavior before Redis OSS 7.0.
#
# Otherwise, Sentinel will use this value as the time (in ms) it is willing to
# accept a -LOADING response after a master has been rebooted, before failing
# accept a -LOADING response after a primary has been rebooted, before failing
# over.

SENTINEL master-reboot-down-after-period mymaster 0
SENTINEL primary-reboot-down-after-period myprimary 0
14 changes: 9 additions & 5 deletions src/sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,9 @@ const char *sentinelHandleConfiguration(char **argv, int argc) {
if ((sentinel.announce_hostnames = yesnotoi(argv[1])) == -1) {
return "Please specify yes or no for the announce-hostnames option.";
}
} else if (!strcasecmp(argv[0], "master-reboot-down-after-period") && argc == 3) {
} else if ((!strcasecmp(argv[0], "primary-reboot-down-after-period") ||
!strcasecmp(argv[0], "master-reboot-down-after-period")) &&
argc == 3) {
/* primary-reboot-down-after-period <name> <milliseconds> */
ri = sentinelGetPrimaryByName(argv[1]);
if (!ri) return "No such master with specified name.";
Expand Down Expand Up @@ -2058,9 +2060,9 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {

/* sentinel primary-reboot-down-after-period */
if (primary->primary_reboot_down_after_period != 0) {
line = sdscatprintf(sdsempty(), "sentinel master-reboot-down-after-period %s %ld", primary->name,
line = sdscatprintf(sdsempty(), "sentinel primary-reboot-down-after-period %s %ld", primary->name,
(long)primary->primary_reboot_down_after_period);
rewriteConfigRewriteLine(state, "sentinel master-reboot-down-after-period", line, 1);
rewriteConfigRewriteLine(state, "sentinel primary-reboot-down-after-period", line, 1);
/* rewriteConfigMarkAsProcessed is handled after the loop */
}

Expand Down Expand Up @@ -2184,7 +2186,7 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
rewriteConfigMarkAsProcessed(state, "sentinel known-replica");
rewriteConfigMarkAsProcessed(state, "sentinel known-sentinel");
rewriteConfigMarkAsProcessed(state, "sentinel rename-command");
rewriteConfigMarkAsProcessed(state, "sentinel master-reboot-down-after-period");
rewriteConfigMarkAsProcessed(state, "sentinel primary-reboot-down-after-period");
}

/* This function uses the config rewriting in order to persist
Expand Down Expand Up @@ -4249,7 +4251,9 @@ void sentinelSetCommand(client *c) {
dictAdd(ri->renamed_commands, oldname, newname);
}
changes++;
} else if (!strcasecmp(option, "master-reboot-down-after-period") && moreargs > 0) {
} else if ((!strcasecmp(option, "primary-reboot-down-after-period") ||
!strcasecmp(option, "master-reboot-down-after-period")) &&
moreargs > 0) {
/* primary-reboot-down-after-period <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o, &ll) == C_ERR || ll < 0) {
Expand Down
10 changes: 6 additions & 4 deletions tests/sentinel/tests/12-master-reboot.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ test "Primary reboot in very short time" {
R $master_id config rewrite

foreach_sentinel_id id {
S $id SENTINEL SET mymaster master-reboot-down-after-period 5000
S $id sentinel debug ping-period 500
S $id sentinel debug ask-period 500
foreach role {master primary} {
S $id SENTINEL SET mymaster $role-reboot-down-after-period 5000
S $id sentinel debug ping-period 500
S $id sentinel debug ask-period 500
}
}

kill_instance valkey $master_id
Expand Down Expand Up @@ -100,4 +102,4 @@ test "The old primary eventually gets reconfigured as a slave" {
} else {
fail "Old master not reconfigured as slave of new master"
}
}
}

0 comments on commit 1a8bd04

Please sign in to comment.