mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
much improved "ls -al" performance
This commit is contained in:
parent
60db731e36
commit
ed8efb5aef
|
@ -70,6 +70,8 @@ func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
|
||||||
dir.attributes = resp.Entry.Attributes
|
dir.attributes = resp.Entry.Attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dir.wfs.listDirectoryEntriesCache.Set(dir.Path, resp.Entry, 300*time.Millisecond)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -185,24 +187,34 @@ 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) {
|
func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fs.Node, err error) {
|
||||||
|
|
||||||
var entry *filer_pb.Entry
|
var entry *filer_pb.Entry
|
||||||
err = dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
|
||||||
|
|
||||||
request := &filer_pb.LookupDirectoryEntryRequest{
|
item := dir.wfs.listDirectoryEntriesCache.Get(path.Join(dir.Path, req.Name))
|
||||||
Directory: dir.Path,
|
if item != nil && !item.Expired() {
|
||||||
Name: req.Name,
|
entry = item.Value().(*filer_pb.Entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("lookup directory entry: %v", request)
|
if entry == nil {
|
||||||
resp, err := client.LookupDirectoryEntry(ctx, request)
|
err = dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
if err != nil {
|
|
||||||
// glog.V(0).Infof("lookup %s/%s: %v", dir.Path, name, err)
|
|
||||||
return fuse.ENOENT
|
|
||||||
}
|
|
||||||
|
|
||||||
entry = resp.Entry
|
request := &filer_pb.LookupDirectoryEntryRequest{
|
||||||
|
Directory: dir.Path,
|
||||||
|
Name: req.Name,
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
glog.V(4).Infof("lookup directory entry: %v", request)
|
||||||
})
|
resp, err := client.LookupDirectoryEntry(ctx, request)
|
||||||
|
if err != nil {
|
||||||
|
// glog.V(0).Infof("lookup %s/%s: %v", dir.Path, name, err)
|
||||||
|
return fuse.ENOENT
|
||||||
|
}
|
||||||
|
|
||||||
|
entry = resp.Entry
|
||||||
|
|
||||||
|
dir.wfs.listDirectoryEntriesCache.Set(path.Join(dir.Path, entry.Name), entry, 1000*time.Millisecond)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if entry != nil {
|
if entry != nil {
|
||||||
if entry.IsDirectory {
|
if entry.IsDirectory {
|
||||||
|
@ -248,7 +260,7 @@ func (dir *Dir) ReadDirAll(ctx context.Context) (ret []fuse.Dirent, err error) {
|
||||||
dirent := fuse.Dirent{Name: entry.Name, Type: fuse.DT_File}
|
dirent := fuse.Dirent{Name: entry.Name, Type: fuse.DT_File}
|
||||||
ret = append(ret, dirent)
|
ret = append(ret, dirent)
|
||||||
}
|
}
|
||||||
dir.wfs.listDirectoryEntriesCache.Set(dir.Path+"/"+entry.Name, entry, 300*time.Millisecond)
|
dir.wfs.listDirectoryEntriesCache.Set(path.Join(dir.Path, entry.Name), entry, 300*time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -275,6 +287,8 @@ func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
|
||||||
return fuse.EIO
|
return fuse.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dir.wfs.listDirectoryEntriesCache.Delete(path.Join(dir.Path, req.Name))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -317,6 +331,8 @@ func (dir *Dir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fus
|
||||||
return fuse.EIO
|
return fuse.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dir.wfs.listDirectoryEntriesCache.Delete(dir.Path)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,8 @@ func (file *File) maybeLoadAttributes(ctx context.Context) error {
|
||||||
|
|
||||||
glog.V(1).Infof("file attr %v %+v: %d", file.fullpath(), file.entry.Attributes, filer2.TotalSize(file.entry.Chunks))
|
glog.V(1).Infof("file attr %v %+v: %d", file.fullpath(), file.entry.Attributes, filer2.TotalSize(file.entry.Chunks))
|
||||||
|
|
||||||
|
file.wfs.listDirectoryEntriesCache.Set(file.fullpath(), file.entry, 300*time.Millisecond)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ type WFS struct {
|
||||||
func NewSeaweedFileSystem(option *Option) *WFS {
|
func NewSeaweedFileSystem(option *Option) *WFS {
|
||||||
return &WFS{
|
return &WFS{
|
||||||
option: option,
|
option: option,
|
||||||
listDirectoryEntriesCache: ccache.New(ccache.Configure().MaxSize(6000).ItemsToPrune(100)),
|
listDirectoryEntriesCache: ccache.New(ccache.Configure().MaxSize(int64(option.DirListingLimit) + 200).ItemsToPrune(100)),
|
||||||
pathToHandleIndex: make(map[string]int),
|
pathToHandleIndex: make(map[string]int),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue