Skip to content

Commit

Permalink
client/http: change the keyspace config name for the GC management ty…
Browse files Browse the repository at this point in the history
…pe (#8000)

ref #8002

Change `safe_point_version` to 'gc_management_type' in keyspace meta config

Signed-off-by: y_static_y@sina.com <y_static_y@sina.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
ystaticy and ti-chi-bot[bot] committed Apr 1, 2024
1 parent 945e29c commit 75b8a4b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
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)
}

0 comments on commit 75b8a4b

Please sign in to comment.