Skip to content

refactor(spider-huntsman): Use auto-incrementing u64 IDs instead of UUIDv7 for database-generated IDs. - #337

Merged
LinZhihao-723 merged 3 commits into
y-scope:mainfrom
sitaowang1998:id-u64
Jun 6, 2026
Merged

refactor(spider-huntsman): Use auto-incrementing u64 IDs instead of UUIDv7 for database-generated IDs.#337
LinZhihao-723 merged 3 commits into
y-scope:mainfrom
sitaowang1998:id-u64

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR changes the following ids from Uuid to u64:

  • job id
  • resource group id
  • execution manager id
    Note that the task id stays usize as it is used as an index to vectors.

This PR also changes the database schema to use AUTOINCREMENT BIGINT UNSIGNED to match the change.

The old id default and new functions, both only used for tests, has changed to:

  • default always return 0
  • new renames to random and returns a randomly generated u64
    This fulfills the need for tests. In production, neither functions should be used, as ids are generated by database.

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

  • No Uuid left, in code and in dependency.
  • GitHub workflows pass.

Summary by CodeRabbit

  • Chores

    • Migrated identifiers from UUIDs to numeric (u64) IDs across the system.
    • Updated storage to use auto-incrementing numeric primary keys and removed UUID dependency.
    • Adjusted logging/file naming to use numeric IDs.
  • Tests

    • Updated unit and integration tests to generate and use randomized numeric IDs instead of UUIDs.

@sitaowang1998
sitaowang1998 requested a review from a team as a code owner June 6, 2026 01:25
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR migrates the core Id from UUID-backed to u64-backed representation, updates serde/Display/SQLx impls, converts MariaDB DDL and queries to BIGINT auto-increment IDs, and updates production logging and test fixtures to use numeric/random ID constructors.

Changes

UUID-to-u64 ID Type Migration

Layer / File(s) Summary
Core ID type and dependencies
components/spider-core/Cargo.toml, components/spider-core/src/types/id.rs
Id<TypeMarker> now stores raw: u64 with PhantomData; constructors/accessors changed to random(), from(u64), get(); manual Display, Serialize, Deserialize target the wrapped u64; SQLx impls updated; rand added and sqlx uuid feature removed.
Database schema and query updates
components/spider-storage/src/db/mariadb.rs
Table DDLs for resource_groups, jobs, and execution_managers switch from UUID/UUID_v7() to BIGINT UNSIGNED NOT NULL AUTO_INCREMENT; insert/select RETURNING and cleanup queries return plain id (no UUID cast); error messages reference {job_id} directly.
Production code updates
components/spider-execution-manager/src/process_pool.rs, components/spider-execution-manager/src/liveness.rs
Executor stderr log filename now uses format!("{}-{executor_id}.log", self.config.em_id) and liveness test spawn uses ExecutionManagerId::random().
Storage tests and fixtures
components/spider-storage/src/state/job_cache.rs, components/spider-storage/src/task_instance_pool.rs, components/spider-storage/tests/mariadb_*.rs, components/spider-storage/tests/scheduling_infra.rs
Tests and helpers switch from *Id::new() or uuid::Uuid::new_v4() to *Id::random() and format!("test-resource-group-{}", rand::random::<u64>()).
TDL and executor integration tests
components/spider-tdl/src/task.rs, components/spider-tdl/src/task_context.rs, components/spider-tdl/tests/test_task_macro.rs, tests/huntsman/task-executor/tests/test_process_pool.rs, tests/huntsman/tdl-integration/tests/complex.rs, tests/huntsman/test-utils/src/executor.rs, tests/huntsman/test-utils/src/mock.rs
TaskContext and executor test helpers generate job_id/resource_group_id/ExecutionManagerId via random() instead of new().

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • y-scope/spider#331: Both PRs refactor components/spider-core/src/types/id.rs; this PR converts UUID-backed Id<TypeMarker> to u64-backed while that PR restructures the TaskId variant.
  • y-scope/spider#328: Overlaps on execution-manager liveness tests and tests/huntsman/test-utils/src/mock.rs MockLiveness construction, both updated to use ExecutionManagerId::random() in this PR.
  • y-scope/spider#326: Updates components/spider-execution-manager/src/process_pool.rs log filename construction to align with the new numeric ExecutionManagerId API introduced in this PR.
