Skip to content

Commit

Permalink
refine variables name
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Aug 2, 2023
1 parent 0faaf79 commit 5b395ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
23 changes: 11 additions & 12 deletions server/api/min_resolved_ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func newMinResolvedTSHandler(svr *server.Server, rd *render.Render) *minResolved

// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
type minResolvedTS struct {
IsRealTime bool `json:"is_real_time,omitempty"`
MinResolvedTS uint64 `json:"min_resolved_ts"`
PersistInterval typeutil.Duration `json:"persist_interval,omitempty"`
StoreMinResolvedTS map[uint64]uint64 `json:"store_min_resolved_ts"`
IsRealTime bool `json:"is_real_time,omitempty"`
MinResolvedTS uint64 `json:"min_resolved_ts"`
PersistInterval typeutil.Duration `json:"persist_interval,omitempty"`
StoresMinResolvedTS map[uint64]uint64 `json:"stores_min_resolved_ts"`
}

// @Tags min_store_resolved_ts
Expand Down Expand Up @@ -80,10 +80,10 @@ func (h *minResolvedTSHandler) GetStoreMinResolvedTS(w http.ResponseWriter, r *h
// @Router /min-resolved-ts [get]
func (h *minResolvedTSHandler) GetMinResolvedTS(w http.ResponseWriter, r *http.Request) {
c := h.svr.GetRaftCluster()
value := c.GetMinResolvedTS()
scopeMinResolvedTS := c.GetMinResolvedTS()
persistInterval := c.GetPDServerConfig().MinResolvedTSPersistenceInterval

var storeMinResolvedTS map[uint64]uint64
var storesMinResolvedTS map[uint64]uint64
if b, err := io.ReadAll(r.Body); err == nil && len(b) != 0 {
// stores ids is an optional parameter.
// if it is not empty, return the min resolved ts of the specified stores into map.
Expand All @@ -93,14 +93,13 @@ func (h *minResolvedTSHandler) GetMinResolvedTS(w http.ResponseWriter, r *http.R
h.rd.JSON(w, http.StatusBadRequest, err.Error())
return
}
c := h.svr.GetRaftCluster()
value, storeMinResolvedTS = c.GetMinResolvedTSByStoreIDs(ids)
scopeMinResolvedTS, storesMinResolvedTS = c.GetMinResolvedTSByStoreIDs(ids)
}

h.rd.JSON(w, http.StatusOK, minResolvedTS{
MinResolvedTS: value,
PersistInterval: persistInterval,
IsRealTime: persistInterval.Duration != 0,
StoreMinResolvedTS: storeMinResolvedTS,
MinResolvedTS: scopeMinResolvedTS,
PersistInterval: persistInterval,
IsRealTime: persistInterval.Duration != 0,
StoresMinResolvedTS: storesMinResolvedTS,
})
}
12 changes: 6 additions & 6 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2489,21 +2489,21 @@ func (c *RaftCluster) GetStoreMinResolvedTS(storeID uint64) uint64 {

// GetMinResolvedTSByStoreIDs returns the min resolved ts of the stores.
func (c *RaftCluster) GetMinResolvedTSByStoreIDs(ids []string) (uint64, map[uint64]uint64) {
curMinResolvedTS := uint64(math.MaxUint64)
allMinResolvedTS := make(map[uint64]uint64)
minResolvedTS := uint64(math.MaxUint64)
storesMinResolvedTS := make(map[uint64]uint64)
for _, idStr := range ids {
storeID, err := strconv.ParseUint(idStr, 10, 64)
if err != nil {
log.Error("parse store id failed", errs.ZapError(err))
continue
}
storeTS := c.GetStoreMinResolvedTS(storeID)
allMinResolvedTS[storeID] = storeTS
if curMinResolvedTS > storeTS {
curMinResolvedTS = storeTS
storesMinResolvedTS[storeID] = storeTS
if minResolvedTS > storeTS {
minResolvedTS = storeTS
}
}
return curMinResolvedTS, allMinResolvedTS
return minResolvedTS, storesMinResolvedTS
}

// GetExternalTS returns the external timestamp.
Expand Down

0 comments on commit 5b395ce

Please sign in to comment.