Skip to content

Commit

Permalink
Locking the scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
Gergely Brautigam committed Nov 29, 2020
1 parent 2d40c7f commit a923f1d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions workers/scheduler/gaiascheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ type Scheduler struct {
// Atomic Counter that represents the current free workers
freeWorkers *int32

// Lock for scheduling
schedulePipelineLock sync.RWMutex
// Lock for scheduling
schedulerLock sync.RWMutex

Expand Down Expand Up @@ -242,6 +244,9 @@ func (s *Scheduler) prepareAndExec(r gaia.PipelineRun) {

// schedule looks in the store for new work and schedules it.
func (s *Scheduler) schedule() {
s.schedulerLock.Lock()
defer s.schedulerLock.Unlock()

// Do we have space left in our buffer?
if s.CountScheduledRuns() >= schedulerBufferLimit {
// No space left. Exit.
Expand Down Expand Up @@ -342,7 +347,6 @@ func (s *Scheduler) schedule() {

// Reset the docker status manipulation
scheduled[id].Docker = true

storeUpdate(scheduled[id], gaia.RunScheduled)
continue
}
Expand Down Expand Up @@ -386,8 +390,8 @@ func (s *Scheduler) SchedulePipeline(p *gaia.Pipeline, startedReason string, arg
// This means that one of the calls will take slightly longer (a couple of nanoseconds)
// while the other finishes to save the pipelinerun.
// This is to ensure that the highest ID for the next pipeline is calculated properly.
s.schedulerLock.Lock()
defer s.schedulerLock.Unlock()
s.schedulePipelineLock.Lock()
defer s.schedulePipelineLock.Unlock()

// Get highest public id used for this pipeline
highestID, err := s.storeService.PipelineGetRunHighestID(p)
Expand Down

0 comments on commit a923f1d

Please sign in to comment.