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

ddl notifier: use pagination for SELECT to reduce memory usage #58376

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

lance6716
Copy link
Contributor

@lance6716 lance6716 commented Dec 18, 2024

What problem does this PR solve?

Issue Number: close #58368

Problem Summary:

What changed and how does it work?

as title. refine the Store.List.

// Store is the (de)serialization and persistent layer.
type Store interface {
...
	// List will start a transaction of given session and read all schema changes
	// through a ListResult. The ownership of session is occupied Store until CloseFn
	// is called.
	List(ctx context.Context, se *sess.Session) ListResult
}

// ListResult is the result stream of a List operation.
type ListResult interface {
	// Read tries to decode at most `len(changes)` SchemaChange into given slices. It
	// returns the number of schemaChanges decoded, 0 means no more schemaChanges.
	//
	// Note that the previous SchemaChange in the slice will be overwritten when call
	// Read.
	Read(changes []*SchemaChange) (int, error)
}

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

Signed-off-by: lance6716 <lance6716@gmail.com>
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 18, 2024
Copy link

tiprow bot commented Dec 18, 2024

Hi @lance6716. 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-sigs/prow repository.

@lance6716 lance6716 requested a review from Copilot December 18, 2024 08:16
@Rustin170506 Rustin170506 requested review from Rustin170506 and time-and-fate and removed request for Copilot December 18, 2024 08:17
@lance6716 lance6716 requested a review from Copilot December 18, 2024 08:20
@lance6716
Copy link
Contributor Author

/check-issue-triage-complete

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

pkg/ddl/notifier/subscribe.go:171

  • The variable name ProcessEventsBatchSize is clear and consistent with the changes made throughout the code.
var ProcessEventsBatchSize = 1024
Signed-off-by: lance6716 <lance6716@gmail.com>
Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 82.45614% with 20 lines in your changes missing coverage. Please review.

Project coverage is 74.8525%. Comparing base (1405c5e) to head (9536b86).
Report is 31 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #58376        +/-   ##
================================================
+ Coverage   73.1849%   74.8525%   +1.6676%     
================================================
  Files          1681       1727        +46     
  Lines        463027     475150     +12123     
================================================
+ Hits         338866     355662     +16796     
+ Misses       103358      97201      -6157     
- Partials      20803      22287      +1484     
Flag Coverage Δ
integration 49.0212% <76.3157%> (?)
unit 72.3076% <82.4561%> (-0.0093%) ⬇️

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

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 60.3572% <ø> (+14.3552%) ⬆️

@lance6716
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Dec 18, 2024

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

In response to this:

/retest

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-sigs/prow repository.

pkg/ddl/notifier/store.go Show resolved Hide resolved
changes := make([]*SchemaChange, ProcessEventsBatchSize)

for {
count, err2 := result.Read(changes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not let read return []*SchemaChange directly?
Return count and use changes[:count] is just a unnecessary detour

Copy link
Contributor Author

@lance6716 lance6716 Dec 19, 2024

Choose a reason for hiding this comment

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

It's like an io.Reader calling convention which is caller pass-in slices so caller can reuse the previous results. Because we are in 1M tables project, I'm afraid that returning 1M []*SchemaChange (it also has internal pointers like TableInfo) will add pressure to GC.

Though it's less common, I think this package / function is the only caller of ListResult.Read. Other developers will not modify this package and will not be confused by it.

However I notice that I use json.Unmarshal on an non-empty object, not sure the leftover of the object will be overwritten or causes some problems. I'll check it tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

What was your test result?

Copy link
Contributor

Choose a reason for hiding this comment

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

 pass-in slices so caller can reuse the previous results

Yes, I mean the same thing, just that the code can be write as:

func f(changes []*SchemaChange) []*SchemaChange {
     ret := changes[:0]
     ret = append(ret, xxx)
     return ret
}

Anyway, this is just some personal taste, so you can choose to accept it or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What was your test result?

I didn't test it yet 😂 I hope other colleague can help check it. Theoretically there's no big query now.

func f(changes []*SchemaChange) []*SchemaChange {

In this new signature, the batch size of one Read is not obvious when input is nil, or it seems like an append where the slice will be grown and batch size is not be limited. Your suggestion is like EncodeBytes but here we want to control the batch size as well as reuse buffer.

Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Copy link

ti-chi-bot bot commented Dec 20, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tiancaiamao
Once this PR has been reviewed and has the lgtm label, please ask for approval from lance6716, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 20, 2024
Copy link

ti-chi-bot bot commented Dec 20, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-12-20 10:14:14.361822185 +0000 UTC m=+1211044.450624723: ☑️ agreed by tiancaiamao.

Signed-off-by: lance6716 <lance6716@gmail.com>
Copy link

ti-chi-bot bot commented Dec 20, 2024

@lance6716: The following tests 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/mysql-test 9536b86 link true /test mysql-test
pull-unit-test-ddlv1 9536b86 link true /test pull-unit-test-ddlv1

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-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-1-more-lgtm Indicates a PR needs 1 more LGTM. 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.

TiDB OOM after created about 6.5M tables
3 participants