Skip to content

Commit 992f464

Browse files
committed
update
Signed-off-by: husharp <jinhao.hu@pingcap.com>
1 parent 08b8fc8 commit 992f464

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

server/api/min_resolved_ts.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ package api
1616

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

21+
"github.com/gorilla/mux"
2022
"github.com/tikv/pd/pkg/typeutil"
2123
"github.com/tikv/pd/server"
2224
"github.com/unrolled/render"
@@ -41,6 +43,30 @@ type minResolvedTS struct {
4143
PersistInterval typeutil.Duration `json:"persist_interval,omitempty"`
4244
}
4345

46+
// @Tags min_store_resolved_ts
47+
// @Summary Get store-level min resolved ts.
48+
// @Produce json
49+
// @Success 200 {array} minResolvedTS
50+
// @Failure 400 {string} string "The input is invalid."
51+
// @Failure 500 {string} string "PD server failed to proceed the request."
52+
// @Router /min-resolved-ts/{store_id} [get]
53+
func (h *minResolvedTSHandler) GetStoreMinResolvedTS(w http.ResponseWriter, r *http.Request) {
54+
c := h.svr.GetRaftCluster()
55+
idStr := mux.Vars(r)["store_id"]
56+
storeID, err := strconv.ParseUint(idStr, 10, 64)
57+
if err != nil {
58+
h.rd.JSON(w, http.StatusBadRequest, err.Error())
59+
return
60+
}
61+
value := c.GetStoreMinResolvedTS(storeID)
62+
persistInterval := c.GetPDServerConfig().MinResolvedTSPersistenceInterval
63+
h.rd.JSON(w, http.StatusOK, minResolvedTS{
64+
MinResolvedTS: value,
65+
PersistInterval: persistInterval,
66+
IsRealTime: persistInterval.Duration != 0,
67+
})
68+
}
69+
4470
// @Tags min_resolved_ts
4571
// @Summary Get cluster-level min resolved ts.
4672
// @Produce json

server/api/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router {
351351
// min resolved ts API
352352
minResolvedTSHandler := newMinResolvedTSHandler(svr, rd)
353353
registerFunc(clusterRouter, "/min-resolved-ts", minResolvedTSHandler.GetMinResolvedTS, setMethods(http.MethodGet), setAuditBackend(prometheus))
354+
registerFunc(clusterRouter, "/min-resolved-ts/{store_id}", minResolvedTSHandler.GetStoreMinResolvedTS, setMethods(http.MethodGet), setAuditBackend(prometheus))
354355

355356
// unsafe admin operation API
356357
unsafeOperationHandler := newUnsafeOperationHandler(svr, rd)

server/cluster/cluster.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,16 @@ func (c *RaftCluster) GetMinResolvedTS() uint64 {
23082308
return c.minResolvedTS
23092309
}
23102310

2311+
// GetStoreMinResolvedTS returns the min resolved ts of the store.
2312+
func (c *RaftCluster) GetStoreMinResolvedTS(storeID uint64) uint64 {
2313+
c.RLock()
2314+
defer c.RUnlock()
2315+
if !c.isInitialized() || !core.IsAvailableForMinResolvedTS(c.GetStore(storeID)) {
2316+
return math.MaxUint64
2317+
}
2318+
return c.GetStore(storeID).GetMinResolvedTS()
2319+
}
2320+
23112321
// GetExternalTS returns the external timestamp.
23122322
func (c *RaftCluster) GetExternalTS() uint64 {
23132323
c.RLock()

0 commit comments

Comments
 (0)