Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schedule: move the logic of patrol region from coordinator to checkers #8428

Merged
merged 7 commits into from
Aug 1, 2024

Conversation

lhy1024
Copy link
Contributor

@lhy1024 lhy1024 commented Jul 22, 2024

What problem does this PR solve?

Issue Number: Ref #7963

What is changed and how does it work?

  1. move the logic of patrol region from coordinator to checkers
  2. introduce PatrolRegionContext
  3. modify some comments

Check List

Tests

  • Unit test

Release note

None.

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 22, 2024
@lhy1024
Copy link
Contributor Author

lhy1024 commented Jul 23, 2024

/test pull-integration-realcluster-test

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 92.75362% with 10 lines in your changes missing coverage. Please review.

Project coverage is 77.36%. Comparing base (45dac53) to head (24a026b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8428      +/-   ##
==========================================
- Coverage   77.40%   77.36%   -0.05%     
==========================================
  Files         472      472              
  Lines       61796    61811      +15     
==========================================
- Hits        47836    47820      -16     
- Misses      10382    10430      +48     
+ Partials     3578     3561      -17     
Flag Coverage Δ
unittests 77.36% <92.75%> (-0.05%) ⬇️

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

Copy link
Member

@HuSharp HuSharp left a comment

Choose a reason for hiding this comment

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

rest LGTM

pkg/schedule/checker/checker_controller.go Show resolved Hide resolved
pkg/schedule/checker/checker_controller.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jul 26, 2024
@@ -233,3 +417,39 @@ func (c *Controller) GetPauseController(name string) (*PauseController, error) {
return nil, errs.ErrCheckerNotFound.FastGenByArgs()
}
}

// PatrolRegionContext is used to store the context of patrol regions.
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will be used in the next pr, it may be more suitable to move it to the next pr?

Copy link
Member

Choose a reason for hiding this comment

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

Should the fields be part of the checker controller? Is it necessary to wrap it?

Copy link
Contributor Author

@lhy1024 lhy1024 Jul 31, 2024

Choose a reason for hiding this comment

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

I think it is needed. It will contain more value and config in the future.

type PatrolRegionContext struct {
syncutil.RWMutex
// config
interval time.Duration
workerCount int
scanLimit int
// status
patrolRoundStartTime time.Time
duration time.Duration
// workers
workersCtx context.Context
workersCancel context.CancelFunc
regionChan chan *core.RegionInfo
wg sync.WaitGroup
}

// PatrolRegions is used to scan regions.
// The checkers will check these regions to decide if they need to do some operations.
func (c *Controller) PatrolRegions() {
c.patrolRegionContext.init(c.cluster)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
c.patrolRegionContext.init(c.cluster)
patrolInterval := cluster.GetCheckerConfig().GetPatrolRegionInterval()
c.patrolRegionContext.init(patrolInterval)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

c.cluster is needed in updateTickerIfNeeded

Copy link
Member

@rleungx rleungx Jul 31, 2024

Choose a reason for hiding this comment

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

init doesn't need it.

func (c *Controller) updateTickerIfNeeded(ticker *time.Ticker) {
// Note: we reset the ticker here to support updating configuration dynamically.
newInterval := c.cluster.GetCheckerConfig().GetPatrolRegionInterval()
if c.patrolRegionContext.interval != newInterval {
Copy link
Member

Choose a reason for hiding this comment

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

Why not keep it the same as before, just reset it every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe move it to patrolRegionContext?

pkg/schedule/checker/checker_controller.go Outdated Show resolved Hide resolved
Comment on lines 424 to 426
interval time.Duration
// status
patrolRoundStartTime time.Time
Copy link
Member

Choose a reason for hiding this comment

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

These fields are unnecessary IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to add a new commit, what do you think? Is it better to move both updateTickerIfNeeded and roundUpdateMetrics to the patrolRegion function, would that make it too long?

Copy link
Contributor

ti-chi-bot bot commented Jul 31, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: HuSharp, rleungx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 31, 2024
Copy link
Contributor

ti-chi-bot bot commented Jul 31, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-26 06:55:30.170099626 +0000 UTC m=+1200952.161041094: ☑️ agreed by HuSharp.
  • 2024-07-31 09:21:12.551101229 +0000 UTC m=+347588.831149295: ☑️ agreed by rleungx.

@rleungx
Copy link
Member

rleungx commented Jul 31, 2024

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 31, 2024
@lhy1024
Copy link
Contributor Author

lhy1024 commented Jul 31, 2024

/test pull-integration-realcluster-test

@lhy1024
Copy link
Contributor Author

lhy1024 commented Jul 31, 2024

/test pull-integration-realcluster-test

Signed-off-by: lhy1024 <[email protected]>
@lhy1024
Copy link
Contributor Author

lhy1024 commented Aug 1, 2024

/retest-required

@rleungx
Copy link
Member

rleungx commented Aug 1, 2024

/hold cancel

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 1, 2024
@ti-chi-bot ti-chi-bot bot merged commit 3ce31ef into tikv:master Aug 1, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants