Skip to content

Fix RedisCluster topology recovery after routing changes - #3007

Closed
moosavimaleki wants to merge 2 commits into
phpredis:developfrom
moosavimaleki:fix/cluster-topology-recovery
Closed

moosavimaleki wants to merge 2 commits into
phpredis:developfrom
moosavimaleki:fix/cluster-topology-recovery

Conversation

@moosavimaleki

Copy link
Copy Markdown

RedisCluster can retain stale topology after MOVED redirects: updating one
slot does not update other moved slots or primary/replica relationships.
Recovery can also fail when the previous primary has no replicas.

This change refreshes the complete topology once per command after MOVED,
using the redirect target, known nodes, and configured seeds. If discovery
fails, the previous map remains available and the validated redirect is
followed for the affected slot.

Changes

  • Build and validate replacement maps before installing them.
  • Keep uncovered slots unmapped and reject overlapping slot ranges.
  • Reuse retained endpoint sockets and disconnect retired connections.
  • Preserve ASK behavior and protect WATCH/MULTI state.
  • Distinguish unsent commands from ambiguous writes; do not replay lost replies.
  • Add limited READONLY/CLUSTERDOWN recovery for ordinary commands, excluding
    scripts, distributed operations, and explicitly directed commands.
  • Preserve authentication during discovery and invalidate stale slot caches.

No public PHP API changes or background polling are introduced.

Validation

Tested with PHP 8.5.4 and Redis 8.0.5:

  • Redis and RedisCluster suites: 536 passed, 106 skipped, no failures.
  • 15 focused topology regressions passed under Valgrind, with no reported
    memory errors or definitely/indirectly/possibly lost allocations.
  • Repeated failovers and two-slot resharding passed, including cache,
    persistent connections, TLS, and ACL authentication.
  • Concurrent load tests executed 5.68 million measured commands without errors.

This overlaps with #2957 and #2958, and touches remapping paths also modified
by #2798 and #2655.

h-mousavi added 2 commits November 16, 2026 16:07
Build replacement slot maps before publishing them, preserve usable sockets,
and close retired connections. Refresh the full map once per command after
MOVED, with known-node discovery and a per-slot fallback if discovery fails.

Distinguish unsent commands from ambiguous writes and limit rejected-command
retries to ordinary commands. Preserve ASK and stateful command boundaries,
handle uncovered slots and empty endpoints, and invalidate stale slot caches.

Add deterministic topology regressions and a disposable-cluster integration
runner. Validate Redis and RedisCluster suites, repeated failovers, resharding,
TLS/ACL, cache/persistent combinations, and memory safety with Valgrind.
Remove the new READONLY/CLUSTERDOWN retry policy and unsent-command recovery.
Restore the existing develop transport helpers and command callers, keeping
only the bounded full-map refresh and its required topology safety changes.

Match the scope of the internal 6.3.0 master backport without importing its
legacy APIs. Keep authentication, cache invalidation, socket ownership, and
WATCH/MULTI protections. Remove tests for the excluded recovery policies.

Rebuild and validate the Redis and RedisCluster suites, focused Valgrind
regressions, and real TLS/ACL failovers and two-slot resharding. Do not repeat
load testing for this scope reduction.
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.

1 participant