mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
do not set attributes if the file is still open
This commit is contained in:
parent
70e67b7c6d
commit
97575e7185
|
@ -32,39 +32,8 @@ func (file *File) fullpath() string {
|
||||||
|
|
||||||
func (file *File) Attr(ctx context.Context, attr *fuse.Attr) error {
|
func (file *File) Attr(ctx context.Context, attr *fuse.Attr) error {
|
||||||
|
|
||||||
if file.attributes == nil || !file.isOpen {
|
if err := file.maybeLoadAttributes(ctx); err != nil {
|
||||||
item := file.wfs.listDirectoryEntriesCache.Get(file.fullpath())
|
return err
|
||||||
if item != nil && !item.Expired() {
|
|
||||||
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(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
glog.V(0).Infof("file attr read file %v: %v", request, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
file.attributes = resp.Attributes
|
|
||||||
file.Chunks = resp.Chunks
|
|
||||||
|
|
||||||
glog.V(1).Infof("file attr %v %+v: %d", file.fullpath(), file.attributes, filer2.TotalSize(file.Chunks))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attr.Mode = os.FileMode(file.attributes.FileMode)
|
attr.Mode = os.FileMode(file.attributes.FileMode)
|
||||||
|
@ -95,7 +64,15 @@ func (file *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.Op
|
||||||
|
|
||||||
func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
|
func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
|
||||||
|
|
||||||
glog.V(3).Infof("%v file setattr %+v, fh=%d", file.fullpath(), req, req.Handle)
|
if err := file.maybeLoadAttributes(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if file.isOpen {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.V(3).Infof("%v file setattr %+v, old:%+v", file.fullpath(), req, file.attributes)
|
||||||
if req.Valid.Size() {
|
if req.Valid.Size() {
|
||||||
|
|
||||||
glog.V(3).Infof("%v file setattr set size=%v", file.fullpath(), req.Size)
|
glog.V(3).Infof("%v file setattr set size=%v", file.fullpath(), req.Size)
|
||||||
|
@ -151,3 +128,41 @@ func (file *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (file *File) maybeLoadAttributes(ctx context.Context) error {
|
||||||
|
if file.attributes == nil || !file.isOpen {
|
||||||
|
item := file.wfs.listDirectoryEntriesCache.Get(file.fullpath())
|
||||||
|
if item != nil && !item.Expired() {
|
||||||
|
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(ctx, request)
|
||||||
|
if err != nil {
|
||||||
|
glog.V(0).Infof("file attr read file %v: %v", request, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
file.attributes = resp.Attributes
|
||||||
|
file.Chunks = resp.Chunks
|
||||||
|
|
||||||
|
glog.V(1).Infof("file attr %v %+v: %d", file.fullpath(), file.attributes, filer2.TotalSize(file.Chunks))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue