|
|
@ -21,6 +21,7 @@ import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
slashpath "path" |
|
|
|
slashpath "path" |
|
|
|
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus" |
|
|
|
"github.com/Sirupsen/logrus" |
|
|
|
) |
|
|
|
) |
|
|
@ -95,6 +96,7 @@ func (xl XL) ReadFile(volume, path string, startOffset int64) (io.ReadCloser, er |
|
|
|
// Calculate the current encoded block size.
|
|
|
|
// Calculate the current encoded block size.
|
|
|
|
curEncBlockSize := getEncodedBlockLen(curBlockSize, metadata.Erasure.DataBlocks) |
|
|
|
curEncBlockSize := getEncodedBlockLen(curBlockSize, metadata.Erasure.DataBlocks) |
|
|
|
enBlocks := make([][]byte, len(xl.storageDisks)) |
|
|
|
enBlocks := make([][]byte, len(xl.storageDisks)) |
|
|
|
|
|
|
|
var wg = &sync.WaitGroup{} |
|
|
|
// Loop through all readers and read.
|
|
|
|
// Loop through all readers and read.
|
|
|
|
for index, reader := range readers { |
|
|
|
for index, reader := range readers { |
|
|
|
// Initialize shard slice and fill the data from each parts.
|
|
|
|
// Initialize shard slice and fill the data from each parts.
|
|
|
@ -102,11 +104,19 @@ func (xl XL) ReadFile(volume, path string, startOffset int64) (io.ReadCloser, er |
|
|
|
if reader == nil { |
|
|
|
if reader == nil { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
_, err = io.ReadFull(reader, enBlocks[index]) |
|
|
|
// Parallelize reading.
|
|
|
|
if err != nil && err != io.ErrUnexpectedEOF { |
|
|
|
wg.Add(1) |
|
|
|
readers[index] = nil |
|
|
|
go func(index int, reader io.Reader) { |
|
|
|
} |
|
|
|
defer wg.Done() |
|
|
|
|
|
|
|
// Read the necessary blocks.
|
|
|
|
|
|
|
|
_, rErr := io.ReadFull(reader, enBlocks[index]) |
|
|
|
|
|
|
|
if rErr != nil && rErr != io.ErrUnexpectedEOF { |
|
|
|
|
|
|
|
readers[index] = nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}(index, reader) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Wait for the read routines to finish.
|
|
|
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
|
|
|
|
|
|
// Check blocks if they are all zero in length.
|
|
|
|
// Check blocks if they are all zero in length.
|
|
|
|
if checkBlockSize(enBlocks) == 0 { |
|
|
|
if checkBlockSize(enBlocks) == 0 { |
|
|
|