← 输入框|github.com|刷新
Skip to content

fix(cluster): recover sharded pubsub topology after node reconnects - #3223

Merged
PavelPashov merged 10 commits into
redis:masterfrom
PavelPashov:fix/cluster-sharded-pubsub-topology-recovery
May 12, 2026
Merged

PavelPashov merged 10 commits into
redis:masterfrom
PavelPashov:fix/cluster-sharded-pubsub-topology-recovery

Conversation

@PavelPashov

@PavelPashov PavelPashov commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Describe your pull request here


Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Note

Medium Risk
Adds automatic background rediscovery triggered by node reconnection events, which changes cluster slot discovery behavior and could cause extra topology refreshes or missed exclusions under reconnection storms.

Overview
Improves cluster recovery by tracking post-ready node reconnection attempts and scheduling a de-duplicated background topology refresh once a configurable delay elapses, while excluding currently reconnecting node addresses from the refresh attempt.

Introduces ClusterReconnectionTracker (with unit tests) and wires it into RedisClusterSlots lifecycle/events (reconnecting/ready/end, node removal, unsubscribe, destroy) to maintain accurate reconnecting state.

Extends RedisClusterSlots.rediscover to optionally start from known nodes (before falling back to root nodes) and adds a new cluster option topologyRefreshOnReconnectionAttemptStrategy to control the refresh delay/behavior. Updates sharded pubsub E2E tests to use shared testUtils harness and exercise multiple failure scenarios (failover/node/proxy/shard) plus unsubscribe behavior.

Reviewed by Cursor Bugbot for commit aae8c63. Bugbot is set up for automated code reviews on this repo. Configure here.

@PavelPashov
PavelPashov marked this pull request as ready for review April 29, 2026 08:22
@PavelPashov
PavelPashov force-pushed the fix/cluster-sharded-pubsub-topology-recovery branch from 3cb7843 to 8281293 Compare April 29, 2026 10:33
Comment thread eslint.config.mjs Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 07c5cf1. Configure here.

@PavelPashov
PavelPashov force-pushed the fix/cluster-sharded-pubsub-topology-recovery branch from 07c5cf1 to aae8c63 Compare May 11, 2026 09:30

@nkaradzhov nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLGTM

