From 11d5353ce62df3823074378a10778389563c9cc9 Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Fri, 9 Aug 2024 13:57:21 +0800 Subject: [PATCH] made other modifications Signed-off-by: Boyang Lyu --- client/http/api.go | 5 +++ client/http/interface.go | 6 ++-- pkg/storage/endpoint/gc_safe_point.go | 2 +- server/api/service_gc_safepoint.go | 2 +- tests/integrations/client/http_client_test.go | 32 ++++--------------- .../pdctl/command/gc_safepoint_command.go | 3 +- 6 files changed, 19 insertions(+), 31 deletions(-) diff --git a/client/http/api.go b/client/http/api.go index 90fa128defd..97d155fe04a 100644 --- a/client/http/api.go +++ b/client/http/api.go @@ -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 +} diff --git a/client/http/interface.go b/client/http/interface.go index ab5064770ac..f5cd1a38211 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -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(). @@ -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 { diff --git a/pkg/storage/endpoint/gc_safe_point.go b/pkg/storage/endpoint/gc_safe_point.go index 137d2abd680..8b6736fe0dc 100644 --- a/pkg/storage/endpoint/gc_safe_point.go +++ b/pkg/storage/endpoint/gc_safe_point.go @@ -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"` diff --git a/server/api/service_gc_safepoint.go b/server/api/service_gc_safepoint.go index 06d7f174a5a..ca29f9c352f 100644 --- a/server/api/service_gc_safepoint.go +++ b/server/api/service_gc_safepoint.go @@ -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"` diff --git a/tests/integrations/client/http_client_test.go b/tests/integrations/client/http_client_test.go index 650279536f9..bc343bf6d72 100644 --- a/tests/integrations/client/http_client_test.go +++ b/tests/integrations/client/http_client_test.go @@ -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) diff --git a/tools/pd-ctl/pdctl/command/gc_safepoint_command.go b/tools/pd-ctl/pdctl/command/gc_safepoint_command.go index 8cbce189693..8849eb2c848 100644 --- a/tools/pd-ctl/pdctl/command/gc_safepoint_command.go +++ b/tools/pd-ctl/pdctl/command/gc_safepoint_command.go @@ -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