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

client/http: change the keyspace config name for the GC management type #8000

Merged
merged 7 commits into from
Apr 1, 2024
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
15 changes: 10 additions & 5 deletions client/http/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ type Client interface {
DeleteOperators(context.Context) error

/* Keyspace interface */
UpdateKeyspaceSafePointVersion(ctx context.Context, keyspaceName string, keyspaceSafePointVersion *KeyspaceSafePointVersionConfig) error

// UpdateKeyspaceGCManagementType update the `gc_management_type` in keyspace meta config.
// If `gc_management_type` is `global_gc`, it means the current keyspace requires a tidb without 'keyspace-name'
// configured to run a global gc worker to calculate a global gc safe point.
// If `gc_management_type` is `keyspace_level_gc` it means the current keyspace can calculate gc safe point by its own.
UpdateKeyspaceGCManagementType(ctx context.Context, keyspaceName string, keyspaceGCManagementType *KeyspaceGCManagementTypeConfig) error
GetKeyspaceMetaByName(ctx context.Context, keyspaceName string) (*keyspacepb.KeyspaceMeta, error)

/* Client-related methods */
Expand Down Expand Up @@ -921,14 +926,14 @@ func (c *client) DeleteOperators(ctx context.Context) error {
WithMethod(http.MethodDelete))
}

// UpdateKeyspaceSafePointVersion patches the keyspace config.
func (c *client) UpdateKeyspaceSafePointVersion(ctx context.Context, keyspaceName string, keyspaceSafePointVersion *KeyspaceSafePointVersionConfig) error {
keyspaceConfigPatchJSON, err := json.Marshal(keyspaceSafePointVersion)
// UpdateKeyspaceGCManagementType patches the keyspace config.
func (c *client) UpdateKeyspaceGCManagementType(ctx context.Context, keyspaceName string, keyspaceGCmanagementType *KeyspaceGCManagementTypeConfig) error {
keyspaceConfigPatchJSON, err := json.Marshal(keyspaceGCmanagementType)
if err != nil {
return errors.Trace(err)
}
return c.request(ctx, newRequestInfo().
WithName(UpdateKeyspaceSafePointVersionName).
WithName(UpdateKeyspaceGCManagementTypeName).
WithURI(GetUpdateKeyspaceConfigURL(keyspaceName)).
WithMethod(http.MethodPatch).
WithBody(keyspaceConfigPatchJSON))
Expand Down
2 changes: 1 addition & 1 deletion client/http/request_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const (
setSnapshotRecoveringMarkName = "SetSnapshotRecoveringMark"
deleteSnapshotRecoveringMarkName = "DeleteSnapshotRecoveringMark"
deleteOperators = "DeleteOperators"
UpdateKeyspaceSafePointVersionName = "UpdateKeyspaceSafePointVersion"
UpdateKeyspaceGCManagementTypeName = "UpdateKeyspaceGCManagementType"
GetKeyspaceMetaByNameName = "GetKeyspaceMetaByName"
)

Expand Down
15 changes: 9 additions & 6 deletions client/http/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,17 @@ type MicroServiceMember struct {
StartTimestamp int64 `json:"start-timestamp"`
}

// KeyspaceSafePointVersion represents parameters needed to modify the safe point version.
type KeyspaceSafePointVersion struct {
SafePointVersion string `json:"safe_point_version,omitempty"`
// KeyspaceGCManagementType represents parameters needed to modify the gc management type.
// If `gc_management_type` is `global_gc`, it means the current keyspace requires a tidb without 'keyspace-name'
// configured to run a global gc worker to calculate a global gc safe point.
// If `gc_management_type` is `keyspace_level_gc` it means the current keyspace can calculate gc safe point by its own.
type KeyspaceGCManagementType struct {
GCManagementType string `json:"gc_management_type,omitempty"`
}

// KeyspaceSafePointVersionConfig represents parameters needed to modify target keyspace's configs.
type KeyspaceSafePointVersionConfig struct {
Config KeyspaceSafePointVersion `json:"config"`
// KeyspaceGCManagementTypeConfig represents parameters needed to modify target keyspace's configs.
type KeyspaceGCManagementTypeConfig struct {
Config KeyspaceGCManagementType `json:"config"`
}

// tempKeyspaceMeta is the keyspace meta struct that returned from the http interface.
Expand Down
22 changes: 12 additions & 10 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,28 +784,30 @@ func (suite *httpClientTestSuite) TestRedirectWithMetrics() {
c.Close()
}

func (suite *httpClientTestSuite) TestUpdateKeyspaceSafePointVersion() {
suite.RunTestInTwoModes(suite.checkUpdateKeyspaceSafePointVersion)
func (suite *httpClientTestSuite) TestUpdateKeyspaceGCManagementType() {
suite.RunTestInTwoModes(suite.checkUpdateKeyspaceGCManagementType)
}

func (suite *httpClientTestSuite) checkUpdateKeyspaceSafePointVersion(mode mode, client pd.Client) {
func (suite *httpClientTestSuite) checkUpdateKeyspaceGCManagementType(mode mode, client pd.Client) {
re := suite.Require()
env := suite.env[mode]

keyspaceName := "DEFAULT"
safePointVersion := "v2"
expectGCManagementType := "keyspace_level_gc"

keyspaceSafePointVersionConfig := pd.KeyspaceSafePointVersionConfig{
Config: pd.KeyspaceSafePointVersion{
SafePointVersion: safePointVersion,
keyspaceSafePointVersionConfig := pd.KeyspaceGCManagementTypeConfig{
Config: pd.KeyspaceGCManagementType{
GCManagementType: expectGCManagementType,
},
}
err := client.UpdateKeyspaceSafePointVersion(env.ctx, keyspaceName, &keyspaceSafePointVersionConfig)
err := client.UpdateKeyspaceGCManagementType(env.ctx, keyspaceName, &keyspaceSafePointVersionConfig)
re.NoError(err)

keyspaceMetaRes, err := client.GetKeyspaceMetaByName(env.ctx, keyspaceName)
re.NoError(err)
val, ok := keyspaceMetaRes.Config["safe_point_version"]
val, ok := keyspaceMetaRes.Config["gc_management_type"]

// Check it can get expect key and value in keyspace meta config.
re.True(ok)
re.Equal(safePointVersion, val)
re.Equal(expectGCManagementType, val)
}
Loading