client: add failover broadcast listener and sentinel active probe - #27
Open
chenshi5012 wants to merge 1 commit into
Open
client: add failover broadcast listener and sentinel active probe#27chenshi5012 wants to merge 1 commit into
chenshi5012 wants to merge 1 commit into
Conversation
Two complementary failover-detection enhancements:
1. Cluster mode – FailoverListener (JedisClusterInfoCache)
Subscribe to the '+switch-master' Pub/Sub channel on every start node.
When the server-side patch publishes a failover notification the listener
immediately calls renewClusterSlots() so that the slot cache is updated
in real time instead of waiting for the next periodic refresh cycle or
an error-driven MOVED/ASK redirect.
Key design points:
- One daemon FailoverListener thread per start node.
- Exponential back-off on reconnect (1s -> 30s cap).
- Performs an immediate slot refresh on (re-)connect to catch any
failover that occurred while the listener was disconnected.
- Can be disabled via setFailoverListenerEnabled(false).
- Properly cleaned up in close().
2. Sentinel mode – ActiveProbeTask (SentineledConnectionProvider)
A single-threaded ScheduledExecutorService calls
SENTINEL GETMASTERADDRBYNAME on every sentinel at a configurable
interval (default 10 s). If the returned master differs from the
current pool target, initMaster() is called immediately.
This provides a safety net for cases where the '+switch-master'
Pub/Sub notification is missed (e.g. network partition, sentinel
restart) and ensures the client converges to the correct master
within at most one probe interval.
Key design points:
- Interval configurable via the new probePeriodMillis constructor
parameter; set to <= 0 to disable.
- Iterates sentinels in order and stops at the first reachable one.
- Daemon thread, stopped in close().
Related: valkey-io/valkey#3881
Signed-off-by: chenshi5012 <chenshi5012@users.noreply.github.com>
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.
Summary
This PR adds two complementary failover-detection enhancements to the Java client, addressing the client-side aspect of valkey-io/valkey#3881.
Changes
1. Cluster mode —
FailoverListenerinJedisClusterInfoCacheA new inner class
FailoverListenersubscribes to the+switch-masterPub/Sub channel on every start node. When the server-side patch (valkey-io/valkey#4340) publishes a failover notification, the listener immediately callsrenewClusterSlots()to update the slot cache in real time.Key design points:
FailoverListenerthread per start node.setFailoverListenerEnabled(false)before first use.close().Before this change: clients discover master role changes only through
MOVED/ASKerrors or periodicCLUSTER SLOTSrefreshes, introducing latency proportional to the refresh interval.After this change: clients react within milliseconds of the failover notification being published.
2. Sentinel mode —
ActiveProbeTaskinSentineledConnectionProviderA single-threaded
ScheduledExecutorServiceperiodically callsSENTINEL GETMASTERADDRBYNAMEon every sentinel. If the returned master address differs from the current pool target,initMaster()is called immediately.Key design points:
probePeriodMillisconstructor parameter).probePeriodMillis <= 0to disable the probe entirely.close().Motivation: The existing
SentinelListenerrelies on the Pub/Sub+switch-masterevent. If the subscription connection is disrupted (network partition, sentinel restart), the client may not receive the notification. The active probe provides a safety net that guarantees convergence within at most one probe interval.Compatibility
FailoverListeneris started automatically afterdiscoverClusterNodesAndSlots()and can be disabled.Related