Sentinel: re-elect primary on failover between already-known nodes#3130
Open
rebaseandpanic wants to merge 1 commit into
Open
Sentinel: re-elect primary on failover between already-known nodes#3130rebaseandpanic wants to merge 1 commit into
rebaseandpanic wants to merge 1 commit into
Conversation
SwitchPrimary only reconfigured when the new primary was an unknown endpoint. On an in-place failover (old master demoted, replica promoted), the new master is already in `servers`, so it no-op'd and the client kept writing to the demoted node until restart. Reconfigure with reconfigureAll:true when a known primary's cached role is stale, so connected nodes re-read their role before re-election. Also move the switch reconfigure out of the sentinelConnectionChildren lock. Refs StackExchange#1891
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On an in-place Sentinel failover (the current primary is demoted to a replica
without changing endpoint, and a known replica is promoted), the client never
switches to the new primary and keeps writing to the demoted node until restart.
Seen in production on a Sentinel-managed Valkey deployment on Kubernetes (pods
not recreated): a Redis Streams consumer stayed pinned to the demoted node for
hours until the process was restarted.
SwitchPrimaryonly reconfigured when the new primary was an endpoint it hadnever seen (
!servers.Contains(...)). When the promoted node is already known,that guard is false and it returns without re-electing. A plain reconfigure also
isn't enough: with
reconfigureAll: falsean already-connected node doesn'tre-read its role, so the election just re-picks the stale node.
Fix: when a known primary's cached view is stale, reconfigure with
reconfigureAll: trueso connected nodes re-read their role first (the guard isself-clearing — no reconfigure storm). Also run that reconfigure outside the
sentinelConnectionChildrenlock so one service's failover doesn't block others.Refs #1891 — the failure logs there show this known-endpoint failover, despite
the title mentioning IP changes; the separate new-primary-IP path is untouched.