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

Improve "SENTINEL FAILOVER" by using the "FAILOVER" command #1292

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from

Conversation

gmbnomis
Copy link
Contributor

This PR implements #1291 and consists of the following commits:

Two commits to fix problems with the sentinel tests:

Commit: Wait for all Sentinels to be connected before starting tests

Up to now the sentinel test initialization verified that all sentinels detect each other.
However, detection does not imply connection, which led to intermittent failures in the
coordinated failover tests (no leader elected since disconnected sentinels do not take part in a
vote).

Fix this by waiting until no sentinel reports being "disconnected".

Commit: sentinel-tests: Clean up config after config set tests

Three commits with the actual implementation:

Commit: Add option for coordinated failover to Sentinel (coordinated failover without leader election)
Commit: Allow Sentinel to recover from a stuck FAILOVER
Commit: SENTINEL FAILOVER COORDINATED actually does a leader election (adds leader election before failover starts)

Up to now the sentinel test initialization verified that all sentinels detect each other.
However, detection does not imply connection, which led to intermittent failures in the
coordinated failover tests (no leader elected since disconnected sentinels do not take part in a
vote).

Fix this by waiting until no sentinel reports being "disconnected".

Signed-off-by: Simon Baatz <[email protected]>
Valkey supports the "FAILOVER" command to switch primary and replica
roles in a coordinated fashion. Add a "COORDINATED" option to "SENTINEL
FAILOVER". When given, use "FAILOVER" in the Sentinel forced failover
procedure. Since we force the failover, i.e. we don't elect a leader,
the failover must succeed quickly before other Sentinels will regard
the primary as down.

Signed-off-by: Simon Baatz <[email protected]>
The FAILOVER command may ["encounter some scenarios it can not automatically remediate from and
may get stuck."](https://valkey.io/commands/failover/#failover-abort). The supervision of the
Sentinels is used to handle these situations:

1. "REPLICAOF" is not accepted during a failover. Thus, send a "FAILOVER ABORT" before sending a
   "REPLICAOF" to a node in `sentinelSendReplicaOf()`. (If there is no ongoing failover, the
   resulting error will just be ignored)
2. Sentinel monitors nodes for deviations from the expected state (wrong role or replication).
   Add a check for replicas that are in a failover state for too long and reconfigure them.

Signed-off-by: Simon Baatz <[email protected]>
Doing a proper leader election allows to increase the time available
for the actual FAILOVER command, as other Sentinels will not attempt
to initiate another failover during the failover timeout.

Interestingly, Sentinel does not take the reported primary up/down
status into account when counting replies to leader election. Thus,
Sentinel will simply proceed with the failover once we reach the
quorum even if we don't are in O_DOWN state.

Signed-off-by: Simon Baatz <[email protected]>
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 92 lines in your changes missing coverage. Please review.

Project coverage is 70.62%. Comparing base (2df56d8) to head (bde2e68).

Files with missing lines Patch % Lines
src/sentinel.c 0.00% 92 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1292      +/-   ##
============================================
- Coverage     70.69%   70.62%   -0.07%     
============================================
  Files           114      114              
  Lines         63161    63247      +86     
============================================
+ Hits          44650    44667      +17     
- Misses        18511    18580      +69     
Files with missing lines Coverage Δ
src/commands.def 100.00% <ø> (ø)
src/sentinel.c 0.00% <0.00%> (ø)

... and 11 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NEW] Improve "SENTINEL FAILOVER" by using the "FAILOVER" command
1 participant