aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/filehandle.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@uber.com>2021-04-14 00:29:58 -0700
committerChris Lu <chris.lu@uber.com>2021-04-14 00:29:58 -0700
commitca0f07a188152ac8ea6b6a54f628a30f61634515 (patch)
tree3b29e536c236254c7c35f3363a5f5c6fca5811aa /weed/filesys/filehandle.go
parent5985a7d38d4823b868117f93dc958dc9635e8950 (diff)
downloadseaweedfs-ca0f07a188152ac8ea6b6a54f628a30f61634515.tar.xz
seaweedfs-ca0f07a188152ac8ea6b6a54f628a30f61634515.zip
move file reader, entryViewCache to file handle
reduce file object size
Diffstat (limited to 'weed/filesys/filehandle.go')
-rw-r--r--weed/filesys/filehandle.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go
index f04952e96..0236fd1cd 100644
--- a/weed/filesys/filehandle.go
+++ b/weed/filesys/filehandle.go
@@ -20,9 +20,11 @@ import (
type FileHandle struct {
// cache file has been written to
- dirtyPages *ContinuousDirtyPages
- contentType string
- handle uint64
+ dirtyPages *ContinuousDirtyPages
+ entryViewCache []filer.VisibleInterval
+ reader io.ReaderAt
+ contentType string
+ handle uint64
sync.Mutex
f *File
@@ -125,20 +127,20 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) {
}
var chunkResolveErr error
- if fh.f.entryViewCache == nil {
- fh.f.entryViewCache, chunkResolveErr = filer.NonOverlappingVisibleIntervals(fh.f.wfs.LookupFn(), entry.Chunks)
+ if fh.entryViewCache == nil {
+ fh.entryViewCache, chunkResolveErr = filer.NonOverlappingVisibleIntervals(fh.f.wfs.LookupFn(), entry.Chunks)
if chunkResolveErr != nil {
return 0, fmt.Errorf("fail to resolve chunk manifest: %v", chunkResolveErr)
}
- fh.f.setReader(nil)
+ fh.reader = nil
}
- reader := fh.f.reader
+ reader := fh.reader
if reader == nil {
- chunkViews := filer.ViewFromVisibleIntervals(fh.f.entryViewCache, 0, math.MaxInt64)
+ chunkViews := filer.ViewFromVisibleIntervals(fh.entryViewCache, 0, math.MaxInt64)
reader = filer.NewChunkReaderAtFromClient(fh.f.wfs.LookupFn(), chunkViews, fh.f.wfs.chunkCache, fileSize)
}
- fh.f.setReader(reader)
+ fh.reader = reader
totalRead, err := reader.ReadAt(buff, offset)
@@ -200,8 +202,6 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err
fh.Lock()
defer fh.Unlock()
- fh.f.entryViewCache = nil
-
if fh.f.isOpen <= 0 {
glog.V(0).Infof("Release reset %s open count %d => %d", fh.f.Name, fh.f.isOpen, 0)
fh.f.isOpen = 0
@@ -211,9 +211,10 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err
if fh.f.isOpen == 1 {
fh.f.isOpen--
+ fh.entryViewCache = nil
+ fh.reader = nil
fh.f.wfs.ReleaseHandle(fh.f.fullpath(), fuse.HandleID(fh.handle))
- fh.f.setReader(nil)
}
return nil