Removing readAllMeta from xl-v1-healing.go and placing it in xl-v1-utils.go (#2296)

master
karthic rao 8 years ago committed by Harshavardhana
parent 1e3d80552f
commit 5fe72cf205
  1. 33
      xl-v1-healing.go
  2. 33
      xl-v1-utils.go

@ -17,7 +17,6 @@
package main package main
import ( import (
"sync"
"time" "time"
) )
@ -78,38 +77,6 @@ func listObjectModtimes(partsMetadata []xlMetaV1, errs []error) (modTimes []time
return modTimes return modTimes
} }
// 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
}
func (xl xlObjects) shouldHeal(onlineDisks []StorageAPI) (heal bool) { func (xl xlObjects) shouldHeal(onlineDisks []StorageAPI) (heal bool) {
onlineDiskCount := diskCount(onlineDisks) onlineDiskCount := diskCount(onlineDisks)
// If online disks count is lesser than configured disks, most // If online disks count is lesser than configured disks, most

@ -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))

Loading…
Cancel
Save