Skip to content

[core] Combine RedisClient into RedisStoreClient - #55655

Merged
edoakes merged 55 commits into
ray-project:masterfrom
edoakes:eoakes/mv-redis-client
Aug 19, 2025
Merged

edoakes merged 55 commits into
ray-project:masterfrom
edoakes:eoakes/mv-redis-client

Conversation

@edoakes

@edoakes edoakes commented Aug 15, 2025 •

Copy link
Copy Markdown
Collaborator
  • RedisClient was a thin and meaningless abstraction over RedisContext, so now the RedisStoreClient uses the RedisContext directly.
  • The only other user of RedisClient was the "periodic health checker." I've moved this into RedisStoreClient as well.
  • Also removed some unnecessary child classes: InMemoryGcsTableStorage, RedisGcsTableStorage.

Before merging I plan to fold the RayConfig options used in RedisStoreClient into the RedisClientOptions.

Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
@edoakes
edoakes requested a review from a team as a code owner August 15, 2025 16:34
@edoakes
edoakes marked this pull request as draft August 15, 2025 16:34
@edoakes edoakes changed the title [WIP [WIP][core] Make redis client private to store_client/ Aug 15, 2025
gemini-code-assist[bot]

This comment was marked as outdated.

edoakes added 22 commits August 15, 2025 11:36
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Aug 19, 2025
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Comment thread src/ray/gcs/BUILD.bazel
Comment on lines -49 to -57
ray_cc_library(
name = "gcs",
deps = [
":gcs_callback",
":gcs_pb_util",
":gcs_redis_client",
"//src/ray/rpc:node_manager_client",
],
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Unused (and we shouldn't have vague/bloated targets like this)

Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
gcs_publisher_ = std::make_unique<gcs::GcsPublisher>(std::move(publisher));
gcs_table_storage_ = std::make_unique<gcs::InMemoryGcsTableStorage>();
gcs_table_storage_ =
std::make_unique<gcs::GcsTableStorage>(std::make_unique<InMemoryStoreClient>());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should be ObservableStoreClient

I have bigger questions on the value of the ObservableStoreClient in its current state and what it provides beyond the io context stats... but don't need to go there rn...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah it should get nuked

for this test though I don't think it matters which we use

int port;

// Redis username and password.
std::string username = "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: the empty strings should be unnecessary as the default ctor for strings does this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

true, but I like it specifying it explicitly to signal to the reader that they're optional

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

actually, I don't think this is even true because this is a struct. so the ones without explicit defaults must be specified.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(correct me if I'm wrong)


/// Get or connect to a redis server
std::shared_ptr<RedisClient> CreateRedisClient(instrumented_io_context &io_service);
std::unique_ptr<RedisStoreClient> CreateRedisStoreClient(

@ZacAttack ZacAttack Aug 19, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So a rabbit hole I've been down lately is that we make liberal use of instrumented_io_context in a lot of places where we don't seem to intend to use the instrumentation. Will we always use the instrumentation when creating a redis client (though I realize it was doing so before)? If not we can just use the raw boost one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

For completeness I think we should leave it in for now given this is the only real visibility we have into an issue such as the redis client slowing down.

This and @dayshah's point above make it clear that we don't have a solid observability story for these clients...

@ZacAttack ZacAttack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like a good cleanup! Just left the one question

@edoakes
edoakes merged commit 46bded1 into ray-project:master Aug 19, 2025
dioptre pushed a commit to sourcetable/ray that referenced this pull request Aug 20, 2025
- `RedisClient` was a thin and meaningless abstraction over
`RedisContext`, so now the `RedisStoreClient` uses the `RedisContext`
directly.
- The only other user of `RedisClient` was the "periodic health
checker." I've moved this into `RedisStoreClient` as well.
- Also removed some unnecessary child classes:
`InMemoryGcsTableStorage`, `RedisGcsTableStorage`.

Before merging I plan to fold the `RayConfig` options used in
`RedisStoreClient` into the `RedisClientOptions`.

---------

Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Andrew Grosser <[email protected]>
edoakes added a commit that referenced this pull request Aug 22, 2025
TSAN tests are failing after my refactor PR:
#55655

This is because the `PeriodicalRunner` does not wait for any spawned
async tasks to complete in its destructor. In the current setup, after
the `PeriodicalRunner` is destroyed, the `RedisStoreClient` is
immediately destroyed. However, there may still be tasks on the IO
service that didn't get cancelled and will try to access the
`RedisStoreClient`, leading to invalid memory accesses.

Simplest fix is to move the `PeriodicalRunner` back to `gcs_server.cc`
and capture a shared pointer to the client in the callback. I also
considered fixing the `PeriodicalRunner` destructor, but that code is
hard to navigate right now.

---------

Signed-off-by: Edward Oakes <[email protected]>
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
- `RedisClient` was a thin and meaningless abstraction over
`RedisContext`, so now the `RedisStoreClient` uses the `RedisContext`
directly.
- The only other user of `RedisClient` was the "periodic health
checker." I've moved this into `RedisStoreClient` as well.
- Also removed some unnecessary child classes:
`InMemoryGcsTableStorage`, `RedisGcsTableStorage`.

Before merging I plan to fold the `RayConfig` options used in
`RedisStoreClient` into the `RedisClientOptions`.

---------

Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: jugalshah291 <[email protected]>
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
…oject#55812)

TSAN tests are failing after my refactor PR:
ray-project#55655

This is because the `PeriodicalRunner` does not wait for any spawned
async tasks to complete in its destructor. In the current setup, after
the `PeriodicalRunner` is destroyed, the `RedisStoreClient` is
immediately destroyed. However, there may still be tasks on the IO
service that didn't get cancelled and will try to access the
`RedisStoreClient`, leading to invalid memory accesses.

Simplest fix is to move the `PeriodicalRunner` back to `gcs_server.cc`
and capture a shared pointer to the client in the callback. I also
considered fixing the `PeriodicalRunner` destructor, but that code is
hard to navigate right now.

---------

Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: jugalshah291 <[email protected]>
dstrodtman pushed a commit that referenced this pull request Oct 6, 2025
- `RedisClient` was a thin and meaningless abstraction over
`RedisContext`, so now the `RedisStoreClient` uses the `RedisContext`
directly.
- The only other user of `RedisClient` was the "periodic health
checker." I've moved this into `RedisStoreClient` as well.
- Also removed some unnecessary child classes:
`InMemoryGcsTableStorage`, `RedisGcsTableStorage`.

Before merging I plan to fold the `RayConfig` options used in
`RedisStoreClient` into the `RedisClientOptions`.

---------

Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman pushed a commit that referenced this pull request Oct 6, 2025
TSAN tests are failing after my refactor PR:
#55655

This is because the `PeriodicalRunner` does not wait for any spawned
async tasks to complete in its destructor. In the current setup, after
the `PeriodicalRunner` is destroyed, the `RedisStoreClient` is
immediately destroyed. However, there may still be tasks on the IO
service that didn't get cancelled and will try to access the
`RedisStoreClient`, leading to invalid memory accesses.

Simplest fix is to move the `PeriodicalRunner` back to `gcs_server.cc`
and capture a shared pointer to the client in the callback. I also
considered fixing the `PeriodicalRunner` destructor, but that code is
hard to navigate right now.

---------

Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
- `RedisClient` was a thin and meaningless abstraction over
`RedisContext`, so now the `RedisStoreClient` uses the `RedisContext`
directly.
- The only other user of `RedisClient` was the "periodic health
checker." I've moved this into `RedisStoreClient` as well.
- Also removed some unnecessary child classes:
`InMemoryGcsTableStorage`, `RedisGcsTableStorage`.

Before merging I plan to fold the `RayConfig` options used in
`RedisStoreClient` into the `RedisClientOptions`.

---------

Signed-off-by: Edward Oakes <[email protected]>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
…oject#55812)

TSAN tests are failing after my refactor PR:
ray-project#55655

This is because the `PeriodicalRunner` does not wait for any spawned
async tasks to complete in its destructor. In the current setup, after
the `PeriodicalRunner` is destroyed, the `RedisStoreClient` is
immediately destroyed. However, there may still be tasks on the IO
service that didn't get cancelled and will try to access the
`RedisStoreClient`, leading to invalid memory accesses.

Simplest fix is to move the `PeriodicalRunner` back to `gcs_server.cc`
and capture a shared pointer to the client in the callback. I also
considered fixing the `PeriodicalRunner` destructor, but that code is
hard to navigate right now.

---------

Signed-off-by: Edward Oakes <[email protected]>
edoakes pushed a commit that referenced this pull request Jun 24, 2026
…64204)

## Description

While testing, `gcs_server` crashed with a SIGSEGV during a Redis
connection error (failover). Looking for a fix I found #48781, which
solves it by reconnecting to Redis, but it was closed as stale without
being merged. Its main blocker at the time (a dependency cycle in the
GCS Redis client) has since been resolved by #49000 and #55655, so this
PR ports that reconnect approach onto the current version.

When the Redis connection is lost, an in-flight request retries against
the released connection and dereferences a null pointer, crashing the
GCS. This PR reconnects to Redis when the connection is dead so requests
retry on a healthy connection instead of crashing.


## Related issues

- Fixes #53475
- Based on #48781 by @MortalHappiness (closed without merge); credit for
the original design.

## Additional information

Reproduction:
1. Run a cluster with GCS fault tolerance backed by an HA Redis.
2. While the cluster is up, trigger a Redis primary failover e.g.
kill/replace the Redis primary so a replica is promoted.
3. Before this PR, `gcs_server` exits with signal 11 and the head pod
restarts; after this PR it reconnects to the new primary and continues.

The exact crash we observed:

```
2026-06-18 04:54:00,110 ERROR scripts.py:1219 -- Some Ray subprocesses exited unexpectedly:
  gcs_server [exit code=-11 (signal 11)]

[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: *** SIGSEGV received at time=1781726136 on cpu 0 ***
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: PC: @     0x55719802efb8  (unknown)  ray::gcs::RedisRequestContext::RedisResponseFn()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x7f6c34fb6520  (unknown)  (unknown)
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719802f1f9       1168  ray::gcs::RedisRequestContext::Run()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719801a748        224  ray::gcs::RedisStoreClient::AsyncCheckHealth()
```

---

## Update:
I first took the reconnect approach above, but a robust in-place
reconnect needs `Connect()` to be non-fatal (it `RAY_CHECK`s today, so a
transient failover still aborts `gcs_server`) - the larger refactor that
stalled #48781. So this PR instead takes the minimal fix: null-guard the
dereference so the request fails gracefully instead of crashing, and GCS
fault tolerance recovers as today. Full reconnect is left as a follow-up
(#48781).

Signed-off-by: Dongjun Na <[email protected]>
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
…ay-project#64204)

## Description

While testing, `gcs_server` crashed with a SIGSEGV during a Redis
connection error (failover). Looking for a fix I found ray-project#48781, which
solves it by reconnecting to Redis, but it was closed as stale without
being merged. Its main blocker at the time (a dependency cycle in the
GCS Redis client) has since been resolved by ray-project#49000 and ray-project#55655, so this
PR ports that reconnect approach onto the current version.

When the Redis connection is lost, an in-flight request retries against
the released connection and dereferences a null pointer, crashing the
GCS. This PR reconnects to Redis when the connection is dead so requests
retry on a healthy connection instead of crashing.


## Related issues

- Fixes ray-project#53475
- Based on ray-project#48781 by @MortalHappiness (closed without merge); credit for
the original design.

## Additional information

Reproduction:
1. Run a cluster with GCS fault tolerance backed by an HA Redis.
2. While the cluster is up, trigger a Redis primary failover e.g.
kill/replace the Redis primary so a replica is promoted.
3. Before this PR, `gcs_server` exits with signal 11 and the head pod
restarts; after this PR it reconnects to the new primary and continues.

The exact crash we observed:

```
2026-06-18 04:54:00,110 ERROR scripts.py:1219 -- Some Ray subprocesses exited unexpectedly:
  gcs_server [exit code=-11 (signal 11)]

[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: *** SIGSEGV received at time=1781726136 on cpu 0 ***
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: PC: @     0x55719802efb8  (unknown)  ray::gcs::RedisRequestContext::RedisResponseFn()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x7f6c34fb6520  (unknown)  (unknown)
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719802f1f9       1168  ray::gcs::RedisRequestContext::Run()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719801a748        224  ray::gcs::RedisStoreClient::AsyncCheckHealth()
```

---

## Update:
I first took the reconnect approach above, but a robust in-place
reconnect needs `Connect()` to be non-fatal (it `RAY_CHECK`s today, so a
transient failover still aborts `gcs_server`) - the larger refactor that
stalled ray-project#48781. So this PR instead takes the minimal fix: null-guard the
dereference so the request fails gracefully instead of crashing, and GCS
fault tolerance recovers as today. Full reconnect is left as a follow-up
(ray-project#48781).

Signed-off-by: Dongjun Na <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…ay-project#64204)

## Description

While testing, `gcs_server` crashed with a SIGSEGV during a Redis
connection error (failover). Looking for a fix I found ray-project#48781, which
solves it by reconnecting to Redis, but it was closed as stale without
being merged. Its main blocker at the time (a dependency cycle in the
GCS Redis client) has since been resolved by ray-project#49000 and ray-project#55655, so this
PR ports that reconnect approach onto the current version.

When the Redis connection is lost, an in-flight request retries against
the released connection and dereferences a null pointer, crashing the
GCS. This PR reconnects to Redis when the connection is dead so requests
retry on a healthy connection instead of crashing.

## Related issues

- Fixes ray-project#53475
- Based on ray-project#48781 by @MortalHappiness (closed without merge); credit for
the original design.

## Additional information

Reproduction:
1. Run a cluster with GCS fault tolerance backed by an HA Redis.
2. While the cluster is up, trigger a Redis primary failover e.g.
kill/replace the Redis primary so a replica is promoted.
3. Before this PR, `gcs_server` exits with signal 11 and the head pod
restarts; after this PR it reconnects to the new primary and continues.

The exact crash we observed:

```
2026-06-18 04:54:00,110 ERROR scripts.py:1219 -- Some Ray subprocesses exited unexpectedly:
  gcs_server [exit code=-11 (signal 11)]

[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: *** SIGSEGV received at time=1781726136 on cpu 0 ***
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: PC: @     0x55719802efb8  (unknown)  ray::gcs::RedisRequestContext::RedisResponseFn()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x7f6c34fb6520  (unknown)  (unknown)
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719802f1f9       1168  ray::gcs::RedisRequestContext::Run()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719801a748        224  ray::gcs::RedisStoreClient::AsyncCheckHealth()
```

---

## Update:
I first took the reconnect approach above, but a robust in-place
reconnect needs `Connect()` to be non-fatal (it `RAY_CHECK`s today, so a
transient failover still aborts `gcs_server`) - the larger refactor that
stalled ray-project#48781. So this PR instead takes the minimal fix: null-guard the
dereference so the request fails gracefully instead of crashing, and GCS
fault tolerance recovers as today. Full reconnect is left as a follow-up
(ray-project#48781).

Signed-off-by: Dongjun Na <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants