-
Notifications
You must be signed in to change notification settings - Fork 722
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' into update-tidb-dashboard/master-v2021.11.01.1…
…-1635700412
- Loading branch information
Showing
17 changed files
with
1,576 additions
and
29 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,79 @@ | ||
// Copyright 2021 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 api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/tikv/pd/pkg/apiutil" | ||
"github.com/tikv/pd/server" | ||
"github.com/unrolled/render" | ||
) | ||
|
||
type unsafeOperationHandler struct { | ||
svr *server.Server | ||
rd *render.Render | ||
} | ||
|
||
func newUnsafeOperationHandler(svr *server.Server, rd *render.Render) *unsafeOperationHandler { | ||
return &unsafeOperationHandler{ | ||
svr: svr, | ||
rd: rd, | ||
} | ||
} | ||
|
||
// @Tags unsafe | ||
// @Summary Remove failed stores unsafely. | ||
// @Produce json | ||
// Success 200 {string} string "Request has been accepted." | ||
// Failure 400 {string} string "The input is invalid." | ||
// Failure 500 {string} string "PD server failed to proceed the request." | ||
// @Router /admin/unsafe/remove-failed-stores [POST] | ||
func (h *unsafeOperationHandler) RemoveFailedStores(w http.ResponseWriter, r *http.Request) { | ||
rc := getCluster(r) | ||
var stores map[uint64]string | ||
if err := apiutil.ReadJSONRespondError(h.rd, w, r.Body, &stores); err != nil { | ||
return | ||
} | ||
if len(stores) == 0 { | ||
h.rd.JSON(w, http.StatusBadRequest, "No store specified") | ||
return | ||
} | ||
if err := rc.GetUnsafeRecoveryController().RemoveFailedStores(stores); err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
h.rd.JSON(w, http.StatusOK, "Request has been accepted.") | ||
} | ||
|
||
// @Tags unsafe | ||
// @Summary Show the current status of failed stores removal. | ||
// @Produce json | ||
// Success 200 {object} []string | ||
// @Router /admin/unsafe/remove-failed-stores/show [GET] | ||
func (h *unsafeOperationHandler) GetFailedStoresRemovalStatus(w http.ResponseWriter, r *http.Request) { | ||
rc := getCluster(r) | ||
h.rd.JSON(w, http.StatusOK, rc.GetUnsafeRecoveryController().Show()) | ||
} | ||
|
||
// @Tags unsafe | ||
// @Summary Show the history of failed stores removal. | ||
// @Produce json | ||
// Success 200 {object} []string | ||
// @Router /admin/unsafe/remove-failed-stores/history [GET] | ||
func (h *unsafeOperationHandler) GetFailedStoresRemovalHistory(w http.ResponseWriter, r *http.Request) { | ||
rc := getCluster(r) | ||
h.rd.JSON(w, http.StatusOK, rc.GetUnsafeRecoveryController().History()) | ||
} |
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,60 @@ | ||
// Copyright 2021 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 api | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
. "github.com/pingcap/check" | ||
"github.com/tikv/pd/server" | ||
) | ||
|
||
var _ = Suite(&testUnsafeAPISuite{}) | ||
|
||
type testUnsafeAPISuite struct { | ||
svr *server.Server | ||
cleanup cleanUpFunc | ||
urlPrefix string | ||
} | ||
|
||
func (s *testUnsafeAPISuite) SetUpSuite(c *C) { | ||
s.svr, s.cleanup = mustNewServer(c) | ||
mustWaitLeader(c, []*server.Server{s.svr}) | ||
|
||
addr := s.svr.GetAddr() | ||
s.urlPrefix = fmt.Sprintf("%s%s/api/v1/admin/unsafe", addr, apiPrefix) | ||
|
||
mustBootstrapCluster(c, s.svr) | ||
} | ||
|
||
func (s *testUnsafeAPISuite) TearDownSuite(c *C) { | ||
s.cleanup() | ||
} | ||
|
||
func (s *testUnsafeAPISuite) TestRemoveFailedStores(c *C) { | ||
input := map[uint64]string{1: ""} | ||
data, err := json.Marshal(input) | ||
c.Assert(err, IsNil) | ||
err = postJSON(testDialClient, s.urlPrefix+"/remove-failed-stores", data) | ||
c.Assert(err, IsNil) | ||
// Test show | ||
var output []string | ||
err = readJSON(testDialClient, s.urlPrefix+"/remove-failed-stores/show", &output) | ||
c.Assert(err, IsNil) | ||
// Test history | ||
err = readJSON(testDialClient, s.urlPrefix+"/remove-failed-stores/history", &output) | ||
c.Assert(err, IsNil) | ||
} |
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
Oops, something went wrong.