From 7a2c1cb4260f073ca157738a0c8d853d86fada6f Mon Sep 17 00:00:00 2001 From: hwware Date: Tue, 16 Jul 2024 18:08:18 +0000 Subject: [PATCH] finish all update for these 4 commands Signed-off-by: hwware --- src/sentinel.c | 12 +++++---- tests/sentinel/tests/00-base.tcl | 28 ++++++++++----------- tests/sentinel/tests/01-conf-update.tcl | 8 +++--- tests/sentinel/tests/02-replicas-reconf.tcl | 2 +- tests/sentinel/tests/12-primary-reboot.tcl | 8 +++--- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/sentinel.c b/src/sentinel.c index 12d94283f6..dda3a677d2 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -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 */ sentinelValkeyInstance *ri; @@ -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 * * Arguments: @@ -3807,7 +3808,8 @@ NULL /* SENTINEL RESET */ 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 */ sentinelValkeyInstance *ri; @@ -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++; diff --git a/tests/sentinel/tests/00-base.tcl b/tests/sentinel/tests/00-base.tcl index c9f23a5c34..6bfca2416c 100644 --- a/tests/sentinel/tests/00-base.tcl +++ b/tests/sentinel/tests/00-base.tcl @@ -57,8 +57,8 @@ 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" { @@ -66,7 +66,7 @@ test "SENTINEL SENTINELS returns a list of sentinel instances" { } 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" { @@ -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]] } @@ -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 } @@ -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 @@ -165,9 +165,9 @@ 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" } } @@ -175,13 +175,13 @@ test "Failover works if we configure for absolute agreement" { 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. @@ -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 } diff --git a/tests/sentinel/tests/01-conf-update.tcl b/tests/sentinel/tests/01-conf-update.tcl index e8550e9e33..a9a2e9e062 100644 --- a/tests/sentinel/tests/01-conf-update.tcl +++ b/tests/sentinel/tests/01-conf-update.tcl @@ -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 @@ -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" } diff --git a/tests/sentinel/tests/02-replicas-reconf.tcl b/tests/sentinel/tests/02-replicas-reconf.tcl index bc1d68eee9..4bf2a35d26 100644 --- a/tests/sentinel/tests/02-replicas-reconf.tcl +++ b/tests/sentinel/tests/02-replicas-reconf.tcl @@ -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 } } diff --git a/tests/sentinel/tests/12-primary-reboot.tcl b/tests/sentinel/tests/12-primary-reboot.tcl index 3d7c7c6ecb..3fb993564c 100644 --- a/tests/sentinel/tests/12-primary-reboot.tcl +++ b/tests/sentinel/tests/12-primary-reboot.tcl @@ -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 @@ -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 @@ -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" } } }