-
Notifications
You must be signed in to change notification settings - Fork 720
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:tikv/pd into sche-redirect
Signed-off-by: lhy1024 <[email protected]>
- Loading branch information
Showing
11 changed files
with
225 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2023 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package errs | ||
|
||
import "github.com/pingcap/errors" | ||
|
||
var ( | ||
// ErrOperatorNotFound is error info for operator not found. | ||
ErrOperatorNotFound = errors.New("operator not found") | ||
// ErrAddOperator is error info for already have an operator when adding operator. | ||
ErrAddOperator = errors.New("failed to add operator, maybe already have one") | ||
// ErrRegionNotAdjacent is error info for region not adjacent. | ||
ErrRegionNotAdjacent = errors.New("two regions are not adjacent") | ||
// ErrRegionNotFound is error info for region not found. | ||
ErrRegionNotFound = func(regionID uint64) error { | ||
return errors.Errorf("region %v not found", regionID) | ||
} | ||
// ErrRegionAbnormalPeer is error info for region has abnormal peer. | ||
ErrRegionAbnormalPeer = func(regionID uint64) error { | ||
return errors.Errorf("region %v has abnormal peer", regionID) | ||
} | ||
// ErrStoreNotFoundByID is error info for store not found. | ||
ErrStoreNotFoundByID = func(storeID uint64) error { | ||
return errors.Errorf("store %v not found", storeID) | ||
} | ||
// ErrPluginNotFound is error info for plugin not found. | ||
ErrPluginNotFound = func(pluginPath string) error { | ||
return errors.Errorf("plugin is not found: %s", pluginPath) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// Copyright 2023 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package apis | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/tikv/pd/pkg/errs" | ||
scheserver "github.com/tikv/pd/pkg/mcs/scheduling/server" | ||
"github.com/tikv/pd/pkg/schedule/operator" | ||
"github.com/tikv/pd/pkg/utils/apiutil/multiservicesapi" | ||
) | ||
|
||
// @Tags operators | ||
// @Summary Get an operator by ID. | ||
// @Param region_id path int true "A Region's Id" | ||
// @Produce json | ||
// @Success 200 {object} operator.OpWithStatus | ||
// @Failure 400 {string} string "The input is invalid." | ||
// @Failure 500 {string} string "PD server failed to proceed the request." | ||
// @Router /operators/{id} [GET] | ||
func getOperatorByRegion(c *gin.Context) { | ||
opController, err := getOpController(c) | ||
if err != nil { | ||
c.String(http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
id := c.Param("id") | ||
regionID, err := strconv.ParseUint(id, 10, 64) | ||
if err != nil { | ||
c.String(http.StatusBadRequest, err.Error()) | ||
return | ||
} | ||
|
||
c.IndentedJSON(http.StatusOK, opController.GetOperatorStatus(regionID)) | ||
} | ||
|
||
// @Tags operators | ||
// @Summary List operators. | ||
// @Param kind query string false "Specify the operator kind." Enums(admin, leader, region, waiting) | ||
// @Produce json | ||
// @Success 200 {array} operator.Operator | ||
// @Failure 500 {string} string "PD server failed to proceed the request." | ||
// @Router /operators [GET] | ||
func getOperators(c *gin.Context) { | ||
Check failure on line 61 in pkg/mcs/scheduling/server/apis/v1/operators.go GitHub Actions / chunks (1)
Check failure on line 61 in pkg/mcs/scheduling/server/apis/v1/operators.go GitHub Actions / statics
|
||
opController, err := getOpController(c) | ||
if err != nil { | ||
c.String(http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
var ( | ||
results []*operator.Operator | ||
ops []*operator.Operator | ||
) | ||
|
||
kinds := c.QueryArray("kind") | ||
if len(kinds) == 0 { | ||
results = opController.GetOperators() | ||
} else { | ||
for _, kind := range kinds { | ||
switch kind { | ||
case operator.OpAdmin.String(): | ||
ops = opController.GetOperatorsOfKind(operator.OpAdmin) | ||
case operator.OpLeader.String(): | ||
ops = opController.GetOperatorsOfKind(operator.OpLeader) | ||
case operator.OpRegion.String(): | ||
ops = opController.GetOperatorsOfKind(operator.OpRegion) | ||
case operator.OpWaiting: | ||
Check failure on line 85 in pkg/mcs/scheduling/server/apis/v1/operators.go GitHub Actions / chunks (1)
Check failure on line 85 in pkg/mcs/scheduling/server/apis/v1/operators.go GitHub Actions / statics
|
||
ops = opController.GetWaitingOperators() | ||
} | ||
results = append(results, ops...) | ||
} | ||
} | ||
|
||
c.IndentedJSON(http.StatusOK, results) | ||
} | ||
|
||
// @Tags operator | ||
// @Summary Cancel a Region's pending operator. | ||
// @Param region_id path int true "A Region's Id" | ||
// @Produce json | ||
// @Success 200 {string} string "The pending operator is canceled." | ||
// @Failure 400 {string} string "The input is invalid." | ||
// @Failure 500 {string} string "PD server failed to proceed the request." | ||
// @Router /operators/{region_id} [delete] | ||
func deleteOperatorByRegion(c *gin.Context) { | ||
opController, err := getOpController(c) | ||
if err != nil { | ||
c.String(http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
id := c.Param("id") | ||
regionID, err := strconv.ParseUint(id, 10, 64) | ||
if err != nil { | ||
c.String(http.StatusBadRequest, err.Error()) | ||
return | ||
} | ||
|
||
op := opController.GetOperator(regionID) | ||
if op == nil { | ||
c.String(http.StatusBadRequest, errs.ErrOperatorNotFound.Error()) | ||
return | ||
} | ||
|
||
opController.RemoveOperator(op, operator.AdminStop) | ||
c.String(http.StatusOK, "The pending operator is canceled.") | ||
} | ||
|
||
// @Tags operator | ||
// @Summary lists the finished operators since the given timestamp in second. | ||
// @Param from query integer false "From Unix timestamp" | ||
// @Produce json | ||
// @Success 200 {object} []operator.OpRecord | ||
// @Failure 400 {string} string "The request is invalid." | ||
// @Failure 500 {string} string "PD server failed to proceed the request." | ||
// @Router /operators/records [get] | ||
func getOperatorRecords(c *gin.Context) { | ||
opController, err := getOpController(c) | ||
if err != nil { | ||
c.String(http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
var from time.Time | ||
if fromStr := c.Param("from"); fromStr != "" { | ||
fromInt, err := strconv.ParseInt(fromStr, 10, 64) | ||
if err != nil { | ||
c.String(http.StatusBadRequest, err.Error()) | ||
return | ||
} | ||
from = time.Unix(fromInt, 0) | ||
} | ||
|
||
records := opController.GetRecords(from) | ||
if len(records) == 0 { | ||
c.String(http.StatusBadRequest, errs.ErrOperatorNotFound.Error()) | ||
return | ||
} | ||
c.IndentedJSON(http.StatusOK, records) | ||
} | ||
|
||
func getOpController(c *gin.Context) (*operator.Controller, error) { | ||
svr := c.MustGet(multiservicesapi.ServiceContextKey).(*scheserver.Server) | ||
opController := svr.GetCoordinator().GetOperatorController() | ||
if opController == nil { | ||
return nil, errs.ErrNotBootstrapped.GenWithStackByArgs() | ||
} | ||
return opController, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters