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

minResolvedTS: Provide an API to fetch the store resolved_ts #6413

Merged
merged 4 commits into from
May 9, 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
26 changes: 26 additions & 0 deletions server/api/min_resolved_ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package api

import (
"net/http"
"strconv"

"github.com/gorilla/mux"
"github.com/tikv/pd/pkg/utils/typeutil"
"github.com/tikv/pd/server"
"github.com/unrolled/render"
Expand All @@ -41,6 +43,30 @@ type minResolvedTS struct {
PersistInterval typeutil.Duration `json:"persist_interval,omitempty"`
}

// @Tags min_store_resolved_ts
// @Summary Get store-level min resolved ts.
// @Produce json
// @Success 200 {array} minResolvedTS
// @Failure 400 {string} string "The input is invalid."
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /min-resolved-ts/{store_id} [get]
func (h *minResolvedTSHandler) GetStoreMinResolvedTS(w http.ResponseWriter, r *http.Request) {
c := h.svr.GetRaftCluster()
idStr := mux.Vars(r)["store_id"]
storeID, err := strconv.ParseUint(idStr, 10, 64)
if err != nil {
h.rd.JSON(w, http.StatusBadRequest, err.Error())
return
}
value := c.GetStoreMinResolvedTS(storeID)
persistInterval := c.GetPDServerConfig().MinResolvedTSPersistenceInterval
h.rd.JSON(w, http.StatusOK, minResolvedTS{
MinResolvedTS: value,
PersistInterval: persistInterval,
IsRealTime: persistInterval.Duration != 0,
})
}

// @Tags min_resolved_ts
// @Summary Get cluster-level min resolved ts.
// @Produce json
Expand Down
1 change: 1 addition & 0 deletions server/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router {
// min resolved ts API
minResolvedTSHandler := newMinResolvedTSHandler(svr, rd)
registerFunc(clusterRouter, "/min-resolved-ts", minResolvedTSHandler.GetMinResolvedTS, setMethods(http.MethodGet), setAuditBackend(prometheus))
registerFunc(clusterRouter, "/min-resolved-ts/{store_id}", minResolvedTSHandler.GetStoreMinResolvedTS, setMethods(http.MethodGet), setAuditBackend(prometheus))

// unsafe admin operation API
unsafeOperationHandler := newUnsafeOperationHandler(svr, rd)
Expand Down
10 changes: 10 additions & 0 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,16 @@ func (c *RaftCluster) GetMinResolvedTS() uint64 {
return c.minResolvedTS
}

// GetStoreMinResolvedTS returns the min resolved ts of the store.
func (c *RaftCluster) GetStoreMinResolvedTS(storeID uint64) uint64 {
c.RLock()
defer c.RUnlock()
if !c.isInitialized() || !core.IsAvailableForMinResolvedTS(c.GetStore(storeID)) {
return math.MaxUint64
}
return c.GetStore(storeID).GetMinResolvedTS()
}

// GetExternalTS returns the external timestamp.
func (c *RaftCluster) GetExternalTS() uint64 {
c.RLock()
Expand Down