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

external: auto switch reader mode #46979

Merged
merged 23 commits into from
Sep 18, 2023
Merged

Conversation

wjhuang2016
Copy link
Member

@wjhuang2016 wjhuang2016 commented Sep 14, 2023

What problem does this PR solve?

Issue Number: close #45719

Problem Summary:
Support switching read mode automatically so the speed does not degrade for the hot-point.

What is changed and how it works?

Record the file access stat, and switch reader mode if necessary.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 14, 2023
@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Merging #46979 (ffc1fa1) into master (59e31f0) will decrease coverage by 0.3388%.
The diff coverage is 91.6666%.

❗ Current head ffc1fa1 differs from pull request most recent head 984d3f6. Consider uploading reports for the commit 984d3f6 to get more accurate results

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #46979        +/-   ##
================================================
- Coverage   73.0821%   72.7434%   -0.3388%     
================================================
  Files          1336       1357        +21     
  Lines        398227     404816      +6589     
================================================
+ Hits         291033     294477      +3444     
- Misses        88451      91686      +3235     
+ Partials      18743      18653        -90     
Flag Coverage Δ
integration 30.3402% <0.0000%> (?)
unit 73.1201% <91.6666%> (+0.0379%) ⬆️

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

Components Coverage Δ
dumpling 53.9913% <ø> (ø)
parser 84.9980% <ø> (ø)
br 48.7498% <91.6666%> (-4.1971%) ⬇️

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Copy link
Contributor

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

@@ -178,6 +178,7 @@ func (r *byteReader) reload() error {
to := r.useConcurrentReader.Load()
now := r.useConcurrentReaderCurrent.Load()
if to != now {
logutil.BgLogger().Info("switch reader mode", zap.Bool("use concurrent mode", to))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logutil.BgLogger().Info("switch reader mode", zap.Bool("use concurrent mode", to))
logutil.Logger(r.ctx).Info("switch reader mode", zap.Bool("use concurrent mode", to))

writer := NewWriterBuilder().
SetPropKeysDistance(100).
SetMemorySizeLimit(512*1024).
Build(st, "testprefix", strconv.Itoa(0))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Build(st, "testprefix", strconv.Itoa(0))
Build(st, "testprefix", "0"))

@@ -42,7 +42,6 @@ func newKVReader(
}
br, err := newByteReader(ctx, sr, bufSize, store, name, false)
if err != nil {
br.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

where do we Close now?

@@ -198,6 +202,23 @@ func (i *mergeIter[T, R]) next() bool {
var zeroT T
i.curr = zeroT
if i.lastReaderIdx >= 0 {
cnt, ok := i.checkHotPointMap[i.lastReaderIdx]
if !ok {
i.checkHotPointMap[i.lastReaderIdx] = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

we can rely on the zero value when map entry is not found, maybe

i.checkHotPointMap[i.lastReaderIdx] = i.checkHotPointMap[i.lastReaderIdx] + 1

if i.checkHotPointCnt == 1000 {
i.checkHotPointCnt = 0
for idx, cnt := range i.checkHotPointMap {
(*i.readers[idx]).setReadMode(cnt > 500)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems byteReader is not concurrently used, we don;t need atomic.Bool to represent useConcurrentReader

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, #46924 works for it

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
br/pkg/lightning/backend/external/iter.go Outdated Show resolved Hide resolved
br/pkg/lightning/backend/external/iter.go Outdated Show resolved Hide resolved
wjhuang2016 and others added 3 commits September 14, 2023 18:38
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 14, 2023
@ti-chi-bot ti-chi-bot bot added the approved label Sep 14, 2023
Signed-off-by: lance6716 <lance6716@gmail.com>
@lance6716
Copy link
Contributor

/retest

2 similar comments
@lance6716
Copy link
Contributor

/retest

@lance6716
Copy link
Contributor

/retest

curr T
lastReaderIdx int
err error
checkHotPointMap map[int]int
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe rename to hotspotMap?

Copy link
Member

Choose a reason for hiding this comment

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

I didn't understand the meaning of this name at first glance too.

Copy link
Contributor

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

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 18, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lance6716, tangenta

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 Sep 18, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 18, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-09-14 10:41:27.695329923 +0000 UTC m=+168453.662917963: ☑️ agreed by lance6716.
  • 2023-09-18 04:12:43.189839893 +0000 UTC m=+490729.157427943: ☑️ agreed by tangenta.

@wjhuang2016
Copy link
Member Author

/test unit-test

@tiprow
Copy link

tiprow bot commented Sep 18, 2023

@wjhuang2016: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test unit-test

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 kubernetes/test-infra repository.

@wjhuang2016
Copy link
Member Author

/test check-dev

@tiprow
Copy link

tiprow bot commented Sep 18, 2023

@wjhuang2016: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test check-dev

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 kubernetes/test-infra repository.

@wjhuang2016
Copy link
Member Author

/test check-dev

@tiprow
Copy link

tiprow bot commented Sep 18, 2023

@wjhuang2016: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test check-dev

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 kubernetes/test-infra repository.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 18, 2023

@wjhuang2016: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/check_dev ffc1fa1 link true /test check-dev

Full PR test history. Your PR dashboard.

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 kubernetes/test-infra repository. I understand the commands that are listed here.

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
@wjhuang2016 wjhuang2016 merged commit 3cd5dce into pingcap:master Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support global sort on S3
4 participants