volume: avoid writing too much data for range requests in large files

related to https://github.com/chrislusf/seaweedfs/issues/3178
This commit is contained in:
chrislu 2022-06-14 11:16:47 -07:00
parent cc5d771088
commit 36d2756978

View file

@ -14,9 +14,10 @@ func (n *Needle) ReadNeedleDataInto(r backend.BackendStorageFile, volumeOffset i
crc := CRC(0)
for x := needleOffset; x < needleOffset+size; x += int64(len(buf)) {
count, err := n.ReadNeedleData(r, volumeOffset, buf, x)
if count > 0 {
crc = crc.Update(buf[0:count])
if _, err = writer.Write(buf[0:count]); err != nil {
toWrite := min(int64(count), needleOffset+size-x)
if toWrite > 0 {
crc = crc.Update(buf[0:toWrite])
if _, err = writer.Write(buf[0:toWrite]); err != nil {
return fmt.Errorf("ReadNeedleData write: %v", err)
}
}