🚥 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 title accurately describes the main change: converting database-generated identifiers from UUID v7 to auto-incrementing u64 across job, resource group, and execution manager IDs.
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/spider-storage/src/db/mariadb.rs (1)

599-615: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Add a real migration path for existing MariaDB schemas.

These new definitions only affect fresh databases. The connector still bootstraps with CREATE TABLE IF NOT EXISTS, so any existing deployment keeps its old UUID/BINARY(16) columns while the rest of this PR now binds and decodes the same IDs as u64. That turns an in-place upgrade into a runtime schema mismatch instead of a clean migration. Please add an explicit ALTER TABLE path or a fail-fast schema-version check before serving traffic.

Also applies to: 640-646

🧹 Nitpick comments (1)
components/spider-core/src/types/id.rs (1)

35-42: 🏗️ Heavy lift

Fence Id::random() behind a test-only API surface.

The doc comment already says production IDs must come from persistent storage, but this helper is still callable in every build. Consider moving it behind a test-utils feature (or a dedicated test helper crate) so downstream tests keep it without inviting production code to mint synthetic DB-owned IDs.

🤖 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-core/src/types/id.rs` around lines 35 - 42, The
Id::random() helper is intended for tests only, so restrict its availability by
gating it behind a test-only feature: annotate the function with #[cfg(any(test,
feature = "test-utils"))] (or just feature="test-utils" if you prefer) and add
#[cfg_attr(docsrs, doc(cfg(feature = "test-utils")))] to keep docs clear; this
preserves Id::random() for downstream tests when the feature is enabled but
prevents production code from calling the minting helper. Ensure the function
signature remains pub fn random() -> Self but only compiled when the feature (or
test) is enabled.
🤖 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-core/src/types/id.rs`:
- Around line 35-42: The Id::random() helper is intended for tests only, so
restrict its availability by gating it behind a test-only feature: annotate the
function with #[cfg(any(test, feature = "test-utils"))] (or just
feature="test-utils" if you prefer) and add #[cfg_attr(docsrs, doc(cfg(feature =
"test-utils")))] to keep docs clear; this preserves Id::random() for downstream
tests when the feature is enabled but prevents production code from calling the
minting helper. Ensure the function signature remains pub fn random() -> Self
but only compiled when the feature (or test) is enabled.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e24c4af8-2864-455e-bb83-f0dc322c24d7

📥 Commits

Reviewing files that changed from the base of the PR and between 100129e and 24c6ce6.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • components/spider-core/Cargo.toml
  • components/spider-core/src/types/id.rs
  • components/spider-execution-manager/src/liveness.rs
  • components/spider-execution-manager/src/process_pool.rs
  • components/spider-storage/Cargo.toml
  • components/spider-storage/src/db/mariadb.rs
  • components/spider-storage/src/state/job_cache.rs
  • components/spider-storage/src/task_instance_pool.rs
  • components/spider-storage/tests/mariadb_infra.rs
  • components/spider-storage/tests/mariadb_test.rs
  • components/spider-storage/tests/scheduling_infra.rs
  • components/spider-tdl/src/task.rs
  • components/spider-tdl/src/task_context.rs
  • components/spider-tdl/tests/test_task_macro.rs
  • tests/huntsman/task-executor/tests/test_process_pool.rs
  • tests/huntsman/tdl-integration/tests/complex.rs
  • tests/huntsman/test-utils/src/executor.rs
  • tests/huntsman/test-utils/src/mock.rs
💤 Files with no reviewable changes (1)
  • components/spider-storage/Cargo.toml

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

Polished the ID implementation a bit. Otherwise lgtm. For the PR title, how about:

refactor(spider-huntsman): Use auto-incrementing u64 IDs instead of UUIDv7 for database-generated IDs.

@sitaowang1998 sitaowang1998 changed the title refactor(spider-huntsmam): Changes ids from Uuid to u64. refactor(spider-huntsman): Use auto-incrementing u64 IDs instead of UUIDv7 for database-generated IDs. Jun 6, 2026
@LinZhihao-723
LinZhihao-723 merged commit d95057f into y-scope:main Jun 6, 2026
14 checks passed
@sitaowang1998
sitaowang1998 deleted the id-u64 branch June 6, 2026 18:50
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