Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Fix #926: Prevent cache warming spin loop by removing the default branch
Browse files Browse the repository at this point in the history
 - added the ability to stop the refresh loop
 - added priority queuing to the refresh loop
  • Loading branch information
stefanprodan committed Feb 5, 2018
1 parent 4f1336a commit d961eb1
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions registry/cache/warming.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ func (w *Warmer) Loop(logger log.Logger, stop <-chan struct{}, wg *sync.WaitGrou
// just rattle through them one by one, however long they take.
ctx := context.Background()

// NB the implicit contract here is that the prioritised
// image has to have been running the last time we
// requested the credentials.
priorityWarm := func (name image.Name) {
logger.Log("priority", name.String())
if creds, ok := imageCreds[name]; ok {
w.warm(ctx, logger, name, creds)
} else {
logger.Log("priority", name.String(), "err", "no creds available")
}
}

// This loop acts keeps a kind of priority queue, whereby image
// names coming in on the `Priority` channel are looked up first.
// If there are none, images used in the cluster are refreshed;
Expand All @@ -72,15 +84,7 @@ func (w *Warmer) Loop(logger log.Logger, stop <-chan struct{}, wg *sync.WaitGrou
logger.Log("stopping", "true")
return
case name := <-w.Priority:
logger.Log("priority", name.String())
// NB the implicit contract here is that the prioritised
// image has to have been running the last time we
// requested the credentials.
if creds, ok := imageCreds[name]; ok {
w.warm(ctx, logger, name, creds)
} else {
logger.Log("priority", name.String(), "err", "no creds available")
}
priorityWarm(name)
continue
default:
}
Expand All @@ -91,15 +95,20 @@ func (w *Warmer) Loop(logger log.Logger, stop <-chan struct{}, wg *sync.WaitGrou
w.warm(ctx, logger, im.Name, im.Credentials)
} else {
select {
case <-stop:
logger.Log("stopping", "true")
return
case <-refresh:
imageCreds = imagesToFetchFunc()
backlog = imageCredsToBacklog(imageCreds)
default:
case name := <-w.Priority:
priorityWarm(name)
}
}
}
}


func imageCredsToBacklog(imageCreds registry.ImageCreds) []backlogItem {
backlog := make([]backlogItem, len(imageCreds))
var i int
Expand Down

0 comments on commit d961eb1

Please sign in to comment.