diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-05-25 01:22:31 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-05-25 01:22:31 -0700 |
| commit | 6d1bcd4b8c9a0579d703ecae3d6d3f06bdff644b (patch) | |
| tree | 5e6511d3b16e3f5a08ac91e2f6130f19d56bf9f7 | |
| parent | 0a223838bdee52fd912f5eb6de4720da44d315ac (diff) | |
| download | seaweedfs-6d1bcd4b8c9a0579d703ecae3d6d3f06bdff644b.tar.xz seaweedfs-6d1bcd4b8c9a0579d703ecae3d6d3f06bdff644b.zip | |
use existing attributes instead of fetching from filer
| -rw-r--r-- | weed/filesys/file.go | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/weed/filesys/file.go b/weed/filesys/file.go index c8d96c316..09ae4c871 100644 --- a/weed/filesys/file.go +++ b/weed/filesys/file.go @@ -28,36 +28,39 @@ type File struct { func (file *File) Attr(context context.Context, attr *fuse.Attr) error { fullPath := filepath.Join(file.dir.Path, file.Name) - item := file.wfs.listDirectoryEntriesCache.Get(fullPath) - if item != nil { - entry := item.Value().(*filer_pb.Entry) - file.Chunks = entry.Chunks - file.attributes = entry.Attributes - glog.V(1).Infof("file attr read cached %v attributes", file.Name) - } else { - err := file.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { - - request := &filer_pb.GetEntryAttributesRequest{ - Name: file.Name, - ParentDir: file.dir.Path, - } - resp, err := client.GetEntryAttributes(context, request) - if err != nil { - glog.V(0).Infof("file attr read file %v: %v", request, err) - return err - } + if file.attributes == nil { + item := file.wfs.listDirectoryEntriesCache.Get(fullPath) + if item != nil { + entry := item.Value().(*filer_pb.Entry) + file.Chunks = entry.Chunks + file.attributes = entry.Attributes + glog.V(1).Infof("file attr read cached %v attributes", file.Name) + } else { + err := file.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { + + request := &filer_pb.GetEntryAttributesRequest{ + Name: file.Name, + ParentDir: file.dir.Path, + } - file.attributes = resp.Attributes - file.Chunks = resp.Chunks + resp, err := client.GetEntryAttributes(context, request) + if err != nil { + glog.V(0).Infof("file attr read file %v: %v", request, err) + return err + } - glog.V(1).Infof("file attr %v %+v: %d", fullPath, file.attributes, filer2.TotalSize(file.Chunks)) + file.attributes = resp.Attributes + file.Chunks = resp.Chunks - return nil - }) + glog.V(1).Infof("file attr %v %+v: %d", fullPath, file.attributes, filer2.TotalSize(file.Chunks)) - if err != nil { - return err + return nil + }) + + if err != nil { + return err + } } } |
