Skip to content

Commit

Permalink
finish all update for these 4 commands
Browse files Browse the repository at this point in the history
Signed-off-by: hwware <wen.hui.ware@gmail.com>
  • Loading branch information
hwware committed Jul 16, 2024
1 parent 192447c commit 737cd6a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
12 changes: 7 additions & 5 deletions src/sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3727,11 +3727,11 @@ NULL
};
/* clang-format on */
addReplyHelp(c, help);
} else if (!strcasecmp(c->argv[1]->ptr, "primaries")) {
} else if (!strcasecmp(c->argv[1]->ptr, "primaries") || !strcasecmp(c->argv[1]->ptr, "masters")) {
/* SENTINEL PRIMARIES */
if (c->argc != 2) goto numargserr;
addReplyDictOfValkeyInstances(c, sentinel.primaries);
} else if (!strcasecmp(c->argv[1]->ptr, "primary")) {
} else if (!strcasecmp(c->argv[1]->ptr, "primary") || !strcasecmp(c->argv[1]->ptr, "master")) {
/* SENTINEL PRIMARY <name> */
sentinelValkeyInstance *ri;

Expand All @@ -3755,7 +3755,8 @@ NULL
} else if (!strcasecmp(c->argv[1]->ptr, "myid") && c->argc == 2) {
/* SENTINEL MYID */
addReplyBulkCBuffer(c, sentinel.myid, CONFIG_RUN_ID_SIZE);
} else if (!strcasecmp(c->argv[1]->ptr, "is-primary-down-by-addr")) {
} else if (!strcasecmp(c->argv[1]->ptr, "is-primary-down-by-addr") ||
!strcasecmp(c->argv[1]->ptr, "is-master-down-by-addr")) {
/* SENTINEL IS-PRIMARY-DOWN-BY-ADDR <ip> <port> <current-epoch> <runid>
*
* Arguments:
Expand Down Expand Up @@ -3807,7 +3808,8 @@ NULL
/* SENTINEL RESET <pattern> */
if (c->argc != 3) goto numargserr;
addReplyLongLong(c, sentinelResetPrimariesByPattern(c->argv[2]->ptr, SENTINEL_GENERATE_EVENT));
} else if (!strcasecmp(c->argv[1]->ptr, "get-primary-addr-by-name")) {
} else if (!strcasecmp(c->argv[1]->ptr, "get-primary-addr-by-name") ||
!strcasecmp(c->argv[1]->ptr, "get-master-addr-by-name")) {
/* SENTINEL GET-PRIMARY-ADDR-BY-NAME <primary-name> */
sentinelValkeyInstance *ri;

Expand Down Expand Up @@ -4483,7 +4485,7 @@ void sentinelAskPrimaryStateToOtherSentinels(sentinelValkeyInstance *primary, in
/* Ask */
ll2string(port, sizeof(port), primary->addr->port);
retval = redisAsyncCommand(
ri->link->cc, sentinelReceiveIsPrimaryDownReply, ri, "%s is-master-down-by-addr %s %s %llu %s",
ri->link->cc, sentinelReceiveIsPrimaryDownReply, ri, "%s is-primary-down-by-addr %s %s %llu %s",
sentinelInstanceMapCommand(ri, "SENTINEL"), announceSentinelAddr(primary->addr), port,
sentinel.current_epoch, (primary->failover_state > SENTINEL_FAILOVER_STATE_NONE) ? sentinel.myid : "*");
if (retval == C_OK) ri->link->pending_commands++;
Expand Down
28 changes: 14 additions & 14 deletions tests/sentinel/tests/00-base.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ test "SENTINEL PENDING-SCRIPTS returns the information about pending scripts" {
}

test "SENTINEL PRIMARIES returns a list of monitored primaries" {
assert_match "*mymaster*" [S 0 SENTINEL MASTERS]
assert_morethan_equal [llength [S 0 SENTINEL MASTERS]] 1
assert_match "*mymaster*" [S 0 SENTINEL PRIMARIES]
assert_morethan_equal [llength [S 0 SENTINEL PRIMARIES]] 1
}

test "SENTINEL SENTINELS returns a list of sentinel instances" {
assert_morethan_equal [llength [S 0 SENTINEL SENTINELS mymaster]] 1
}

test "SENTINEL SLAVES returns a list of the monitored replicas" {
assert_morethan_equal [llength [S 0 SENTINEL SLAVES mymaster]] 1
assert_morethan_equal [llength [S 0 SENTINEL REPLICAS mymaster]] 1
}

test "SENTINEL SIMULATE-FAILURE HELP list supported flags" {
Expand All @@ -77,20 +77,20 @@ test "SENTINEL SIMULATE-FAILURE HELP list supported flags" {

test "Basic failover works if the primary is down" {
set old_port [RPort $master_id]
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
assert {[lindex $addr 1] == $old_port}
kill_instance valkey $master_id
foreach_sentinel_id id {
S $id sentinel debug ping-period 500
S $id sentinel debug ask-period 500
wait_for_condition 1000 100 {
[lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
[lindex [S $id SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster] 1] != $old_port
} else {
fail "At least one Sentinel did not receive failover info"
}
}
restart_instance valkey $master_id
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
set master_id [get_instance_id_by_port valkey [lindex $addr 1]]
}

Expand Down Expand Up @@ -123,12 +123,12 @@ test "ODOWN is not possible without N (quorum) Sentinels reports" {
S $id SENTINEL SET mymaster quorum [expr $sentinels+1]
}
set old_port [RPort $master_id]
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
assert {[lindex $addr 1] == $old_port}
kill_instance valkey $master_id

# Make sure failover did not happened.
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
assert {[lindex $addr 1] == $old_port}
restart_instance valkey $master_id
}
Expand All @@ -147,7 +147,7 @@ test "Failover is not possible without majority agreement" {
kill_instance valkey $master_id

# Make sure failover did not happened.
set addr [S $quorum SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S $quorum SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
assert {[lindex $addr 1] == $old_port}
restart_instance valkey $master_id

Expand All @@ -165,23 +165,23 @@ test "Failover works if we configure for absolute agreement" {
# Wait for Sentinels to monitor the master again
foreach_sentinel_id id {
wait_for_condition 1000 100 {
[dict get [S $id SENTINEL MASTER mymaster] info-refresh] < 100000
[dict get [S $id SENTINEL PRIMARY mymaster] info-refresh] < 100000
} else {
fail "At least one Sentinel is not monitoring the master"
fail "At least one Sentinel is not monitoring the primary"
}
}

kill_instance valkey $master_id

foreach_sentinel_id id {
wait_for_condition 1000 100 {
[lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
[lindex [S $id SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster] 1] != $old_port
} else {
fail "At least one Sentinel did not receive failover info"
}
}
restart_instance valkey $master_id
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
set master_id [get_instance_id_by_port valkey [lindex $addr 1]]

# Set the min ODOWN agreement back to strict majority.
Expand All @@ -200,7 +200,7 @@ test "SENTINEL RESET can resets the primary" {
for {set j 0} {$j < 10} {incr j} {
assert_equal 1 [S 0 SENTINEL RESET mymaster]
set res1 [llength [S 0 SENTINEL SENTINELS mymaster]]
set res2 [llength [S 0 SENTINEL SLAVES mymaster]]
set res2 [llength [S 0 SENTINEL REPLICAS mymaster]]
set res3 [llength [S 0 SENTINEL REPLICAS mymaster]]
if {$res1 eq 0 && $res2 eq 0 && $res3 eq 0} break
}
Expand Down
8 changes: 4 additions & 4 deletions tests/sentinel/tests/01-conf-update.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "../tests/includes/init-tests.tcl"

test "We can failover with Sentinel 1 crashed" {
set old_port [RPort $master_id]
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
assert {[lindex $addr 1] == $old_port}

# Crash Sentinel 1
Expand All @@ -14,21 +14,21 @@ test "We can failover with Sentinel 1 crashed" {
foreach_sentinel_id id {
if {$id != 1} {
wait_for_condition 1000 50 {
[lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
[lindex [S $id SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster] 1] != $old_port
} else {
fail "Sentinel $id did not receive failover info"
}
}
}
restart_instance valkey $master_id
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
set master_id [get_instance_id_by_port valkey [lindex $addr 1]]
}

test "After Sentinel 1 is restarted, its config gets updated" {
restart_instance sentinel 1
wait_for_condition 1000 50 {
[lindex [S 1 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
[lindex [S 1 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster] 1] != $old_port
} else {
fail "Restarted Sentinel did not receive failover info"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/sentinel/tests/02-replicas-reconf.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test "Wait for failover to end" {
while {$inprogress} {
set inprogress 0
foreach_sentinel_id id {
if {[dict exists [S $id SENTINEL MASTER mymaster] failover-state]} {
if {[dict exists [S $id SENTINEL PRIMARY mymaster] failover-state]} {
incr inprogress
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/sentinel/tests/12-primary-reboot.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ proc reboot_instance {type id} {

test "Primary reboot in very short time" {
set old_port [RPort $master_id]
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
assert {[lindex $addr 1] == $old_port}

R $master_id debug populate 10000
Expand All @@ -59,13 +59,13 @@ test "Primary reboot in very short time" {

foreach_sentinel_id id {
wait_for_condition 1000 100 {
[lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
[lindex [S $id SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster] 1] != $old_port
} else {
fail "At least one Sentinel did not receive failover info"
}
}

set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
set addr [S 0 SENTINEL GET-PRIMARY-ADDR-BY-NAME mymaster]
set master_id [get_instance_id_by_port valkey [lindex $addr 1]]

# Make sure the instance load all the dataset
Expand All @@ -90,7 +90,7 @@ test "All the other slaves now point to the new primary" {
wait_for_condition 1000 50 {
[RI $id master_port] == [lindex $addr 1]
} else {
fail "Valkey ID $id not configured to replicate with new master"
fail "Valkey ID $id not configured to replicate with new primary"
}
}
}
Expand Down

0 comments on commit 737cd6a

Please sign in to comment.