Skip to content

feat(spider-storage): Add gRPC service implementation:#364

Merged
LinZhihao-723 merged 34 commits into
y-scope:mainfrom
sitaowang1998:storage-grpc-services
Jul 5, 2026
Merged

feat(spider-storage): Add gRPC service implementation:#364
LinZhihao-723 merged 34 commits into
y-scope:mainfrom
sitaowang1998:storage-grpc-services

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator
  • InboundQueueService
  • ResourceGroupManagementService
  • ExecutionManagerLivenessService
  • SessionManagementService

Description

This PR

  • Adds the storage server implementation for InboundQueue, ResourceGroupManagement and SchedulerRegistration services.
  • Adds request unpack for the two services.
  • Refactors common error handling into helper functions.

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

  • GitHub workflows pass.

Summary by CodeRabbit

Summary

  • New Features
    • Added scheduler registration support, including scheduler registration/query handling and protobuf-to-storage conversion.
    • Implemented additional storage gRPC RPCs (ready-task polling, resource-group management, execution-manager liveness, and session retrieval).
  • Bug Fixes
    • Strengthened request validation with consistent InvalidArgument handling for IP/port/time inputs.
    • Updated resource-group authentication so wrong passwords now return UNAUTHENTICATED.
    • Improved unexpected internal error handling across storage service adapters.
    • Removed a stale-session storage error variant.
  • Tests
    • Added/updated unit and RPC tests covering conversions and error mapping.

sitaowang1998 and others added 20 commits June 26, 2026 16:31
# Conflicts:
#	components/spider-proto-rust/src/generated/storage.rs
#	components/spider-proto/storage/storage.proto
#	components/spider-scheduler/src/storage_client/grpc.rs
@sitaowang1998
sitaowang1998 requested a review from a team as a code owner June 29, 2026 04:26
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds storage-side proto unpacking and scheduler conversion support, updates shared gRPC error handling, and implements previously missing storage RPC handlers.

Changes

Storage gRPC RPC Implementations

Layer / File(s) Summary
Proto request unpacking and scheduler conversion
components/spider-proto-rust/src/lib.rs, components/spider-proto-rust/src/scheduler_registration.rs, components/spider-proto-rust/src/unpack/storage.rs
Exposes scheduler_registration, adds From<RegisteredScheduler> for storage::Scheduler, and implements request unpacking for resource-group, execution-manager, scheduler, and ready-task polling requests.
Shared error helpers and mapping
components/spider-storage/src/grpc.rs, components/spider-storage/src/state.rs, components/spider-scheduler/src/error.rs
Updates gRPC error mapping, adds shared internal-status helpers, removes StorageClientError::StaleSession, and makes test_utils crate-visible.
RPC handlers and readiness response building
components/spider-storage/src/grpc.rs
Implements polling, resource-group, execution-manager, scheduler, and session RPCs, and adds ready-task response construction.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • y-scope/spider#323: Adds the same resource-group, execution-manager, and ready-task service flow on the API side.
  • y-scope/spider#340: Adds client-side requests that correspond to the new server-side unpacking and handlers here.
  • y-scope/spider#358: Touches the same gRPC error-mapping and stale-session handling paths.

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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: implementing additional gRPC services in spider-storage.
✨ 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.

@sitaowang1998

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sitaowang1998

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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-proto-rust/src/unpack/storage.rs`:
- Around line 203-205: Reject port 0 during unpacking in `Storage::unpack` so
invalid scheduler registrations fail early instead of being stored and
advertised. Update the existing `u16::try_from(self.port)` validation to also
return `invalid_argument` when `self.port` is zero, while keeping the current
fit-in-`u16` check for `port` intact. Use the `Storage::unpack` path and the
`invalid_argument` helper as the key places to adjust.
🪄 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: 0e0c1e47-489f-4d0b-8dd5-6a680c432743

📥 Commits

Reviewing files that changed from the base of the PR and between c0fe56f and 3ec8e32.

📒 Files selected for processing (6)
  • components/spider-proto-rust/src/lib.rs
  • components/spider-proto-rust/src/scheduler_registration.rs
  • components/spider-proto-rust/src/unpack/storage.rs
  • components/spider-scheduler/src/error.rs
  • components/spider-storage/src/grpc.rs
  • components/spider-storage/src/state.rs
💤 Files with no reviewable changes (1)
  • components/spider-scheduler/src/error.rs

Comment on lines +203 to +205
let port = u16::try_from(self.port)
.map_err(|_| invalid_argument(format!("port does not fit in `u16`: {}", self.port)))?;
Ok((ip_address, port))

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the relevant files first
git ls-files \
  components/spider-proto-rust/src/unpack/storage.rs \
  components/spider-storage/src/grpc.rs \
  components/spider-proto-rust/src/scheduler_registration.rs \
  | sed 's/^/FILE: /'

echo
echo "== storage.rs around the port unpacking =="
sed -n '180,220p' components/spider-proto-rust/src/unpack/storage.rs

echo
echo "== grpc.rs scheduler registration/storage flow =="
sed -n '1,240p' components/spider-storage/src/grpc.rs

echo
echo "== scheduler_registration.rs serialization =="
sed -n '1,220p' components/spider-proto-rust/src/scheduler_registration.rs

echo
echo "== search for port validation / zero handling =="
rg -n "port == 0|must be in 1..=65535|INVALID_ARGUMENT|invalid_argument\\(" components/spider-proto-rust components/spider-storage -S

echo
echo "== protobuf definition for RegisterSchedulerRequest =="
rg -n "message RegisterSchedulerRequest|port" components -g '*.proto' -S

Repository: y-scope/spider

Length of output: 14237


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== RegisterSchedulerRequest definition =="
sed -n '168,186p' components/spider-proto/storage/storage.proto

echo
echo "== related scheduler message(s) in storage.proto =="
sed -n '186,210p' components/spider-proto/storage/storage.proto

echo
echo "== search for any explicit allowance of port 0 / ephemeral ports =="
rg -n "port 0|ephemeral|zero.*port|port must|1..=65535|65535|scheduler.*port" components -S

Repository: y-scope/spider

Length of output: 3589


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== register_scheduler implementation =="
sed -n '640,720p' components/spider-storage/src/state/service.rs

echo
echo "== db protocol docs for register_scheduler =="
sed -n '430,470p' components/spider-storage/src/db/protocol.rs

echo
echo "== db implementation search for scheduler port handling =="
rg -n "register_scheduler\\(|scheduler.*port|port.*scheduler" components/spider-storage/src -S

Repository: y-scope/spider

Length of output: 4969


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== mariadb register_scheduler implementation =="
sed -n '580,660p' components/spider-storage/src/db/mariadb.rs

echo
echo "== scheduler table/schema search =="
rg -n "scheduler.*table|port.*u16|port.*INT|scheduler.*port|CREATE TABLE.*scheduler|scheduler_id" components/spider-storage/src -S

echo
echo "== tests around scheduler registration semantics =="
sed -n '980,1055p' components/spider-storage/tests/mariadb_test.rs

Repository: y-scope/spider

Length of output: 8046


Reject port 0 in scheduler registration.
The unpacker only checks that the value fits in u16, so 0 still reaches storage and gets advertised back unchanged. If 0 is not intended by the protocol, return INVALID_ARGUMENT here.

🤖 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-proto-rust/src/unpack/storage.rs` around lines 203 - 205,
Reject port 0 during unpacking in `Storage::unpack` so invalid scheduler
registrations fail early instead of being stored and advertised. Update the
existing `u16::try_from(self.port)` validation to also return `invalid_argument`
when `self.port` is zero, while keeping the current fit-in-`u16` check for
`port` intact. Use the `Storage::unpack` path and the `invalid_argument` helper
as the key places to adjust.

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

The same question again, have you ever read the diff?
How could we still have a PR in this shape after last Friday's offline discussion????

