diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2021-12-27 23:47:51 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-27 23:47:51 -0800 |
| commit | 6c8caea09cf40d27d0404c408bd5792d43256534 (patch) | |
| tree | 8d733aad6f6f811287ee2278d2578f2503ea53cb | |
| parent | 80db8b13d8852a27fb7bb7c9869fa68192c8132d (diff) | |
| parent | 47c30e3add996bb5685347be0a33b1923e4699a1 (diff) | |
| download | seaweedfs-6c8caea09cf40d27d0404c408bd5792d43256534.tar.xz seaweedfs-6c8caea09cf40d27d0404c408bd5792d43256534.zip | |
Merge pull request #2539 from ck789987/filer-list-use-context
filer list entries use context to break job
| -rw-r--r-- | weed/filer/filer.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/weed/filer/filer.go b/weed/filer/filer.go index 7ca198b38..0f34adb4d 100644 --- a/weed/filer/filer.go +++ b/weed/filer/filer.go @@ -306,14 +306,19 @@ func (f *Filer) FindEntry(ctx context.Context, p util.FullPath) (entry *Entry, e func (f *Filer) doListDirectoryEntries(ctx context.Context, p util.FullPath, startFileName string, inclusive bool, limit int64, prefix string, eachEntryFunc ListEachEntryFunc) (expiredCount int64, lastFileName string, err error) { lastFileName, err = f.Store.ListDirectoryPrefixedEntries(ctx, p, startFileName, inclusive, limit, prefix, func(entry *Entry) bool { - if entry.TtlSec > 0 { - if entry.Crtime.Add(time.Duration(entry.TtlSec) * time.Second).Before(time.Now()) { - f.Store.DeleteOneEntry(ctx, entry) - expiredCount++ - return true + select { + case <-ctx.Done(): + return false + default: + if entry.TtlSec > 0 { + if entry.Crtime.Add(time.Duration(entry.TtlSec) * time.Second).Before(time.Now()) { + f.Store.DeleteOneEntry(ctx, entry) + expiredCount++ + return true + } } + return eachEntryFunc(entry) } - return eachEntryFunc(entry) }) if err != nil { return expiredCount, lastFileName, err |
