bug fix in the data received from cache processing (#6002)

The patch addresses #3745.

The cache should return the exact amount of data requested by the buffer.
By construction of the cache it is always all requested data range
or we have error happening.

The old use of minsize miscalculate the requested data size,
if non zero offset is requested.
This commit is contained in:
Eugeniy E. Mikhailov
2024-09-10 16:30:18 -04:00
committed by GitHub
parent d660d5c7d4
commit c04edeed68

View File

@@ -57,7 +57,7 @@ func (c *TieredChunkCache) ReadChunkAt(data []byte, fileId string, offset uint64
if err != nil { if err != nil {
glog.Errorf("failed to read from memcache: %s", err) glog.Errorf("failed to read from memcache: %s", err)
} }
if n >= int(minSize) { if n == int(len(data)) {
return n, nil return n, nil
} }
} }
@@ -65,24 +65,24 @@ func (c *TieredChunkCache) ReadChunkAt(data []byte, fileId string, offset uint64
fid, err := needle.ParseFileIdFromString(fileId) fid, err := needle.ParseFileIdFromString(fileId)
if err != nil { if err != nil {
glog.Errorf("failed to parse file id %s", fileId) glog.Errorf("failed to parse file id %s", fileId)
return n, nil return 0, nil
} }
if minSize <= c.onDiskCacheSizeLimit0 { if minSize <= c.onDiskCacheSizeLimit0 {
n, err = c.diskCaches[0].readChunkAt(data, fid.Key, offset) n, err = c.diskCaches[0].readChunkAt(data, fid.Key, offset)
if n >= int(minSize) { if n == int(len(data)) {
return return
} }
} }
if minSize <= c.onDiskCacheSizeLimit1 { if minSize <= c.onDiskCacheSizeLimit1 {
n, err = c.diskCaches[1].readChunkAt(data, fid.Key, offset) n, err = c.diskCaches[1].readChunkAt(data, fid.Key, offset)
if n >= int(minSize) { if n == int(len(data)) {
return return
} }
} }
{ {
n, err = c.diskCaches[2].readChunkAt(data, fid.Key, offset) n, err = c.diskCaches[2].readChunkAt(data, fid.Key, offset)
if n >= int(minSize) { if n == int(len(data)) {
return return
} }
} }