@@ -195,10 +195,23 @@ func (h *schedulerHandler) CreateScheduler(w http.ResponseWriter, r *http.Reques
195
195
return
196
196
}
197
197
198
- case schedulers .GrantLeaderName :
199
- h .addEvictOrGrant (w , input , schedulers .GrantLeaderName )
200
- case schedulers .EvictLeaderName :
201
- h .addEvictOrGrant (w , input , schedulers .EvictLeaderName )
198
+ case schedulers .GrantLeaderName , schedulers .EvictLeaderName :
199
+ storeID , ok := input ["store_id" ].(float64 )
200
+ if ! ok {
201
+ h .r .JSON (w , http .StatusBadRequest , "missing store id" )
202
+ return
203
+ }
204
+ exist , err := h .AddEvictOrGrant (storeID , name )
205
+ if err != nil {
206
+ h .r .JSON (w , http .StatusInternalServerError , err .Error ())
207
+ return
208
+ }
209
+ // we should ensure whether it is the first time to create evict-leader-scheduler
210
+ // or just update the evict-leader.
211
+ if exist {
212
+ h .r .JSON (w , http .StatusOK , "The scheduler has been applied to the store." )
213
+ return
214
+ }
202
215
case schedulers .ShuffleLeaderName :
203
216
if err := h .AddShuffleLeaderScheduler (); err != nil {
204
217
h .r .JSON (w , http .StatusInternalServerError , err .Error ())
@@ -257,18 +270,6 @@ func (h *schedulerHandler) CreateScheduler(w http.ResponseWriter, r *http.Reques
257
270
h .r .JSON (w , http .StatusOK , "The scheduler is created." )
258
271
}
259
272
260
- func (h * schedulerHandler ) addEvictOrGrant (w http.ResponseWriter , input map [string ]interface {}, name string ) {
261
- storeID , ok := input ["store_id" ].(float64 )
262
- if ! ok {
263
- h .r .JSON (w , http .StatusBadRequest , "missing store id" )
264
- return
265
- }
266
- err := h .AddEvictOrGrant (storeID , name )
267
- if err != nil {
268
- h .r .JSON (w , http .StatusInternalServerError , err .Error ())
269
- }
270
- }
271
-
272
273
// @Tags scheduler
273
274
// @Summary Delete a scheduler.
274
275
// @Param name path string true "The name of the scheduler."
0 commit comments