mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
filer: keep a directory that holds an S3 object when its children expire
An S3 key that also has keys below it is promoted to a directory row that keeps the object's data. When the last child expired, the empty-directory cleanup deleted that row and the object with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d0420bcae0
commit
b15183e4d3
2 files changed
+32
No files matched your search
@@ -1239,6 +1239,10 @@ func (f *Filer) DeleteEmptyParentDirectories(ctx context.Context, dirPath util.F
|
||||
return
|
||||
}
|
||||
|
||||
if isKeyObject, keyErr := f.IsDirectoryKeyObject(ctx, dirPath); keyErr != nil || isKeyObject {
|
||||
return
|
||||
}
|
||||
|
||||
// Directory is empty, try to delete it
|
||||
glog.V(2).InfofCtx(ctx, "DeleteEmptyParentDirectories: deleting empty directory %s", dirPath)
|
||||
parentDir, _ := dirPath.DirAndName()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
)
|
||||
|
||||
@@ -147,3 +148,30 @@ func TestSweepsExpiredEntriesOnlyOnceForASharedStore(t *testing.T) {
|
||||
t.Errorf("%s: not swept here although its owner has a store of its own", ownedByPeer)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSweepExpiredEntriesKeepsADirectoryKeyObject(t *testing.T) {
|
||||
f, store := newTestFilerWithStubStore(t)
|
||||
f.DirBucketsPath = "/buckets"
|
||||
f.FilerConf = NewFilerConf()
|
||||
if err := f.FilerConf.SetLocationConf(&filer_pb.FilerConf_PathConf{LocationPrefix: "/buckets/b/", Ttl: "2m"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
old := time.Now().Add(-time.Hour)
|
||||
putSweepTestEntry(t, store, "/buckets", true, 0, old)
|
||||
putSweepTestEntry(t, store, "/buckets/b", true, 0, old)
|
||||
reports := &Entry{FullPath: "/buckets/b/reports", Attr: Attr{Mode: os.ModeDir | 0o755, Crtime: old, Mtime: old, Mime: "text/plain"},
|
||||
Extended: map[string][]byte{s3_constants.SeaweedFSPrefixObject: []byte("true")}}
|
||||
if err := store.InsertEntry(context.Background(), reports); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
putSweepTestEntry(t, store, "/buckets/b/reports/day1", false, 120, old)
|
||||
|
||||
f.sweepExpiredEntries(context.Background(), "", make(map[string]time.Time), time.Now())
|
||||
|
||||
if store.getEntry("/buckets/b/reports/day1") != nil {
|
||||
t.Fatal("expired child not removed")
|
||||
}
|
||||
if store.getEntry("/buckets/b/reports") == nil {
|
||||
t.Fatal("directory holding an object removed with its last child")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user