Comment thread components/spider-storage/src/grpc.rs Outdated
) -> Result<Response<storage::PollReadyTasksResponse>, Status> {
todo!("Not implemented")
let (max_items, wait) = request.into_inner().unpack()?;
tracing::debug!(max_items, ?wait, "Poll ready tasks request received.");

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.

  • Why this is debug log?
  • Why ? without space?

Comment thread components/spider-storage/src/grpc.rs Outdated
Comment thread components/spider-storage/src/grpc.rs Outdated
> SchedulerRegistrationService
for GrpcServiceState<ReadyQueueSenderType, DbConnectorType, TaskInstancePoolConnectorType>
{
async fn register_scheduler(

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.

Why is ' SchedulerRegistrationService ' also being implemented in this PR, while it's not mentioned in the PR description?

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.

Changed PR title and description.

Comment thread components/spider-storage/src/grpc.rs Outdated
@sitaowang1998 sitaowang1998 changed the title feat(spider-storage): Add InboundQueue and ResourceGroupManagement service implementation. feat(spider-storage): Add InboundQueue , ResourceGroupManagement and SchedulerRegistration service implementation. Jul 3, 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.

Still on my way for fixing these issues. Point out these things since they should really be avoided in any pending PRs (if you haven't check, do it).
I think a worth takeaway from this PR is: if the scope/change of the PR is large enough to a point where you can't even review it carefully yourselve, you should split it (which was I originally suggested: one PR per service). The scope of touching four different services is even making me feel not comfortable to review: too many context switches.

Comment thread components/spider-storage/src/grpc.rs Outdated
Comment on lines +162 to +158
_ => {
tracing::error!(
error = % error,
service = SERVICE_NAME,
tag,
"Unexpected internal error."
);
Status::internal("internal error")
}
_ => self.unexpected_internal_status(SERVICE_NAME, tag, &error),

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.

This is wrong: the internal error in this case shouldn't be a fatal error, meaning that it shouldn't cancel the service.
It is expected that such behavior changes are documented. Imagine if you're reviewing this code, how much of a chance do you think you will miss this?

Comment thread components/spider-storage/src/grpc.rs Outdated
Comment on lines +365 to +369
StorageServerError::Cache(CacheError::Internal(e)) => {
self.fatal_internal_status(SERVICE_NAME, tag, &e)
}

error => self.unexpected_internal_status(SERVICE_NAME, tag, &error),

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.

Similarly:

  • Cache internal error can never happen in this case; adding this branch is very confusing and looks like AI-generated code learned from other similar functions but without human review.
  • An unexpected error shouldn't be considered fatal in this case.

/// * `FAILED_PRECONDITION` when the execution manager has already been reaped.
/// * `INVALID_ARGUMENT` for an illegal execution manager ID.
/// * `INTERNAL` for:
/// * A fatal cache-internal error (the service will restart).

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.

Makes no sense.

request: Request<storage::RegisterExecutionManagerRequest>,
) -> Result<Response<storage::RegisterExecutionManagerResponse>, Status> {
todo!("Not implemented")
let ip_address = request.into_inner().unpack()?;

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.

fyi: just realize this PR also includes EM registration service. So the PR actually implements four services.

Comment thread components/spider-storage/src/grpc.rs Outdated
/// * A fatal cache-internal error (the service will restart).
/// * Any other (database or otherwise unexpected) error.
/// * `UNAUTHENTICATED` for an unknown or unauthorized resource group.
/// * `UNAUTHENTICATED` for an unknown or unauthorized resource group, or a wrong password.

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.

"unauthorized" already indicates "wrong password".

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

I've removed the scheduler registration service: the implementation is wrong with the ready-queue resending part missing.

///
/// An `INTERNAL` [`Status`] with a generic storage service error message.
#[must_use]
fn default_error_handler(

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.

This should be a more maintainable general-purpose error hander: each service implements their own error handler to check errors they care about. The rest of errors will be passed into this default handler. The default handler asserts fatal errors and cancel the storage service when needed.

@LinZhihao-723 LinZhihao-723 changed the title feat(spider-storage): Add InboundQueue , ResourceGroupManagement and SchedulerRegistration service implementation. feat(spider-storage): Add gRPC service implementation: Jul 5, 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.
Please review my comments and changes carefully, and make sure you understand our expectation for how to make future PRs ready-to-review.

@LinZhihao-723
LinZhihao-723 merged commit 99b43d0 into y-scope:main Jul 5, 2026
15 checks passed
@sitaowang1998
sitaowang1998 deleted the storage-grpc-services branch July 5, 2026 20:44
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