@@ -57,16 +57,16 @@ var (
5757)
5858
5959type evictLeaderSchedulerConfig struct {
60- mu syncutil.RWMutex
60+ syncutil.RWMutex
6161 storage endpoint.ConfigStorage
6262 StoreIDWithRanges map [uint64 ][]core.KeyRange `json:"store-id-ranges"`
6363 cluster * core.BasicCluster
6464 removeSchedulerCb func (string ) error
6565}
6666
6767func (conf * evictLeaderSchedulerConfig ) getStores () []uint64 {
68- conf .mu . RLock ()
69- defer conf .mu . RUnlock ()
68+ conf .RLock ()
69+ defer conf .RUnlock ()
7070 stores := make ([]uint64 , 0 , len (conf .StoreIDWithRanges ))
7171 for storeID := range conf .StoreIDWithRanges {
7272 stores = append (stores , storeID )
@@ -90,15 +90,15 @@ func (conf *evictLeaderSchedulerConfig) BuildWithArgs(args []string) error {
9090 if err != nil {
9191 return err
9292 }
93- conf .mu . Lock ()
94- defer conf .mu . Unlock ()
93+ conf .Lock ()
94+ defer conf .Unlock ()
9595 conf .StoreIDWithRanges [id ] = ranges
9696 return nil
9797}
9898
9999func (conf * evictLeaderSchedulerConfig ) Clone () * evictLeaderSchedulerConfig {
100- conf .mu . RLock ()
101- defer conf .mu . RUnlock ()
100+ conf .RLock ()
101+ defer conf .RUnlock ()
102102 storeIDWithRanges := make (map [uint64 ][]core.KeyRange )
103103 for id , ranges := range conf .StoreIDWithRanges {
104104 storeIDWithRanges [id ] = append (storeIDWithRanges [id ], ranges ... )
@@ -110,8 +110,8 @@ func (conf *evictLeaderSchedulerConfig) Clone() *evictLeaderSchedulerConfig {
110110
111111func (conf * evictLeaderSchedulerConfig ) Persist () error {
112112 name := conf .getSchedulerName ()
113- conf .mu . RLock ()
114- defer conf .mu . RUnlock ()
113+ conf .RLock ()
114+ defer conf .RUnlock ()
115115 data , err := EncodeConfig (conf )
116116 failpoint .Inject ("persistFail" , func () {
117117 err = errors .New ("fail to persist" )
@@ -127,8 +127,8 @@ func (conf *evictLeaderSchedulerConfig) getSchedulerName() string {
127127}
128128
129129func (conf * evictLeaderSchedulerConfig ) getRanges (id uint64 ) []string {
130- conf .mu . RLock ()
131- defer conf .mu . RUnlock ()
130+ conf .RLock ()
131+ defer conf .RUnlock ()
132132 ranges := conf .StoreIDWithRanges [id ]
133133 res := make ([]string , 0 , len (ranges )* 2 )
134134 for index := range ranges {
@@ -138,8 +138,8 @@ func (conf *evictLeaderSchedulerConfig) getRanges(id uint64) []string {
138138}
139139
140140func (conf * evictLeaderSchedulerConfig ) removeStore (id uint64 ) (succ bool , last bool ) {
141- conf .mu . Lock ()
142- defer conf .mu . Unlock ()
141+ conf .Lock ()
142+ defer conf .Unlock ()
143143 _ , exists := conf .StoreIDWithRanges [id ]
144144 succ , last = false , false
145145 if exists {
@@ -152,15 +152,15 @@ func (conf *evictLeaderSchedulerConfig) removeStore(id uint64) (succ bool, last
152152}
153153
154154func (conf * evictLeaderSchedulerConfig ) resetStore (id uint64 , keyRange []core.KeyRange ) {
155- conf .mu . Lock ()
156- defer conf .mu . Unlock ()
155+ conf .Lock ()
156+ defer conf .Unlock ()
157157 conf .cluster .PauseLeaderTransfer (id )
158158 conf .StoreIDWithRanges [id ] = keyRange
159159}
160160
161161func (conf * evictLeaderSchedulerConfig ) getKeyRangesByID (id uint64 ) []core.KeyRange {
162- conf .mu . RLock ()
163- defer conf .mu . RUnlock ()
162+ conf .RLock ()
163+ defer conf .RUnlock ()
164164 if ranges , exist := conf .StoreIDWithRanges [id ]; exist {
165165 return ranges
166166 }
@@ -203,14 +203,14 @@ func (s *evictLeaderScheduler) GetType() string {
203203}
204204
205205func (s * evictLeaderScheduler ) EncodeConfig () ([]byte , error ) {
206- s .conf .mu . RLock ()
207- defer s .conf .mu . RUnlock ()
206+ s .conf .RLock ()
207+ defer s .conf .RUnlock ()
208208 return EncodeConfig (s .conf )
209209}
210210
211211func (s * evictLeaderScheduler ) ReloadConfig () error {
212- s .conf .mu . Lock ()
213- defer s .conf .mu . Unlock ()
212+ s .conf .Lock ()
213+ defer s .conf .Unlock ()
214214 cfgData , err := s .conf .storage .LoadSchedulerConfig (s .GetName ())
215215 if err != nil {
216216 return err
@@ -227,25 +227,9 @@ func (s *evictLeaderScheduler) ReloadConfig() error {
227227 return nil
228228}
229229
230- // pauseAndResumeLeaderTransfer checks the old and new store IDs, and pause or resume the leader transfer.
231- func pauseAndResumeLeaderTransfer (cluster * core.BasicCluster , old , new map [uint64 ][]core.KeyRange ) {
232- for id := range old {
233- if _ , ok := new [id ]; ok {
234- continue
235- }
236- cluster .ResumeLeaderTransfer (id )
237- }
238- for id := range new {
239- if _ , ok := old [id ]; ok {
240- continue
241- }
242- cluster .PauseLeaderTransfer (id )
243- }
244- }
245-
246- func (s * evictLeaderScheduler ) Prepare (cluster sche.SchedulerCluster ) error {
247- s .conf .mu .RLock ()
248- defer s .conf .mu .RUnlock ()
230+ func (s * evictLeaderScheduler ) PrepareConfig (cluster sche.SchedulerCluster ) error {
231+ s .conf .RLock ()
232+ defer s .conf .RUnlock ()
249233 var res error
250234 for id := range s .conf .StoreIDWithRanges {
251235 if err := cluster .PauseLeaderTransfer (id ); err != nil {
@@ -255,9 +239,9 @@ func (s *evictLeaderScheduler) Prepare(cluster sche.SchedulerCluster) error {
255239 return res
256240}
257241
258- func (s * evictLeaderScheduler ) Cleanup (cluster sche.SchedulerCluster ) {
259- s .conf .mu . RLock ()
260- defer s .conf .mu . RUnlock ()
242+ func (s * evictLeaderScheduler ) CleanConfig (cluster sche.SchedulerCluster ) {
243+ s .conf .RLock ()
244+ defer s .conf .RUnlock ()
261245 for id := range s .conf .StoreIDWithRanges {
262246 cluster .ResumeLeaderTransfer (id )
263247 }
@@ -386,15 +370,15 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
386370 idFloat , ok := input ["store_id" ].(float64 )
387371 if ok {
388372 id = (uint64 )(idFloat )
389- handler .config .mu . RLock ()
373+ handler .config .RLock ()
390374 if _ , exists = handler .config .StoreIDWithRanges [id ]; ! exists {
391375 if err := handler .config .cluster .PauseLeaderTransfer (id ); err != nil {
392- handler .config .mu . RUnlock ()
376+ handler .config .RUnlock ()
393377 handler .rd .JSON (w , http .StatusInternalServerError , err .Error ())
394378 return
395379 }
396380 }
397- handler .config .mu . RUnlock ()
381+ handler .config .RUnlock ()
398382 args = append (args , strconv .FormatUint (id , 10 ))
399383 }
400384
@@ -407,9 +391,9 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
407391
408392 err := handler .config .BuildWithArgs (args )
409393 if err != nil {
410- handler .config .mu . Lock ()
394+ handler .config .Lock ()
411395 handler .config .cluster .ResumeLeaderTransfer (id )
412- handler .config .mu . Unlock ()
396+ handler .config .Unlock ()
413397 handler .rd .JSON (w , http .StatusBadRequest , err .Error ())
414398 return
415399 }
0 commit comments