Skip to content

feat(redis): add Redis Sentinel support for HA cache discovery#2618

Open
ex0a wants to merge 5 commits intomozilla:mainfrom
ex0a:feat/redis-sentinel
Open

feat(redis): add Redis Sentinel support for HA cache discovery#2618
ex0a wants to merge 5 commits intomozilla:mainfrom
ex0a:feat/redis-sentinel

Conversation

@ex0a
Copy link

@ex0a ex0a commented Feb 16, 2026

Adds Redis Sentinel support so sccache can discover the current master from a sentinel cluster instead of hardcoding a single Redis endpoint.

When endpoint starts with redis-sentinel://, sccache queries each sentinel node with SENTINEL GET-MASTER-ADDR-BY-NAME, connects to the discovered master, and builds the opendal operator against it.

URL format: redis-sentinel://[:password@]host1[:port1][,host2[:port2],...]/master_name[/db]

Example config:

[cache.redis]
endpoint = "redis-sentinel://sentinel1:26379,sentinel2:26379/mymaster"

username, password, and db config fields are ignored for sentinel URLs (embed credentials in the URL). A warning is logged if they're set.

URL parsing is extracted into parse_sentinel_url() with unit tests covering multi-node, password with @, db selection, and error cases.

@sylvestre
Copy link
Collaborator

sorry, it conflicts

@ex0a
Copy link
Author

ex0a commented Feb 16, 2026

What would you suggest? I'm using this personally but thought it might help someone else

@AJIOB
Copy link
Contributor

AJIOB commented Feb 17, 2026

Hi @ex0a ,

You should rebase your changes to the latest master branch changes or just merge them to your branch - and resolve the conflicts.

Then you need to push your changes to your branch.

That's should be fine!

@AJIOB
Copy link
Contributor

AJIOB commented Feb 17, 2026

CC @Xuanwo

IMO, we should implement the Redis Sentinel support as a part of the OpenDAL. And just use it here.

Possibly, it's already done.

@ex0a ex0a force-pushed the feat/redis-sentinel branch from d088922 to 5288c2d Compare February 17, 2026 10:52
@ex0a
Copy link
Author

ex0a commented Feb 17, 2026

Thanks for the review! I've pushed updates addressing both points:
Feature gating: redis has been restored to the all feature list and the redis crate dependency is now properly optional via dep:redis, so it won't be compiled in unless the redis feature is enabled. I've also removed the hard tracing dependency I accidentally added.
Credentials warning: Added a warn!() when username, password, or db are provided alongside a redis-sentinel:// URL, since those fields are ignored in sentinel mode (credentials should be embedded in the URL itself).
Regarding OpenDAL: I considered this approach, but OpenDAL's Redis service doesn't currently support Sentinel natively. My implementation handles discovery at the sccache layer — querying sentinels to resolve the current master address, then building a normal single-node OpenDAL connection to it. This keeps the OpenDAL layer unchanged and avoids requiring upstream OpenDAL changes. Happy to revisit if OpenDAL adds Sentinel support in the future.

@ex0a ex0a force-pushed the feat/redis-sentinel branch from 5288c2d to b477146 Compare February 17, 2026 10:59
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 8.69565% with 105 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.17%. Comparing base (67e1118) to head (acd6804).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/cache/redis.rs 0.00% 99 Missing ⚠️
src/cache/cache.rs 62.50% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2618      +/-   ##
==========================================
- Coverage   73.36%   73.17%   -0.20%     
==========================================
  Files          68       68              
  Lines       37337    37442     +105     
==========================================
+ Hits        27393    27397       +4     
- Misses       9944    10045     +101     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sylvestre
Copy link
Collaborator

please fix the jobs

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 4, 2026

Merging this PR will not alter performance

✅ 60 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing ex0a:feat/redis-sentinel (acd6804) with main (7b92ba4)2

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (67e1118) during the generation of this report, so 7b92ba4 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@ex0a
Copy link
Author

ex0a commented Mar 5, 2026

Hi @sylvestre — CodSpeed results came in: +3.56% improvement on normalize_win_path_utf8 (3.4 µs → 3.3 µs), no regressions. clippy, rustfmt, and taplo are all passing, and @AJIOB has approved. Let me know if there's anything else needed before merge.

Copilot AI review requested due to automatic review settings March 5, 2026 21:55
@sylvestre sylvestre force-pushed the feat/redis-sentinel branch from c16ad8b to 51c20d1 Compare March 5, 2026 21:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Redis Sentinel support for high-availability cache discovery in sccache. When an endpoint config value starts with redis-sentinel://, the code routes to a new build_sentinel() function that manually queries sentinel nodes using the SENTINEL GET-MASTER-ADDR-BY-NAME command, discovers the current master's address, then builds a normal Redis Operator pointed at that master.

Changes:

  • build_sentinel() added to RedisCache to parse sentinel URLs, query sentinels, and discover the master address
  • cache.rs updated to detect redis-sentinel:// endpoint URLs and route them to the sentinel builder
  • Cargo.toml updated to add the redis crate (for direct sentinel querying) and tracing as direct dependencies

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/cache/redis.rs Adds build_sentinel() which manually parses sentinel URLs and queries sentinels for master address
src/cache/cache.rs Routes redis-sentinel:// endpoint URLs to the new sentinel handler
Cargo.toml Adds redis crate (optional, feature-gated) and tracing (non-optional) as direct dependencies
Cargo.lock Reflects resolved dependency versions including redis 0.32.7 and updated tracing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@ex0a ex0a force-pushed the feat/redis-sentinel branch from 51c20d1 to fcfe986 Compare March 5, 2026 22:15
@ex0a
Copy link
Author

ex0a commented Mar 5, 2026

Rebased onto latest main and addressed all four Copilot findings:

  • Fixed the sentinel code path to actually call build_sentinel instead of build_from_url
  • Switched to rsplit_once('@') for password parsing so passwords containing @ don't break the URL split
  • Dropped the unused sentinel feature flag from the redis crate dep
  • Removed the stray tracing dependency

clippy, rustfmt, and taplo all pass clean.

ex0a added 5 commits March 6, 2026 09:14
- Add build_sentinel() function to discover Redis master via Sentinel
- Parse redis-sentinel://host:port,host2:port2/master_name URLs
- Query sentinels with SENTINEL GET-MASTER-ADDR-BY-NAME
- Add comprehensive logging for debugging discovery issues
- Support password auth and optional DB selection
- Route sentinel URLs from endpoint config path in cache.rs
- Warn when username/password/db are provided with sentinel URLs
- Fix redis feature gating with dep:redis
- Fix build_from_url -> build_sentinel call so sentinel discovery is
  actually used (cache.rs)
- Use rsplit_once('@') for password parsing to handle '@' in passwords
  (redis.rs)
- Remove unused `sentinel` feature flag from redis crate (Cargo.toml)
- Remove unnecessary `tracing` dependency (Cargo.toml)
Avoid set-then-unwrap pattern by binding the formatted message to a
local before moving it into last_error.
- Extract parse_sentinel_url() for testable URL parsing
- Add SentinelUrl struct for parsed components
- Add 9 unit tests: simple, multi-node, password, password-with-@,
  db selection, full URL, missing master, invalid db, no port
- Fix remaining set-then-unwrap in sentinel query/response error paths
- Use splitn(3, '/') to prevent over-splitting on db segment
- Add doc comments to build_sentinel with URL format spec
@ex0a ex0a force-pushed the feat/redis-sentinel branch from f37f161 to 5d433c2 Compare March 6, 2026 14:14
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.

5 participants