Skip to content

Commit

Permalink
tmp work
Browse files Browse the repository at this point in the history
Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high committed Aug 31, 2023
1 parent d213f45 commit 9a169af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 2 additions & 4 deletions pkg/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ func (adp *LocalAdapter) Convert(ctx context.Context, source string) error {
return err
}
adp.content.GcMutex.RLock()
defer adp.content.GcMutex.RUnlock()
if _, err = adp.cvt.Convert(ctx, source, target, cacheRef); err != nil {
adp.content.GcMutex.RUnlock()
return err
}
adp.content.GcMutex.RUnlock()
if err := adp.content.GC(ctx); err != nil {
return err
}
go adp.content.GC(ctx)
return nil
}

Expand Down
21 changes: 12 additions & 9 deletions pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,30 @@ func (content *Content) Size() (int64, error) {
}

// GC clean the local caches by cfg.Provider.GCPolicy configuration
func (content *Content) GC(ctx context.Context) error {
func (content *Content) GC(ctx context.Context) {
size, err := content.Size()
if err != nil {
return err
logrus.Error(errors.Wrap(err, "gc get content size"))
return
}
// if the local content size over eighty percent of threshold, gc start
if size > (content.threshold*int64(80))/100 {
if _, err, _ := content.gcSingleflight.Do(accelerationServiceNamespace, func() (interface{}, error) {
content.gcSingleflight.Do(accelerationServiceNamespace, func() (interface{}, error) {
content.GcMutex.Lock()
defer content.GcMutex.Unlock()
// recalculate the local cache size
size, err := content.Size()
if err != nil {
return nil, err
logrus.Error(errors.Wrap(err, "gc get content size"))
return nil, nil
}
return nil, content.garbageCollect(ctx, size-(content.threshold*int64(80))/100)
}); err != nil {
return err
}
if err := content.garbageCollect(ctx, size-(content.threshold*int64(80))/100); err != nil {
logrus.Error(errors.Wrap(err, "gc"))
return nil, nil
}
return nil, nil
})
}
return nil
}

// garbageCollect clean the local caches by lease
Expand Down

0 comments on commit 9a169af

Please sign in to comment.