Skip to content

Commit bdbf328

Browse files
api: add MinServiceGcSafepoint filed when list safepoints (tikv#7768)
close tikv#7767 Signed-off-by: nolouch <nolouch@gmail.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent ef6bdf1 commit bdbf328

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

server/api/service_gc_safepoint.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package api
1616

1717
import (
1818
"net/http"
19+
"time"
1920

2021
"github.com/gorilla/mux"
2122
"github.com/tikv/pd/pkg/storage/endpoint"
@@ -38,8 +39,9 @@ func newServiceGCSafepointHandler(svr *server.Server, rd *render.Render) *servic
3839
// ListServiceGCSafepoint is the response for list service GC safepoint.
3940
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
4041
type ListServiceGCSafepoint struct {
41-
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
42-
GCSafePoint uint64 `json:"gc_safe_point"`
42+
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
43+
MinServiceGcSafepoint uint64 `json:"min_service_gc_safe_point,omitempty"`
44+
GCSafePoint uint64 `json:"gc_safe_point"`
4345
}
4446

4547
// @Tags service_gc_safepoint
@@ -60,9 +62,21 @@ func (h *serviceGCSafepointHandler) GetGCSafePoint(w http.ResponseWriter, r *htt
6062
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
6163
return
6264
}
65+
var minSSp *endpoint.ServiceSafePoint
66+
for _, ssp := range ssps {
67+
if (minSSp == nil || minSSp.SafePoint > ssp.SafePoint) &&
68+
ssp.ExpiredAt > time.Now().Unix() {
69+
minSSp = ssp
70+
}
71+
}
72+
minServiceGcSafepoint := uint64(0)
73+
if minSSp != nil {
74+
minServiceGcSafepoint = minSSp.SafePoint
75+
}
6376
list := ListServiceGCSafepoint{
64-
GCSafePoint: gcSafepoint,
65-
ServiceGCSafepoints: ssps,
77+
GCSafePoint: gcSafepoint,
78+
ServiceGCSafepoints: ssps,
79+
MinServiceGcSafepoint: minServiceGcSafepoint,
6680
}
6781
h.rd.JSON(w, http.StatusOK, list)
6882
}

server/api/service_gc_safepoint_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func (suite *serviceGCSafepointTestSuite) TestServiceGCSafepoint() {
7777
SafePoint: 3,
7878
},
7979
},
80-
GCSafePoint: 1,
80+
GCSafePoint: 1,
81+
MinServiceGcSafepoint: 1,
8182
}
8283
for _, ssp := range list.ServiceGCSafepoints {
8384
err := storage.SaveServiceGCSafePoint(ssp)

0 commit comments

Comments
 (0)