Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger manual failover on SIGTERM / shutdown to cluster primary #1091

Open
wants to merge 31 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6ab8888
Trigger manual failover on SIGTERM / shutdown to cluster primary
enjoy-binbin Sep 30, 2024
4b49f03
fix typo
enjoy-binbin Sep 30, 2024
f9ca731
Merge remote-tracking branch 'upstream/unstable' into shutdown_failover
enjoy-binbin Oct 6, 2024
df0ef8d
add comment in the test
enjoy-binbin Oct 6, 2024
594fd5a
Merge remote-tracking branch 'upstream/unstable' into shutdown_failover
enjoy-binbin Oct 21, 2024
519eb2a
removing mf_is_primary_failover
enjoy-binbin Oct 21, 2024
32043dd
try to fix test
enjoy-binbin Oct 27, 2024
e7b33fa
try to stable the test
enjoy-binbin Oct 27, 2024
d6649e5
Move the logic to clusterHandleServerShutdown
enjoy-binbin Oct 27, 2024
64831c9
Adjust the tests
enjoy-binbin Oct 28, 2024
b06a8c4
Do shutdown failover only when offset is match
enjoy-binbin Oct 28, 2024
5f7b429
Merge remote-tracking branch 'upstream/unstable' into shutdown_failover
enjoy-binbin Jan 8, 2025
e56a360
remove count++ and fix confilct
enjoy-binbin Jan 8, 2025
0ccc4e4
Merge remote-tracking branch 'upstream/unstable' into shutdown_failover
enjoy-binbin Jan 23, 2025
c9bfd69
CLUSTER FAILOVER replicaid node-id
enjoy-binbin Jan 23, 2025
c8037a1
code review v1
enjoy-binbin Jan 24, 2025
d70036b
Merge remote-tracking branch 'upstream/unstable' into shutdown_failover
enjoy-binbin Feb 5, 2025
7d55db6
code review: remove error reply check, add cross-version test
enjoy-binbin Feb 5, 2025
4d5da8a
fix format and add log to debug the test
enjoy-binbin Feb 7, 2025
a1f957c
Update valkey.conf
enjoy-binbin Feb 7, 2025
37147e8
minor fixes in regexp, avoid matching the second line
enjoy-binbin Feb 7, 2025
bf60ed6
Merge remote-tracking branch 'upstream/unstable' into shutdown_failover
enjoy-binbin Feb 7, 2025
27b6f6d
code review from Ping
enjoy-binbin Feb 11, 2025
61dd999
Merge remote-tracking branch 'upstream/unstable' into shutdown_failover
enjoy-binbin Feb 11, 2025
8423921
Fix test
enjoy-binbin Feb 11, 2025
ed8c9bb
Merge remote-tracking branch 'upstream/unstable' into shutdown_failover
enjoy-binbin Feb 25, 2025
9e00910
change to use replconf set-cluster-node-id
enjoy-binbin Feb 25, 2025
8cba555
Update valkey.conf
enjoy-binbin Feb 25, 2025
ade48cb
Change nodeid to sds
enjoy-binbin Feb 25, 2025
6b5cf7f
code review from Ping, add the assert <= 128
enjoy-binbin Feb 25, 2025
e3fdb7c
Fix the index
enjoy-binbin Feb 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/support/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ proc check_replica_acked_ofs {primary replica_ip replica_port} {
return 0
}

proc wait_replica_acked_ofs {primary replica_ip replica_port} {
proc wait_replica_acked_ofs {primary replica replica_ip replica_port} {
$primary config set repl-ping-replica-period 3600
$replica config set hz 500
wait_for_condition 50 100 {
[check_replica_acked_ofs $primary $replica_ip $replica_port] eq 1
} else {
puts "INFO REPLICATION: [$primary info replication]"
fail "replica acked offset didn't match in time"
}
$primary config set repl-ping-replica-period 10
$replica config set hz 10
}

proc wait_for_ofs_sync {r1 r2} {
Expand Down
40 changes: 28 additions & 12 deletions tests/unit/cluster/auto-failover-on-shutdown.tcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
proc shutdown_on_how {srv_id how} {
proc shutdown_how {srv_id how} {
if {$how == "shutdown"} {
catch {R $srv_id shutdown nosave}
} elseif {$how == "sigterm"} {
Expand All @@ -9,15 +9,18 @@ proc shutdown_on_how {srv_id how} {
# We will start a cluster with 3 primary nodes and 4 replicas, the primary 1 will have 2 replicas.
# We will pause the replica 1, and then shutdown the primary 1, and making replica 2 to become
# the new primary.
proc test_main {how} {
test "auto-failover-on-shutdown will always pick a best replica and send CLUSTER FAILOVER - $how" {
proc test_main {how shutdown_timeout} {
test "auto-failover-on-shutdown will always pick a best replica and send CLUSTER FAILOVER - $how - shutdown-timeout: $shutdown_timeout" {
set primary [srv 0 client]
set replica1 [srv -3 client]
set replica1_pid [s -3 process_id]
set replica2 [srv -6 client]
set replica2_ip [srv -6 host]
set replica2_port [srv -6 port]

$primary config set auto-failover-on-shutdown yes
$primary config set shutdown-timeout $shutdown_timeout

# Pause a replica so it has no chance to catch up with the offset.
pause_process $replica1_pid

Expand All @@ -26,12 +29,17 @@ proc test_main {how} {
$primary incr key_991803
}

# Wait the replica2 catch up with the offset
wait_for_ofs_sync $primary $replica2
wait_replica_acked_ofs $primary $replica2_ip $replica2_port
if {$shutdown_timeout != 0} {
# Wait the replica2 catch up with the offset
wait_for_ofs_sync $primary $replica2
wait_replica_acked_ofs $primary $replica2 $replica2_ip $replica2_port
} else {
# If shutdown-timeout is enable, we expect the primary to pause writing
# and wait for the replica to catch up with the offset.
}

# Shutdown the primary.
shutdown_on_how 0 $how
shutdown_how 0 $how

# Wait for the replica2 to become a primary.
wait_for_condition 1000 50 {
Expand All @@ -56,17 +64,25 @@ proc test_main {how} {
pause_process $replica1_pid

$primary client kill type replica
shutdown_on_how 6 $how
shutdown_how 6 $how
wait_for_log_messages -6 {"*Unable to find a replica to perform an auto failover on shutdown*"} 0 1000 10

resume_process $replica1_pid
}
}

start_cluster 3 4 {tags {external:skip cluster} overrides {cluster-ping-interval 1000 cluster-node-timeout 5000 shutdown-timeout 0 auto-failover-on-shutdown yes}} {
test_main "shutdown"
start_cluster 3 4 {tags {external:skip cluster}} {
test_main "shutdown" 0
}

start_cluster 3 4 {tags {external:skip cluster}} {
test_main "sigterm" 0
}

start_cluster 3 4 {tags {external:skip cluster}} {
test_main "shutdown" 10
}

start_cluster 3 4 {tags {external:skip cluster} overrides {cluster-ping-interval 1000 cluster-node-timeout 5000 shutdown-timeout 0 auto-failover-on-shutdown yes}} {
test_main "sigterm"
start_cluster 3 4 {tags {external:skip cluster}} {
test_main "sigterm" 10
}