SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
add back last read chunk cache to reader and properly close the reader
Chris Lu8e78187a975e
diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.goindex 405572f188..6193dbd453 100644--- a/weed/filer/reader_at.go+++ b/weed/filer/reader_at.go@@ -24,9 +24,12 @@ type ChunkReadAt struct {fetchGroup singleflight.GroupchunkCache 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, nextChunkViewchunkData = 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.goindex abe77f0630..b70d90f6c4 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