Skip to content
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

*: reset prepare checker once the cache is reset #8860

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions pkg/mcs/scheduling/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func deleteAllRegionCache(c *gin.Context) {
return
}
cluster.ResetRegionCache()
cluster.ResetPrepared()
c.String(http.StatusOK, "All regions are removed from server cache.")
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/mcs/scheduling/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ func (c *Cluster) SetPrepared() {
c.coordinator.GetPrepareChecker().SetPrepared()
}

// ResetPrepared reset the prepare checker.
func (c *Cluster) ResetPrepared() {
c.coordinator.GetPrepareChecker().ResetPrepared()
}

// IsSchedulingHalted returns whether the scheduling is halted.
// Currently, the microservice scheduling is halted when:
// - The `HaltScheduling` persist option is set to true.
Expand Down
3 changes: 3 additions & 0 deletions pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,6 @@ func (mc *Cluster) ObserveRegionsStats() {
storeIDs, writeBytesRates, writeKeysRates := mc.BasicCluster.GetStoresWriteRate()
mc.HotStat.ObserveRegionsStats(storeIDs, writeBytesRates, writeKeysRates)
}

// ResetPrepared mocks method.
func (*Cluster) ResetPrepared() {}
7 changes: 7 additions & 0 deletions pkg/schedule/prepare_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,10 @@ func (checker *prepareChecker) SetPrepared() {
defer checker.Unlock()
checker.prepared = true
}

// ResetPrepared is for test purpose
func (checker *prepareChecker) ResetPrepared() {
checker.Lock()
defer checker.Unlock()
checker.prepared = false
}
2 changes: 2 additions & 0 deletions pkg/unsaferecovery/unsafe_recovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const (
type cluster interface {
core.StoreSetInformer

ResetPrepared()
ResetRegionCache()
AllocID() (uint64, error)
BuryStore(storeID uint64, forceBury bool) error
Expand Down Expand Up @@ -545,6 +546,7 @@ func (u *Controller) changeStage(stage stage) {
if u.step > 1 {
// == 1 means no operation has done, no need to invalid cache
u.cluster.ResetRegionCache()
u.cluster.ResetPrepared()
}
output.Info = "Unsafe recovery Finished"
output.Details = u.getAffectedTableDigest()
Expand Down
1 change: 1 addition & 0 deletions server/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (h *adminHandler) DeleteAllRegionCache(w http.ResponseWriter, r *http.Reque
var err error
rc := getCluster(r)
rc.ResetRegionCache()
rc.ResetPrepared()
msg := "All regions are removed from server cache."
if rc.IsServiceIndependent(constant.SchedulingServiceName) {
err = h.deleteRegionCacheInSchedulingServer()
Expand Down
7 changes: 7 additions & 0 deletions server/cluster/scheduling_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ func (sc *schedulingController) SetPrepared() {
sc.coordinator.GetPrepareChecker().SetPrepared()
}

// ResetPrepared reset the prepare checker.
func (sc *schedulingController) ResetPrepared() {
sc.mu.RLock()
defer sc.mu.RUnlock()
sc.coordinator.GetPrepareChecker().ResetPrepared()
}

// IsSchedulingControllerRunning returns whether the scheduling controller is running. Only for test purpose.
func (sc *schedulingController) IsSchedulingControllerRunning() bool {
sc.mu.RLock()
Expand Down