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

ctl: replace gc_safepoint call with HTTP SDK #8494

Closed
wants to merge 7 commits into from
Closed
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
2 changes: 2 additions & 0 deletions client/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const (
// Keyspace
KeyspaceConfig = "/pd/api/v2/keyspaces/%s/config"
GetKeyspaceMetaByName = "/pd/api/v2/keyspaces/%s"
// safepoint
GCSafepoint = "pd/api/v1/gc/safepoint"
)

// RegionByID returns the path of PD HTTP API to get region by ID.
Expand Down
30 changes: 30 additions & 0 deletions client/http/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ type Client interface {
WithTargetURL(string) Client
// Close gracefully closes the HTTP client.
Close()

//safepoint
GetGCSafePoint(context.Context) (Safepoint, error)
DeleteGCSafePoint(context.Context, string) (string, error)
}

var _ Client = (*client)(nil)
Expand Down Expand Up @@ -1024,3 +1028,29 @@ func (c *client) GetKeyspaceMetaByName(ctx context.Context, keyspaceName string)
}
return &keyspaceMetaPB, nil
}

func (c *client) GetGCSafePoint(ctx context.Context) (Safepoint ,error) {
var sfp Safepoint
err := c.request(ctx, newRequestInfo().
WithName(GetGCSafePointName).
WithURI(GCSafepoint).
WithMethod(http.MethodGet).
WithResp(&sfp))
if err != nil {
return nil, err
}
return sfp, nil
}

func (c *client) DeleteGCSafePoint(ctx context.Context, serviceID string) (string ,error) {
var msg string
err := c.request(ctx, newRequestInfo().
WithName(DeleteGCSafePointName).
WithURI(GCSafepoint + "/" + serviceID).
WithMethod(http.MethodDelete).
WithResp(&msg))
if err != nil {
return nil, err
}
return msg, nil
}
2 changes: 2 additions & 0 deletions client/http/request_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const (
deleteOperators = "DeleteOperators"
UpdateKeyspaceGCManagementTypeName = "UpdateKeyspaceGCManagementType"
GetKeyspaceMetaByNameName = "GetKeyspaceMetaByName"
GetGCSafePointName = "GetGCSafePoint"
DeleteGCSafePointName = "DeleteGCSafePoint"
)

type requestInfo struct {
Expand Down
6 changes: 6 additions & 0 deletions client/http/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,9 @@ type Health struct {
ClientUrls []string `json:"client_urls"`
Health bool `json:"health"`
}

type Safepoint struct {
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
MinServiceGcSafepoint uint64 `json:"min_service_gc_safe_point,omitempty"`
GCSafePoint uint64 `json:"gc_safe_point"`
}
1 change: 1 addition & 0 deletions server/api/service_gc_safepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +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.
// - Need to sync with client/http/types.go#Safepoint
type ListServiceGCSafepoint struct {
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
MinServiceGcSafepoint uint64 `json:"min_service_gc_safe_point,omitempty"`
Expand Down
16 changes: 7 additions & 9 deletions tools/pd-ctl/pdctl/command/gc_safepoint_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import (
"github.com/tikv/pd/server/api"
)

var (
serviceGCSafepointPrefix = "pd/api/v1/gc/safepoint"
)

// NewServiceGCSafepointCommand return a service gc safepoint subcommand of rootCmd
func NewServiceGCSafepointCommand() *cobra.Command {
l := &cobra.Command{
Expand All @@ -50,12 +46,13 @@ func NewDeleteServiceGCSafepointCommand() *cobra.Command {
}

func showSSPs(cmd *cobra.Command, _ []string) {
r, err := doRequest(cmd, serviceGCSafepointPrefix, http.MethodGet, http.Header{})
// r, err := doRequest(cmd, serviceGCSafepointPrefix, http.MethodGet, http.Header{})
r, err := PDCli.GetGCSafePoint(cmd.Context())
if err != nil {
cmd.Printf("Failed to get service GC safepoint: %s\n", err)
return
}
var safepoint api.ListServiceGCSafepoint
var safepoint Safepoint
if err := json.Unmarshal([]byte(r), &safepoint); err != nil {
cmd.Printf("Failed to unmarshal service GC safepoint: %s\n", err)
return
Expand All @@ -76,9 +73,10 @@ func deleteSSP(cmd *cobra.Command, args []string) {
cmd.Usage()
return
}
serviceID := args[0]
deleteURL := serviceGCSafepointPrefix + "/" + serviceID
r, err := doRequest(cmd, deleteURL, http.MethodDelete, http.Header{})
// serviceID := args[0]
// deleteURL := serviceGCSafepointPrefix + "/" + serviceID
// r, err := doRequest(cmd, deleteURL, http.MethodDelete, http.Header{})
r, err := PDCli.DeleteGCSafePoint(cmd.Context(), args[0])
if err != nil {
cmd.Printf("Failed to delete service GC safepoint: %s\n", err)
return
Expand Down
Loading