@@ -22,6 +22,7 @@ import (
2222 "net/url"
2323 "sort"
2424 "strconv"
25+ "strings"
2526
2627 "github.com/gorilla/mux"
2728 "github.com/pingcap/failpoint"
@@ -836,6 +837,64 @@ func (h *regionsHandler) AccelerateRegionsScheduleInRange(w http.ResponseWriter,
836837 h .rd .Text (w , http .StatusOK , fmt .Sprintf ("Accelerate regions scheduling in a given range [%s,%s)" , rawStartKey , rawEndKey ))
837838}
838839
840+ // @Tags region
841+ // @Summary Accelerate regions scheduling in given ranges, only receive hex format for keys
842+ // @Accept json
843+ // @Param body body object true "json params"
844+ // @Param limit query integer false "Limit count" default(256)
845+ // @Produce json
846+ // @Success 200 {string} string "Accelerate regions scheduling in given ranges [startKey1, endKey1), [startKey2, endKey2), ..."
847+ // @Failure 400 {string} string "The input is invalid."
848+ // @Router /regions/accelerate-schedule/batch [post]
849+ func (h * regionsHandler ) AccelerateRegionsScheduleInRanges (w http.ResponseWriter , r * http.Request ) {
850+ rc := getCluster (r )
851+ var input []map [string ]interface {}
852+ if err := apiutil .ReadJSONRespondError (h .rd , w , r .Body , & input ); err != nil {
853+ return
854+ }
855+ limit := 256
856+ if limitStr := r .URL .Query ().Get ("limit" ); limitStr != "" {
857+ var err error
858+ limit , err = strconv .Atoi (limitStr )
859+ if err != nil {
860+ h .rd .JSON (w , http .StatusBadRequest , err .Error ())
861+ return
862+ }
863+ }
864+ if limit > maxRegionLimit {
865+ limit = maxRegionLimit
866+ }
867+ var msgBuilder strings.Builder
868+ msgBuilder .Grow (128 )
869+ msgBuilder .WriteString ("Accelerate regions scheduling in given ranges: " )
870+ regionsIDSet := make (map [uint64 ]struct {})
871+ for _ , rg := range input {
872+ startKey , rawStartKey , err := apiutil .ParseKey ("start_key" , rg )
873+ if err != nil {
874+ h .rd .JSON (w , http .StatusBadRequest , err .Error ())
875+ return
876+ }
877+ endKey , rawEndKey , err := apiutil .ParseKey ("end_key" , rg )
878+ if err != nil {
879+ h .rd .JSON (w , http .StatusBadRequest , err .Error ())
880+ return
881+ }
882+ regions := rc .ScanRegions (startKey , endKey , limit )
883+ for _ , region := range regions {
884+ regionsIDSet [region .GetID ()] = struct {}{}
885+ }
886+ msgBuilder .WriteString (fmt .Sprintf ("[%s,%s), " , rawStartKey , rawEndKey ))
887+ }
888+ if len (regionsIDSet ) > 0 {
889+ regionsIDList := make ([]uint64 , 0 , len (regionsIDSet ))
890+ for id := range regionsIDSet {
891+ regionsIDList = append (regionsIDList , id )
892+ }
893+ rc .AddSuspectRegions (regionsIDList ... )
894+ }
895+ h .rd .Text (w , http .StatusOK , msgBuilder .String ())
896+ }
897+
839898func (h * regionsHandler ) GetTopNRegions (w http.ResponseWriter , r * http.Request , less func (a , b * core.RegionInfo ) bool ) {
840899 rc := getCluster (r )
841900 limit := defaultRegionLimit
0 commit comments