Skip to content

Optimize single-node master/replica reads#3758

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
redis:mainfrom
Sean-Kenneth-Doherty:codex/masterreplica-single-selection-fastpath
Open

Optimize single-node master/replica reads#3758
Sean-Kenneth-Doherty wants to merge 1 commit into
redis:mainfrom
Sean-Kenneth-Doherty:codex/masterreplica-single-selection-fastpath

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

@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: small performance-oriented change to the READ connection selection path plus a unit test; behavior only differs by skipping the open-filter/Flux pipeline when exactly one node is selected.

Overview
Optimizes master/replica READ connection selection by short-circuiting to a direct connection when ReadFrom resolves to exactly one node, avoiding construction/subscription of the Reactor Flux chain.

Updates the selection logic to only use the order-sensitive isOpen filtering path for multi-node selections, and adds a unit test ensuring the single-node path returns the connection directly without calling isOpen().

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

@Sean-Kenneth-Doherty
Copy link
Copy Markdown
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 [email protected] -- 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.

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

2 participants