Skip to content

Commit

Permalink
api: add MinServiceGcSafepoint filed when list safepoints
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <[email protected]>
  • Loading branch information
nolouch committed Jan 26, 2024
1 parent 91bca92 commit 11de224
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
22 changes: 18 additions & 4 deletions server/api/service_gc_safepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package api

import (
"net/http"
"time"

"github.com/gorilla/mux"
"github.com/tikv/pd/pkg/storage/endpoint"
Expand All @@ -38,8 +39,9 @@ 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 {
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
GCSafePoint uint64 `json:"gc_safe_point"`
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
MinServiceGcSafepoint uint64 `json:"min_service_gc_safe_point,omitempty"`
GCSafePoint uint64 `json:"gc_safe_point, "`

Check failure on line 44 in server/api/service_gc_safepoint.go

View workflow job for this annotation

GitHub Actions / statics

structtag: struct field tag `json:"gc_safe_point, "` not compatible with reflect.StructTag.Get: suspicious space in struct tag value (govet)
}

// @Tags service_gc_safepoint
Expand All @@ -60,9 +62,21 @@ func (h *serviceGCSafepointHandler) GetGCSafePoint(w http.ResponseWriter, r *htt
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
var minSSp *endpoint.ServiceSafePoint
for _, ssp := range ssps {
if (minSSp == nil || minSSp.SafePoint > ssp.SafePoint) &&
ssp.ExpiredAt > time.Now().Unix() {
minSSp = ssp
}
}
minServiceGcSafepoint := uint64(0)
if minSSp != nil {
minServiceGcSafepoint = minSSp.SafePoint
}
list := ListServiceGCSafepoint{
GCSafePoint: gcSafepoint,
ServiceGCSafepoints: ssps,
GCSafePoint: gcSafepoint,
ServiceGCSafepoints: ssps,
MinServiceGcSafepoint: minServiceGcSafepoint,
}
h.rd.JSON(w, http.StatusOK, list)
}
Expand Down
3 changes: 2 additions & 1 deletion server/api/service_gc_safepoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (suite *serviceGCSafepointTestSuite) TestServiceGCSafepoint() {
SafePoint: 3,
},
},
GCSafePoint: 1,
GCSafePoint: 1,
MinServiceGcSafepoint: 1,
}
for _, ssp := range list.ServiceGCSafepoints {
err := storage.SaveServiceGCSafePoint(ssp)
Expand Down

0 comments on commit 11de224

Please sign in to comment.