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

importinto: use one writer for each kv group for all concurrent encoder #47185

Merged
merged 10 commits into from
Sep 22, 2023

Conversation

D3Hunter
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #46704

Problem Summary:

in current design of global sort, each kv group, such as data kv or kv of same index id, should uses 1 writer

importinto change to it too

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Sep 22, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 22, 2023

Hi @D3Hunter. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@tiprow
Copy link

tiprow bot commented Sep 22, 2023

Hi @D3Hunter. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@D3Hunter
Copy link
Contributor Author

/ok-to-test

@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 22, 2023

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/ok-to-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.

@D3Hunter
Copy link
Contributor Author

/label ok-to-test

@tiprow
Copy link

tiprow bot commented Sep 22, 2023

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/ok-to-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.

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Sep 22, 2023
@D3Hunter
Copy link
Contributor Author

/remove-label needs-ok-to-test

@ti-chi-bot ti-chi-bot bot removed the needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. label Sep 22, 2023
@wuhuizuo
Copy link
Contributor

/test all

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Merging #47185 (145542b) into master (7a116f3) will decrease coverage by 0.3016%.
Report is 2 commits behind head on master.
The diff coverage is 73.2673%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #47185        +/-   ##
================================================
- Coverage   72.9737%   72.6722%   -0.3016%     
================================================
  Files          1340       1361        +21     
  Lines        399989     406308      +6319     
================================================
+ Hits         291887     295273      +3386     
- Misses        89206      92260      +3054     
+ Partials      18896      18775       -121     
Flag Coverage Δ
integration 32.3259% <4.9505%> (?)
unit 72.9807% <73.2673%> (+0.0069%) ⬆️

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

Components Coverage Δ
dumpling 53.9913% <ø> (ø)
parser 84.9365% <ø> (ø)
br 48.6979% <100.0000%> (-4.3420%) ⬇️

@@ -488,6 +488,9 @@ func (w *Writer) createStorageWriter(ctx context.Context) (

// EngineWriter implements backend.EngineWriter interface.
type EngineWriter struct {
// Only 1 writer is used for some kv group(data or some index), no matter
// how many routines are encoding data, so need to sync write to it.
sync.Mutex
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why here add new Mutex,Could we reuse,global sort mutex that wenjun introduced in #47131

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see comments, i think that's quite clear

global sort mutex that wenjun introduced in #47131

that's shared among all writers

@Benjamin2037
Copy link
Collaborator

/assign windtalker

@Benjamin2037
Copy link
Collaborator

/assign @windtalker

@@ -94,6 +95,10 @@ func newByteReader(

// switchReaderMode switches to concurrent reader.
func (r *byteReader) switchReaderMode(useConcurrent bool) {
failpoint.Inject("disableConcurrentReader", func() {
// current impl only supports S3, but we need test using GCS
useConcurrent = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator

@Benjamin2037 Benjamin2037 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 22, 2023
@@ -488,6 +488,9 @@ func (w *Writer) createStorageWriter(ctx context.Context) (

// EngineWriter implements backend.EngineWriter interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe mention it's concurrent safe in comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

writer = w.writerFactory(indexID)
w.writers[indexID] = writer
}
writer := w.getWriter(indexID)
if err = writer.WriteRow(ctx, item.Key, item.Val, nil); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems if one writer has entered WriteRow, it will block other kvs which also need to access this writer. We can improve it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean kvs in this loop? or in other concurrency?

Copy link
Contributor

@lance6716 lance6716 Sep 22, 2023

Choose a reason for hiding this comment

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

other concurrent call of WriteRow. I expect the idle writer can still do something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

depends on whether it's same index, other concurrency can still use writers of other index

@ti-chi-bot ti-chi-bot bot added the lgtm label Sep 22, 2023
@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 22, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 22, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-09-22 06:01:05.813523199 +0000 UTC m=+842831.781111247: ☑️ agreed by Benjamin2037.
  • 2023-09-22 06:33:06.82576401 +0000 UTC m=+844752.793352060: ☑️ agreed by lance6716.

@D3Hunter
Copy link
Contributor Author

/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 Sep 22, 2023
@D3Hunter
Copy link
Contributor Author

need wait #47170 merged

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Benjamin2037, lance6716, windtalker

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 the approved label Sep 22, 2023
@D3Hunter
Copy link
Contributor Author

/retest

@D3Hunter
Copy link
Contributor Author

/unhold

@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 Sep 22, 2023
@ti-chi-bot ti-chi-bot bot merged commit 4e82952 into pingcap:master Sep 22, 2023
@D3Hunter D3Hunter deleted the use-one-writer branch September 22, 2023 11:03
D3Hunter added a commit to D3Hunter/tidb that referenced this pull request Oct 12, 2023
D3Hunter added a commit to D3Hunter/tidb that referenced this pull request Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants