tidb
tidb copied to clipboard
br: support to stop gc memory limit tuner when restore
What problem does this PR solve?
Issue Number: close #51078
Problem Summary: gc memory limit tuner decreases the frequency of GC triggered by memory limitation. backup/restore would downlaod/unmarshal much schema data, which creates large temporary data in memory. Therefore, BR needs to stop gc memory limit tuner.
What changed and how does it work?
add a switch to invalidate the debug.SetMemoryLimit operation in gc memory limit tuner.
Check List
Tests
- [x] 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.
introduce a parameter `--memory-limit`(Byte) to set go memory limit.
Hi @Leavrth. 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.
Codecov Report
Merging #51082 (46403b6) into master (f46bded) will increase coverage by
2.3251%. Report is 127 commits behind head on master. The diff coverage is69.2307%.
Additional details and impacted files
@@ Coverage Diff @@
## master #51082 +/- ##
================================================
+ Coverage 70.5615% 72.8867% +2.3251%
================================================
Files 1467 1476 +9
Lines 434897 457418 +22521
================================================
+ Hits 306870 333397 +26527
+ Misses 108755 103650 -5105
- Partials 19272 20371 +1099
| Flag | Coverage Δ | |
|---|---|---|
| integration | 49.2622% <5.5555%> (?) |
|
| unit | 70.5516% <69.2307%> (+0.1842%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Components | Coverage Δ | |
|---|---|---|
| dumpling | 54.2644% <ø> (-0.0297%) |
:arrow_down: |
| parser | ∅ <ø> (∅) |
|
| br | 49.9730% <50.0000%> (+4.2012%) |
:arrow_up: |
/review default
@lijie0123:
Review comments
Overall, the changes are well-structured, and it's clear what issue this pull request is trying to solve. However, there are some points that need attention:
-
Documentation: The newly added function
setMemoryLimitinmemory_limit_tuner.golacks function-level comments. Please add comments to describe its functionality and usage. -
Error handling: In the function
DisableSetMemoryLimit, there is no error handling for the case whendebug.SetMemoryLimit(limit)fails. Please handle this error appropriately. -
Test Coverage: The test
TestSetMemoryLimitinmemory_limit_tuner_test.goonly tests the happy path. Please also add error cases to validate the behavior of the function when errors occur. -
Data Race: The counter
disableinsetMemoryLimitSwitchstruct is not protected by a mutex for all operations. This could lead to data race issues if theEnableSetMemoryLimitandDisableSetMemoryLimitfunctions are called concurrently from different goroutines. Please ensure that all operations on shared data are protected by mutexes. -
Consistent naming: The function name
DisableSetMemoryLimitsuggests that it would disable setting the memory limit but it actually sets the memory limit if the limit is greater than 0. Consider renaming it to better reflect its functionality.
Suggested changes:
diff --git a/pkg/util/gctuner/memory_limit_tuner.go b/pkg/util/gctuner/memory_limit_tuner.go
index b01c6beae3da..b01c6beae3db 100644
--- a/pkg/util/gctuner/memory_limit_tuner.go
+++ b/pkg/util/gctuner/memory_limit_tuner.go
@@ -40,7 +40,7 @@ func setMemoryLimit(limit int64) int64 {
return 0
}
-// DisableSetMemoryLimit disables the memory limit tuner to set go memory limit.
+// SetMemoryLimitAndDisableTuner sets the go memory limit and disables the memory limit tuner.
// It also set the go memory limit and return the original go memory limit if in need.
func DisableSetMemoryLimit(limit int64) int64 {
globalSetMemoryLimitSwitch.Lock()
@@ -60,11 +60,14 @@ func (t *memoryLimitTuner) tuning() {
// MemoryLimit after the **next**
......
> Response is trunked for length limits.
<details>
In response to [this](https://github.com/pingcap/tidb/pull/51082#issuecomment-1938121008):
>/review default
Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: wshwsh12, YuJuncen
The full list of commands accepted by this bot can be found here.
The pull request process is described here
[LGTM Timeline notifier]
Timeline:
@Leavrth: 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 |
|---|---|---|---|---|
| tidb_parser_test | 46403b67290426619bb8f6e79483d447bf694af3 | link | true | /test tidb_parser_test |
| fast_test_tiprow | 46403b67290426619bb8f6e79483d447bf694af3 | link | true | /test fast_test_tiprow |
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.