mirror of
https://github.com/pgsty/minio.git
synced 2026-08-10 08:13:28 +03:00
XL: Bring in some modularity into format verification and healing. (#1832)
This commit is contained in:
+31
-4
@@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
"math/rand"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -38,14 +39,40 @@ func randInts(count int) []int {
|
||||
return ints
|
||||
}
|
||||
|
||||
// readAll reads from bucket, object until an error or returns the data it read until io.EOF.
|
||||
func readAll(disk StorageAPI, bucket, object string) ([]byte, error) {
|
||||
// readAll - returns contents from volume/path as byte array.
|
||||
func readAll(disk StorageAPI, volume string, path string) ([]byte, error) {
|
||||
var writer = new(bytes.Buffer)
|
||||
startOffset := int64(0)
|
||||
|
||||
// Allocate 10MiB buffer.
|
||||
buf := make([]byte, blockSizeV1)
|
||||
|
||||
// Read until io.EOF.
|
||||
for {
|
||||
buf := make([]byte, blockSizeV1)
|
||||
n, err := disk.ReadFile(bucket, object, startOffset, buf)
|
||||
n, err := disk.ReadFile(volume, path, startOffset, buf)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
writer.Write(buf[:n])
|
||||
startOffset += n
|
||||
}
|
||||
return writer.Bytes(), nil
|
||||
}
|
||||
|
||||
// readXLMeta reads `xl.json` returns contents as byte array.
|
||||
func readXLMeta(disk StorageAPI, bucket string, object string) ([]byte, error) {
|
||||
var writer = new(bytes.Buffer)
|
||||
startOffset := int64(0)
|
||||
|
||||
// Allocate 2MiB buffer, this is sufficient for the most of `xl.json`.
|
||||
buf := make([]byte, 2*1024*1024)
|
||||
|
||||
// Read until io.EOF.
|
||||
for {
|
||||
n, err := disk.ReadFile(bucket, path.Join(object, xlMetaJSONFile), startOffset, buf)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user