aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/filehandle.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-11-30 04:34:04 -0800
committerChris Lu <chris.lu@gmail.com>2020-11-30 04:34:04 -0800
commitf4abd01adf9fb2ebdefa844b2a4f0aaf8eeb1ccc (patch)
tree87406670846a99820d7b6bb37dc3d2cf9362a9de /weed/filesys/filehandle.go
parenta9c6be5fc3fffad6403ce63aa3951121491eb1d1 (diff)
downloadseaweedfs-f4abd01adf9fb2ebdefa844b2a4f0aaf8eeb1ccc.tar.xz
seaweedfs-f4abd01adf9fb2ebdefa844b2a4f0aaf8eeb1ccc.zip
filer: cache small file to filer store
Diffstat (limited to 'weed/filesys/filehandle.go')
-rw-r--r--weed/filesys/filehandle.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go
index 54410a0ba..abe77f063 100644
--- a/weed/filesys/filehandle.go
+++ b/weed/filesys/filehandle.go
@@ -110,6 +110,12 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) {
return 0, io.EOF
}
+ if offset+int64(len(buff)) <= int64(len(fh.f.entry.Content)) {
+ totalRead := copy(buff, fh.f.entry.Content[offset:])
+ glog.V(4).Infof("file handle read cached %s [%d,%d] %d", fh.f.fullpath(), offset, offset+int64(totalRead), totalRead)
+ return int64(totalRead), nil
+ }
+
var chunkResolveErr error
if fh.f.entryViewCache == nil {
fh.f.entryViewCache, chunkResolveErr = filer.NonOverlappingVisibleIntervals(filer.LookupFn(fh.f.wfs), fh.f.entry.Chunks)
@@ -149,6 +155,7 @@ func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *f
copy(data, req.Data)
}
+ fh.f.entry.Content = nil
fh.f.entry.Attributes.FileSize = uint64(max(req.Offset+int64(len(data)), int64(fh.f.entry.Attributes.FileSize)))
glog.V(4).Infof("%v write [%d,%d) %d", fh.f.fullpath(), req.Offset, req.Offset+int64(len(req.Data)), len(req.Data))