-
Notifications
You must be signed in to change notification settings - Fork 759
[cherry-pick 6327] server: add accelerate-schedule/batch api #6348
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |||||||||
| "net/url" | ||||||||||
| "sort" | ||||||||||
| "strconv" | ||||||||||
| "strings" | ||||||||||
|
|
||||||||||
| "github.com/gorilla/mux" | ||||||||||
| "github.com/pingcap/failpoint" | ||||||||||
|
|
@@ -836,6 +837,61 @@ func (h *regionsHandler) AccelerateRegionsScheduleInRange(w http.ResponseWriter, | |||||||||
| h.rd.Text(w, http.StatusOK, fmt.Sprintf("Accelerate regions scheduling in a given range [%s,%s)", rawStartKey, rawEndKey)) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // @Tags region | ||||||||||
| // @Summary Accelerate regions scheduling in given ranges, only receive hex format for keys | ||||||||||
| // @Accept json | ||||||||||
| // @Param body body object true "json params" | ||||||||||
| // @Param limit query integer false "Limit count" default(256) | ||||||||||
| // @Produce json | ||||||||||
| // @Success 200 {string} string "Accelerate regions scheduling in given ranges [startKey1, endKey1), [startKey2, endKey2), ..." | ||||||||||
| // @Failure 400 {string} string "The input is invalid." | ||||||||||
| // @Router /regions/accelerate-schedule/batch [post] | ||||||||||
| func (h *regionsHandler) AccelerateRegionsScheduleInRanges(w http.ResponseWriter, r *http.Request) { | ||||||||||
| rc := getCluster(r) | ||||||||||
| var input []map[string]interface{} | ||||||||||
| if err := apiutil.ReadJSONRespondError(h.rd, w, r.Body, &input); err != nil { | ||||||||||
| return | ||||||||||
| } | ||||||||||
| limit := 256 | ||||||||||
| if limitStr := r.URL.Query().Get("limit"); limitStr != "" { | ||||||||||
| var err error | ||||||||||
| limit, err = strconv.Atoi(limitStr) | ||||||||||
| if err != nil { | ||||||||||
| h.rd.JSON(w, http.StatusBadRequest, err.Error()) | ||||||||||
| return | ||||||||||
| } | ||||||||||
| } | ||||||||||
| if limit > maxRegionLimit { | ||||||||||
| limit = maxRegionLimit | ||||||||||
| } | ||||||||||
| var msgBuilder strings.Builder | ||||||||||
| msgBuilder.Grow(128) | ||||||||||
| msgBuilder.WriteString("Accelerate regions scheduling in given ranges: ") | ||||||||||
| var regions []*core.RegionInfo | ||||||||||
|
||||||||||
| for _, rg := range input { | ||||||||||
| startKey, rawStartKey, err := apiutil.ParseKey("start_key", rg) | ||||||||||
| if err != nil { | ||||||||||
| h.rd.JSON(w, http.StatusBadRequest, err.Error()) | ||||||||||
| return | ||||||||||
| } | ||||||||||
| endKey, rawEndKey, err := apiutil.ParseKey("end_key", rg) | ||||||||||
| if err != nil { | ||||||||||
| h.rd.JSON(w, http.StatusBadRequest, err.Error()) | ||||||||||
| return | ||||||||||
| } | ||||||||||
| regions = append(regions, rc.ScanRegions(startKey, endKey, limit)...) | ||||||||||
|
||||||||||
| c.items[key] = ttlCacheItem{ | |
| value: value, | |
| expire: time.Now().Add(ttl), | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about exract the same code as function from
AccelerateRegionsScheduleInRange?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AccelerateRegionsScheduleInRangeis not used anymore, maybe we can remove it later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the old api can't be remove, you don't know the other compoment has depends on it .