mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-08-01 15:57:42 +08:00
mount: file handler release memory
This commit is contained in:
parent
69ef6459c3
commit
05c53820b9
@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
"io"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ type FileHandle struct {
|
|||||||
dirtyMetadata bool
|
dirtyMetadata bool
|
||||||
dirtyPages *PageWriter
|
dirtyPages *PageWriter
|
||||||
entryViewCache []filer.VisibleInterval
|
entryViewCache []filer.VisibleInterval
|
||||||
reader io.ReaderAt
|
reader *filer.ChunkReadAt
|
||||||
contentType string
|
contentType string
|
||||||
handle uint64
|
handle uint64
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
@ -99,8 +98,16 @@ func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) {
|
|||||||
fh.entryViewCache = nil
|
fh.entryViewCache = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fh *FileHandle) SetReader(reader *filer.ChunkReadAt) {
|
||||||
|
if fh.reader != nil {
|
||||||
|
fh.reader.Close()
|
||||||
|
}
|
||||||
|
fh.reader = reader
|
||||||
|
}
|
||||||
|
|
||||||
func (fh *FileHandle) Release() {
|
func (fh *FileHandle) Release() {
|
||||||
fh.dirtyPages.Destroy()
|
fh.dirtyPages.Destroy()
|
||||||
|
fh.SetReader(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func lessThan(a, b *filer_pb.FileChunk) bool {
|
func lessThan(a, b *filer_pb.FileChunk) bool {
|
||||||
|
@ -62,7 +62,7 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) {
|
|||||||
if chunkResolveErr != nil {
|
if chunkResolveErr != nil {
|
||||||
return 0, fmt.Errorf("fail to resolve chunk manifest: %v", chunkResolveErr)
|
return 0, fmt.Errorf("fail to resolve chunk manifest: %v", chunkResolveErr)
|
||||||
}
|
}
|
||||||
fh.reader = nil
|
fh.SetReader(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
reader := fh.reader
|
reader := fh.reader
|
||||||
@ -74,7 +74,7 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) {
|
|||||||
}
|
}
|
||||||
reader = filer.NewChunkReaderAtFromClient(fh.wfs.LookupFn(), chunkViews, fh.wfs.chunkCache, fileSize)
|
reader = filer.NewChunkReaderAtFromClient(fh.wfs.LookupFn(), chunkViews, fh.wfs.chunkCache, fileSize)
|
||||||
}
|
}
|
||||||
fh.reader = reader
|
fh.SetReader(reader)
|
||||||
|
|
||||||
totalRead, err := reader.ReadAt(buff, offset)
|
totalRead, err := reader.ReadAt(buff, offset)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user