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

pkg: remove old duplicated task #8234

Merged
merged 8 commits into from
Jun 13, 2024
Merged

pkg: remove old duplicated task #8234

merged 8 commits into from
Jun 13, 2024

Conversation

rleungx
Copy link
Member

@rleungx rleungx commented May 31, 2024

What problem does this PR solve?

Issue Number: ref #7897.

What is changed and how does it work?

Check List

Tests

  • Unit test

Release note

None.

Copy link
Contributor

ti-chi-bot bot commented May 31, 2024

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • nolouch

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot bot requested review from lhy1024 and nolouch May 31, 2024 06:57
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed do-not-merge/needs-linked-issue labels May 31, 2024
Copy link

codecov bot commented May 31, 2024

Codecov Report

Attention: Patch coverage is 85.41667% with 7 lines in your changes missing coverage. Please review.

Project coverage is 77.36%. Comparing base (9348164) to head (746e7f1).

Current head 746e7f1 differs from pull request most recent head c10679d

Please upload reports for the commit c10679d to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8234      +/-   ##
==========================================
+ Coverage   77.28%   77.36%   +0.07%     
==========================================
  Files         471      471              
  Lines       61383    61395      +12     
==========================================
+ Hits        47441    47497      +56     
+ Misses      10382    10338      -44     
  Partials     3560     3560              
Flag Coverage Δ
unittests 77.36% <85.41%> (+0.07%) ⬆️

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

Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 31, 2024
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
pkg/core/region.go Outdated Show resolved Hide resolved
Signed-off-by: Ryan Leung <rleungx@gmail.com>
@rleungx rleungx requested a review from nolouch June 4, 2024 06:35
@@ -42,16 +42,16 @@ const (

// Runner is the interface for running tasks.
type Runner interface {
RunTask(ctx context.Context, name string, f func(context.Context), opts ...TaskOption) error
RunTask(id, name string, f func(), opts ...TaskOption) error
Copy link
Contributor

Choose a reason for hiding this comment

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

I think RunTask(id uint64, name string, f func(), opts ...TaskOption) error is ok. fmt.Sprint has an allocation cost.

Copy link
Member Author

@rleungx rleungx Jun 4, 2024

Choose a reason for hiding this comment

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

But the same id may have different tasks. If we don't use fmt.Sprint, then we need a map[uint64]map[string]struct{}.

Copy link
Contributor

Choose a reason for hiding this comment

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

package main

import (
        "fmt"
        "strings"
        "testing"
)

func BenchmarkSprintfKey(b *testing.B) {
        m := make(map[string]int)
        b.ReportAllocs()
        for i := 0; i < b.N; i++ {
                key := fmt.Sprintf("%s %s", "hello", "world")
                m[key]++
        }
}

func BenchmarkStructKey(b *testing.B) {
        type myKey struct{
           id int64
           name string
        }
        m := make(map[myKey]int)
        b.ReportAllocs()
        for i := 0; i < b.N; i++ {
                key := myKey{id: 1, name: "test"}
                m[key]++
        }
}
➜  bench_sprintf go test -bench=. -benchmem
goos: darwin
goarch: arm64
pkg: bench
BenchmarkSprintfKey-12        	20207793	        60.09 ns/op	      16 B/op	       1 allocs/op
BenchmarkStructKey-12         	83140879	        14.91 ns/op	       0 B/op	       0 allocs/op

@@ -188,22 +193,25 @@ func (cr *ConcurrentRunner) RunTask(ctx context.Context, name string, f func(con

pendingTaskNum := len(cr.pendingTasks)
if pendingTaskNum > 0 {
if t, ok := cr.pendingRegionTasks[task.id]; ok {
t.f = f
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment to explain the function will be overwrite and it doesn't matter

rest lgtm

Signed-off-by: Ryan Leung <rleungx@gmail.com>
@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 4, 2024
Copy link
Contributor

ti-chi-bot bot commented Jun 4, 2024

@okJiang: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Start()
Stop()
}

// Task is a task to be run.
type Task struct {
ctx context.Context
id uint64
Copy link
Member

Choose a reason for hiding this comment

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

can use taskID directly

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's ok and use less memory.

@rleungx rleungx requested a review from JmPotato June 6, 2024 06:30
@@ -61,16 +61,23 @@ type Task struct {
var ErrMaxWaitingTasksExceeded = errors.New("max waiting tasks exceeded")

// ConcurrentRunner is a simple task runner that limits the number of concurrent tasks.
Copy link
Member

Choose a reason for hiding this comment

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

It's a mismatched comment line.

Copy link
Contributor

ti-chi-bot bot commented Jun 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JmPotato, nolouch, okJiang

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

Copy link
Contributor

ti-chi-bot bot commented Jun 12, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-12 09:57:27.973382922 +0000 UTC m=+545002.026694843: ☑️ agreed by JmPotato.

Signed-off-by: Ryan Leung <rleungx@gmail.com>
@rleungx
Copy link
Member Author

rleungx commented Jun 13, 2024

/merge

Copy link
Contributor

ti-chi-bot bot commented Jun 13, 2024

@rleungx: We have migrated to builtin LGTM and approve plugins for reviewing.

👉 Please use /approve when you want approve this pull request.

The changes announcement: Proposal: Strengthen configuration change approval.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@rleungx rleungx added require-LGT1 Indicates that the PR requires an LGTM. lgtm and removed require-LGT1 Indicates that the PR requires an LGTM. needs-1-more-lgtm labels Jun 13, 2024
Copy link
Contributor

ti-chi-bot bot commented Jun 13, 2024

@rleungx: Your PR was out of date, I have automatically updated it for you.

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot bot merged commit bf02fb5 into tikv:master Jun 13, 2024
16 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 lgtm release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants