fix: restore safe erasure read buffer pooling

Wire the preallocated pooled shard slices into parallelReader instead
of discarding them and allocating a buffer for each disk.

Keep readerToBuf as a permutation while preferred readers are reordered.
The former assignments could duplicate a buffer slot after multiple
swaps, causing concurrent writes and a possible decode stall. Add pool
aliasing and mapping regression coverage.

Co-authored-by: ChatGPT <noreply@openai.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Feng Ruohang
2026-08-01 11:06:24 +08:00
parent 3e14733f15
commit 9247179269
2 changed files with 86 additions and 3 deletions
+2 -3
View File
@@ -69,7 +69,7 @@ func newParallelReader(readers []io.ReaderAt, e Erasure, offset, totalLength int
offset: (offset / e.blockSize) * e.ShardSize(),
shardSize: e.ShardSize(),
shardFileSize: e.ShardFileSize(totalLength),
buf: make([][]byte, len(readers)),
buf: bufs,
readerToBuf: r2b,
stashBuffer: b,
}
@@ -106,8 +106,7 @@ func (p *parallelReader) preferReaders(prefer []bool) {
// Move reader with index i to index next.
// Do this by swapping next and i
p.readers[next], p.readers[i] = p.readers[i], p.readers[next]
p.readerToBuf[next] = i
p.readerToBuf[i] = next
p.readerToBuf[next], p.readerToBuf[i] = p.readerToBuf[i], p.readerToBuf[next]
next++
}
}