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

This commit is contained in:
Krishna Srinivas 2015-07-29 19:36:41 +05:30
parent e1280779ed
commit bdc00624fd

View File

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