-
Notifications
You must be signed in to change notification settings - Fork 778
pd-ctl: add GC state inspection commands #11054
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
519ee19
client: expose keyspace-level GC mode
wfxr b4e6606
pd-ctl: add GC state JSON projections
wfxr 6066b9d
pd-ctl: cover empty global GC barriers
wfxr 045d188
pd-ctl: add gc-state commands
wfxr 6242d9e
pd-ctl: test gc-state against PD
wfxr b25d2cb
test: require GC state fixtures
wfxr 1575e08
docs: document pd-ctl gc-state
wfxr d71f055
client: fix GC test license header
wfxr 21761f2
pd-ctl: fix gc-state static checks
wfxr 4901984
test: isolate gc-state JSON decodes
wfxr 1897495
test: isolate cluster ID initialization
wfxr 2ea4924
pd-ctl: add global GC state view
wfxr 188ae40
pd-ctl: test and document global GC state
wfxr 02b9ba5
pd-ctl: derive NullKeyspace ID in help
wfxr d0245cb
pd-ctl: omit unified GC placeholders
wfxr ae378a1
pd-ctl: harden GC state inspection
wfxr 201ba64
docs: add GC barrier output examples
wfxr da195a8
pd-ctl: hide expired GC barriers by default
wfxr d1c509c
test: adapt GC state tests to API v3
wfxr 162c550
docs: add GC state global barrier refactor design
wfxr a08163c
docs: add GC state refactor implementation plan
wfxr 682f5ab
docs: merge GC state command refactor stages
wfxr bc9a7d8
client: preserve GC mode with global barriers
wfxr 90d0453
pd-ctl: use GetGCState for global barriers
wfxr cfc81e8
test: cover optional global GC state output
wfxr 78c56dc
docs: update GC state troubleshooting workflow
wfxr 0696343
pd-ctl: fix GC state test formatting
wfxr 4badda9
docs: remove GC state agent workflow artifacts
wfxr 2b3ff09
pd-ctl: make GC state RPC timeout configurable
wfxr a43f633
pd-ctl: address GC state review comments
wfxr c239a4a
pd-ctl: stabilize GC state snapshot tests
wfxr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright 2026 TiKV Project Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package pd | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/pingcap/kvproto/pkg/pdpb" | ||
| ) | ||
|
|
||
| func TestPBToGCStatePreservesKeyspaceLevelGC(t *testing.T) { | ||
| requestStart := time.Unix(100, 0) | ||
| for _, testCase := range []struct { | ||
| name string | ||
| isKeyspaceLevelGC bool | ||
| excludeBarriers bool | ||
| }{ | ||
| {name: "keyspace-level-with-barriers", isKeyspaceLevelGC: true}, | ||
| { | ||
| name: "keyspace-level-without-barriers", | ||
| isKeyspaceLevelGC: true, | ||
| excludeBarriers: true, | ||
| }, | ||
| {name: "unified-with-barriers", isKeyspaceLevelGC: false}, | ||
| { | ||
| name: "unified-without-barriers", | ||
| isKeyspaceLevelGC: false, | ||
| excludeBarriers: true, | ||
| }, | ||
| } { | ||
| t.Run(testCase.name, func(t *testing.T) { | ||
| pbState := &pdpb.GCState{ | ||
| KeyspaceScope: wrapKeyspaceScope(42), | ||
| IsKeyspaceLevelGc: testCase.isKeyspaceLevelGC, | ||
| TxnSafePoint: 100, | ||
| GcSafePoint: 90, | ||
| GcBarriers: []*pdpb.GCBarrierInfo{ | ||
| {BarrierId: "backup", BarrierTs: 95, TtlSeconds: 60}, | ||
| }, | ||
| } | ||
|
|
||
| state := pbToGCState( | ||
| pbState, | ||
| requestStart, | ||
| testCase.excludeBarriers, | ||
| ) | ||
| require.Equal(t, testCase.isKeyspaceLevelGC, | ||
| state.IsKeyspaceLevelGC) | ||
| require.Equal(t, uint32(42), state.KeyspaceID) | ||
| require.Equal(t, uint64(100), state.TxnSafePoint) | ||
| require.Equal(t, uint64(90), state.GCSafePoint) | ||
| require.Equal(t, !testCase.excludeBarriers, | ||
| state.HasGCBarriers()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestPBToGCStateWithGlobalBarriersPreservesKeyspaceLevelGC(t *testing.T) { | ||
| requestStart := time.Unix(100, 0) | ||
| state := pbToGCStateWithGlobalGCBarriers( | ||
| &pdpb.GCState{ | ||
| KeyspaceScope: wrapKeyspaceScope(42), | ||
| IsKeyspaceLevelGc: true, | ||
| TxnSafePoint: 100, | ||
| GcSafePoint: 90, | ||
| }, | ||
| &pdpb.GlobalGCBarriersInfo{ | ||
| Barriers: []*pdpb.GlobalGCBarrierInfo{ | ||
| {BarrierId: "snapshot", BarrierTs: 95, TtlSeconds: 60}, | ||
| }, | ||
| }, | ||
| requestStart, | ||
| true, | ||
| ) | ||
|
|
||
| require.True(t, state.IsKeyspaceLevelGC) | ||
| require.False(t, state.HasGCBarriers()) | ||
| require.True(t, state.HasGlobalGCBarriers()) | ||
| barriers, err := state.GetGlobalGCBarriers() | ||
| require.NoError(t, err) | ||
| require.Len(t, barriers, 1) | ||
| require.Equal(t, "snapshot", barriers[0].BarrierID) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The markdown in this document has strange, premature line breaks. I don't think they're necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed