diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-12-13 10:05:43 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-12-13 10:05:43 -0800 |
| commit | 05c3b795dcc159f0e6397af972d93a497ac555ae (patch) | |
| tree | 849650a65ed8260d1fa933f9b54a783ebe768e8a /weed/filesys/dir.go | |
| parent | 987108a2b16e61595d0c7768ca47937d0652d5c4 (diff) | |
| download | seaweedfs-05c3b795dcc159f0e6397af972d93a497ac555ae.tar.xz seaweedfs-05c3b795dcc159f0e6397af972d93a497ac555ae.zip | |
filer: configurable directory list cache size
Diffstat (limited to 'weed/filesys/dir.go')
| -rw-r--r-- | weed/filesys/dir.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go index fd5356ae0..f632fd997 100644 --- a/weed/filesys/dir.go +++ b/weed/filesys/dir.go @@ -30,6 +30,8 @@ var _ = fs.NodeSetattrer(&Dir{}) func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error { + glog.V(3).Infof("dir Attr %s", dir.Path) + // https://github.com/bazil/fuse/issues/196 attr.Valid = time.Second @@ -40,6 +42,9 @@ func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error { item := dir.wfs.listDirectoryEntriesCache.Get(dir.Path) if item != nil && !item.Expired() { + + glog.V(4).Infof("dir Attr cache hit %s", dir.Path) + entry := item.Value().(*filer_pb.Entry) attr.Mtime = time.Unix(entry.Attributes.Mtime, 0) @@ -51,6 +56,8 @@ func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error { return nil } + glog.V(3).Infof("dir Attr cache miss %s", dir.Path) + entry, err := filer2.GetEntry(ctx, dir.wfs, dir.Path) if err != nil { glog.V(2).Infof("read dir %s attr: %v, error: %v", dir.Path, dir.attributes, err) @@ -175,6 +182,8 @@ func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, err func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fs.Node, err error) { + glog.V(4).Infof("dir Lookup %s: %s", dir.Path, req.Name) + var entry *filer_pb.Entry fullFilePath := path.Join(dir.Path, req.Name) @@ -184,10 +193,14 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse. } if entry == nil { + glog.V(3).Infof("dir Lookup cache miss %s", fullFilePath) entry, err = filer2.GetEntry(ctx, dir.wfs, fullFilePath) if err != nil { return nil, err } + dir.wfs.listDirectoryEntriesCache.Set(fullFilePath, entry, 5*time.Second) + } else { + glog.V(4).Infof("dir Lookup cache hit %s", fullFilePath) } if entry != nil { @@ -212,7 +225,9 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse. func (dir *Dir) ReadDirAll(ctx context.Context) (ret []fuse.Dirent, err error) { - cacheTtl := 3 * time.Second + glog.V(3).Infof("dir ReadDirAll %s", dir.Path) + + cacheTtl := 10 * time.Minute readErr := filer2.ReadDirAllEntries(ctx, dir.wfs, dir.Path, "", func(entry *filer_pb.Entry, isLast bool) { if entry.IsDirectory { @@ -222,7 +237,6 @@ func (dir *Dir) ReadDirAll(ctx context.Context) (ret []fuse.Dirent, err error) { dirent := fuse.Dirent{Name: entry.Name, Type: fuse.DT_File} ret = append(ret, dirent) } - cacheTtl = cacheTtl + 2 * time.Millisecond dir.wfs.listDirectoryEntriesCache.Set(path.Join(dir.Path, entry.Name), entry, cacheTtl) }) if readErr != nil { |
