Skip to content

feat(compression-coordinator): Add scaffolding S3CompressionJobHandle for driving an S3 compression job to completion. - #2405

Merged
LinZhihao-723 merged 2 commits into
y-scope:mainfrom
LinZhihao-723:compression-job-handle
Jul 23, 2026
Merged

feat(compression-coordinator): Add scaffolding S3CompressionJobHandle for driving an S3 compression job to completion.#2405
LinZhihao-723 merged 2 commits into
y-scope:mainfrom
LinZhihao-723:compression-job-handle

Conversation

@LinZhihao-723

@LinZhihao-723 LinZhihao-723 commented Jul 21, 2026

Copy link
Copy Markdown
Member

Description

Adds S3CompressionJobHandle, the object that owns a single CLP compression job for its whole lifetime: it turns a ClpIoConfig into Spider task inputs, submits the job, records the Spider job ID against the CLP compression job, waits for the job to finish, and reports the outcome back to the CLP database.

This PR lands the orchestration flow and the type's public surface. The database-facing steps are declared and documented but left as todo!(), to be filled in by a follow-up; see Deferred work below.

S3CompressionJobHandle

The handle is generic over SubmitterType: S3CompressionJobSubmitter, so the Spider client added in the submitter-implementation PR can be swapped for a mock in tests without this type depending on a concrete client.

new validates and normalizes the job's configuration up front, so the rest of the flow can assume it is well-formed:

  • The input config must be an InputConfig::S3ObjectMetadataInputConfig; any other variant is rejected with Error::UnsupportedInputConfig. This handle drives jobs whose inputs come from the S3 object metadata table, which is the only shape the coordinator produces today.
  • A configured dataset name is checked against VALID_DATASET_NAME_REGEX and rejected with Error::InvalidDataset, so an invalid name fails before any Spider or database work is done rather than partway through the job.
  • The output config is collapsed into the ClpSCompressionOption shared by every task in the job, so the per-task settings are computed once instead of at each submission site.

Two entry points consume the handle, and both take self by value so a handle cannot be driven twice:

  • run performs the full flow: prepare the task inputs, ensure the dataset's metadata tables exist, submit the job to Spider, persist the returned Spider job ID, then wait for completion.
  • recover skips submission and waits on a Spider job ID that was already persisted. This is the restart path: the Spider job ID is written to the database before the coordinator begins waiting, so a coordinator that dies mid-job can find the in-flight job and resume tracking it instead of resubmitting work that is already running.

Both funnel failures through report_failure, which marks the compression job as CompressionJobStatus::Failed with the originating error as its status message. A failure to record that status is logged rather than propagated, so a database problem while reporting cannot mask the error that actually caused the job to fail.

SpiderOption

Groups the Spider-side knobs that apply to a whole job — the compression tasks' retry limit, the commit task's execution policy, and the job-state poll backoffs. It is held behind an Arc because these settings are process-wide and identical across every concurrently running handle.

Error

The crate error type gains the variants this flow can produce: Sqlx for database failures, and InvalidDataset / UnsupportedInputConfig for the configuration rejections described above.

ClpSCompressionOption changes

Two changes to the task I/O type added in the scaffolding PR, both to match what clp-s actually accepts:

  • compression_level narrows from i32 to u8. The value is a zstd compression level, which is never negative and never exceeds the u8 range, so the wider signed type allowed states the task could not act on.
  • A new unstructured field carries the input config's unstructured flag through to the compression task, which needs it to select the correct clp-s mode.

This alters the msgpack payload exchanged with the Spider tasks. No released component consumes it yet, so no migration is required.

Deferred work

The following methods are declared, documented, and left as todo!(), since they all depend on the coordinator's database access layer:

  • prepare_task_inputs — read object metadata from the S3 object metadata table, partition it into per-task inputs, and derive each task's execution policy.
  • upsert_metadata_tables — create the dataset's archive and column metadata tables if absent.
  • persist_spider_job_id — associate the Spider job ID with the compression job and mark it running.
  • to_completion — wait for the Spider job to reach a terminal state and finalize the compression job accordingly.
  • update_job_status — write a compression job's status and status message.

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

Summary by CodeRabbit

  • New Features
    • Added public support for initiating and resuming S3-based compression jobs.
    • Introduced an S3 job handling abstraction with improved failure reporting and status persistence.
    • Updated compression options to include an unstructured flag and tightened compression_level to an unsigned range.
  • Improvements
    • Expanded coordinator error reporting for invalid datasets, unsupported configurations, and S3 mismatch scenarios.

@LinZhihao-723
LinZhihao-723 requested a review from a team as a code owner July 21, 2026 02:43
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b2945381-20ce-43b1-94c8-0bbee4e05028

📥 Commits

Reviewing files that changed from the base of the PR and between 3398399 and 64e2834.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • components/compression-coordinator/Cargo.toml
  • components/compression-coordinator/src/error.rs
  • components/compression-coordinator/src/lib.rs

Walkthrough

The PR updates the CLP S3 compression option contract and adds a public S3CompressionJobHandle with configuration validation, Spider submission and recovery flows, failure reporting, and stubbed persistence/completion operations.

Changes

S3 compression coordinator

Layer / File(s) Summary
Coordinator contracts and exports
components/clp-rust-utils/src/task_io/compression.rs, components/compression-coordinator/Cargo.toml, components/compression-coordinator/src/error.rs, components/compression-coordinator/src/lib.rs
The compression option uses u8 levels and adds unstructured; coordinator dependencies and structured error variants are added, and job_handle is publicly exported.
Job handle configuration
components/compression-coordinator/src/job_handle.rs
SpiderOption and S3CompressionJobHandle are defined; construction validates S3 input configuration and optional dataset names before deriving compression options.
Submission, recovery, and failure lifecycle
components/compression-coordinator/src/job_handle.rs
Run and recovery paths submit or resume Spider jobs, persist identifiers, wait for completion, and report failures; persistence, completion, and status-update methods remain todo! stubs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant S3CompressionJobHandle
  participant S3CompressionJobSubmitter
  participant Spider
  participant CLPDatabase
  S3CompressionJobHandle->>S3CompressionJobHandle: Prepare task inputs
  S3CompressionJobHandle->>S3CompressionJobSubmitter: Submit compression task
  S3CompressionJobSubmitter->>Spider: Create job
  Spider-->>S3CompressionJobSubmitter: Return spider_job_id
  S3CompressionJobHandle->>CLPDatabase: Persist spider_job_id
  S3CompressionJobHandle->>Spider: Wait for completion
  S3CompressionJobHandle->>CLPDatabase: Update job status
Loading

Possibly related PRs

  • y-scope/clp#2401: Updates the shared ClpSCompressionOption fields and types.
  • y-scope/clp#2402: Connects the compression option and job handle to Spider job completion flow.
  • y-scope/clp#2403: Modifies the coordinator error enum with related S3 mismatch variants.

Suggested reviewers: bill-hbrhbr

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding scaffolding for S3CompressionJobHandle in compression-coordinator.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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.

@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: 2

🤖 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/compression-coordinator/src/job_handle.rs`:
- Around line 181-198: Update the job flow around submit_s3_compression_job and
persist_spider_job_id so a persistence failure triggers a best-effort
cancellation of the already-submitted Spider job before propagating the original
error; if cancellation cannot be completed, emit a high-priority error
containing both job IDs and failure details.
- Around line 155-161: Refactor the error handling in recover around
to_completion to use the same if-let-Err structure as run: return success
directly when completion succeeds, and on failure call report_failure with the
error before returning it. Preserve the existing error propagation and
failure-reporting behavior.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f676b35c-edda-402d-8b84-c6f8c75bc727

📥 Commits

Reviewing files that changed from the base of the PR and between 0f08ff9 and 3398399.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • components/clp-rust-utils/src/task_io/compression.rs
  • components/compression-coordinator/Cargo.toml
  • components/compression-coordinator/src/error.rs
  • components/compression-coordinator/src/job_handle.rs
  • components/compression-coordinator/src/lib.rs

Comment thread components/compression-coordinator/src/job_handle.rs
Comment thread components/compression-coordinator/src/job_handle.rs

@Bill-hbrhbr Bill-hbrhbr 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 good for now

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