From eb8005cc650f264c2deae5efa0623edee4b4c1f4 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Sun, 22 Mar 2015 18:49:18 -0700 Subject: [PATCH] Reading correct block size in erasure coded data --- pkg/storage/donut/erasure.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/storage/donut/erasure.go b/pkg/storage/donut/erasure.go index 3c361351f..731796f7c 100644 --- a/pkg/storage/donut/erasure.go +++ b/pkg/storage/donut/erasure.go @@ -14,22 +14,27 @@ func erasureReader(readers []io.ReadCloser, donutMetadata map[string]string, wri totalChunks, _ := strconv.Atoi(donutMetadata["chunkCount"]) totalLeft, _ := strconv.Atoi(donutMetadata["totalLength"]) blockSize, _ := strconv.Atoi(donutMetadata["blockSize"]) - params, _ := erasure.ParseEncoderParams(8, 8, erasure.Cauchy) + k, _ := strconv.Atoi(donutMetadata["erasureK"]) + m, _ := strconv.Atoi(donutMetadata["erasureM"]) + // TODO select technique properly + params, _ := erasure.ParseEncoderParams(uint8(k), uint8(m), erasure.Cauchy) encoder := erasure.NewEncoder(params) for _, reader := range readers { defer reader.Close() } for i := 0; i < totalChunks; i++ { + curBlockSize := totalLeft + if blockSize < totalLeft { + curBlockSize = blockSize + } + curChunkSize := erasure.GetEncodedChunkLen(curBlockSize, uint8(k)) + encodedBytes := make([][]byte, 16) for i, reader := range readers { var bytesBuffer bytes.Buffer - io.Copy(&bytesBuffer, reader) + io.CopyN(&bytesBuffer, reader, int64(curChunkSize)) encodedBytes[i] = bytesBuffer.Bytes() } - curBlockSize := totalLeft - if blockSize < totalLeft { - curBlockSize = blockSize - } decodedData, err := encoder.Decode(encodedBytes, curBlockSize) if err != nil { writer.CloseWithError(err)