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: sort gc safepoint in pd-ctl #7233

Merged
merged 4 commits into from
Oct 26, 2023
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
7 changes: 4 additions & 3 deletions server/api/service_gc_safepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ 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.
type listServiceGCSafepoint struct {
type ListServiceGCSafepoint struct {
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
GCSafePoint uint64 `json:"gc_safe_point"`
}

// @Tags service_gc_safepoint
// @Summary Get all service GC safepoint.
// @Produce json
// @Success 200 {array} listServiceGCSafepoint
// @Success 200 {array} ListServiceGCSafepoint
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /gc/safepoint [get]
func (h *serviceGCSafepointHandler) GetGCSafePoint(w http.ResponseWriter, r *http.Request) {
Expand All @@ -59,7 +60,7 @@ func (h *serviceGCSafepointHandler) GetGCSafePoint(w http.ResponseWriter, r *htt
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
list := listServiceGCSafepoint{
list := ListServiceGCSafepoint{
GCSafePoint: gcSafepoint,
ServiceGCSafepoints: ssps,
}
Expand Down
4 changes: 2 additions & 2 deletions server/api/service_gc_safepoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (suite *serviceGCSafepointTestSuite) TestServiceGCSafepoint() {
sspURL := suite.urlPrefix + "/gc/safepoint"

storage := suite.svr.GetStorage()
list := &listServiceGCSafepoint{
list := &ListServiceGCSafepoint{
ServiceGCSafepoints: []*endpoint.ServiceSafePoint{
{
ServiceID: "a",
Expand Down Expand Up @@ -87,7 +87,7 @@ func (suite *serviceGCSafepointTestSuite) TestServiceGCSafepoint() {
res, err := testDialClient.Get(sspURL)
suite.NoError(err)
defer res.Body.Close()
listResp := &listServiceGCSafepoint{}
listResp := &ListServiceGCSafepoint{}
err = apiutil.ReadJSON(res.Body, listResp)
suite.NoError(err)
suite.Equal(list, listResp)
Expand Down
18 changes: 17 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,9 +15,12 @@
package command

import (
"encoding/json"
"net/http"
"sort"

"github.com/spf13/cobra"
"github.com/tikv/pd/server/api"
)

var (
Expand Down Expand Up @@ -52,7 +55,20 @@ func showSSPs(cmd *cobra.Command, args []string) {
cmd.Printf("Failed to get service GC safepoint: %s\n", err)
return
}
cmd.Println(r)
var safepoint api.ListServiceGCSafepoint
if err := json.Unmarshal([]byte(r), &safepoint); err != nil {
cmd.Printf("Failed to unmarshal service GC safepoint: %s\n", err)
return
}
sort.Slice(safepoint.ServiceGCSafepoints, func(i, j int) bool {
return safepoint.ServiceGCSafepoints[i].SafePoint < safepoint.ServiceGCSafepoints[j].SafePoint
})
data, err := json.MarshalIndent(safepoint, "", " ")
if err != nil {
cmd.Printf("Failed to marshal service GC safepoint: %s\n", err)
return
}
cmd.Println(string(data))
}

func deleteSSP(cmd *cobra.Command, args []string) {
Expand Down
Loading