aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2/filer.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-03-09 01:02:01 -0700
committerChris Lu <chris.lu@gmail.com>2020-03-09 01:02:01 -0700
commit89eb05b50f10b6ca74a374e5435df2f72019f635 (patch)
tree9544704b3dd90da8a9cb4ecc3647ad7398e97d3e /weed/filer2/filer.go
parent8a899992f2d3f1b248f91065f3d5c8db3e10f325 (diff)
downloadseaweedfs-89eb05b50f10b6ca74a374e5435df2f72019f635.tar.xz
seaweedfs-89eb05b50f10b6ca74a374e5435df2f72019f635.zip
filer: support TTL for all filer stores
Diffstat (limited to 'weed/filer2/filer.go')
-rw-r--r--weed/filer2/filer.go28
1 files changed, 25 insertions, 3 deletions
diff --git a/weed/filer2/filer.go b/weed/filer2/filer.go
index 0b6a5c96e..c3048b45d 100644
--- a/weed/filer2/filer.go
+++ b/weed/filer2/filer.go
@@ -223,14 +223,36 @@ func (f *Filer) FindEntry(ctx context.Context, p FullPath) (entry *Entry, err er
},
}, nil
}
- return f.store.FindEntry(ctx, p)
+ entry, err = f.store.FindEntry(ctx, p)
+ if entry != nil && entry.TtlSec > 0 {
+ if entry.Crtime.Add(time.Duration(entry.TtlSec) * time.Second).Before(time.Now()) {
+ f.store.DeleteEntry(ctx, p.Child(entry.Name()))
+ return nil, filer_pb.ErrNotFound
+ }
+ }
+ return
+
}
-func (f *Filer) ListDirectoryEntries(ctx context.Context, p FullPath, startFileName string, inclusive bool, limit int) ([]*Entry, error) {
+func (f *Filer) ListDirectoryEntries(ctx context.Context, p FullPath, startFileName string, inclusive bool, limit int) (entries []*Entry, expiredCount int, err error) {
if strings.HasSuffix(string(p), "/") && len(p) > 1 {
p = p[0 : len(p)-1]
}
- return f.store.ListDirectoryEntries(ctx, p, startFileName, inclusive, limit)
+ listedEntries, listErr := f.store.ListDirectoryEntries(ctx, p, startFileName, inclusive, limit)
+ if listErr != nil {
+ return listedEntries, expiredCount, err
+ }
+ for _, entry := range listedEntries {
+ if entry.TtlSec > 0 {
+ if entry.Crtime.Add(time.Duration(entry.TtlSec) * time.Second).Before(time.Now()) {
+ f.store.DeleteEntry(ctx, p.Child(entry.Name()))
+ expiredCount++
+ continue
+ }
+ }
+ entries = append(entries, entry)
+ }
+ return
}
func (f *Filer) cacheDelDirectory(dirpath string) {