cache: reenable last used metadata

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-05-10 22:33:51 -07:00
parent acdaf17cf0
commit a66885e70c
2 changed files with 22 additions and 24 deletions

40
cache/metadata.go vendored
View File

@ -185,24 +185,22 @@ func getLastUsed(si *metadata.StorageItem) (int, *time.Time) {
return usageCount, &tm
}
// TODO: temporarily removed until there is an implementation that can do this
// on background or one that doesn't get new refs for every operation
// func updateLastUsed(si *metadata.StorageItem) error {
// count, _ := getLastUsed(si)
// count++
//
// v, err := metadata.NewValue(count)
// if err != nil {
// return errors.Wrap(err, "failed to create usageCount value")
// }
// v2, err := metadata.NewValue(time.Now().UnixNano())
// if err != nil {
// return errors.Wrap(err, "failed to create lastUsedAt value")
// }
// return si.Update(func(b *bolt.Bucket) error {
// if err := si.SetValue(b, keyUsageCount, v); err != nil {
// return err
// }
// return si.SetValue(b, keyLastUsedAt, v2)
// })
// }
func updateLastUsed(si *metadata.StorageItem) error {
count, _ := getLastUsed(si)
count++
v, err := metadata.NewValue(count)
if err != nil {
return errors.Wrap(err, "failed to create usageCount value")
}
v2, err := metadata.NewValue(time.Now().UnixNano())
if err != nil {
return errors.Wrap(err, "failed to create lastUsedAt value")
}
return si.Update(func(b *bolt.Bucket) error {
if err := si.SetValue(b, keyUsageCount, v); err != nil {
return err
}
return si.SetValue(b, keyLastUsedAt, v2)
})
}

6
cache/refs.go vendored
View File

@ -212,11 +212,10 @@ func (sr *immutableRef) Release(ctx context.Context) error {
}
func (sr *immutableRef) release(ctx context.Context) error {
// updateLastUsed(sr.md)
delete(sr.refs, sr)
if len(sr.refs) == 0 {
updateLastUsed(sr.md)
if sr.viewMount != nil { // TODO: release viewMount earlier if possible
if err := sr.cm.Snapshotter.Remove(ctx, sr.view); err != nil {
return err
@ -333,7 +332,6 @@ func (sr *mutableRef) Release(ctx context.Context) error {
func (sr *mutableRef) release(ctx context.Context) error {
delete(sr.refs, sr)
// updateLastUsed(sr.md)
if getCachePolicy(sr.md) != cachePolicyRetain {
if sr.equalImmutable != nil {
if getCachePolicy(sr.equalImmutable.md) == cachePolicyRetain {
@ -349,6 +347,8 @@ func (sr *mutableRef) release(ctx context.Context) error {
}
}
return sr.remove(ctx, true)
} else {
updateLastUsed(sr.md)
}
return nil
}