gc: Optimize GetAllKeyspacesGCStates for scenarios where there are too many keyspaces#9777
Conversation
…ort cancelling during execution Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
|
Skipping CI for Draft Pull Request. |
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (72.10%) is below the target coverage (74.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #9777 +/- ##
==========================================
+ Coverage 76.75% 76.88% +0.13%
==========================================
Files 488 491 +3
Lines 77727 78547 +820
==========================================
+ Hits 59658 60392 +734
- Misses 14414 14464 +50
- Partials 3655 3691 +36
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
/retest |
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
| m.mu.Lock() | ||
| defer m.mu.Unlock() | ||
|
|
||
| ensureUnlocked := func() { |
There was a problem hiding this comment.
To ensure the mutex is unlocked if the function is aborted abnormally (e.g., panicking), or more return path is introduced in the future.
| const sealedFlag int64 = 1 << 62 | ||
|
|
||
| func newTask[TResult any]() *task[TResult] { | ||
| ctx, cancel := context.WithCancel(context.Background()) |
There was a problem hiding this comment.
Do we need to pass a context instead of using a background context?
There was a problem hiding this comment.
This is to make it able to be canceled if all calls waiting for the result is canceled, but it won't be canceled immediately if the call that triggers the execution of the inner function is canceled while there are still other calls waiting for the result. If it should be an externally provided context, which should it be? Sounds like it should be a context that is canceled when the PD server process exits, if there is one.
pkg/keyspace/keyspace.go
Outdated
| func newKeyspaceIterator(manager *Manager, startID uint32) *Iterator { | ||
| return &Iterator{ | ||
| manager: manager, | ||
| startID: startID, |
There was a problem hiding this comment.
It's mistakenly left unused. As we don't need it for now, I removed it.
But I just noticed that there's no test that directly covers the IterateKeyspaces itself.. it's indirectly covered by the tests of GC states though.
Maybe I'd better add some?
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
|
/retest |
|
@MyonKeminta: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
|
BTW, I suggest using a separate goroutine to get GC states periodically in the future. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JmPotato, rleungx The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/cherry-pick release-nextgen-20251011 |
ref tikv#8978 Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
|
@rleungx: new pull request created to branch DetailsIn response to this:
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. |
…o many keyspaces (#9777) (#9872) ref #8978 This PR supports loading keyspaces by smaller batches in `GetAllKeyspacesGCStates`. This avoids it througing errors due to etcd txn size limit when there are too many keyspaces. Also makes `GetAllKeyspacesGCStates` support cancelling. This is not the ultimate solution for tracking GC states changes. The best way is to implement a streaming API that watches the changes of the GC states. However, this PR provides a simpler fix to make it able to run. Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io> Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com> Co-authored-by: MyonKeminta <9948422+MyonKeminta@users.noreply.github.com> Co-authored-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
What problem does this PR solve?
Issue Number: Ref #8978
What is changed and how does it work?
Check List
Tests
Code changes
-
Side effects
Related changes
pingcap/docs/pingcap/docs-cn:pingcap/tiup:Release note