Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

scheduler: use pause instead of remove schedulers #551

Merged
merged 12 commits into from
Oct 15, 2020
Prev Previous commit
Next Next commit
fix test
  • Loading branch information
3pointer committed Oct 13, 2020
commit ec67cb711d8aafbab2d2af611436c8712dbc0d32
6 changes: 4 additions & 2 deletions pkg/pdutil/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ func (p *PdController) pauseSchedulerWith(ctx context.Context, scheduler string,
return err
}
log.Info("pause scheduler at beginning", zap.String("name", scheduler))

p.schedulerPauseCh[scheduler] = make(chan struct{})

go func() {
Expand All @@ -301,7 +300,6 @@ func (p *PdController) pauseSchedulerWith(ctx context.Context, scheduler string,
log.Warn("pause scheduler failed, ignore it and wait next time pause", zap.Error(err))
}
case <-p.schedulerPauseCh[scheduler]:
close(p.schedulerPauseCh[scheduler])
log.Info("exit pause scheduler successful", zap.String("name", scheduler))
return
}
Expand Down Expand Up @@ -516,6 +514,10 @@ func (p *PdController) RemoveSchedulers(ctx context.Context) (undo utils.UndoFun
// Close close the connection to pd.
func (p *PdController) Close() {
p.pdClient.Close()

for _, ch := range p.schedulerPauseCh {
close(ch)
}
}

func removePDLeaderScheduler(ctx context.Context, pd *PdController, existSchedulers []string) ([]string, error) {
Expand Down
10 changes: 9 additions & 1 deletion pkg/pdutil/pd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ func (s *testPDControllerSuite) TestScheduler(c *C) {
mock := func(context.Context, string, string, *http.Client, string, io.Reader) ([]byte, error) {
return nil, errors.New("failed")
}
pdController := &PdController{addrs: []string{"", ""}}
schedulerPauseCh := make(map[string]chan struct{})
pdController := &PdController{addrs: []string{"", ""}, schedulerPauseCh: schedulerPauseCh}
schedulerPauseCh[scheduler] = make(chan struct{})
err := pdController.pauseSchedulerWith(ctx, scheduler, mock)
c.Assert(err, ErrorMatches, "failed")

go func() {
<-schedulerPauseCh[scheduler]
}()
err = pdController.stopPauseSchedulerWith(ctx, scheduler, mock)
c.Assert(err, ErrorMatches, "failed")

Expand All @@ -52,6 +57,9 @@ func (s *testPDControllerSuite) TestScheduler(c *C) {
err = pdController.pauseSchedulerWith(ctx, scheduler, mock)
c.Assert(err, IsNil)

go func() {
<-schedulerPauseCh[scheduler]
}()
err = pdController.stopPauseSchedulerWith(ctx, scheduler, mock)
c.Assert(err, IsNil)

Expand Down