diff --git a/server/api/service_gc_safepoint.go b/server/api/service_gc_safepoint.go index 270edca58bf..1e4c271e9f3 100644 --- a/server/api/service_gc_safepoint.go +++ b/server/api/service_gc_safepoint.go @@ -16,6 +16,7 @@ package api import ( "net/http" + "time" "github.com/gorilla/mux" "github.com/tikv/pd/pkg/storage/endpoint" @@ -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"` } // @Tags service_gc_safepoint @@ -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) } diff --git a/server/api/service_gc_safepoint_test.go b/server/api/service_gc_safepoint_test.go index c2d0603ac49..6325babd438 100644 --- a/server/api/service_gc_safepoint_test.go +++ b/server/api/service_gc_safepoint_test.go @@ -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)