2016-06-17 14:57:51 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-05-25 19:42:31 -04:00
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
2017-01-19 12:34:18 -05:00
|
|
|
"sort"
|
2016-11-16 19:42:23 -05:00
|
|
|
"sync"
|
|
|
|
)
|
2016-10-17 05:10:23 -04:00
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
// healFormatXL - heals missing `format.json` on freshly or corrupted
|
|
|
|
// disks (missing format.json but does have erasure coded data in it).
|
|
|
|
func healFormatXL(storageDisks []StorageAPI) (err error) {
|
|
|
|
// Attempt to load all `format.json`.
|
|
|
|
formatConfigs, sErrs := loadAllFormats(storageDisks)
|
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
// Generic format check.
|
|
|
|
// - if (no quorum) return error
|
|
|
|
// - if (disks not recognized) // Always error.
|
2016-12-11 18:18:55 -05:00
|
|
|
if err = genericFormatCheckXL(formatConfigs, sErrs); err != nil {
|
2016-11-16 19:42:23 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handles different cases properly.
|
|
|
|
switch reduceFormatErrs(sErrs, len(storageDisks)) {
|
|
|
|
case errCorruptedFormat:
|
|
|
|
if err = healFormatXLCorruptedDisks(storageDisks); err != nil {
|
|
|
|
return fmt.Errorf("Unable to repair corrupted format, %s", err)
|
|
|
|
}
|
|
|
|
case errSomeDiskUnformatted:
|
|
|
|
// All drives online but some report missing format.json.
|
|
|
|
if err = healFormatXLFreshDisks(storageDisks); err != nil {
|
|
|
|
// There was an unexpected unrecoverable error during healing.
|
|
|
|
return fmt.Errorf("Unable to heal backend %s", err)
|
|
|
|
}
|
|
|
|
case errSomeDiskOffline:
|
|
|
|
// FIXME: in future.
|
|
|
|
return fmt.Errorf("Unable to initialize format %s and %s", errSomeDiskOffline, errSomeDiskUnformatted)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Heals a bucket if it doesn't exist on one of the disks, additionally
|
|
|
|
// also heals the missing entries for bucket metadata files
|
|
|
|
// `policy.json, notification.xml, listeners.json`.
|
2016-10-17 05:10:23 -04:00
|
|
|
func (xl xlObjects) HealBucket(bucket string) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkBucketExist(bucket, xl); err != nil {
|
|
|
|
return err
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
// Heal bucket.
|
|
|
|
if err := healBucket(xl.storageDisks, bucket, xl.writeQuorum); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proceed to heal bucket metadata.
|
2016-11-21 04:47:26 -05:00
|
|
|
return healBucketMetadata(xl.storageDisks, bucket, xl.readQuorum)
|
2016-11-16 19:42:23 -05:00
|
|
|
}
|
2016-10-17 05:10:23 -04:00
|
|
|
|
2016-11-19 20:37:57 -05:00
|
|
|
// Heal bucket - create buckets on disks where it does not exist.
|
2016-11-16 19:42:23 -05:00
|
|
|
func healBucket(storageDisks []StorageAPI, bucket string, writeQuorum int) error {
|
2016-12-10 19:15:12 -05:00
|
|
|
bucketLock := globalNSMutex.NewNSLock(bucket, "")
|
2016-11-09 13:58:41 -05:00
|
|
|
bucketLock.Lock()
|
|
|
|
defer bucketLock.Unlock()
|
2016-10-17 05:10:23 -04:00
|
|
|
|
|
|
|
// Initialize sync waitgroup.
|
|
|
|
var wg = &sync.WaitGroup{}
|
|
|
|
|
|
|
|
// Initialize list of errors.
|
2016-11-16 19:42:23 -05:00
|
|
|
var dErrs = make([]error, len(storageDisks))
|
2016-10-17 05:10:23 -04:00
|
|
|
|
|
|
|
// Make a volume entry on all underlying storage disks.
|
2016-11-16 19:42:23 -05:00
|
|
|
for index, disk := range storageDisks {
|
2016-10-17 05:10:23 -04:00
|
|
|
if disk == nil {
|
|
|
|
dErrs[index] = traceError(errDiskNotFound)
|
|
|
|
continue
|
2016-05-25 19:42:31 -04:00
|
|
|
}
|
2016-10-17 05:10:23 -04:00
|
|
|
wg.Add(1)
|
|
|
|
// Make a volume inside a go-routine.
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
if _, err := disk.StatVol(bucket); err != nil {
|
|
|
|
if err != errVolumeNotFound {
|
|
|
|
dErrs[index] = traceError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err = disk.MakeVol(bucket); err != nil {
|
|
|
|
dErrs[index] = traceError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}(index, disk)
|
2016-05-25 19:42:31 -04:00
|
|
|
}
|
2016-07-12 18:20:31 -04:00
|
|
|
|
2016-10-17 05:10:23 -04:00
|
|
|
// Wait for all make vol to finish.
|
|
|
|
wg.Wait()
|
2016-07-12 18:20:31 -04:00
|
|
|
|
2017-02-01 14:16:17 -05:00
|
|
|
reducedErr := reduceWriteQuorumErrs(dErrs, bucketOpIgnoredErrs, writeQuorum)
|
|
|
|
if errorCause(reducedErr) == errXLWriteQuorum {
|
2016-10-17 05:10:23 -04:00
|
|
|
// Purge successfully created buckets if we don't have writeQuorum.
|
2016-11-16 19:42:23 -05:00
|
|
|
undoMakeBucket(storageDisks, bucket)
|
2016-07-12 18:20:31 -04:00
|
|
|
}
|
2017-02-01 14:16:17 -05:00
|
|
|
return reducedErr
|
2016-05-25 19:42:31 -04:00
|
|
|
}
|
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
// Heals all the metadata associated for a given bucket, this function
|
|
|
|
// heals `policy.json`, `notification.xml` and `listeners.json`.
|
2016-11-21 04:47:26 -05:00
|
|
|
func healBucketMetadata(storageDisks []StorageAPI, bucket string, readQuorum int) error {
|
2016-11-16 19:42:23 -05:00
|
|
|
healBucketMetaFn := func(metaPath string) error {
|
2016-12-10 19:15:12 -05:00
|
|
|
metaLock := globalNSMutex.NewNSLock(minioMetaBucket, metaPath)
|
2016-11-16 19:42:23 -05:00
|
|
|
metaLock.RLock()
|
|
|
|
defer metaLock.RUnlock()
|
2016-11-19 20:37:57 -05:00
|
|
|
// Heals the given file at metaPath.
|
2016-11-21 04:47:26 -05:00
|
|
|
if err := healObject(storageDisks, minioMetaBucket, metaPath, readQuorum); err != nil && !isErrObjectNotFound(err) {
|
2016-11-16 19:42:23 -05:00
|
|
|
return err
|
|
|
|
} // Success.
|
|
|
|
return nil
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
2016-06-17 14:57:51 -04:00
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
// Heal `policy.json` for missing entries, ignores if `policy.json` is not found.
|
2017-01-16 20:05:00 -05:00
|
|
|
policyPath := pathJoin(bucketConfigPrefix, bucket, bucketPolicyConfig)
|
2016-11-16 19:42:23 -05:00
|
|
|
if err := healBucketMetaFn(policyPath); err != nil {
|
|
|
|
return err
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
2016-05-25 19:42:31 -04:00
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
// Heal `notification.xml` for missing entries, ignores if `notification.xml` is not found.
|
|
|
|
nConfigPath := path.Join(bucketConfigPrefix, bucket, bucketNotificationConfig)
|
|
|
|
if err := healBucketMetaFn(nConfigPath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Heal `listeners.json` for missing entries, ignores if `listeners.json` is not found.
|
|
|
|
lConfigPath := path.Join(bucketConfigPrefix, bucket, bucketListenerConfig)
|
|
|
|
return healBucketMetaFn(lConfigPath)
|
|
|
|
}
|
2016-10-17 05:10:23 -04:00
|
|
|
|
2017-01-19 12:34:18 -05:00
|
|
|
// listAllBuckets lists all buckets from all disks. It also
|
|
|
|
// returns the occurrence of each buckets in all disks
|
|
|
|
func listAllBuckets(storageDisks []StorageAPI) (buckets map[string]VolInfo, bucketsOcc map[string]int, err error) {
|
|
|
|
buckets = make(map[string]VolInfo)
|
|
|
|
bucketsOcc = make(map[string]int)
|
2016-11-16 19:42:23 -05:00
|
|
|
for _, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var volsInfo []VolInfo
|
|
|
|
volsInfo, err = disk.ListVols()
|
|
|
|
if err == nil {
|
|
|
|
for _, volInfo := range volsInfo {
|
|
|
|
// StorageAPI can send volume names which are
|
|
|
|
// incompatible with buckets, handle it and skip them.
|
|
|
|
if !IsValidBucketName(volInfo.Name) {
|
|
|
|
continue
|
|
|
|
}
|
2017-01-17 13:02:58 -05:00
|
|
|
// Skip special volume buckets.
|
|
|
|
if isMinioMetaBucketName(volInfo.Name) {
|
2016-11-16 19:42:23 -05:00
|
|
|
continue
|
|
|
|
}
|
2017-01-19 12:34:18 -05:00
|
|
|
// Increase counter per bucket name
|
|
|
|
bucketsOcc[volInfo.Name]++
|
|
|
|
// Save volume info under bucket name
|
|
|
|
buckets[volInfo.Name] = volInfo
|
2016-11-16 19:42:23 -05:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Ignore any disks not found.
|
2016-11-23 23:05:04 -05:00
|
|
|
if isErrIgnored(err, bucketMetadataOpIgnoredErrs...) {
|
2016-11-16 19:42:23 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
2017-01-19 12:34:18 -05:00
|
|
|
return buckets, bucketsOcc, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// reduceHealStatus - fetches the worst heal status in a provided slice
|
|
|
|
func reduceHealStatus(status []healStatus) healStatus {
|
|
|
|
worstStatus := healthy
|
|
|
|
for _, st := range status {
|
|
|
|
if st > worstStatus {
|
|
|
|
worstStatus = st
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return worstStatus
|
|
|
|
}
|
|
|
|
|
|
|
|
// bucketHealStatus - returns the heal status of the provided bucket. Internally,
|
|
|
|
// this function lists all object heal status of objects inside meta bucket config
|
|
|
|
// directory and returns the worst heal status that can be found
|
|
|
|
func (xl xlObjects) bucketHealStatus(bucketName string) (healStatus, error) {
|
|
|
|
// A list of all the bucket config files
|
|
|
|
configFiles := []string{bucketPolicyConfig, bucketNotificationConfig, bucketListenerConfig}
|
|
|
|
// The status of buckets config files
|
|
|
|
configsHealStatus := make([]healStatus, len(configFiles))
|
|
|
|
// The list of errors found during checking heal status of each config file
|
|
|
|
configsErrs := make([]error, len(configFiles))
|
|
|
|
// The path of meta bucket that contains all config files
|
|
|
|
configBucket := path.Join(minioMetaBucket, bucketConfigPrefix, bucketName)
|
|
|
|
|
|
|
|
// Check of config files heal status in go-routines
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
// Loop over config files
|
|
|
|
for idx, configFile := range configFiles {
|
|
|
|
wg.Add(1)
|
|
|
|
// Compute heal status of current config file
|
|
|
|
go func(bucket, object string, index int) {
|
|
|
|
defer wg.Done()
|
|
|
|
// Check
|
|
|
|
listObjectsHeal, err := xl.listObjectsHeal(bucket, object, "", "", 1)
|
|
|
|
// If any error, save and immediately quit
|
|
|
|
if err != nil {
|
|
|
|
configsErrs[index] = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Check if current bucket contains any not healthy config file and save heal status
|
|
|
|
if len(listObjectsHeal.Objects) > 0 {
|
|
|
|
configsHealStatus[index] = listObjectsHeal.Objects[0].HealObjectInfo.Status
|
|
|
|
}
|
|
|
|
}(configBucket, configFile, idx)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
// Return any found error
|
|
|
|
for _, err := range configsErrs {
|
|
|
|
if err != nil {
|
|
|
|
return healthy, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reduce and return heal status
|
|
|
|
return reduceHealStatus(configsHealStatus), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListBucketsHeal - Find all buckets that need to be healed
|
|
|
|
func (xl xlObjects) ListBucketsHeal() ([]BucketInfo, error) {
|
|
|
|
listBuckets := []BucketInfo{}
|
|
|
|
// List all buckets that can be found in all disks
|
|
|
|
buckets, occ, err := listAllBuckets(xl.storageDisks)
|
|
|
|
if err != nil {
|
|
|
|
return listBuckets, err
|
|
|
|
}
|
|
|
|
// Iterate over all buckets
|
|
|
|
for _, currBucket := range buckets {
|
|
|
|
// Check the status of bucket metadata
|
|
|
|
bucketHealStatus, err := xl.bucketHealStatus(currBucket.Name)
|
|
|
|
if err != nil {
|
|
|
|
return []BucketInfo{}, err
|
|
|
|
}
|
|
|
|
// If all metadata are sane, check if the bucket directory is present in all disks
|
|
|
|
if bucketHealStatus == healthy && occ[currBucket.Name] != len(xl.storageDisks) {
|
|
|
|
// Current bucket is missing in some of the storage disks
|
|
|
|
bucketHealStatus = canHeal
|
|
|
|
}
|
|
|
|
// Add current bucket to the returned result if not healthy
|
|
|
|
if bucketHealStatus != healthy {
|
|
|
|
listBuckets = append(listBuckets,
|
|
|
|
BucketInfo{
|
|
|
|
Name: currBucket.Name,
|
|
|
|
Created: currBucket.Created,
|
|
|
|
HealBucketInfo: &HealBucketInfo{Status: bucketHealStatus},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// Sort found buckets
|
|
|
|
sort.Sort(byBucketName(listBuckets))
|
|
|
|
return listBuckets, nil
|
2016-11-16 19:42:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// This function is meant for all the healing that needs to be done
|
|
|
|
// during startup i.e healing of buckets, bucket metadata (policy.json,
|
|
|
|
// notification.xml, listeners.json) etc. Currently this function
|
|
|
|
// supports quick healing of buckets, bucket metadata.
|
|
|
|
//
|
|
|
|
// TODO :-
|
|
|
|
// - add support for healing dangling `uploads.json`.
|
|
|
|
// - add support for healing dangling `xl.json`.
|
2016-11-21 04:47:26 -05:00
|
|
|
func quickHeal(storageDisks []StorageAPI, writeQuorum int, readQuorum int) error {
|
2016-11-16 19:42:23 -05:00
|
|
|
// List all bucket names from all disks.
|
2017-01-19 12:34:18 -05:00
|
|
|
bucketNames, _, err := listAllBuckets(storageDisks)
|
2016-11-16 19:42:23 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// All bucket names and bucket metadata should be healed.
|
|
|
|
for bucketName := range bucketNames {
|
|
|
|
// Heal bucket and then proceed to heal bucket metadata.
|
|
|
|
if err = healBucket(storageDisks, bucketName, writeQuorum); err == nil {
|
2016-11-21 04:47:26 -05:00
|
|
|
if err = healBucketMetadata(storageDisks, bucketName, readQuorum); err == nil {
|
2016-11-16 19:42:23 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Heals an object only the corrupted/missing erasure blocks.
|
2016-11-21 04:47:26 -05:00
|
|
|
func healObject(storageDisks []StorageAPI, bucket string, object string, quorum int) error {
|
2016-11-16 19:42:23 -05:00
|
|
|
partsMetadata, errs := readAllXLMetadata(storageDisks, bucket, object)
|
2017-03-04 17:53:28 -05:00
|
|
|
// readQuorum suffices for xl.json since we use monotonic
|
|
|
|
// system time to break the tie when a split-brain situation
|
|
|
|
// arises.
|
2016-11-21 04:47:26 -05:00
|
|
|
if reducedErr := reduceReadQuorumErrs(errs, nil, quorum); reducedErr != nil {
|
|
|
|
return toObjectErr(reducedErr, bucket, object)
|
2016-05-25 19:42:31 -04:00
|
|
|
}
|
2016-08-17 14:36:33 -04:00
|
|
|
|
2016-10-17 05:10:23 -04:00
|
|
|
if !xlShouldHeal(partsMetadata, errs) {
|
|
|
|
// There is nothing to heal.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// List of disks having latest version of the object.
|
2016-11-16 19:42:23 -05:00
|
|
|
latestDisks, modTime := listOnlineDisks(storageDisks, partsMetadata, errs)
|
2017-03-04 17:53:28 -05:00
|
|
|
|
|
|
|
// List of disks having all parts as per latest xl.json.
|
|
|
|
availableDisks, errs, aErr := disksWithAllParts(latestDisks, partsMetadata, errs, bucket, object)
|
|
|
|
if aErr != nil {
|
|
|
|
return toObjectErr(aErr, bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
numAvailableDisks := 0
|
|
|
|
for _, disk := range availableDisks {
|
|
|
|
if disk != nil {
|
|
|
|
numAvailableDisks++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If less than read quorum number of disks have all the parts
|
|
|
|
// of the data, we can't reconstruct the erasure-coded data.
|
|
|
|
if numAvailableDisks < quorum {
|
|
|
|
return toObjectErr(errXLReadQuorum, bucket, object)
|
|
|
|
}
|
|
|
|
|
2016-10-17 05:10:23 -04:00
|
|
|
// List of disks having outdated version of the object or missing object.
|
2017-03-04 17:53:28 -05:00
|
|
|
outDatedDisks := outDatedDisks(storageDisks, availableDisks, errs, partsMetadata,
|
|
|
|
bucket, object)
|
|
|
|
|
|
|
|
// Latest xlMetaV1 for reference. If a valid metadata is not
|
|
|
|
// present, it is as good as object not found.
|
2016-11-20 23:56:44 -05:00
|
|
|
latestMeta, pErr := pickValidXLMeta(partsMetadata, modTime)
|
|
|
|
if pErr != nil {
|
2017-03-04 17:53:28 -05:00
|
|
|
return toObjectErr(pErr, bucket, object)
|
2016-11-20 23:56:44 -05:00
|
|
|
}
|
2016-10-17 05:10:23 -04:00
|
|
|
|
|
|
|
for index, disk := range outDatedDisks {
|
|
|
|
// Before healing outdated disks, we need to remove xl.json
|
|
|
|
// and part files from "bucket/object/" so that
|
|
|
|
// rename(".minio.sys", "tmp/tmpuuid/", "bucket", "object/") succeeds.
|
|
|
|
if disk == nil {
|
|
|
|
// Not an outdated disk.
|
2016-08-17 14:36:33 -04:00
|
|
|
continue
|
|
|
|
}
|
2017-01-30 03:45:56 -05:00
|
|
|
|
|
|
|
// errFileNotFound implies that xl.json is missing. We
|
|
|
|
// may have object parts still present in the object
|
|
|
|
// directory. This needs to be deleted for object to
|
|
|
|
// healed successfully.
|
|
|
|
if errs[index] != nil && !isErr(errs[index], errFileNotFound) {
|
2016-08-17 14:36:33 -04:00
|
|
|
continue
|
|
|
|
}
|
2017-01-30 03:45:56 -05:00
|
|
|
|
2016-10-17 05:10:23 -04:00
|
|
|
// Outdated object with the same name exists that needs to be deleted.
|
|
|
|
outDatedMeta := partsMetadata[index]
|
2017-01-30 03:45:56 -05:00
|
|
|
// Consult valid metadata picked when there is no
|
|
|
|
// metadata available on this disk.
|
|
|
|
if isErr(errs[index], errFileNotFound) {
|
|
|
|
outDatedMeta = latestMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete all the parts. Ignore if parts are not found.
|
|
|
|
for _, part := range outDatedMeta.Parts {
|
2017-03-04 17:53:28 -05:00
|
|
|
dErr := disk.DeleteFile(bucket, pathJoin(object, part.Name))
|
|
|
|
if dErr != nil && !isErr(dErr, errFileNotFound) {
|
|
|
|
return toObjectErr(traceError(dErr), bucket, object)
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
|
|
|
}
|
2017-01-30 03:45:56 -05:00
|
|
|
|
|
|
|
// Delete xl.json file. Ignore if xl.json not found.
|
2017-03-04 17:53:28 -05:00
|
|
|
dErr := disk.DeleteFile(bucket, pathJoin(object, xlMetaJSONFile))
|
|
|
|
if dErr != nil && !isErr(dErr, errFileNotFound) {
|
|
|
|
return toObjectErr(traceError(dErr), bucket, object)
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reorder so that we have data disks first and parity disks next.
|
2017-02-24 12:20:40 -05:00
|
|
|
latestDisks = shuffleDisks(latestDisks, latestMeta.Erasure.Distribution)
|
|
|
|
outDatedDisks = shuffleDisks(outDatedDisks, latestMeta.Erasure.Distribution)
|
|
|
|
partsMetadata = shufflePartsMetadata(partsMetadata, latestMeta.Erasure.Distribution)
|
2016-10-17 05:10:23 -04:00
|
|
|
|
|
|
|
// We write at temporary location and then rename to fianal location.
|
2016-11-22 19:52:37 -05:00
|
|
|
tmpID := mustGetUUID()
|
2016-10-17 05:10:23 -04:00
|
|
|
|
|
|
|
// Checksum of the part files. checkSumInfos[index] will contain checksums
|
|
|
|
// of all the part files in the outDatedDisks[index]
|
|
|
|
checkSumInfos := make([][]checkSumInfo, len(outDatedDisks))
|
|
|
|
|
|
|
|
// Heal each part. erasureHealFile() will write the healed part to
|
|
|
|
// .minio/tmp/uuid/ which needs to be renamed later to the final location.
|
|
|
|
for partIndex := 0; partIndex < len(latestMeta.Parts); partIndex++ {
|
|
|
|
partName := latestMeta.Parts[partIndex].Name
|
|
|
|
partSize := latestMeta.Parts[partIndex].Size
|
|
|
|
erasure := latestMeta.Erasure
|
2016-10-18 14:13:25 -04:00
|
|
|
sumInfo := latestMeta.Erasure.GetCheckSumInfo(partName)
|
2016-10-17 05:10:23 -04:00
|
|
|
// Heal the part file.
|
2017-03-04 17:53:28 -05:00
|
|
|
checkSums, hErr := erasureHealFile(latestDisks, outDatedDisks,
|
2016-10-17 05:10:23 -04:00
|
|
|
bucket, pathJoin(object, partName),
|
2016-11-20 17:25:43 -05:00
|
|
|
minioMetaTmpBucket, pathJoin(tmpID, partName),
|
2016-10-17 05:10:23 -04:00
|
|
|
partSize, erasure.BlockSize, erasure.DataBlocks, erasure.ParityBlocks, sumInfo.Algorithm)
|
2017-03-04 17:53:28 -05:00
|
|
|
if hErr != nil {
|
|
|
|
return toObjectErr(hErr, bucket, object)
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
|
|
|
for index, sum := range checkSums {
|
2016-11-19 20:37:57 -05:00
|
|
|
if outDatedDisks[index] != nil {
|
|
|
|
checkSumInfos[index] = append(checkSumInfos[index], checkSumInfo{
|
|
|
|
Name: partName,
|
|
|
|
Algorithm: sumInfo.Algorithm,
|
|
|
|
Hash: sum,
|
|
|
|
})
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// xl.json should be written to all the healed disks.
|
|
|
|
for index, disk := range outDatedDisks {
|
2016-08-17 14:36:33 -04:00
|
|
|
if disk == nil {
|
2016-10-17 05:10:23 -04:00
|
|
|
continue
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
2016-10-17 05:10:23 -04:00
|
|
|
partsMetadata[index] = latestMeta
|
|
|
|
partsMetadata[index].Erasure.Checksum = checkSumInfos[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate and write `xl.json` generated from other disks.
|
2017-03-04 17:53:28 -05:00
|
|
|
aErr = writeUniqueXLMetadata(outDatedDisks, minioMetaTmpBucket, tmpID, partsMetadata, diskCount(outDatedDisks))
|
|
|
|
if aErr != nil {
|
|
|
|
return toObjectErr(aErr, bucket, object)
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
|
|
|
|
2016-10-17 05:10:23 -04:00
|
|
|
// Rename from tmp location to the actual location.
|
|
|
|
for _, disk := range outDatedDisks {
|
|
|
|
if disk == nil {
|
2016-08-31 14:42:57 -04:00
|
|
|
continue
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
2016-10-17 05:10:23 -04:00
|
|
|
// Remove any lingering partial data from current namespace.
|
2017-03-04 17:53:28 -05:00
|
|
|
aErr = disk.DeleteFile(bucket, retainSlash(object))
|
|
|
|
if aErr != nil && aErr != errFileNotFound {
|
|
|
|
return toObjectErr(traceError(aErr), bucket, object)
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
2016-10-17 05:10:23 -04:00
|
|
|
// Attempt a rename now from healed data to final location.
|
2017-03-04 17:53:28 -05:00
|
|
|
aErr = disk.RenameFile(minioMetaTmpBucket, retainSlash(tmpID), bucket, retainSlash(object))
|
|
|
|
if aErr != nil {
|
|
|
|
return toObjectErr(traceError(aErr), bucket, object)
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
|
|
|
}
|
2016-10-17 05:10:23 -04:00
|
|
|
return nil
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
|
|
|
|
// HealObject heals a given object for all its missing entries.
|
|
|
|
// FIXME: If an object object was deleted and one disk was down,
|
|
|
|
// and later the disk comes back up again, heal on the object
|
|
|
|
// should delete it.
|
|
|
|
func (xl xlObjects) HealObject(bucket, object string) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkGetObjArgs(bucket, object); err != nil {
|
|
|
|
return err
|
2016-11-16 19:42:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lock the object before healing.
|
2016-12-10 19:15:12 -05:00
|
|
|
objectLock := globalNSMutex.NewNSLock(bucket, object)
|
2016-11-16 19:42:23 -05:00
|
|
|
objectLock.RLock()
|
|
|
|
defer objectLock.RUnlock()
|
|
|
|
|
|
|
|
// Heal the object.
|
2016-11-21 04:47:26 -05:00
|
|
|
return healObject(xl.storageDisks, bucket, object, xl.readQuorum)
|
2016-11-16 19:42:23 -05:00
|
|
|
}
|