From 900d22c6eca41533de88f95ff84f56754517527b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 8 Dec 2020 02:38:53 -0800 Subject: [PATCH] mount: avoid memory leaking read buffer fix https://github.com/chrislusf/seaweedfs/issues/1654 the reader goes together with the file handle, which may stay for a long time. --- weed/filer/reader_at.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go index ccc746b90..405572f18 100644 --- a/weed/filer/reader_at.go +++ b/weed/filer/reader_at.go @@ -23,8 +23,6 @@ type ChunkReadAt struct { fileSize int64 fetchGroup singleflight.Group - lastChunkFileId string - lastChunkData []byte chunkCache chunk_cache.ChunkCache } @@ -107,7 +105,6 @@ func (c *ChunkReadAt) ReadAt(p []byte, offset int64) (n int, err error) { func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) { - var buffer []byte startOffset, remaining := offset, int64(len(p)) var nextChunk *ChunkView for i, chunk := range c.chunkViews { @@ -134,6 +131,7 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) { continue } glog.V(4).Infof("read [%d,%d), %d/%d chunk %s [%d,%d)", chunkStart, chunkStop, i, len(c.chunkViews), chunk.FileId, chunk.LogicOffset-chunk.Offset, chunk.LogicOffset-chunk.Offset+int64(chunk.Size)) + var buffer []byte buffer, err = c.readFromWholeChunkData(chunk, nextChunk) if err != nil { glog.Errorf("fetching chunk %+v: %v\n", chunk, err) @@ -164,10 +162,6 @@ 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 { @@ -176,9 +170,6 @@ 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)