Skip to content

refactor: Remove unused code and test related to scheduler state. - #93

Merged
sitaowang1998 merged 8 commits into
y-scope:mainfrom
sitaowang1998:scheduler_state
Apr 7, 2025
Merged

refactor: Remove unused code and test related to scheduler state.#93
sitaowang1998 merged 8 commits into
y-scope:mainfrom
sitaowang1998:scheduler_state

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Apr 3, 2025

Copy link
Copy Markdown
Collaborator

Description

In early design, scheduler has three states: normal, gc and recovery. However, this design has been ditched a long time ago. Now the scheduler does not have any state so it can serves schedule task request all the time, and gc and recovery are performed in another thread. This pr removes the codes and tests related to the scheduler state.

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
  • Unite tests pass in dev container
  • Integration tests pass in dev container

Summary by CodeRabbit

  • Refactor
    • Simplified the internal cleanup process by removing redundant state-management steps for more efficient operations.
  • Database Changes
    • Updated the scheduler storage schema by eliminating an outdated state-tracking field.
  • Tests
    • Modified scheduler tests to focus on address retrieval, ensuring alignment with the updated functionality.

@sitaowang1998
sitaowang1998 requested a review from a team as a code owner April 3, 2025 19:35
@coderabbitai

coderabbitai Bot commented Apr 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request simplifies scheduler state management and cleanup processes. The cleanup_loop function no longer manages scheduler states, removing parameters and error handling linked to state changes. In the metadata storage and MySQL storage classes, methods for getting and setting scheduler state have been eliminated in favour of solely retrieving scheduler addresses. Additionally, the SQL schema for the schedulers table has been updated by removing the state column. A related test case has been adjusted to focus on scheduler address validation only.

Changes

Files Change Summary
src/spider/scheduler/scheduler.cpp Updated cleanup_loop signature: removed metadata_store and scheduler parameters. Removed state-change logic and error handling; now only performs dangling data cleanup controlled by stop_token.
src/spider/storage/MetadataStorage.hpp
src/spider/storage/mysql/MySqlStorage.cpp
src/spider/storage/mysql/MySqlStorage.hpp
Removed methods get_scheduler_state and set_scheduler_state. Retained get_scheduler_addr to retrieve scheduler address information.
src/spider/storage/mysql/mysql_stmt.hpp
tools/scripts/storage/init_db.sql
Removed the state column (ENUM: 'normal', 'recovery', 'gc') from the schedulers table. In init_db.sql, removed the state column from the schedulers table.
tests/storage/test-MetadataStorage.cpp Renamed test case from "Scheduler state and addr" to "Scheduler addr" and removed assertions related to scheduler state, focusing solely on address and port verification.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant CleanupLoop
    participant DataStore
    participant StopToken

    Caller ->> CleanupLoop: invoke cleanup_loop()
    loop Cleanup Process
        CleanupLoop ->> StopToken: check stop condition
        alt Continue cleaning
            CleanupLoop ->> DataStore: remove dangling data
        else Stop condition met
            CleanupLoop -->> Caller: exit cleanup_loop
        end
    end
Loading

Possibly related PRs

Suggested reviewers

  • davidlion

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8062659 and a444a78.

📒 Files selected for processing (1)
  • tools/scripts/storage/init_db.sql (0 hunks)
💤 Files with no reviewable changes (1)
  • tools/scripts/storage/init_db.sql
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: lint

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sitaowang1998
sitaowang1998 requested a review from davidlion April 3, 2025 19:36
@sitaowang1998 sitaowang1998 changed the title refactor: Remove unused scheduler state refactor: Remove unused scheduler state. Apr 5, 2025
Comment thread tools/scripts/storage/init_db.sql Outdated
Comment on lines +109 to +118
CREATE TABLE IF NOT EXISTS `scheduler_leases`
(
`scheduler_id` BINARY(16) NOT NULL,
`task_id` BINARY(16) NOT NULL,
`lease_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `lease_scheduler_id` FOREIGN KEY (`scheduler_id`) REFERENCES `schedulers` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT `lease_task_id` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
INDEX (`scheduler_id`)
);

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.

Is this change unrelated to the PR? There is no mention of it in the description and none of the other changes are related to leases or require a new table (as far as I can tell).

Is it possible to move this to another more relevant PR?

@davidlion davidlion Apr 7, 2025

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.

After looking at #98 I'm pretty sure this table should be removed from this PR and added in that one.

@davidlion davidlion changed the title refactor: Remove unused scheduler state. refactor: Remove unused code and test related to scheduler state. Apr 7, 2025
@sitaowang1998
sitaowang1998 requested a review from davidlion April 7, 2025 14:08
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