Invalidate the blob store descriptor caches when content is removed from from
the proxy. Also, switch to reference in the scheduler API. Signed-off-by: Richard Scothern <richard.scothern@gmail.com>
This commit is contained in:
parent
a7740f5d0f
commit
3e570e59f1
7 changed files with 152 additions and 62 deletions
|
@ -7,13 +7,12 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/distribution/registry/storage/driver"
|
||||
)
|
||||
|
||||
// onTTLExpiryFunc is called when a repository's TTL expires
|
||||
type expiryFunc func(string) error
|
||||
type expiryFunc func(reference.Reference) error
|
||||
|
||||
const (
|
||||
entryTypeBlob = iota
|
||||
|
@ -82,19 +81,20 @@ func (ttles *TTLExpirationScheduler) OnManifestExpire(f expiryFunc) {
|
|||
}
|
||||
|
||||
// AddBlob schedules a blob cleanup after ttl expires
|
||||
func (ttles *TTLExpirationScheduler) AddBlob(dgst digest.Digest, ttl time.Duration) error {
|
||||
func (ttles *TTLExpirationScheduler) AddBlob(blobRef reference.Canonical, ttl time.Duration) error {
|
||||
ttles.Lock()
|
||||
defer ttles.Unlock()
|
||||
|
||||
if ttles.stopped {
|
||||
return fmt.Errorf("scheduler not started")
|
||||
}
|
||||
ttles.add(dgst.String(), ttl, entryTypeBlob)
|
||||
|
||||
ttles.add(blobRef, ttl, entryTypeBlob)
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddManifest schedules a manifest cleanup after ttl expires
|
||||
func (ttles *TTLExpirationScheduler) AddManifest(repoName reference.Named, ttl time.Duration) error {
|
||||
func (ttles *TTLExpirationScheduler) AddManifest(manifestRef reference.Canonical, ttl time.Duration) error {
|
||||
ttles.Lock()
|
||||
defer ttles.Unlock()
|
||||
|
||||
|
@ -102,7 +102,7 @@ func (ttles *TTLExpirationScheduler) AddManifest(repoName reference.Named, ttl t
|
|||
return fmt.Errorf("scheduler not started")
|
||||
}
|
||||
|
||||
ttles.add(repoName.Name(), ttl, entryTypeManifest)
|
||||
ttles.add(manifestRef, ttl, entryTypeManifest)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -156,17 +156,17 @@ func (ttles *TTLExpirationScheduler) Start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ttles *TTLExpirationScheduler) add(key string, ttl time.Duration, eType int) {
|
||||
func (ttles *TTLExpirationScheduler) add(r reference.Reference, ttl time.Duration, eType int) {
|
||||
entry := &schedulerEntry{
|
||||
Key: key,
|
||||
Key: r.String(),
|
||||
Expiry: time.Now().Add(ttl),
|
||||
EntryType: eType,
|
||||
}
|
||||
context.GetLogger(ttles.ctx).Infof("Adding new scheduler entry for %s with ttl=%s", entry.Key, entry.Expiry.Sub(time.Now()))
|
||||
if oldEntry, present := ttles.entries[key]; present && oldEntry.timer != nil {
|
||||
if oldEntry, present := ttles.entries[entry.Key]; present && oldEntry.timer != nil {
|
||||
oldEntry.timer.Stop()
|
||||
}
|
||||
ttles.entries[key] = entry
|
||||
ttles.entries[entry.Key] = entry
|
||||
entry.timer = ttles.startTimer(entry, ttl)
|
||||
ttles.indexDirty = true
|
||||
}
|
||||
|
@ -184,13 +184,18 @@ func (ttles *TTLExpirationScheduler) startTimer(entry *schedulerEntry, ttl time.
|
|||
case entryTypeManifest:
|
||||
f = ttles.onManifestExpire
|
||||
default:
|
||||
f = func(repoName string) error {
|
||||
return fmt.Errorf("Unexpected scheduler entry type")
|
||||
f = func(reference.Reference) error {
|
||||
return fmt.Errorf("scheduler entry type")
|
||||
}
|
||||
}
|
||||
|
||||
if err := f(entry.Key); err != nil {
|
||||
context.GetLogger(ttles.ctx).Errorf("Scheduler error returned from OnExpire(%s): %s", entry.Key, err)
|
||||
ref, err := reference.Parse(entry.Key)
|
||||
if err == nil {
|
||||
if err := f(ref); err != nil {
|
||||
context.GetLogger(ttles.ctx).Errorf("Scheduler error returned from OnExpire(%s): %s", entry.Key, err)
|
||||
}
|
||||
} else {
|
||||
context.GetLogger(ttles.ctx).Errorf("Error unpacking reference: %s", err)
|
||||
}
|
||||
|
||||
delete(ttles.entries, entry.Key)
|
||||
|
@ -249,6 +254,5 @@ func (ttles *TTLExpirationScheduler) readState() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue