diff options
| author | chrislu <chris.lu@gmail.com> | 2022-07-16 10:49:38 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-07-16 10:49:38 -0700 |
| commit | 8050f9202f87c4a9b273180faa4136fa1002ba73 (patch) | |
| tree | f1cf3a26010ad278d8ddb204528b830c286a5a3e /weed/filer/reader_cache.go | |
| parent | 113a4546fd36b9a0eb78c4e462f38f7488cf1e88 (diff) | |
| parent | 1db012485f996df0615a1d6a7ece9faace2e536c (diff) | |
| download | seaweedfs-8050f9202f87c4a9b273180faa4136fa1002ba73.tar.xz seaweedfs-8050f9202f87c4a9b273180faa4136fa1002ba73.zip | |
Merge branch 'master' into messaging
Diffstat (limited to 'weed/filer/reader_cache.go')
| -rw-r--r-- | weed/filer/reader_cache.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/weed/filer/reader_cache.go b/weed/filer/reader_cache.go index 4c92f71c8..4f375e764 100644 --- a/weed/filer/reader_cache.go +++ b/weed/filer/reader_cache.go @@ -76,7 +76,9 @@ func (rc *ReaderCache) ReadChunkAt(buffer []byte, fileId string, cipherKey []byt rc.Lock() defer rc.Unlock() if cacher, found := rc.downloaders[fileId]; found { - return cacher.readChunkAt(buffer, offset) + if n, err := cacher.readChunkAt(buffer, offset); n != 0 && err == nil { + return n, err + } } if shouldCache || rc.lookupFileIdFn == nil { n, err := rc.chunkCache.ReadChunkAt(buffer, fileId, uint64(offset)) @@ -176,6 +178,9 @@ func (s *SingleChunkCacher) startCaching() { } func (s *SingleChunkCacher) destroy() { + s.Lock() + defer s.Unlock() + if s.data != nil { mem.Free(s.data) s.data = nil @@ -194,6 +199,10 @@ func (s *SingleChunkCacher) readChunkAt(buf []byte, offset int64) (int, error) { return 0, s.err } + if len(s.data) == 0 { + return 0, nil + } + return copy(buf, s.data[offset:]), nil } |
