Skip to content

keyspace: set GCManagementType default value to KeyspaceLevelGC for NextGen #9399

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 4 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/tikv/pd/pkg/utils/keypath"
"github.com/tikv/pd/pkg/utils/logutil"
"github.com/tikv/pd/pkg/utils/syncutil"
"github.com/tikv/pd/pkg/versioninfo/kerneltype"
)

const (
Expand Down Expand Up @@ -233,6 +234,12 @@ func (manager *Manager) CreateKeyspace(request *CreateKeyspaceRequest) (*keyspac
request.Config[UserKindKey] = config[UserKindKey]
}
}
// Set default value of GCManagementType to KeyspaceLevelGC for NextGen
if kerneltype.IsNextGen() {
if v, ok := request.Config[GCManagementType]; !ok || len(v) == 0 {
request.Config[GCManagementType] = KeyspaceLevelGC
}
}
// Create a disabled keyspace meta for tikv-server to get the config on keyspace split.
keyspace := &keyspacepb.KeyspaceMeta{
Id: newID,
Expand Down
42 changes: 42 additions & 0 deletions pkg/keyspace/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,48 @@ func (suite *keyspaceTestSuite) TestCreateKeyspace() {
re.Error(err)
}

func (suite *keyspaceTestSuite) TestGCManagementTypeDefaultValue() {
re := suite.Require()
manager := suite.manager

now := time.Now().Unix()
const classic = `return(false)`
const nextGen = `return(true)`

type testCase struct {
nextGenFlag string
gcManagementType string
expect string
}

cases := []testCase{
{classic, "", ""},
{classic, UnifiedGC, UnifiedGC},
{classic, KeyspaceLevelGC, KeyspaceLevelGC},
{nextGen, "", KeyspaceLevelGC},
{nextGen, UnifiedGC, UnifiedGC},
{classic, KeyspaceLevelGC, KeyspaceLevelGC},
}
defer failpoint.Disable("github.com/tikv/pd/pkg/versioninfo/kerneltype/mockNextGenBuildFlag")
for idx, tc := range cases {
failpoint.Enable("github.com/tikv/pd/pkg/versioninfo/kerneltype/mockNextGenBuildFlag", tc.nextGenFlag)
cfg := make(map[string]string)
if tc.gcManagementType != "" {
cfg[GCManagementType] = tc.gcManagementType
}
req := &CreateKeyspaceRequest{
Name: fmt.Sprintf("test_gc_management_type_%d", idx),
CreateTime: now,
Config: cfg,
}
created, err := manager.CreateKeyspace(req)
re.NoError(err)
loaded, err := manager.LoadKeyspaceByID(created.Id)
re.NoError(err)
re.Equal(tc.expect, loaded.Config[GCManagementType])
}
}

func makeCreateKeyspaceByIDRequests(count int) []*CreateKeyspaceByIDRequest {
now := time.Now().Unix()
requests := make([]*CreateKeyspaceByIDRequest, count)
Expand Down
9 changes: 9 additions & 0 deletions pkg/versioninfo/kerneltype/classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@

package kerneltype

import (
"github.com/pingcap/failpoint"
)

var (
// KernelType is the current kernel type, which is Classic in this case.
KernelType = "Classic"
)

// IsNextGen returns true if the current kernel type is NextGen.
func IsNextGen() bool {
failpoint.Inject("mockNextGenBuildFlag", func(val failpoint.Value) {
if v, ok := val.(bool); ok {
failpoint.Return(v)
}
})
return false
}
9 changes: 9 additions & 0 deletions pkg/versioninfo/kerneltype/nextgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package kerneltype

import (
"github.com/pingcap/failpoint"
)

var (
// KernelType is the current kernel type, which is Next Generation in this case.
KernelType = "Next Generation"
Expand All @@ -24,5 +28,10 @@ var (
// IsNextGen returns true if the current kernel type is Next Generation.
// see doc.go for more info.
func IsNextGen() bool {
failpoint.Inject("mockNextGenBuildFlag", func(val failpoint.Value) {
if v, ok := val.(bool); ok {
failpoint.Return(v)
}
})
return true
}