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

Fix cache warming rapid loop #928

Merged
merged 1 commit into from
Feb 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")

This comment was marked as abuse.

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