|
|
@ -20,6 +20,7 @@ import ( |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"hash/crc32" |
|
|
|
"hash/crc32" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
|
|
|
|
"sync" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Returns number of errors that occurred the most (incl. nil) and the
|
|
|
|
// Returns number of errors that occurred the most (incl. nil) and the
|
|
|
@ -112,6 +113,38 @@ func readXLMeta(disk StorageAPI, bucket string, object string) (xlMeta xlMetaV1, |
|
|
|
return xlMeta, nil |
|
|
|
return xlMeta, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reads all `xl.json` metadata as a xlMetaV1 slice.
|
|
|
|
|
|
|
|
// Returns error slice indicating the failed metadata reads.
|
|
|
|
|
|
|
|
func readAllXLMetadata(disks []StorageAPI, bucket, object string) ([]xlMetaV1, []error) { |
|
|
|
|
|
|
|
errs := make([]error, len(disks)) |
|
|
|
|
|
|
|
metadataArray := make([]xlMetaV1, len(disks)) |
|
|
|
|
|
|
|
var wg = &sync.WaitGroup{} |
|
|
|
|
|
|
|
// Read `xl.json` parallelly across disks.
|
|
|
|
|
|
|
|
for index, disk := range disks { |
|
|
|
|
|
|
|
if disk == nil { |
|
|
|
|
|
|
|
errs[index] = errDiskNotFound |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
wg.Add(1) |
|
|
|
|
|
|
|
// Read `xl.json` in routine.
|
|
|
|
|
|
|
|
go func(index int, disk StorageAPI) { |
|
|
|
|
|
|
|
defer wg.Done() |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
metadataArray[index], err = readXLMeta(disk, bucket, object) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
errs[index] = err |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}(index, disk) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for all the routines to finish.
|
|
|
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return all the metadata.
|
|
|
|
|
|
|
|
return metadataArray, errs |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Return ordered partsMetadata depeinding on distribution.
|
|
|
|
// Return ordered partsMetadata depeinding on distribution.
|
|
|
|
func getOrderedPartsMetadata(distribution []int, partsMetadata []xlMetaV1) (orderedPartsMetadata []xlMetaV1) { |
|
|
|
func getOrderedPartsMetadata(distribution []int, partsMetadata []xlMetaV1) (orderedPartsMetadata []xlMetaV1) { |
|
|
|
orderedPartsMetadata = make([]xlMetaV1, len(partsMetadata)) |
|
|
|
orderedPartsMetadata = make([]xlMetaV1, len(partsMetadata)) |
|
|
|