diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-12-08 22:26:46 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-12-08 22:26:46 -0800 |
| commit | 8e78187a975ef6f554905e0c7128a011f5d908eb (patch) | |
| tree | 8dc628653648d614743528ef1c9ff38b6ae59af5 | |
| parent | 900d22c6eca41533de88f95ff84f56754517527b (diff) | |
| download | seaweedfs-8e78187a975ef6f554905e0c7128a011f5d908eb.tar.xz seaweedfs-8e78187a975ef6f554905e0c7128a011f5d908eb.zip | |
add back last read chunk cache to reader and properly close the reader
| -rw-r--r-- | weed/filer/reader_at.go | 18 | ||||
| -rw-r--r-- | weed/filesys/filehandle.go | 3 |
2 files changed, 20 insertions, 1 deletions
diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go index 405572f18..6193dbd45 100644 --- a/weed/filer/reader_at.go +++ b/weed/filer/reader_at.go @@ -24,9 +24,12 @@ type ChunkReadAt struct { fetchGroup singleflight.Group chunkCache chunk_cache.ChunkCache + lastChunkFileId string + lastChunkData []byte } -// var _ = io.ReaderAt(&ChunkReadAt{}) +var _ = io.ReaderAt(&ChunkReadAt{}) +var _ = io.Closer(&ChunkReadAt{}) type LookupFileIdFunctionType func(fileId string) (targetUrls []string, err error) @@ -94,6 +97,12 @@ func NewChunkReaderAtFromClient(filerClient filer_pb.FilerClient, chunkViews []* } } +func (c *ChunkReadAt) Close() error { + c.lastChunkData = nil + c.lastChunkFileId = "" + return nil +} + func (c *ChunkReadAt) ReadAt(p []byte, offset int64) (n int, err error) { c.readerLock.Lock() @@ -162,6 +171,10 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) { func (c *ChunkReadAt) readFromWholeChunkData(chunkView *ChunkView, nextChunkViews ...*ChunkView) (chunkData []byte, err error) { + if c.lastChunkFileId == chunkView.FileId { + return c.lastChunkData, nil + } + v, doErr := c.readOneWholeChunk(chunkView) if doErr != nil { @@ -170,6 +183,9 @@ func (c *ChunkReadAt) readFromWholeChunkData(chunkView *ChunkView, nextChunkView chunkData = v.([]byte) + c.lastChunkData = chunkData + c.lastChunkFileId = chunkView.FileId + for _, nextChunkView := range nextChunkViews { if c.chunkCache != nil && nextChunkView != nil { go c.readOneWholeChunk(nextChunkView) diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index abe77f063..b70d90f6c 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -202,6 +202,9 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err } fh.f.wfs.ReleaseHandle(fh.f.fullpath(), fuse.HandleID(fh.handle)) + if closer, ok := fh.f.reader.(io.Closer); ok { + closer.Close() + } } return nil |
