Skip to content

refactor: pass context to run gc task#4042

Merged
gaius-qi merged 1 commit intomainfrom
refactor/gc-task-ctx
May 7, 2025
Merged

refactor: pass context to run gc task#4042
gaius-qi merged 1 commit intomainfrom
refactor/gc-task-ctx

Conversation

@chlins
Copy link
Copy Markdown
Member

@chlins chlins commented May 7, 2025

This pull request introduces changes to the garbage collection (GC) system across multiple files to add support for context.Context. The updates ensure that GC operations are context-aware, allowing for better control and cancellation of long-running tasks. Below are the most important changes grouped by theme.

Core GC System Updates:

  • Updated the GC interface in pkg/gc/gc.go to include context.Context as a parameter for methods like Run, RunAll, Start, and their implementations. This ensures all GC operations are context-aware. [1] [2] [3]
  • Modified the Runner interface in pkg/gc/task.go to include context.Context in the RunGC method.

Integration with GC Consumers:

  • Updated RunGC methods in manager/gc/audit.go, manager/gc/job.go, and manager/manager.go to accept context.Context as a parameter. [1] [2] [3]
  • Refactored HostManager interfaces and implementations in scheduler/resource/persistentcache/host_manager.go and scheduler/resource/standard/host_manager.go to pass context.Context during GC operations. [1] [2] [3] [4]

Mock and Test Updates:

  • Updated mock implementations in pkg/gc/gc_mock.go, pkg/gc/runner_mock.go, scheduler/resource/persistentcache/host_manager_mock.go, and scheduler/resource/standard/host_manager_mock.go to include context.Context in mocked RunGC and related methods. [1] [2] [3] [4]
  • Adjusted test cases in pkg/gc/gc_test.go, scheduler/resource/persistentcache/host_manager_test.go, and scheduler/resource/standard/host_manager_test.go to pass context.Background() to GC-related methods. [1] [2] [3]

These changes improve the flexibility and robustness of the GC system by enabling context propagation, which is critical for modern concurrent applications.

Description

Related Issue

Motivation and Context

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation Update (if none of the other choices apply)

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

Signed-off-by: chlins <chlins.zhang@gmail.com>
@chlins chlins requested a review from a team as a code owner May 7, 2025 10:52
@chlins chlins added the enhancement New feature or request label May 7, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2025

Codecov Report

Attention: Patch coverage is 31.03448% with 40 lines in your changes missing coverage. Please review.

Project coverage is 34.41%. Comparing base (a8325d5) to head (9d1b4b6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/gc/gc_mock.go 0.00% 12 Missing ⚠️
scheduler/resource/standard/peer_manager.go 14.28% 1 Missing and 5 partials ⚠️
...uler/resource/persistentcache/host_manager_mock.go 0.00% 4 Missing ⚠️
scheduler/resource/standard/host_manager_mock.go 0.00% 4 Missing ⚠️
scheduler/resource/standard/peer_manager_mock.go 0.00% 4 Missing ⚠️
scheduler/resource/standard/task_manager_mock.go 0.00% 4 Missing ⚠️
manager/gc/audit.go 0.00% 1 Missing ⚠️
manager/gc/job.go 0.00% 1 Missing ⚠️
manager/manager.go 0.00% 1 Missing ⚠️
pkg/gc/gc.go 90.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4042      +/-   ##
==========================================
+ Coverage   34.40%   34.41%   +0.01%     
==========================================
  Files         343      343              
  Lines       40211    40211              
==========================================
+ Hits        13835    13840       +5     
+ Misses      25459    25455       -4     
+ Partials      917      916       -1     
Flag Coverage Δ
unittests 34.41% <31.03%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/gc/runner_mock.go 100.00% <100.00%> (ø)
pkg/gc/task.go 64.70% <ø> (ø)
scheduler/resource/standard/host_manager.go 72.36% <100.00%> (ø)
scheduler/resource/standard/task_manager.go 87.80% <100.00%> (ø)
manager/gc/audit.go 0.00% <0.00%> (ø)
manager/gc/job.go 0.00% <0.00%> (ø)
manager/manager.go 0.00% <0.00%> (ø)
pkg/gc/gc.go 93.93% <90.00%> (ø)
scheduler/resource/persistentcache/host_manager.go 30.57% <66.66%> (ø)
scheduler/scheduler.go 0.00% <0.00%> (ø)
... and 6 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@Liam-Zhao Liam-Zhao left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@gaius-qi gaius-qi left a comment

Choose a reason for hiding this comment

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

LGTM

@gaius-qi gaius-qi merged commit fb5e1d7 into main May 7, 2025
29 of 30 checks passed
@gaius-qi gaius-qi deleted the refactor/gc-task-ctx branch May 7, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants