Skip to content

Optimize single-node master/replica reads#3758

Merged
a-TODO-rov merged 2 commits into
redis:mainfrom
Sean-Kenneth-Doherty:codex/masterreplica-single-selection-fastpath
May 20, 2026
Merged

Optimize single-node master/replica reads#3758
a-TODO-rov merged 2 commits into
redis:mainfrom
Sean-Kenneth-Doherty:codex/masterreplica-single-selection-fastpath

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown
Contributor

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty commented May 17, 2026

Summary

  • return the selected connection directly when ReadFrom resolves to exactly one node
  • avoid building/subscribing a Reactor Flux chain on the single-node hot path
  • add a unit test that verifies the single-node path bypasses the old open-filter path

Fixes #3744.

Verification

  • ~/.local/share/mise/installs/maven/3.9.11/apache-maven-3.9.11/bin/mvn -Dtest=io.lettuce.core.masterreplica.MasterReplicaConnectionProviderUnitTests test
    • Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Note: mvn via the mise shim was not configured in this shell, so I used the installed Maven 3.9.11 binary directly.


Note

Low Risk
Low risk behavioral change limited to ReadFrom read selection when it resolves to a single node; it mainly skips Reactor assembly and isOpen filtering, with a unit test covering the new path.

Overview
Optimizes master/replica read connection selection by short-circuiting when ReadFrom resolves to exactly one node, returning that node’s connection directly instead of building a Reactor Flux chain.

This removes the redundant single-node isOpen/fallback logic from the reactive selection path and adds a unit test (shouldUseDirectConnectionForSingleReadSelection) to assert the direct-connection behavior (and that isOpen() is not consulted).

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

@Sean-Kenneth-Doherty
Copy link
Copy Markdown
Contributor Author

Local validation on head 7a4a1621d4cf8cd57b795f85edad7e1080c13324:

  • inspected the patch; it only touches MasterReplicaConnectionProvider and the corresponding unit test
  • the fast path returns the sole selected node directly before building/filtering the Reactor connection sequence
  • the new unit test covers ReadFrom.ANY with a single selected node and verifies the returned connection is the node connection while isOpen() is not called
  • mise x maven@3.9.11 -- mvn -Dtest=MasterReplicaConnectionProviderUnitTests test -> build success; 2 tests run, 0 failures, 0 errors
  • git diff --check origin/main...HEAD -> clean

Hosted PR checks currently show no failures; only Cursor Bugbot and Jit Security are configured on this PR.

@a-TODO-rov
Copy link
Copy Markdown
Contributor

Thanks @Sean-Kenneth-Doherty
@atakavci do you think we can merge this ?
It looks good to me.

@atakavci
Copy link
Copy Markdown
Collaborator

hey, seems pretty good to me.
thank you @Sean-Kenneth-Doherty 🙏

@a-TODO-rov a-TODO-rov merged commit 33d46af into redis:main May 20, 2026
13 checks passed
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.

Performance: small optimisation in MasterReplica connections

3 participants