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

*: add a memdb memory tracker #35225

Closed
wants to merge 20 commits into from
Closed

Conversation

ekexium
Copy link
Contributor

@ekexium ekexium commented Jun 8, 2022

Signed-off-by: ekexium ekexium@fastmail.com

What problem does this PR solve?

Issue Number: ref #35203

Problem Summary:

What is changed and how it works?

  • It replaces the EntriesSize in TxnInfo with a memory tracker of MemDB.
  • We set a hook of the memory change of memdb, thus the manual update of the field is unnecessary.
  • [TODO] An appropriate limit and an action haven't been set for the tracker. Before we decide how to control it, use total-txn-size-limit for now.

Relates to tikv/client-go#520

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code
MySQL root@172.16.5.181:CREDIT_CARD> show config where name like '%txn-total%'
+------+-------------------+----------------------------------+------------+
| Type | Instance          | Name                             | Value      |
+------+-------------------+----------------------------------+------------+
| tidb | 172.16.5.181:4000 | performance.txn-total-size-limit | 1099511620 |
+------+-------------------+----------------------------------+------------+
1 row in set
Time: 0.067s
MySQL root@172.16.5.181:CREDIT_CARD> delete from t_1;
You're about to run a destructive command.
Do you want to proceed? (y/n): y
Your call!
(1105, 'Out Of Memory Quota![conn_id=0]')

The statement aborts when the memdb memory footprint reaches the limit (1.02G).

image
image

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
Copy link
Member

ti-chi-bot commented Jun 8, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • wshwsh12

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 added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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 Jun 8, 2022
@ekexium ekexium force-pushed the memdb-tracker branch 2 times, most recently from bd16bfd to 2bda643 Compare June 8, 2022 08:57
@ekexium ekexium requested a review from XuHuaiyu June 8, 2022 08:59
@ekexium ekexium marked this pull request as ready for review June 8, 2022 09:27
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 8, 2022
@ekexium
Copy link
Contributor Author

ekexium commented Jun 8, 2022

/run-build

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 15, 2022
@XuHuaiyu XuHuaiyu requested a review from wshwsh12 June 23, 2022 03:12
@@ -119,7 +119,7 @@ func TestBasicTxnState(t *testing.T) {
require.Nil(t, info)
}

func TestEntriesCountAndSize(t *testing.T) {
func TestEntriesCount(t *testing.T) {
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 check Size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now size is checked by the new test because it now reflects the actual memory footprint and thus is not a fixed number.

tests/realtikvtest/txntest/txn_state_test.go Outdated Show resolved Hide resolved
ekexium and others added 5 commits June 24, 2022 16:36
Signed-off-by: ekexium <ekexium@fastmail.com>
Signed-off-by: ekexium <ekexium@fastmail.com>
Signed-off-by: ekexium <ekexium@fastmail.com>
Signed-off-by: ekexium <ekexium@fastmail.com>
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 24, 2022
Signed-off-by: ekexium <ekexium@fastmail.com>
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 30, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Jul 5, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ hawkingrei
✅ ti-chi-bot
❌ ekexium


ekexium seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 16, 2022
@ekexium ekexium force-pushed the memdb-tracker branch 2 times, most recently from 0b661bd to 30a86ff Compare November 16, 2022 09:38
Copy link
Contributor

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

@@ -2607,7 +2607,12 @@ func (e *tidbTrxTableRetriever) retrieve(ctx context.Context, sctx sessionctx.Co
row = append(row, types.NewDatum(nil))
}
} else {
row = append(row, e.txnInfo[i].ToDatum(c.Name.O))
if c.Name.O == txninfo.MemBufferBytesStr {
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 use switch-case-default is better..

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 21, 2022
func (s *session) SetMemoryFootprintChangeHook() {
hook := func(mem uint64) {
if s.sessionVars.MemDBFootprint == nil {
tracker := memory.NewTracker(memory.LabelForMemDB, -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the total-txn-size-limit actually deprecated after this commit?

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's still used in memdb. But I think we could consider deprecating the config.

Signed-off-by: ekexium <eke@fastmail.com>
Signed-off-by: ekexium <eke@fastmail.com>
Signed-off-by: ekexium <eke@fastmail.com>
@ekexium
Copy link
Contributor Author

ekexium commented Nov 23, 2022

There's a test failed for data race. Let's wait for tikv/client-go#621

@ekexium ekexium force-pushed the memdb-tracker branch 2 times, most recently from c2e303b to 33122d4 Compare November 23, 2022 12:03
Signed-off-by: ekexium <eke@fastmail.com>
@ekexium
Copy link
Contributor Author

ekexium commented Nov 24, 2022

PTAL @XuHuaiyu

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 24, 2022
@XuHuaiyu
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: f1b87fc

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 24, 2022
@ti-chi-bot
Copy link
Member

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

At the same time I will also trigger all tests for you:

/run-all-tests

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.

@ekexium ekexium mentioned this pull request Nov 24, 2022
12 tasks
@ekexium
Copy link
Contributor Author

ekexium commented Nov 24, 2022

I changed the email address of my git config and caused the CLA check failure. I've made a new PR #39372

@ekexium ekexium closed this Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants