Skip to content

Commit

Permalink
made other modifications
Browse files Browse the repository at this point in the history
Signed-off-by: Boyang Lyu <[email protected]>
  • Loading branch information
JackL9u committed Aug 9, 2024
1 parent 6c7de04 commit 11d5353
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 31 deletions.
5 changes: 5 additions & 0 deletions client/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,8 @@ func GetUpdateKeyspaceConfigURL(keyspaceName string) string {
func GetKeyspaceMetaByNameURL(keyspaceName string) string {
return fmt.Sprintf(GetKeyspaceMetaByName, keyspaceName)
}

// GetDeleteSafePointURI returns the URI for delete safepoint service
func GetDeleteSafePointURI(serviceID string) string {
return safepoint + "/" + serviceID
}
6 changes: 3 additions & 3 deletions client/http/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ func (c *client) GetKeyspaceMetaByName(ctx context.Context, keyspaceName string)
return &keyspaceMetaPB, nil
}

// GetGCSafePoint get the gc_safepoint
// GetGCSafePoint gets the GC safe point list.
func (c *client) GetGCSafePoint(ctx context.Context) (ListServiceGCSafepoint, error) {
var gcSafePoint ListServiceGCSafepoint
err := c.request(ctx, newRequestInfo().
Expand All @@ -1041,12 +1041,12 @@ func (c *client) GetGCSafePoint(ctx context.Context) (ListServiceGCSafepoint, er
return gcSafePoint, nil
}

// DeleteGCSafePoint deletes a gc safepoint
// DeleteGCSafePoint deletes a GC safe point with the given service ID.
func (c *client) DeleteGCSafePoint(ctx context.Context, serviceID string) (string, error) {
var msg string
err := c.request(ctx, newRequestInfo().
WithName(DeleteGCSafePointName).
WithURI(safepoint+"/"+serviceID).
WithURI(GetDeleteSafePointURI(serviceID)).
WithMethod(http.MethodDelete).
WithResp(&msg))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/endpoint/gc_safe_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// ServiceSafePoint is the safepoint for a specific service
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
// this type is in sync with client/http/types.go
// This type is in sync with `client/http/types.go`.
type ServiceSafePoint struct {
ServiceID string `json:"service_id"`
ExpiredAt int64 `json:"expired_at"`
Expand Down
2 changes: 1 addition & 1 deletion server/api/service_gc_safepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newServiceGCSafepointHandler(svr *server.Server, rd *render.Render) *servic

// ListServiceGCSafepoint is the response for list service GC safepoint.
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
// this type is now in sync with pd/client/http/types.go ListServiceGCSafepoint
// This type is in sync with `pd/client/http/types.go`.
type ListServiceGCSafepoint struct {
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
MinServiceGcSafepoint uint64 `json:"min_service_gc_safe_point,omitempty"`
Expand Down
32 changes: 7 additions & 25 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,33 +881,15 @@ func (suite *httpClientTestSuite) TestGetSafePoint() {
re.Len(l.ServiceGCSafepoints, 3)

for i, val := range l.ServiceGCSafepoints {
if i == 0 {
re.Equal("AAA", val.ServiceID)
re.Equal(uint64(1), val.SafePoint)
}

if i == 1 {
re.Equal("BBB", val.ServiceID)
re.Equal(uint64(2), val.SafePoint)
}

if i == 2 {
re.Equal("CCC", val.ServiceID)
re.Equal(uint64(3), val.SafePoint)
}
re.Equal(list.ServiceGCSafepoints[i].ServiceID, val.ServiceID)
re.Equal(list.ServiceGCSafepoints[i].SafePoint, val.SafePoint)
}

msg1, err1 := client.DeleteGCSafePoint(ctx, "AAA")
re.NoError(err1)
re.Equal("Delete service GC safepoint successfully.", msg1)

msg2, err2 := client.DeleteGCSafePoint(ctx, "BBB")
re.NoError(err2)
re.Equal("Delete service GC safepoint successfully.", msg2)

msg3, err3 := client.DeleteGCSafePoint(ctx, "DDD")
re.NoError(err3)
re.Equal("Delete service GC safepoint successfully.", msg3)
for i := 0; i < 3; i++ {
msg, err := client.DeleteGCSafePoint(ctx, list.ServiceGCSafepoints[i].ServiceID)
re.NoError(err)
re.Equal("Delete service GC safepoint successfully.", msg)
}

_, err4 := client.DeleteGCSafePoint(ctx, "gc_worker")
re.Error(err4)
Expand Down
3 changes: 2 additions & 1 deletion tools/pd-ctl/pdctl/command/gc_safepoint_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package command

import (
"github.com/spf13/cobra"
"sort"

"github.com/spf13/cobra"
)

// NewServiceGCSafepointCommand return a service gc safepoint subcommand of rootCmd
Expand Down

0 comments on commit 11d5353

Please sign in to comment.