get erros from buffered channel. Return error during object read only if we have readers < k

master
Krishna Srinivas 10 years ago
parent e1280779ed
commit bdc00624fd
  1. 16
      pkg/donut/bucket.go

@ -544,23 +544,31 @@ func (b bucket) decodeEncodedData(totalLeft, blockSize int64, readers map[int]io
} }
encodedBytes := make([][]byte, encoder.k+encoder.m) encodedBytes := make([][]byte, encoder.k+encoder.m)
errCh := make(chan error) errCh := make(chan error, len(readers))
var errRet error var errRet error
readCnt := 0
for i, reader := range readers { for i, reader := range readers {
go func(i int, reader io.Reader) { i := i
reader := reader
go func() {
encodedBytes[i] = make([]byte, curChunkSize) encodedBytes[i] = make([]byte, curChunkSize)
_, err := io.ReadFull(reader, encodedBytes[i]) _, err := io.ReadFull(reader, encodedBytes[i])
if err != nil {
encodedBytes[i] = nil
}
errCh <- err errCh <- err
}(i, reader) }()
} }
for range readers { for range readers {
err := <-errCh err := <-errCh
if err != nil { if err != nil {
errRet = err errRet = err
} else {
readCnt++
} }
} }
if errRet != nil { if readCnt < int(encoder.k) {
return nil, iodine.New(errRet, nil) return nil, iodine.New(errRet, nil)
} }
decodedData, err := encoder.Decode(encodedBytes, int(curBlockSize)) decodedData, err := encoder.Decode(encodedBytes, int(curBlockSize))

Loading…
Cancel
Save