aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-12-08 02:38:53 -0800
committerChris Lu <chris.lu@gmail.com>2020-12-08 02:38:53 -0800
commit900d22c6eca41533de88f95ff84f56754517527b (patch)
treec7f58d07099c6003daaf6f6d9bc3e6749f17d4c9
parent06bb7bf6c00982deb9eae953c85a730a1745c368 (diff)
downloadseaweedfs-900d22c6eca41533de88f95ff84f56754517527b.tar.xz
seaweedfs-900d22c6eca41533de88f95ff84f56754517527b.zip
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.
-rw-r--r--weed/filer/reader_at.go11
1 files changed, 1 insertions, 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)