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)

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

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

Project coverage is 70.68%. Comparing base (33f42d7) to head (55473d8).
Report is 16 commits behind head on unstable.

Files with missing lines Patch % Lines
src/sentinel.c 0.00% 98 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1292      +/-   ##
============================================
- Coverage     70.76%   70.68%   -0.09%     
============================================
  Files           116      118       +2     
  Lines         63300    63478     +178     
============================================
+ Hits          44793    44867      +74     
- Misses        18507    18611     +104     
Files with missing lines Coverage Δ
src/commands.def 100.00% <ø> (ø)
src/sentinel.c 0.00% <0.00%> (ø)

... and 30 files with indirect coverage changes

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.

In addition, monitoring the failover state is used to find out whether the FAILOVER command
is supported by the Valkey instance. If not, don't use "FAILOVER" or "FAILOVER ABORT".

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]>
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