@PavelPashov
PavelPashov merged commit 0460312 into redis:master May 12, 2026
18 checks passed
@PavelPashov
PavelPashov deleted the fix/cluster-sharded-pubsub-topology-recovery branch May 12, 2026 11:18
hellices added a commit to hellices/devguidesample that referenced this pull request Oct 24, 2026
직접 작성한 연결 재생성 코드를 제거하고 각 라이브러리가 공식 제공하는 방식으로 바꿨다.
- node-redis: 6.0.0(redis/node-redis#3223)의 topologyRefreshOnReconnectionAttemptStrategy로 노드 재연결 시 토폴로지를 다시 읽는다. 5.x는 Microsoft Learn·Azure 가이드의 연결 재생성 권고만 안내하고 ioredis slotsRefreshInterval을 대안으로 적었다.
- node-redis 예제는 connectTimeout·reconnectStrategy·commandOptions 기본값을 사용하고 v6 마이그레이션 영향을 정리했다.
- Smart client handoffs 지원 서버 목록에 Azure Managed Redis가 없음을 명시했다.
- Jedis·Spring Boot·Redisson 예제에 Azure 모범 사례와 공식 API·속성 출처를 붙였다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hellices added a commit to hellices/devguidesample that referenced this pull request Oct 24, 2026
* docs(redis): 클러스터링 정책 사례 재구성과 eviction·TTL 가이드 추가

Azure Managed Redis 사례 문서를 클러스터링 정책(OSS·Enterprise·Non-clustered)
중심으로 재구성했다. Node.js(node-redis, ioredis)와 Java(Lettuce, Jedis,
Spring Boot)의 정책별 연결 방식, Azure Cache for Redis에서 옮길 때 기존
연결 형태별 마이그레이션 판단, 기본 정책이 OSS라는 점을 한 문서에 정리하고
기존 장애 분석은 사례 장으로 보존했다.

eviction policy와 TTL 설계 가이드를 새 topic으로 추가했다. 기본값
volatile-lru, allkeys-lru 근사 LRU 동작, 캐시·세션·영구 저장소별 권장
정책과 클라이언트 TTL의 의미를 다룬다.

직접 작성한 그림은 topic sample에 Excalidraw 원본과 SVG로 두고 publish로
게시한다. 재구성으로 바뀐 기준선 구조는 pre-Pages inventory에 현재 문서의
대체 위치를 근거로 검토 기록했다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(redis): 사례 계보를 유지하고 정책 가이드를 자식 문서로 분리

기준선 문서를 대폭 확장하면 git 이름 변경 유사도가 1%로 떨어져
pre-Pages 계보 감사가 기준선 경로를 삭제로 판정했다. 사례 진입 문서는
기존 장애 분석 원문을 유지한 채 그림, 원인 분석 보강, 연결 재생성
방안을 더하고(유사도 46%), 정책·클라이언트·마이그레이션 정리는 같은
topic의 자식 가이드로 옮겼다. 교체한 방안 2의 기준선 구조 4건만
inventory에 검토 기록했다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(redis): 아키텍처 PNG를 한 곳에만 두고 참조

같은 Microsoft Learn 아키텍처 그림이 두 topic에 중복 저장되어 중복 자산 검사에 걸렸다. eviction 가이드는 클러스터링 정책 가이드의 이미지를 상대 경로로 참조한다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(redis): 연결 재생성 패턴의 명령 대기와 노드별 실패 추적 보완

PR 리뷰 지적에 따라 재생성 판단을 명령 결과와 분리했다. node-redis 5.11.0은 재연결 중 명령을 offline queue에 보관해 await가 끝나지 않을 수 있으므로 commandOptions.timeout으로 대기를 제한하고, 정상 샤드의 명령 성공이 다른 샤드의 실패 기록을 지우지 않도록 cluster.masters의 노드별 isReady를 타이머로 감시한다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(redis): 리뷰 반영 - 재생성 drain, TTL·OOM 표현, 원본 포트

- recreateCluster가 이전 client를 즉시 파기하지 않고 명령 timeout 뒤에 정리해 in-flight 요청 실패를 막는다.
- EXPIRE 재호출은 만료 시각을 재설정한다고 고치고 짧게 주면 앞당겨짐과 GT 옵션을 적었다.
- noeviction의 OOM은 메모리를 늘리는 쓰기에만 적용된다고 그림과 본문을 고쳤다.
- Enterprise/Enterprise Flash 원본 포트를 10000으로 구분했다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(redis): 요청 전체 시간 제한과 새 client 연결 제한 추가

PR 리뷰 지적에 따라 연결 재생성 패턴을 보완했다.
- node-redis 5.11.0의 commandOptions.timeout은 전송 전 queue 대기만 제한하므로 runRedis()로 응답 대기까지 포함한 요청 전체 시간을 제한하고, 가이드의 관련 설명도 고쳤다.
- 초기 connect도 reconnectStrategy로 재시도해 끝나지 않을 수 있으므로 새 client 연결에 시간 제한을 두고 실패 시 파기 후 다음 검사에서 다시 시도한다.
- client 세대별 진행 중 요청을 추적해 끝나거나 요청 제한 시간이 지난 뒤 이전 client를 정리한다.
- 시간 초과된 쓰기는 결과가 불확실하다는 주의와 멱등 쓰기 권장을 추가했다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(redis): 연결 복구를 라이브러리 공식 기능 기준으로 정리

직접 작성한 연결 재생성 코드를 제거하고 각 라이브러리가 공식 제공하는 방식으로 바꿨다.
- node-redis: 6.0.0(redis/node-redis#3223)의 topologyRefreshOnReconnectionAttemptStrategy로 노드 재연결 시 토폴로지를 다시 읽는다. 5.x는 Microsoft Learn·Azure 가이드의 연결 재생성 권고만 안내하고 ioredis slotsRefreshInterval을 대안으로 적었다.
- node-redis 예제는 connectTimeout·reconnectStrategy·commandOptions 기본값을 사용하고 v6 마이그레이션 영향을 정리했다.
- Smart client handoffs 지원 서버 목록에 Azure Managed Redis가 없음을 명시했다.
- Jedis·Spring Boot·Redisson 예제에 Azure 모범 사례와 공식 API·속성 출처를 붙였다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(redis): 방안 2의 설정 참조 문구 정리

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(redis): Java TLS 예제와 allkeys-lru 설명 보강

- Jedis 예제에 SslOptions(호스트 이름 검증)와 hostAndPortMapper를 적용하고 7.5.0 전후 동작 차이를 명시
- Lettuce OSS 예제에 Azure 가이드의 MappingSocketAddressResolver를 반영
- Spring Boot OSS에 ClientResourcesBuilderCustomizer 빈 예제 추가
- allkeys-lru가 항상 쓰기에 성공한다는 절대 표현을 수정

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants