Skip to content

feat(spider-storage): Add scheduler registration protocols and MariaDB implementation.#347

Merged
sitaowang1998 merged 7 commits into
y-scope:mainfrom
sitaowang1998:storage-scheduler
Jun 18, 2026
Merged

feat(spider-storage): Add scheduler registration protocols and MariaDB implementation.#347
sitaowang1998 merged 7 commits into
y-scope:mainfrom
sitaowang1998:storage-scheduler

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR:

  • Adds scheduler table in MariaDB, and its insertion and query.
  • Adds scheduler registration and get in gRPC.

Note

We assume at any given time, there is only one scheduler. The current registration removes all previous scheduler registration.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Adds new database tests.
  • GitHub workflows pass.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added scheduler registration and management support across the storage layer, including registering scheduler endpoints (IP + port), retrieving the full list of registered schedulers, and checking whether a scheduler is registered.
  • Tests

    • Added MariaDB coverage for scheduler registration, including verifying that a new registration replaces any previously registered scheduler entry.

@sitaowang1998
sitaowang1998 requested a review from a team as a code owner June 16, 2026 20:33
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds full-stack scheduler registration support: a new SchedulerRegistrationService gRPC proto with RegisterScheduler and GetSchedulers RPCs, a Rust SchedulerRegistrationManagement trait and RegisteredScheduler model, a MariaDB implementation with transactional upsert and table DDL, ServiceState forwarding methods, a mock connector, and integration tests.

Changes

Scheduler Registration Storage Support

Layer / File(s) Summary
gRPC proto service and message definitions
components/spider-proto/storage/storage.proto
Defines SchedulerRegistrationService with RegisterScheduler and GetSchedulers RPCs, all request/response message types, and SchedulerRegistrationError with an ErrCode enum.
Storage protocol trait, data model, and re-exports
components/spider-core/src/types.rs, components/spider-core/src/types/scheduler.rs, components/spider-storage/src/db/protocol.rs, components/spider-storage/src/db.rs
Adds RegisteredScheduler struct with id, ip_address, and port fields; introduces SchedulerRegistrationManagement async trait with register_scheduler, get_schedulers, and is_scheduler_registered methods; extends DbStorage supertrait; and re-exports the trait from db.rs.
MariaDB table DDL and implementation
components/spider-storage/src/db/mariadb.rs
Adds schedulers table DDL, wires table creation into connect, and implements SchedulerRegistrationManagement for MariaDbStorageConnector with transactional delete-then-insert registration, ordered retrieval with SchedulerRowProjection, IP string parsing, and existence checks.
ServiceState methods and MockDbConnector
components/spider-storage/src/state/service.rs, components/spider-storage/src/state/test_utils.rs
Adds register_scheduler and get_schedulers async methods to ServiceState forwarding to the DB connector and mapping errors to StorageServerError. Implements SchedulerRegistrationManagement for MockDbConnector with unreachable! stubs.
Integration tests
components/spider-storage/tests/mariadb_test.rs
Adds test_register_scheduler_replaces_previous_scheduler integration test verifying that re-registration removes the prior scheduler, changes the scheduler ID, and stores only the updated entry with correct IP and port.

Sequence Diagram(s)

sequenceDiagram
    participant Client as gRPC Client
    participant StorageServer as StorageServer (SchedulerRegistrationService)
    participant ServiceState
    participant MariaDbStorageConnector
    participant DB as MariaDB

    Client->>StorageServer: RegisterScheduler(ip_address, port)
    StorageServer->>ServiceState: register_scheduler(ip_address, port)
    ServiceState->>MariaDbStorageConnector: register_scheduler(ip_address, port)
    MariaDbStorageConnector->>DB: BEGIN TRANSACTION
    MariaDbStorageConnector->>DB: DELETE FROM schedulers
    MariaDbStorageConnector->>DB: INSERT (ip_address, port)
    DB-->>MariaDbStorageConnector: SchedulerId
    MariaDbStorageConnector->>DB: COMMIT
    MariaDbStorageConnector-->>ServiceState: Ok(SchedulerId)
    ServiceState-->>StorageServer: Ok(SchedulerId)
    StorageServer-->>Client: RegisterSchedulerResponse { scheduler }

    Client->>StorageServer: GetSchedulers()
    StorageServer->>ServiceState: get_schedulers()
    ServiceState->>MariaDbStorageConnector: get_schedulers()
    MariaDbStorageConnector->>DB: SELECT * FROM schedulers ORDER BY id
    DB-->>MariaDbStorageConnector: Vec<RegisteredScheduler>
    MariaDbStorageConnector-->>ServiceState: Ok(Vec<RegisteredScheduler>)
    ServiceState-->>StorageServer: Ok(Vec<RegisteredScheduler>)
    StorageServer-->>Client: GetSchedulersResponse { scheduler_registrations }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • LinZhihao-723
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The pull request title accurately describes the main changes: adding scheduler registration protocols and MariaDB implementation to the storage layer.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/spider-storage/src/db/mariadb.rs`:
- Around line 599-619: The register_scheduler function performs a DELETE
followed by INSERT within a transaction, but concurrent invocations can
interleave causing multiple schedulers to be registered simultaneously,
violating the single-active-scheduler invariant. Fix this by ensuring the DELETE
and INSERT operations are atomic and exclusive: either use a higher transaction
isolation level (SERIALIZABLE), add row-level locking with SELECT FOR UPDATE on
a singleton control row, or modify the logic to use an atomic REPLACE/UPDATE
statement that naturally enforces the single-active constraint. Additionally,
the same concurrency issue exists in the code referenced at line 738-744 (Also
applies to), so apply the same singleton-enforcing mechanism there to ensure
both locations consistently prevent multiple active schedulers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7edf5154-2274-4510-af3c-c0e9fe4ba3d4

📥 Commits

Reviewing files that changed from the base of the PR and between da8f574 and 9f92765.

⛔ Files ignored due to path filters (1)
  • components/spider-proto-rust/src/generated/storage.rs is excluded by !**/generated/**
📒 Files selected for processing (7)
  • components/spider-proto/storage/storage.proto
  • components/spider-storage/src/db.rs
  • components/spider-storage/src/db/mariadb.rs
  • components/spider-storage/src/db/protocol.rs
  • components/spider-storage/src/state/service.rs
  • components/spider-storage/src/state/test_utils.rs
  • components/spider-storage/tests/mariadb_test.rs

Comment thread components/spider-storage/src/db/mariadb.rs

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
components/spider-storage/src/state/test_utils.rs (1)

256-273: ⚡ Quick win

Implement scheduler registration methods for testability.

All three SchedulerRegistrationManagement methods are stubbed with unreachable!(), which will panic if called by any test. This prevents unit testing of ServiceState scheduler methods and is inconsistent with other mock trait implementations in this file (e.g., ExecutionManagerLivenessManagement at lines 217-254).

Consider implementing a simple in-memory mock similar to the execution manager implementation using Arc<DashMap<SchedulerId, RegisteredScheduler>> and an atomic counter for ID generation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/spider-storage/src/state/test_utils.rs` around lines 256 - 273,
The three methods register_scheduler, get_schedulers, and
is_scheduler_registered in the SchedulerRegistrationManagement trait
implementation for MockDbConnector are stubbed with unreachable!() macros, which
will panic if called during tests. Replace these stubs with actual in-memory
mock implementations using Arc<DashMap> to store registered schedulers and an
atomic counter for generating unique SchedulerIds (similar to the
ExecutionManagerLivenessManagement implementation pattern already in the file).
The register_scheduler method should generate a new ID and store the scheduler
entry, get_schedulers should return all stored scheduler entries, and
is_scheduler_registered should check if a given ID exists in the map.
components/spider-storage/src/db/protocol.rs (1)

432-471: ⚡ Quick win

Consider whether get_schedulers return type matches the singleton constraint.

The documentation at line 437 states that "only one scheduler can be registered at a time," and the PR objectives confirm this design assumption. However, get_schedulers returns Vec<RegisteredScheduler>, which suggests support for multiple schedulers.

If the singleton constraint is a temporary limitation and multiple schedulers may be supported in the future, the Vec return type provides forward compatibility. Otherwise, consider returning Option<RegisteredScheduler> to make the single-scheduler constraint explicit in the API signature.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/spider-storage/src/db/protocol.rs` around lines 432 - 471, The
SchedulerRegistrationManagement trait's get_schedulers method returns
Vec<RegisteredScheduler>, which contradicts the documented singleton constraint
that states only one scheduler can be registered at a time. To align the API
signature with the documented design constraint, change the return type of the
get_schedulers method from Vec<RegisteredScheduler> to
Option<RegisteredScheduler>. This makes the single-scheduler limitation explicit
in the type system and clarifies to API consumers that only zero or one
scheduler can be registered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@components/spider-storage/src/db/protocol.rs`:
- Around line 432-471: The SchedulerRegistrationManagement trait's
get_schedulers method returns Vec<RegisteredScheduler>, which contradicts the
documented singleton constraint that states only one scheduler can be registered
at a time. To align the API signature with the documented design constraint,
change the return type of the get_schedulers method from
Vec<RegisteredScheduler> to Option<RegisteredScheduler>. This makes the
single-scheduler limitation explicit in the type system and clarifies to API
consumers that only zero or one scheduler can be registered.

In `@components/spider-storage/src/state/test_utils.rs`:
- Around line 256-273: The three methods register_scheduler, get_schedulers, and
is_scheduler_registered in the SchedulerRegistrationManagement trait
implementation for MockDbConnector are stubbed with unreachable!() macros, which
will panic if called during tests. Replace these stubs with actual in-memory
mock implementations using Arc<DashMap> to store registered schedulers and an
atomic counter for generating unique SchedulerIds (similar to the
ExecutionManagerLivenessManagement implementation pattern already in the file).
The register_scheduler method should generate a new ID and store the scheduler
entry, get_schedulers should return all stored scheduler entries, and
is_scheduler_registered should check if a given ID exists in the map.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5a457c28-75d3-441c-9cfd-5fbe45efd336

📥 Commits

Reviewing files that changed from the base of the PR and between 9f92765 and be5d3d4.

📒 Files selected for processing (7)
  • components/spider-core/src/types.rs
  • components/spider-core/src/types/scheduler.rs
  • components/spider-storage/src/db.rs
  • components/spider-storage/src/db/mariadb.rs
  • components/spider-storage/src/db/protocol.rs
  • components/spider-storage/src/state/service.rs
  • components/spider-storage/src/state/test_utils.rs
💤 Files with no reviewable changes (1)
  • components/spider-storage/src/db.rs
✅ Files skipped from review due to trivial changes (1)
  • components/spider-core/src/types.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/spider-storage/src/db/mariadb.rs

@LinZhihao-723 LinZhihao-723 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes I made:

  • Move RegisteredScheduler into spider-core. This type should be shared across other crates. And it's not the best idea to depend on spider-storage for type sharing.
  • The mock DB connector for the service doesn't make sense: the correctness of this service purely depends on the DB layer implementation; the service doesn't do anything but forward the request. These test cases are not actually testing the service, but testing wheteher ur mock DB connector is "mocking" the intentional behavior, lol. Removed them all for cleaning.


message GetSchedulersResponse {
oneof result {
SchedulerRegistrations schedulers = 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand why we need session ID in SchedulerRegistrations, but this is why also needed for GetSchedulersResponse?

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.

This is likely the first function the execution manager calls. It can get the session id the first chance it has.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The first call is EM registration, right?
We should probably design this API to be session-independent since it might be called multiple times through the lifetime of an EM.

@LinZhihao-723 LinZhihao-723 changed the title feat(spider-storage): Add scheduler registration. feat(spider-storage): Add scheduler registration protocols and MariaDB implementation. Jun 18, 2026

@LinZhihao-723 LinZhihao-723 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Directly modified the PR title.

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.

2 participants