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

improve ps gc speed by dumping snapshot from memory directly #7668

Merged
merged 15 commits into from
Jun 30, 2023

Conversation

lidezhu
Copy link
Contributor

@lidezhu lidezhu commented Jun 16, 2023

What problem does this PR solve?

Issue Number: ref #6827

Problem Summary: Previously, when dumping snapshot for PageDirectory, we load all target wal files and create a temp PageDirectory for dumping. And after dumping the snapshot, we can reclaim all the target wal files.
But under heavy write scenario, the dump snapshot speed is a little slow. This will make the number of wal files keep increasing and make the process of dumping snapshot cost more and more memory.

What is changed and how it works?

Change the type of being_ref_count from Int64 to MultiVersionRefCount *;

  1. If being_ref_count is nullptr, it means 1;
  2. We maintain a map PageVersion -> RefCount inside MultiVersionRefCount;
  3. When creating a ref page id, increasing the ref by calling getLatestRefCount and appendRefCount;
  4. When delete a ref in gc process, deleting the ref by calling decrLatestRefCountInSnap. And it will also reclaim older version of ref count;

When dumping snapshot, ref count increasing caused by new ref page will just be appended to MultiVersionRefCount, so it won't affect the ref count value that the snapshot can see.
GC process can still change ref count value for a snapshot, but it doesn't matter because gc won't run concurrently with dumping snapshot.

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

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 16, 2023
@lidezhu lidezhu changed the title Improve ps gc speed by dumping snapshot from memory directly improve ps gc speed by dumping snapshot from memory directly Jun 16, 2023
@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/rebuild

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/run-all-tests

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/rebuild

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/run-integration-test

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/run-unit-test

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/run-all-tests

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/run-all-tests

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/run-integration-test

1 similar comment
@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 16, 2023

/run-integration-test

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 17, 2023

/run-all-tests

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 17, 2023

/run-integration-test

1 similar comment
@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 17, 2023

/run-integration-test

dbms/src/Storages/Page/V3/GCDefines.cpp Show resolved Hide resolved
dbms/src/Storages/Page/V3/PageDirectory.h Outdated Show resolved Hide resolved
dbms/src/Storages/Page/V3/PageDirectory.h Outdated Show resolved Hide resolved
Co-authored-by: JaySon <tshent@qq.com>
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 26, 2023
@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 26, 2023

/run-all-tests

Co-authored-by: JaySon <tshent@qq.com>
Copy link
Contributor

@JaySon-Huang JaySon-Huang 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 lgtm label Jun 30, 2023
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jun 30, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flowbehappy, JaySon-Huang

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:
  • OWNERS [JaySon-Huang,flowbehappy]

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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 30, 2023
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jun 30, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-06-26 08:07:27.245242872 +0000 UTC m=+608612.646493326: ☑️ agreed by flowbehappy.
  • 2023-06-30 08:52:05.67748904 +0000 UTC m=+75609.052066890: ☑️ agreed by JaySon-Huang.

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 30, 2023

/merge

@JaySon-Huang
Copy link
Contributor

/run-all-tests

@lidezhu
Copy link
Contributor Author

lidezhu commented Jun 30, 2023

/run-unit-test

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants