mount: fix bug during busy writes

fix https://github.com/chrislusf/seaweedfs/issues/3315
This commit is contained in:
chrislu 2022-07-15 01:03:17 -07:00
parent aca20cd9f4
commit 1db012485f

View file

@ -76,7 +76,9 @@ func (rc *ReaderCache) ReadChunkAt(buffer []byte, fileId string, cipherKey []byt
rc.Lock() rc.Lock()
defer rc.Unlock() defer rc.Unlock()
if cacher, found := rc.downloaders[fileId]; found { 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 { if shouldCache || rc.lookupFileIdFn == nil {
n, err := rc.chunkCache.ReadChunkAt(buffer, fileId, uint64(offset)) n, err := rc.chunkCache.ReadChunkAt(buffer, fileId, uint64(offset))
@ -176,6 +178,9 @@ func (s *SingleChunkCacher) startCaching() {
} }
func (s *SingleChunkCacher) destroy() { func (s *SingleChunkCacher) destroy() {
s.Lock()
defer s.Unlock()
if s.data != nil { if s.data != nil {
mem.Free(s.data) mem.Free(s.data)
s.data = nil s.data = nil
@ -194,6 +199,10 @@ func (s *SingleChunkCacher) readChunkAt(buf []byte, offset int64) (int, error) {
return 0, s.err return 0, s.err
} }
if len(s.data) == 0 {
return 0, nil
}
return copy(buf, s.data[offset:]), nil return copy(buf, s.data[offset:]), nil
} }