Skip to content

[core][gcs][Actice-Passive] Phase 2.1 Add Active-Passive leader-election interface (protocol, status, client cache) - #65132

Merged
edoakes merged 6 commits into
ray-project:masterfrom
YoyinZyc:passive_interface
Aug 12, 2026
Merged

edoakes merged 6 commits into
ray-project:masterfrom
YoyinZyc:passive_interface

Conversation

@YoyinZyc

@YoyinZyc YoyinZyc commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

This is the foundational, interface-only PR for the Active-Passive GCS feature (split from the larger #64422). It introduces the wire-protocol field, status code, config flag, and client-side leadership-caching plumbing — all feature-gated behind LEADER_ELECT / RAY_LEADER_ELECT, which defaults to OFF. No server-side passive behavior is included here; this PR is pure additive scaffolding that later PRs build on.

Issue

#63643

High-level changes

Layer Change
Protocol Add optional bool is_leader = 4 to CheckAliveReply. Marked optional so a new client can distinguish "field absent" (an old GCS during a rolling upgrade) from an explicit false.
Status New StatusCode::GcsPassive (38) with Status::GcsPassive() and IsGcsPassive(), registered in the code↔string maps. No code path returns it yet.
Config New RAY_CONFIG(bool, LEADER_ELECT, false) (C++) and matching ray_constants.RAY_LEADER_ELECT (Python), kept in sync via the RAY_LEADER_ELECT env var.
C++ client NodeInfoAccessor caches an atomic<bool> is_gcs_leader_, updated from each CheckAlive reply (has_is_leader() ? is_leader() : true — absence is treated as the legacy leader). Exposes IsGcsLeader(). When LEADER_ELECT is off, it initializes to true and never changes (legacy behavior). The test-only default constructor sets client_impl_ = nullptr.
Python bindings GcsClient.is_gcs_leader_local() (reads the cache) and is_gcs_leader() (triggers a CheckAlive, then reads the cache). Both return True when RAY_LEADER_ELECT is off. check_status maps GcsPassive → RpcError(UNAVAILABLE).

Behavior change / backward compatibility

  • With LEADER_ELECT off (the default): zero observable change. is_gcs_leader() / is_gcs_leader_local() always return True; the GcsPassive status code and the is_leader field are never produced.
  • Wire compatibility: the new proto field is optional and defaults to absent, so old/new clients and servers interoperate during rolling upgrades (absence = legacy leader).
  • No public API signatures change; all additions are new symbols.

Test plan

Unit (C++) — accessor_test.cc

  • TestIsGcsLeaderCaching — cache defaults to true; store/load behave correctly.
  • TestLeaderElectionDisabledByDefault — with LEADER_ELECT off, the accessor always reports itself as leader regardless of any is_leader value (rolling-upgrade / legacy guard).
  • Command: bazel test //src/ray/gcs_rpc_client/tests:accessor_test → PASS

Integration (Python) — test_gcs_utils.py

  • test_is_gcs_leader_defaults — default path: both methods return True; and in a spawned subprocess with RAY_LEADER_ELECT=true, is_gcs_leader_local() starts as False (client-side cache init). The cross-layer server assertion is intentionally deferred to a later PR.
  • Command: python -m pytest python/ray/tests/test_gcs_utils.py::test_is_gcs_leader_defaults → PASS

@YoyinZyc
YoyinZyc requested a review from a team as a code owner July 30, 2026 17:19

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces support for active-passive GCS leader election for high availability in Ray. It adds a new GcsPassive status code, exposes is_gcs_leader and is_gcs_leader_local methods in the Python GCS client, and updates the C++ NodeInfoAccessor to cache and track GCS leadership status based on CheckAlive replies. Feedback on this PR highlights two main points: first, in gcs_client.pxi, the is_gcs_leader method should also catch RaySystemError to prevent unexpected crashes when GCS is unreachable; second, a comment in accessor.cc should be updated to correctly describe dereferencing a null pointer as undefined behavior rather than a "well-defined crash".

Comment thread python/ray/includes/gcs_client.pxi Resolved
Comment thread src/ray/gcs_rpc_client/accessor.cc Resolved
Comment thread src/ray/gcs_rpc_client/accessor.cc Resolved
Comment thread src/ray/protobuf/gcs_service.proto Resolved
Comment thread src/ray/gcs_rpc_client/accessor.h Resolved
@YoyinZyc

Copy link
Copy Markdown
Contributor Author

@rueian @ryanaoleary I break down the big pr #64422 into smaller pieces. Please take a look on this pr which focuses on API and proto. Thanks!

@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Jul 30, 2026
@rueian rueian self-assigned this Jul 30, 2026
@rueian rueian added the go add ONLY when ready to merge, run all tests label Jul 30, 2026
Comment thread src/ray/gcs_rpc_client/accessor.cc Resolved
Comment thread python/ray/_private/ray_constants.py Resolved
@rueian
rueian self-requested a review August 6, 2026 18:33
@YoyinZyc
YoyinZyc force-pushed the passive_interface branch from 1c1e47d to d19405c Compare August 6, 2026 18:39

@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 using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit d19405c. Configure here.

Comment thread python/ray/includes/gcs_client.pxi Resolved
@YoyinZyc
YoyinZyc force-pushed the passive_interface branch from d19405c to 2f02fe8 Compare August 6, 2026 18:53
@YoyinZyc YoyinZyc changed the title [core][gcs][Actice-Passive] Phase 2.1 Add Active-Passive leader-election interface (protocol, status, client cache)Passive interface [core][gcs][Actice-Passive] Phase 2.1 Add Active-Passive leader-election interface (protocol, status, client cache) Aug 6, 2026
Add an is_leader field to CheckAliveReply so the GCS server can report
whether it is the active leader in its health-check reply. This is the
wire-protocol foundation for the active-passive GCS feature.

The field is optional and defaults to false, so it is backward compatible:
old clients ignore it and new clients reading an old GCS see the default.

Signed-off-by: Yuchen Zhou <[email protected]>
Add a new StatusCode::GcsPassive (38) with the Status::GcsPassive()
factory and IsGcsPassive() predicate, and register it in the code<->string
maps. A passive (read-only) GCS server will return this status to reject
requests it cannot serve while not the active leader.

This commit only introduces the status code; no code path returns it yet,
so behavior is unchanged.

Signed-off-by: Yuchen Zhou <[email protected]>
…NodeInfoAccessor

Add the LEADER_ELECT config (default false, overridable via RAY_LEADER_ELECT)
and cache the GCS leadership status in NodeInfoAccessor. The accessor now
stores an atomic is_gcs_leader_ that is updated from each CheckAlive reply's
is_leader field, and exposes IsGcsLeader().

When LEADER_ELECT is disabled (the default), is_gcs_leader_ is initialized to
true and the accessor always reports itself as leader, preserving legacy
behavior for existing clusters and rolling upgrades.

Signed-off-by: Yuchen Zhou <[email protected]>
Expose the cached GCS leadership status to Python via the GcsClient
methods is_gcs_leader_local() (reads the cache) and is_gcs_leader()
(triggers a CheckAlive then reads the cache), and map the GcsPassive
status code in check_status.

When RAY_LEADER_ELECT is not set, both Python methods always return True,
matching legacy behavior.

Add C++ unit tests for the leadership cache (including a default-disabled
guard) and a Python test covering both the default and LEADER_ELECT-enabled
paths.

Signed-off-by: Yuchen Zhou <[email protected]>
@YoyinZyc
YoyinZyc force-pushed the passive_interface branch from 2f02fe8 to 8e52c36 Compare August 6, 2026 20:46
@YoyinZyc

YoyinZyc commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

The previous CI test failure seems unrelated. Rebased to see if it passes.

It was passed locally after rebase

➜  ray git:(passive_interface) ✗ cd /usr/local/google/home/yczhou/Projects/ray
source .venv13/bin/activate
mkdir -p /tmp/rt
export TMPDIR=/tmp/rt RAY_TMPDIR=/tmp/rt RAY_TRAIN_V2_ENABLED=0 RAY_DATA_USE_LEGACY_DATASET_IDS=1
python -m pytest python/ray/train/tests/test_state.py -v
============================================================= test session starts =============================================================
platform linux -- Python 3.13.14, pytest-9.0.3, pluggy-1.6.0 -- /usr/local/google/home/yczhou/Projects/ray/.venv13/bin/python
cachedir: .pytest_cache
rootdir: /usr/local/google/home/yczhou/Projects/ray
configfile: pytest.ini
plugins: aiohttp-1.1.0, anyio-4.13.0, asyncio-1.4.0, localserver-0.10.0, pytest_httpserver-1.1.5
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 8 items

python/ray/train/tests/test_state.py::test_schema_equivalance PASSED                                                                    [ 12%]
python/ray/train/tests/test_state.py::test_state_actor_api PASSED                                                                       [ 25%]
python/ray/train/tests/test_state.py::test_state_manager PASSED                                                                         [ 37%]
python/ray/train/tests/test_state.py::test_track_e2e_training[0] PASSED                                                                 [ 50%]
python/ray/train/tests/test_state.py::test_track_e2e_training[1] PASSED                                                                 [ 62%]
python/ray/train/tests/test_state.py::test_track_e2e_training[2] PASSED                                                                 [ 75%]
python/ray/train/tests/test_state.py::test_train_run_status[True] PASSED                                                                [ 87%]
python/ray/train/tests/test_state.py::test_train_run_status[False] PASSED                                                               [100%]

======================================================== 8 passed in 97.89s (0:01:37) =========================================================

@edoakes
edoakes merged commit 41e11a7 into ray-project:master Aug 12, 2026
6 checks passed
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…ion interface (protocol, status, client cache) (ray-project#65132)

## Description

This is the foundational, interface-only PR for the Active-Passive GCS
feature (split from the larger ray-project#64422). It introduces the wire-protocol
field, status code, config flag, and client-side leadership-caching
plumbing — all feature-gated behind `LEADER_ELECT` / `RAY_LEADER_ELECT`,
which **defaults to OFF**. No server-side passive behavior is included
here; this PR is pure additive scaffolding that later PRs build on.

## Issue
ray-project#63643

## High-level changes

| Layer | Change |
| :--- | :--- |
| **Protocol** | Add `optional bool is_leader = 4` to `CheckAliveReply`.
Marked `optional` so a new client can distinguish "field absent" (an old
GCS during a rolling upgrade) from an explicit `false`. |
| **Status** | New `StatusCode::GcsPassive` (38) with
`Status::GcsPassive()` and `IsGcsPassive()`, registered in the
code↔string maps. No code path returns it yet. |
| **Config** | New `RAY_CONFIG(bool, LEADER_ELECT, false)` (C++) and
matching `ray_constants.RAY_LEADER_ELECT` (Python), kept in sync via the
`RAY_LEADER_ELECT` env var. |
| **C++ client** | `NodeInfoAccessor` caches an `atomic<bool>
is_gcs_leader_`, updated from each `CheckAlive` reply (`has_is_leader()
? is_leader() : true` — absence is treated as the legacy leader).
Exposes `IsGcsLeader()`. When `LEADER_ELECT` is off, it initializes to
`true` and never changes (legacy behavior). The test-only default
constructor sets `client_impl_ = nullptr`. |
| **Python bindings** | `GcsClient.is_gcs_leader_local()` (reads the
cache) and `is_gcs_leader()` (triggers a `CheckAlive`, then reads the
cache). Both return `True` when `RAY_LEADER_ELECT` is off.
`check_status` maps `GcsPassive → RpcError(UNAVAILABLE)`. |

## Behavior change / backward compatibility

- **With `LEADER_ELECT` off (the default): zero observable change.**
`is_gcs_leader()` / `is_gcs_leader_local()` always return `True`; the
`GcsPassive` status code and the `is_leader` field are never produced.
- **Wire compatibility:** the new proto field is `optional` and defaults
to absent, so old/new clients and servers interoperate during rolling
upgrades (absence = legacy leader).
- **No public API signatures change**; all additions are new symbols.

## Test plan

**Unit (C++)** — accessor_test.cc
- `TestIsGcsLeaderCaching` — cache defaults to `true`; `store`/`load`
behave correctly.
- `TestLeaderElectionDisabledByDefault` — with `LEADER_ELECT` off, the
accessor always reports itself as leader regardless of any `is_leader`
value (rolling-upgrade / legacy guard).
- Command: `bazel test //src/ray/gcs_rpc_client/tests:accessor_test` →
**PASS**

**Integration (Python)** — test_gcs_utils.py
- `test_is_gcs_leader_defaults` — default path: both methods return
`True`; and in a spawned subprocess with `RAY_LEADER_ELECT=true`,
`is_gcs_leader_local()` starts as `False` (client-side cache init). The
cross-layer server assertion is intentionally deferred to a later PR.
- Command: `python -m pytest
python/ray/tests/test_gcs_utils.py::test_is_gcs_leader_defaults` →
**PASS**

---------

Signed-off-by: Yuchen Zhou <[email protected]>
Signed-off-by: 400Ping <[email protected]>
rueian added a commit that referenced this pull request Sep 15, 2026
…ion RPC gating (#65711)

## Description

This is the C++ RPC-gating layer for the Active-Passive GCS feature
(split from the larger #64422, following the interface PR #65132). It
adds the server-side mechanism that, when a GCS is **not** the active
leader, rejects mutating RPCs with `Status::GcsPassive()` while
forwarding bootstrap/read RPCs. Everything is gated behind
`LEADER_ELECT`, which **defaults to off**, so a normal single-GCS
cluster behaves exactly as before.

This PR intentionally contains **only the gating mechanism**. The
deferred-loading / promotion lifecycle (which flips a GCS from passive
to active, updates the `is_leader` and the clears the
`passive_local_node_`) and the end-to-end passive-head startup are in a
follow-up PR. Since the gcs hasn't connected with the leader election
model, setting `LEADER_ELECT` will not have gcs leader election
behavior.

AI assistance was used to prepare this change.

## Issue

#63643

## High-level changes

| Area | Change |
| :--- | :--- |
| **Leader-gated proxy handlers** | New gcs_leader_gated_handlers.h: a
per-service proxy (`LeaderGated*Handler`) that wraps each real GCS
service handler. `GCS_GATED_RPC` / `GCS_ALLOWED_RPC` macros make each
RPC's gated-or-allowed status a single, auditable line; adding a new RPC
to a service is a compile-time-enforced one-liner. |
| **GcsNodeManager leadership + passive cache** | Injects an
`is_leader_fn` (defaults to `[]{return true;}`), reports it in
`HandleCheckAlive` via `reply->set_is_leader(...)`, and adds an
in-memory `passive_local_node_` cache (`CachePassiveLocalNode`) so the
local head node is visible while passive and flushed through the normal
RegisterNode path on promotion. |
| **Centralized service registration** | All 14
`rpc_server_.RegisterService(...)` calls are moved out of the individual
`InitXxx()` methods into one `GcsServer::RegisterRpcServices()`, called
from `DoStart` after all managers are constructed. Gated services go
through `MaybeGate`; `RaySyncer` is registered in an explicit
"intentionally NOT gated" section with a documented rationale. |

## Test plan

**Unit (C++)** — new
- `gcs_leader_gated_handlers_test.cc`
- `gcs_node_manager_test.cc` 
-  `gcs_client_test.cc`

**Integration / backward-compat (C++)** — existing
- `gcs_server_rpc_test` 

**Real-cluster smoke (default config, `LEADER_ELECT` off)**
- ensure backward compatibility

---------

Signed-off-by: Yuchen Zhou <[email protected]>
Signed-off-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ion interface (protocol, status, client cache) (ray-project#65132)

## Description

This is the foundational, interface-only PR for the Active-Passive GCS
feature (split from the larger ray-project#64422). It introduces the wire-protocol
field, status code, config flag, and client-side leadership-caching
plumbing — all feature-gated behind `LEADER_ELECT` / `RAY_LEADER_ELECT`,
which **defaults to OFF**. No server-side passive behavior is included
here; this PR is pure additive scaffolding that later PRs build on.

## Issue
ray-project#63643

## High-level changes

| Layer | Change |
| :--- | :--- |
| **Protocol** | Add `optional bool is_leader = 4` to `CheckAliveReply`.
Marked `optional` so a new client can distinguish "field absent" (an old
GCS during a rolling upgrade) from an explicit `false`. |
| **Status** | New `StatusCode::GcsPassive` (38) with
`Status::GcsPassive()` and `IsGcsPassive()`, registered in the
code↔string maps. No code path returns it yet. |
| **Config** | New `RAY_CONFIG(bool, LEADER_ELECT, false)` (C++) and
matching `ray_constants.RAY_LEADER_ELECT` (Python), kept in sync via the
`RAY_LEADER_ELECT` env var. |
| **C++ client** | `NodeInfoAccessor` caches an `atomic<bool>
is_gcs_leader_`, updated from each `CheckAlive` reply (`has_is_leader()
? is_leader() : true` — absence is treated as the legacy leader).
Exposes `IsGcsLeader()`. When `LEADER_ELECT` is off, it initializes to
`true` and never changes (legacy behavior). The test-only default
constructor sets `client_impl_ = nullptr`. |
| **Python bindings** | `GcsClient.is_gcs_leader_local()` (reads the
cache) and `is_gcs_leader()` (triggers a `CheckAlive`, then reads the
cache). Both return `True` when `RAY_LEADER_ELECT` is off.
`check_status` maps `GcsPassive → RpcError(UNAVAILABLE)`. |

## Behavior change / backward compatibility

- **With `LEADER_ELECT` off (the default): zero observable change.**
`is_gcs_leader()` / `is_gcs_leader_local()` always return `True`; the
`GcsPassive` status code and the `is_leader` field are never produced.
- **Wire compatibility:** the new proto field is `optional` and defaults
to absent, so old/new clients and servers interoperate during rolling
upgrades (absence = legacy leader).
- **No public API signatures change**; all additions are new symbols.

## Test plan

**Unit (C++)** — accessor_test.cc
- `TestIsGcsLeaderCaching` — cache defaults to `true`; `store`/`load`
behave correctly.
- `TestLeaderElectionDisabledByDefault` — with `LEADER_ELECT` off, the
accessor always reports itself as leader regardless of any `is_leader`
value (rolling-upgrade / legacy guard).
- Command: `bazel test //src/ray/gcs_rpc_client/tests:accessor_test` →
**PASS**

**Integration (Python)** — test_gcs_utils.py
- `test_is_gcs_leader_defaults` — default path: both methods return
`True`; and in a spawned subprocess with `RAY_LEADER_ELECT=true`,
`is_gcs_leader_local()` starts as `False` (client-side cache init). The
cross-layer server assertion is intentionally deferred to a later PR.
- Command: `python -m pytest
python/ray/tests/test_gcs_utils.py::test_is_gcs_leader_defaults` →
**PASS**

---------

Signed-off-by: Yuchen Zhou <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ion RPC gating (ray-project#65711)

## Description

This is the C++ RPC-gating layer for the Active-Passive GCS feature
(split from the larger ray-project#64422, following the interface PR ray-project#65132). It
adds the server-side mechanism that, when a GCS is **not** the active
leader, rejects mutating RPCs with `Status::GcsPassive()` while
forwarding bootstrap/read RPCs. Everything is gated behind
`LEADER_ELECT`, which **defaults to off**, so a normal single-GCS
cluster behaves exactly as before.

This PR intentionally contains **only the gating mechanism**. The
deferred-loading / promotion lifecycle (which flips a GCS from passive
to active, updates the `is_leader` and the clears the
`passive_local_node_`) and the end-to-end passive-head startup are in a
follow-up PR. Since the gcs hasn't connected with the leader election
model, setting `LEADER_ELECT` will not have gcs leader election
behavior.

AI assistance was used to prepare this change.

## Issue

ray-project#63643

## High-level changes

| Area | Change |
| :--- | :--- |
| **Leader-gated proxy handlers** | New gcs_leader_gated_handlers.h: a
per-service proxy (`LeaderGated*Handler`) that wraps each real GCS
service handler. `GCS_GATED_RPC` / `GCS_ALLOWED_RPC` macros make each
RPC's gated-or-allowed status a single, auditable line; adding a new RPC
to a service is a compile-time-enforced one-liner. |
| **GcsNodeManager leadership + passive cache** | Injects an
`is_leader_fn` (defaults to `[]{return true;}`), reports it in
`HandleCheckAlive` via `reply->set_is_leader(...)`, and adds an
in-memory `passive_local_node_` cache (`CachePassiveLocalNode`) so the
local head node is visible while passive and flushed through the normal
RegisterNode path on promotion. |
| **Centralized service registration** | All 14
`rpc_server_.RegisterService(...)` calls are moved out of the individual
`InitXxx()` methods into one `GcsServer::RegisterRpcServices()`, called
from `DoStart` after all managers are constructed. Gated services go
through `MaybeGate`; `RaySyncer` is registered in an explicit
"intentionally NOT gated" section with a documented rationale. |

## Test plan

**Unit (C++)** — new
- `gcs_leader_gated_handlers_test.cc`
- `gcs_node_manager_test.cc` 
-  `gcs_client_test.cc`

**Integration / backward-compat (C++)** — existing
- `gcs_server_rpc_test` 

**Real-cluster smoke (default config, `LEADER_ELECT` off)**
- ensure backward compatibility

---------

Signed-off-by: Yuchen Zhou <[email protected]>
Signed-off-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community 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.

3 participants