Skip to content

Commit

Permalink
Merge branch 'master' into support-qps-float
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot[bot] authored Nov 7, 2024
2 parents 86015e9 + 39575d2 commit 6e2465b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
7 changes: 6 additions & 1 deletion server/api/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,16 @@ func (h *schedulerHandler) CreateScheduler(w http.ResponseWriter, r *http.Reques
return
}
case types.GrantLeaderScheduler, types.EvictLeaderScheduler:
storeID, ok := input["store_id"].(float64)
_, ok := input["store_id"]
if !ok {
h.r.JSON(w, http.StatusBadRequest, "missing store id")
return
}
storeID, ok := input["store_id"].(float64)
if !ok {
h.r.JSON(w, http.StatusBadRequest, "please input a right store id")
return
}
var (
exist bool
err error
Expand Down
10 changes: 9 additions & 1 deletion server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,14 @@ func (c *RaftCluster) runServiceCheckJob() {
case <-schedulingTicker.C:
c.checkSchedulingService()
case <-tsoTicker.C:
c.checkTSOService()
// ensure raft cluster is running
// avoid unexpected startTSOJobsIfNeeded when raft cluster is stopping
// ref: https://github.com/tikv/pd/issues/8781
c.RLock()
if c.running {
c.checkTSOService()
}
c.RUnlock()
}
}
}
Expand Down Expand Up @@ -488,6 +495,7 @@ func (c *RaftCluster) stopTSOJobsIfNeeded() error {
return err
}
if allocator.IsInitialize() {
log.Info("closing the global TSO allocator")
c.tsoAllocator.ResetAllocatorGroup(tso.GlobalDCLocation, true)
failpoint.Inject("updateAfterResetTSO", func() {
allocator, _ := c.tsoAllocator.GetAllocator(tso.GlobalDCLocation)
Expand Down
20 changes: 17 additions & 3 deletions tests/server/api/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,24 @@ func (suite *scheduleTestSuite) checkOriginAPI(cluster *tests.TestCluster) {

input := make(map[string]any)
input["name"] = "evict-leader-scheduler"
input["store_id"] = 1
body, err := json.Marshal(input)
re.NoError(err)
re.NoError(tu.CheckPostJSON(tests.TestDialClient, urlPrefix, body, tu.StatusOK(re)))
suite.NoError(err)
suite.NoError(tu.CheckPostJSON(tests.TestDialClient, urlPrefix, body,
tu.Status(re, http.StatusBadRequest),
tu.StringEqual(re, "missing store id")),
)
input["store_id"] = "abc" // bad case
body, err = json.Marshal(input)
suite.NoError(err)
suite.NoError(tu.CheckPostJSON(tests.TestDialClient, urlPrefix, body,
tu.Status(re, http.StatusBadRequest),
tu.StringEqual(re, "please input a right store id")),
)

input["store_id"] = 1
body, err = json.Marshal(input)
suite.NoError(err)
suite.NoError(tu.CheckPostJSON(tests.TestDialClient, urlPrefix, body, tu.StatusOK(re)))

suite.assertSchedulerExists(urlPrefix, "evict-leader-scheduler")
resp := make(map[string]any)
Expand Down

0 comments on commit 6e2465b

Please sign in to comment.