mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
* mount: update a directory's times once, without retries touchDirMtimeCtime sent its UpdateEntry through saveEntry's retries, 1, 2 and 4 s apart. Every create, link, rename and removal in the directory waits for that update and ignores how it went. In a directory many writers share, the update of its entry conflicts in the filer store with theirs (TiKV reports "write conflict"), and the call waited out the backoffs: in one directory about 200 jobs shared, three mounts logged 3646 such retries in two hours, each holding a create or a rename for up to about 7 s. saveEntry takes a bestEffort flag: such an update is tried once and its failure logged at V(1). touchDirMtimeCtime sets it; setattr and the xattr calls keep their retries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: shorten the directory times comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
118 lines
3.8 KiB
Go
118 lines
3.8 KiB
Go
package mount
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/go-fuse/v2/fuse"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// savedEntriesFiler records the entries a mount saves, refusing each with
|
|
// refuse when it is set.
|
|
type savedEntriesFiler struct {
|
|
filer_pb.UnimplementedSeaweedFilerServer
|
|
mu sync.Mutex
|
|
updates []*filer_pb.UpdateEntryRequest
|
|
refuse error
|
|
}
|
|
|
|
func (s *savedEntriesFiler) UpdateEntry(_ context.Context, req *filer_pb.UpdateEntryRequest) (*filer_pb.UpdateEntryResponse, error) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
s.updates = append(s.updates, proto.Clone(req).(*filer_pb.UpdateEntryRequest))
|
|
if s.refuse != nil {
|
|
return nil, s.refuse
|
|
}
|
|
return &filer_pb.UpdateEntryResponse{}, nil
|
|
}
|
|
|
|
func (s *savedEntriesFiler) updateCount() int {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
return len(s.updates)
|
|
}
|
|
|
|
// Creating or removing an entry directly in the mount root must not save the
|
|
// root: its entry is synthesized from the mount options, so saving it would
|
|
// replace the real directory on the filer, wiping a bucket's quota and the
|
|
// settings S3 keeps on it. Directories below the root are still saved.
|
|
func TestTouchDirMtimeCtimeLeavesTheMountRootOnTheFiler(t *testing.T) {
|
|
wfs := newInvalidateTestWFS(t)
|
|
root := util.FullPath("/buckets/b1")
|
|
wfs.option.FilerMountRootPath = string(root)
|
|
fake := &savedEntriesFiler{}
|
|
startFakeFiler(t, wfs, fake)
|
|
|
|
wfs.inodeToPath.Lookup(root, 1, true, false, 0, false)
|
|
wfs.inodeToPath.MarkChildrenCached(root)
|
|
sub := &filer_pb.Entry{
|
|
Name: "sub",
|
|
IsDirectory: true,
|
|
Attributes: &filer_pb.FuseAttributes{FileMode: uint32(os.ModeDir | 0755), Mtime: 1},
|
|
}
|
|
if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(string(root), sub), 1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
wfs.touchDirMtimeCtime(root)
|
|
wfs.touchDirMtimeCtime(root.Child("sub"))
|
|
|
|
fake.mu.Lock()
|
|
defer fake.mu.Unlock()
|
|
var saved []string
|
|
for _, req := range fake.updates {
|
|
saved = append(saved, string(util.NewFullPath(req.Directory, req.Entry.Name)))
|
|
}
|
|
if len(saved) != 1 || saved[0] != "/buckets/b1/sub" {
|
|
t.Fatalf("saved %v, want only /buckets/b1/sub", saved)
|
|
}
|
|
if fake.updates[0].Entry.Attributes.Mtime <= 1 {
|
|
t.Errorf("sub mtime = %d, want it touched", fake.updates[0].Entry.Attributes.Mtime)
|
|
}
|
|
}
|
|
|
|
// The directory times update is tried once; other saves still retry.
|
|
func TestTouchDirMtimeCtimeIsTriedOnce(t *testing.T) {
|
|
wfs := newInvalidateTestWFS(t)
|
|
root := util.FullPath("/buckets/b1")
|
|
wfs.option.FilerMountRootPath = string(root)
|
|
fake := &savedEntriesFiler{refuse: status.Error(codes.Unknown, "write conflict")}
|
|
startFakeFiler(t, wfs, fake)
|
|
|
|
wfs.inodeToPath.Lookup(root, 1, true, false, 0, false)
|
|
wfs.inodeToPath.MarkChildrenCached(root)
|
|
sub := &filer_pb.Entry{
|
|
Name: "sub",
|
|
IsDirectory: true,
|
|
Attributes: &filer_pb.FuseAttributes{FileMode: uint32(os.ModeDir | 0755), Mtime: 1},
|
|
}
|
|
if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(string(root), sub), 1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var backoffs []time.Duration
|
|
oldSleep := metadataFlushSleep
|
|
metadataFlushSleep = func(_ context.Context, d time.Duration) { backoffs = append(backoffs, d) }
|
|
defer func() { metadataFlushSleep = oldSleep }()
|
|
|
|
wfs.touchDirMtimeCtime(root.Child("sub"))
|
|
if n := fake.updateCount(); n != 1 || len(backoffs) != 0 {
|
|
t.Fatalf("touch sent %d updates and waited out backoffs %v, want 1 update and none", n, backoffs)
|
|
}
|
|
|
|
if code := wfs.saveEntry(root.Child("sub"), proto.Clone(sub).(*filer_pb.Entry), false); code == fuse.OK {
|
|
t.Fatal("refused save reported OK")
|
|
}
|
|
if n := fake.updateCount(); n < 3 {
|
|
t.Fatalf("save sent %d updates in all, want it to retry", n)
|
|
}
|
|
}
|