Repository navigation
[core][gcs][Actice-Passive] Phase 2.1 Add Active-Passive leader-election interface (protocol, status, client cache) - #65132
Conversation
There was a problem hiding this comment.
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".
|
@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! |
1c1e47d to
d19405c
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit d19405c. Configure here.
d19405c to
2f02fe8
Compare
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]>
Signed-off-by: Yuchen Zhou <[email protected]>
2f02fe8 to
8e52c36
Compare
|
The previous CI test failure seems unrelated. Rebased to see if it passes. It was passed locally after rebase |
…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]>
…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]>
…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]>
…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]>

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
optional bool is_leader = 4toCheckAliveReply. Markedoptionalso a new client can distinguish "field absent" (an old GCS during a rolling upgrade) from an explicitfalse.StatusCode::GcsPassive(38) withStatus::GcsPassive()andIsGcsPassive(), registered in the code↔string maps. No code path returns it yet.RAY_CONFIG(bool, LEADER_ELECT, false)(C++) and matchingray_constants.RAY_LEADER_ELECT(Python), kept in sync via theRAY_LEADER_ELECTenv var.NodeInfoAccessorcaches anatomic<bool> is_gcs_leader_, updated from eachCheckAlivereply (has_is_leader() ? is_leader() : true— absence is treated as the legacy leader). ExposesIsGcsLeader(). WhenLEADER_ELECTis off, it initializes totrueand never changes (legacy behavior). The test-only default constructor setsclient_impl_ = nullptr.GcsClient.is_gcs_leader_local()(reads the cache) andis_gcs_leader()(triggers aCheckAlive, then reads the cache). Both returnTruewhenRAY_LEADER_ELECTis off.check_statusmapsGcsPassive → RpcError(UNAVAILABLE).Behavior change / backward compatibility
LEADER_ELECToff (the default): zero observable change.is_gcs_leader()/is_gcs_leader_local()always returnTrue; theGcsPassivestatus code and theis_leaderfield are never produced.optionaland defaults to absent, so old/new clients and servers interoperate during rolling upgrades (absence = legacy leader).Test plan
Unit (C++) — accessor_test.cc
TestIsGcsLeaderCaching— cache defaults totrue;store/loadbehave correctly.TestLeaderElectionDisabledByDefault— withLEADER_ELECToff, the accessor always reports itself as leader regardless of anyis_leadervalue (rolling-upgrade / legacy guard).bazel test //src/ray/gcs_rpc_client/tests:accessor_test→ PASSIntegration (Python) — test_gcs_utils.py
test_is_gcs_leader_defaults— default path: both methods returnTrue; and in a spawned subprocess withRAY_LEADER_ELECT=true,is_gcs_leader_local()starts asFalse(client-side cache init). The cross-layer server assertion is intentionally deferred to a later PR.python -m pytest python/ray/tests/test_gcs_utils.py::test_is_gcs_leader_defaults→ PASS