2016-06-17 20:57:51 +02:00
|
|
|
/*
|
2020-06-13 05:04:01 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc.
|
2016-06-17 20:57:51 +02:00
|
|
|
*
|
|
|
|
* 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-19 01:23:42 +02:00
|
|
|
package cmd
|
2016-05-26 01:42:31 +02:00
|
|
|
|
2016-11-17 01:42:23 +01:00
|
|
|
import (
|
2018-03-14 20:01:47 +01:00
|
|
|
"context"
|
2016-11-17 01:42:23 +01:00
|
|
|
"fmt"
|
2019-01-17 13:58:18 +01:00
|
|
|
"io"
|
2020-06-13 05:04:01 +02:00
|
|
|
"sync"
|
2019-01-30 19:53:57 +01:00
|
|
|
"time"
|
2017-11-25 20:58:29 +01:00
|
|
|
|
2018-04-06 00:04:40 +02:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-01-22 23:54:55 +01:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2019-10-14 18:44:51 +02:00
|
|
|
"github.com/minio/minio/pkg/sync/errgroup"
|
2016-11-17 01:42:23 +01:00
|
|
|
)
|
2016-10-17 11:10:23 +02:00
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
func (er erasureObjects) ReloadFormat(ctx context.Context, dryRun bool) error {
|
2018-04-10 18:36:37 +02:00
|
|
|
logger.LogIf(ctx, NotImplemented{})
|
|
|
|
return NotImplemented{}
|
2018-04-09 19:25:41 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
func (er erasureObjects) HealFormat(ctx context.Context, dryRun bool) (madmin.HealResultItem, error) {
|
2018-04-06 00:04:40 +02:00
|
|
|
logger.LogIf(ctx, NotImplemented{})
|
|
|
|
return madmin.HealResultItem{}, NotImplemented{}
|
2016-11-17 01:42:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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`.
|
2020-06-13 05:04:01 +02:00
|
|
|
func (er erasureObjects) HealBucket(ctx context.Context, bucket string, dryRun, remove bool) (
|
2019-02-11 04:53:13 +01:00
|
|
|
result madmin.HealResultItem, err error) {
|
2020-04-27 19:06:21 +02:00
|
|
|
if !dryRun {
|
|
|
|
defer ObjectPathUpdated(bucket)
|
|
|
|
}
|
2018-01-22 23:54:55 +01:00
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
storageDisks := er.getDisks()
|
|
|
|
storageEndpoints := er.getEndpoints()
|
2018-03-16 23:09:31 +01:00
|
|
|
|
2017-12-22 12:28:13 +01:00
|
|
|
// get write quorum for an object
|
2020-03-31 18:32:16 +02:00
|
|
|
writeQuorum := getWriteQuorum(len(storageDisks))
|
2017-12-22 12:28:13 +01:00
|
|
|
|
2016-11-17 01:42:23 +01:00
|
|
|
// Heal bucket.
|
2020-06-11 02:10:31 +02:00
|
|
|
return healBucket(ctx, storageDisks, storageEndpoints, bucket, writeQuorum, dryRun)
|
2016-11-17 01:42:23 +01:00
|
|
|
}
|
2016-10-17 11:10:23 +02:00
|
|
|
|
2016-11-20 02:37:57 +01:00
|
|
|
// Heal bucket - create buckets on disks where it does not exist.
|
2020-06-11 02:10:31 +02:00
|
|
|
func healBucket(ctx context.Context, storageDisks []StorageAPI, storageEndpoints []string, bucket string, writeQuorum int,
|
2018-01-22 23:54:55 +01:00
|
|
|
dryRun bool) (res madmin.HealResultItem, err error) {
|
2016-10-17 11:10:23 +02:00
|
|
|
|
|
|
|
// Initialize sync waitgroup.
|
2019-10-14 18:44:51 +02:00
|
|
|
g := errgroup.WithNErrs(len(storageDisks))
|
2016-10-17 11:10:23 +02:00
|
|
|
|
2018-01-22 23:54:55 +01:00
|
|
|
// Disk states slices
|
|
|
|
beforeState := make([]string, len(storageDisks))
|
|
|
|
afterState := make([]string, len(storageDisks))
|
|
|
|
|
2016-10-17 11:10:23 +02:00
|
|
|
// Make a volume entry on all underlying storage disks.
|
2019-10-14 18:44:51 +02:00
|
|
|
for index := range storageDisks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if storageDisks[index] == nil {
|
|
|
|
beforeState[index] = madmin.DriveStateOffline
|
|
|
|
afterState[index] = madmin.DriveStateOffline
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
if _, serr := storageDisks[index].StatVol(bucket); serr != nil {
|
2018-04-10 18:36:37 +02:00
|
|
|
if serr == errDiskNotFound {
|
2018-02-16 02:45:57 +01:00
|
|
|
beforeState[index] = madmin.DriveStateOffline
|
|
|
|
afterState[index] = madmin.DriveStateOffline
|
2019-10-14 18:44:51 +02:00
|
|
|
return serr
|
2018-02-16 02:45:57 +01:00
|
|
|
}
|
2018-04-10 18:36:37 +02:00
|
|
|
if serr != errVolumeNotFound {
|
2018-01-22 23:54:55 +01:00
|
|
|
beforeState[index] = madmin.DriveStateCorrupt
|
|
|
|
afterState[index] = madmin.DriveStateCorrupt
|
2019-10-14 18:44:51 +02:00
|
|
|
return serr
|
2016-10-17 11:10:23 +02:00
|
|
|
}
|
2018-01-22 23:54:55 +01:00
|
|
|
|
|
|
|
beforeState[index] = madmin.DriveStateMissing
|
|
|
|
afterState[index] = madmin.DriveStateMissing
|
|
|
|
|
|
|
|
// mutate only if not a dry-run
|
|
|
|
if dryRun {
|
2019-10-14 18:44:51 +02:00
|
|
|
return nil
|
2018-01-22 23:54:55 +01:00
|
|
|
}
|
|
|
|
|
2020-01-25 00:38:07 +01:00
|
|
|
return serr
|
2016-10-17 11:10:23 +02:00
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
beforeState[index] = madmin.DriveStateOk
|
|
|
|
afterState[index] = madmin.DriveStateOk
|
2019-10-14 18:44:51 +02:00
|
|
|
return nil
|
|
|
|
}, index)
|
2016-05-26 01:42:31 +02:00
|
|
|
}
|
2016-07-13 00:20:31 +02:00
|
|
|
|
2019-10-14 18:44:51 +02:00
|
|
|
errs := g.Wait()
|
2016-07-13 00:20:31 +02:00
|
|
|
|
2020-01-25 00:38:07 +01:00
|
|
|
reducedErr := reduceWriteQuorumErrs(ctx, errs, bucketOpIgnoredErrs, writeQuorum-1)
|
|
|
|
if reducedErr == errVolumeNotFound {
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2018-01-22 23:54:55 +01:00
|
|
|
// Initialize heal result info
|
|
|
|
res = madmin.HealResultItem{
|
|
|
|
Type: madmin.HealItemBucket,
|
|
|
|
Bucket: bucket,
|
|
|
|
DiskCount: len(storageDisks),
|
|
|
|
}
|
2020-01-25 00:38:07 +01:00
|
|
|
|
2019-10-14 18:44:51 +02:00
|
|
|
for i := range beforeState {
|
2020-06-11 02:10:31 +02:00
|
|
|
res.Before.Drives = append(res.Before.Drives, madmin.HealDriveInfo{
|
|
|
|
UUID: "",
|
|
|
|
Endpoint: storageEndpoints[i],
|
|
|
|
State: beforeState[i],
|
|
|
|
})
|
2018-01-22 23:54:55 +01:00
|
|
|
}
|
|
|
|
|
2020-01-25 00:38:07 +01:00
|
|
|
// Initialize sync waitgroup.
|
|
|
|
g = errgroup.WithNErrs(len(storageDisks))
|
|
|
|
|
|
|
|
// Make a volume entry on all underlying storage disks.
|
|
|
|
for index := range storageDisks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if beforeState[index] == madmin.DriveStateMissing {
|
|
|
|
makeErr := storageDisks[index].MakeVol(bucket)
|
|
|
|
if makeErr == nil {
|
|
|
|
afterState[index] = madmin.DriveStateOk
|
|
|
|
}
|
|
|
|
return makeErr
|
|
|
|
}
|
|
|
|
return errs[index]
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
errs = g.Wait()
|
|
|
|
|
|
|
|
reducedErr = reduceWriteQuorumErrs(ctx, errs, bucketOpIgnoredErrs, writeQuorum)
|
2020-04-20 22:48:54 +02:00
|
|
|
if reducedErr != nil {
|
|
|
|
return res, reducedErr
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range afterState {
|
2020-06-11 02:10:31 +02:00
|
|
|
res.After.Drives = append(res.After.Drives, madmin.HealDriveInfo{
|
|
|
|
UUID: "",
|
|
|
|
Endpoint: storageEndpoints[i],
|
|
|
|
State: afterState[i],
|
|
|
|
})
|
2016-07-13 00:20:31 +02:00
|
|
|
}
|
2020-04-20 22:48:54 +02:00
|
|
|
return res, nil
|
2016-05-26 01:42:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-19 18:34:18 +01:00
|
|
|
// listAllBuckets lists all buckets from all disks. It also
|
|
|
|
// returns the occurrence of each buckets in all disks
|
2020-05-06 23:25:05 +02:00
|
|
|
func listAllBuckets(storageDisks []StorageAPI, healBuckets map[string]VolInfo) (err error) {
|
2016-11-17 01:42:23 +01:00
|
|
|
for _, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var volsInfo []VolInfo
|
|
|
|
volsInfo, err = disk.ListVols()
|
2018-01-22 23:54:55 +01:00
|
|
|
if err != nil {
|
2018-04-10 18:36:37 +02:00
|
|
|
if IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) {
|
2018-01-22 23:54:55 +01:00
|
|
|
continue
|
2016-11-17 01:42:23 +01:00
|
|
|
}
|
2020-05-06 23:25:05 +02:00
|
|
|
return err
|
2017-01-19 18:34:18 +01:00
|
|
|
}
|
2018-01-22 23:54:55 +01:00
|
|
|
for _, volInfo := range volsInfo {
|
|
|
|
// StorageAPI can send volume names which are
|
|
|
|
// incompatible with buckets - these are
|
|
|
|
// skipped, like the meta-bucket.
|
2019-04-04 08:10:37 +02:00
|
|
|
if isReservedOrInvalidBucket(volInfo.Name, false) {
|
2018-01-22 23:54:55 +01:00
|
|
|
continue
|
2017-01-19 18:34:18 +01:00
|
|
|
}
|
2020-05-06 23:25:05 +02:00
|
|
|
// always save unique buckets across drives.
|
|
|
|
if _, ok := healBuckets[volInfo.Name]; !ok {
|
|
|
|
healBuckets[volInfo.Name] = volInfo
|
|
|
|
}
|
|
|
|
|
2017-01-19 18:34:18 +01:00
|
|
|
}
|
|
|
|
}
|
2020-05-06 23:25:05 +02:00
|
|
|
return nil
|
2017-01-19 18:34:18 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 19:53:57 +01:00
|
|
|
// Only heal on disks where we are sure that healing is needed. We can expand
|
|
|
|
// this list as and when we figure out more errors can be added to this list safely.
|
2020-06-13 05:04:01 +02:00
|
|
|
func shouldHealObjectOnDisk(erErr, dataErr error, meta FileInfo, quorumModTime time.Time) bool {
|
|
|
|
switch erErr {
|
2020-07-06 17:09:48 +02:00
|
|
|
case errFileNotFound, errFileVersionNotFound:
|
2019-01-30 19:53:57 +01:00
|
|
|
return true
|
|
|
|
case errCorruptedFormat:
|
|
|
|
return true
|
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
if erErr == nil {
|
|
|
|
// If er.meta was read fine but there may be problem with the part.N files.
|
2019-10-01 22:12:15 +02:00
|
|
|
if IsErr(dataErr, []error{
|
|
|
|
errFileNotFound,
|
2020-07-06 17:09:48 +02:00
|
|
|
errFileVersionNotFound,
|
2019-10-01 22:12:15 +02:00
|
|
|
errFileCorrupt,
|
|
|
|
}...) {
|
2019-01-30 19:53:57 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
if !quorumModTime.Equal(meta.ModTime) {
|
2019-01-30 19:53:57 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-01-22 23:54:55 +01:00
|
|
|
// Heals an object by re-writing corrupt/missing erasure blocks.
|
2020-06-13 05:04:01 +02:00
|
|
|
func (er erasureObjects) healObject(ctx context.Context, bucket string, object string,
|
|
|
|
partsMetadata []FileInfo, errs []error, latestFileInfo FileInfo,
|
2019-03-26 22:57:44 +01:00
|
|
|
dryRun bool, remove bool, scanMode madmin.HealScanMode) (result madmin.HealResultItem, err error) {
|
2019-03-14 21:08:51 +01:00
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
dataBlocks := latestFileInfo.Erasure.DataBlocks
|
2018-01-22 23:54:55 +01:00
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
storageDisks := er.getDisks()
|
|
|
|
storageEndpoints := er.getEndpoints()
|
2016-10-17 11:10:23 +02:00
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
// List of disks having latest version of the object er.meta
|
2018-01-22 23:54:55 +01:00
|
|
|
// (by modtime).
|
2016-11-17 01:42:23 +01:00
|
|
|
latestDisks, modTime := listOnlineDisks(storageDisks, partsMetadata, errs)
|
2017-03-04 23:53:28 +01:00
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
// List of disks having all parts as per latest er.meta.
|
2019-03-14 21:08:51 +01:00
|
|
|
availableDisks, dataErrs := disksWithAllParts(ctx, latestDisks, partsMetadata, errs, bucket, object, scanMode)
|
2017-03-04 23:53:28 +01:00
|
|
|
|
2018-01-22 23:54:55 +01:00
|
|
|
// Initialize heal result object
|
|
|
|
result = madmin.HealResultItem{
|
2019-03-26 22:57:44 +01:00
|
|
|
Type: madmin.HealItemObject,
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
DiskCount: len(storageDisks),
|
2020-07-08 05:54:09 +02:00
|
|
|
ParityBlocks: len(storageDisks) / 2,
|
|
|
|
DataBlocks: len(storageDisks) / 2,
|
2018-01-22 23:54:55 +01:00
|
|
|
|
|
|
|
// Initialize object size to -1, so we can detect if we are
|
|
|
|
// unable to reliably find the object size.
|
|
|
|
ObjectSize: -1,
|
2017-04-14 19:28:35 +02:00
|
|
|
}
|
|
|
|
|
2018-01-22 23:54:55 +01:00
|
|
|
// Loop to find number of disks with valid data, per-drive
|
|
|
|
// data state and a list of outdated disks on which data needs
|
|
|
|
// to be healed.
|
|
|
|
outDatedDisks := make([]StorageAPI, len(storageDisks))
|
2017-04-14 19:28:35 +02:00
|
|
|
numAvailableDisks := 0
|
2018-01-22 23:54:55 +01:00
|
|
|
disksToHealCount := 0
|
|
|
|
for i, v := range availableDisks {
|
|
|
|
driveState := ""
|
|
|
|
switch {
|
|
|
|
case v != nil:
|
|
|
|
driveState = madmin.DriveStateOk
|
2017-03-04 23:53:28 +01:00
|
|
|
numAvailableDisks++
|
2018-01-22 23:54:55 +01:00
|
|
|
// If data is sane on any one disk, we can
|
|
|
|
// extract the correct object size.
|
2020-06-13 05:04:01 +02:00
|
|
|
result.ObjectSize = partsMetadata[i].Size
|
2020-07-08 05:54:09 +02:00
|
|
|
if partsMetadata[i].Erasure.ParityBlocks > 0 && partsMetadata[i].Erasure.DataBlocks > 0 {
|
|
|
|
result.ParityBlocks = partsMetadata[i].Erasure.ParityBlocks
|
|
|
|
result.DataBlocks = partsMetadata[i].Erasure.DataBlocks
|
|
|
|
}
|
2018-10-03 02:13:51 +02:00
|
|
|
case errs[i] == errDiskNotFound, dataErrs[i] == errDiskNotFound:
|
2018-01-22 23:54:55 +01:00
|
|
|
driveState = madmin.DriveStateOffline
|
2018-04-10 18:36:37 +02:00
|
|
|
case errs[i] == errFileNotFound, errs[i] == errVolumeNotFound:
|
2018-01-22 23:54:55 +01:00
|
|
|
fallthrough
|
2020-07-06 17:09:48 +02:00
|
|
|
case dataErrs[i] == errFileNotFound, dataErrs[i] == errFileVersionNotFound, dataErrs[i] == errVolumeNotFound:
|
2018-01-22 23:54:55 +01:00
|
|
|
driveState = madmin.DriveStateMissing
|
|
|
|
default:
|
|
|
|
// all remaining cases imply corrupt data/metadata
|
|
|
|
driveState = madmin.DriveStateCorrupt
|
|
|
|
}
|
|
|
|
|
2019-01-30 19:53:57 +01:00
|
|
|
if shouldHealObjectOnDisk(errs[i], dataErrs[i], partsMetadata[i], modTime) {
|
2018-01-22 23:54:55 +01:00
|
|
|
outDatedDisks[i] = storageDisks[i]
|
|
|
|
disksToHealCount++
|
2018-02-16 02:45:57 +01:00
|
|
|
result.Before.Drives = append(result.Before.Drives, madmin.HealDriveInfo{
|
|
|
|
UUID: "",
|
2020-06-11 02:10:31 +02:00
|
|
|
Endpoint: storageEndpoints[i],
|
2018-02-16 02:45:57 +01:00
|
|
|
State: driveState,
|
|
|
|
})
|
|
|
|
result.After.Drives = append(result.After.Drives, madmin.HealDriveInfo{
|
|
|
|
UUID: "",
|
2020-06-11 02:10:31 +02:00
|
|
|
Endpoint: storageEndpoints[i],
|
2018-02-16 02:45:57 +01:00
|
|
|
State: driveState,
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
result.Before.Drives = append(result.Before.Drives, madmin.HealDriveInfo{
|
|
|
|
UUID: "",
|
2020-06-11 02:10:31 +02:00
|
|
|
Endpoint: storageEndpoints[i],
|
2018-02-16 02:45:57 +01:00
|
|
|
State: driveState,
|
|
|
|
})
|
|
|
|
result.After.Drives = append(result.After.Drives, madmin.HealDriveInfo{
|
|
|
|
UUID: "",
|
2020-06-11 02:10:31 +02:00
|
|
|
Endpoint: storageEndpoints[i],
|
2018-02-16 02:45:57 +01:00
|
|
|
State: driveState,
|
|
|
|
})
|
2017-09-29 00:57:19 +02:00
|
|
|
}
|
|
|
|
|
2017-03-04 23:53:28 +01:00
|
|
|
// If less than read quorum number of disks have all the parts
|
|
|
|
// of the data, we can't reconstruct the erasure-coded data.
|
2019-03-26 22:57:44 +01:00
|
|
|
if numAvailableDisks < dataBlocks {
|
2020-06-13 05:04:01 +02:00
|
|
|
// Check if er.meta, and corresponding parts are also missing.
|
2019-03-26 22:57:44 +01:00
|
|
|
if m, ok := isObjectDangling(partsMetadata, errs, dataErrs); ok {
|
|
|
|
writeQuorum := m.Erasure.DataBlocks + 1
|
|
|
|
if m.Erasure.DataBlocks == 0 {
|
2020-03-31 18:32:16 +02:00
|
|
|
writeQuorum = getWriteQuorum(len(storageDisks))
|
2019-03-26 22:57:44 +01:00
|
|
|
}
|
|
|
|
if !dryRun && remove {
|
2020-07-08 05:54:09 +02:00
|
|
|
if latestFileInfo.VersionID == "" {
|
|
|
|
err = er.deleteObject(ctx, bucket, object, writeQuorum)
|
|
|
|
} else {
|
|
|
|
err = er.deleteObjectVersion(ctx, bucket, object, writeQuorum, FileInfo{VersionID: latestFileInfo.VersionID})
|
|
|
|
}
|
2019-03-26 22:57:44 +01:00
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
return defaultHealResult(latestFileInfo, storageDisks, storageEndpoints, errs, bucket, object), err
|
2019-03-26 22:57:44 +01:00
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
return result, toObjectErr(errErasureReadQuorum, bucket, object)
|
2017-03-04 23:53:28 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 23:54:55 +01:00
|
|
|
if disksToHealCount == 0 {
|
|
|
|
// Nothing to heal!
|
|
|
|
return result, nil
|
|
|
|
}
|
2017-03-04 23:53:28 +01:00
|
|
|
|
2018-01-22 23:54:55 +01:00
|
|
|
// After this point, only have to repair data on disk - so
|
|
|
|
// return if it is a dry-run
|
|
|
|
if dryRun {
|
|
|
|
return result, nil
|
2017-04-01 02:55:15 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
// Latest FileInfo for reference. If a valid metadata is not
|
2017-03-04 23:53:28 +01:00
|
|
|
// present, it is as good as object not found.
|
2020-06-13 05:04:01 +02:00
|
|
|
latestMeta, pErr := pickValidFileInfo(ctx, partsMetadata, modTime, dataBlocks)
|
2016-11-21 05:56:44 +01:00
|
|
|
if pErr != nil {
|
2018-01-22 23:54:55 +01:00
|
|
|
return result, toObjectErr(pErr, bucket, object)
|
2016-11-21 05:56:44 +01:00
|
|
|
}
|
2016-10-17 11:10:23 +02:00
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
cleanFileInfo := func(fi FileInfo) FileInfo {
|
|
|
|
// Returns a copy of the 'fi' with checksums and parts nil'ed.
|
|
|
|
nfi := fi
|
|
|
|
nfi.Erasure.Checksums = nil
|
|
|
|
nfi.Parts = nil
|
|
|
|
return nfi
|
2016-10-17 11:10:23 +02:00
|
|
|
}
|
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
// We write at temporary location and then rename to final location.
|
|
|
|
tmpID := mustGetUUID()
|
|
|
|
|
2019-01-17 13:58:18 +01:00
|
|
|
for i := range outDatedDisks {
|
|
|
|
if outDatedDisks[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
partsMetadata[i] = cleanFileInfo(latestMeta)
|
2019-01-17 13:58:18 +01:00
|
|
|
}
|
2016-10-17 11:10:23 +02:00
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
if !latestMeta.Deleted {
|
|
|
|
result.DataBlocks = latestMeta.Erasure.DataBlocks
|
|
|
|
result.ParityBlocks = latestMeta.Erasure.ParityBlocks
|
2016-10-17 11:10:23 +02:00
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
// Reorder so that we have data disks first and parity disks next.
|
|
|
|
latestDisks = shuffleDisks(availableDisks, latestMeta.Erasure.Distribution)
|
|
|
|
outDatedDisks = shuffleDisks(outDatedDisks, latestMeta.Erasure.Distribution)
|
|
|
|
partsMetadata = shufflePartsMetadata(partsMetadata, latestMeta.Erasure.Distribution)
|
2018-08-07 00:14:08 +02:00
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
// Heal each part. erasureHealFile() will write the healed
|
|
|
|
// part to .minio/tmp/uuid/ which needs to be renamed later to
|
|
|
|
// the final location.
|
|
|
|
erasure, err := NewErasure(ctx, latestMeta.Erasure.DataBlocks,
|
|
|
|
latestMeta.Erasure.ParityBlocks, latestMeta.Erasure.BlockSize)
|
2020-06-13 05:04:01 +02:00
|
|
|
if err != nil {
|
|
|
|
return result, toObjectErr(err, bucket, object)
|
2016-10-17 11:10:23 +02:00
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
erasureInfo := latestMeta.Erasure
|
|
|
|
for partIndex := 0; partIndex < len(latestMeta.Parts); partIndex++ {
|
|
|
|
partSize := latestMeta.Parts[partIndex].Size
|
|
|
|
partActualSize := latestMeta.Parts[partIndex].ActualSize
|
|
|
|
partNumber := latestMeta.Parts[partIndex].Number
|
|
|
|
tillOffset := erasure.ShardFileOffset(0, partSize, partSize)
|
|
|
|
readers := make([]io.ReaderAt, len(latestDisks))
|
|
|
|
checksumAlgo := erasureInfo.GetChecksumInfo(partNumber).Algorithm
|
|
|
|
for i, disk := range latestDisks {
|
|
|
|
if disk == OfflineDisk {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
checksumInfo := partsMetadata[i].Erasure.GetChecksumInfo(partNumber)
|
|
|
|
partPath := pathJoin(object, latestMeta.DataDir, fmt.Sprintf("part.%d", partNumber))
|
|
|
|
readers[i] = newBitrotReader(disk, bucket, partPath, tillOffset, checksumAlgo, checksumInfo.Hash, erasure.ShardSize())
|
|
|
|
}
|
|
|
|
writers := make([]io.Writer, len(outDatedDisks))
|
|
|
|
for i, disk := range outDatedDisks {
|
|
|
|
if disk == OfflineDisk {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
partPath := pathJoin(tmpID, latestMeta.DataDir, fmt.Sprintf("part.%d", partNumber))
|
|
|
|
writers[i] = newBitrotWriter(disk, minioMetaTmpBucket, partPath, tillOffset, DefaultBitrotAlgorithm, erasure.ShardSize())
|
2017-09-29 00:57:19 +02:00
|
|
|
}
|
2020-07-08 05:54:09 +02:00
|
|
|
err = erasure.Heal(ctx, readers, writers, partSize)
|
|
|
|
closeBitrotReaders(readers)
|
|
|
|
closeBitrotWriters(writers)
|
|
|
|
if err != nil {
|
|
|
|
return result, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
// outDatedDisks that had write errors should not be
|
|
|
|
// written to for remaining parts, so we nil it out.
|
|
|
|
for i, disk := range outDatedDisks {
|
|
|
|
if disk == OfflineDisk {
|
|
|
|
continue
|
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
// A non-nil stale disk which did not receive
|
|
|
|
// a healed part checksum had a write error.
|
|
|
|
if writers[i] == nil {
|
|
|
|
outDatedDisks[i] = nil
|
|
|
|
disksToHealCount--
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
partsMetadata[i].AddObjectPart(partNumber, "", partSize, partActualSize)
|
|
|
|
partsMetadata[i].Erasure.AddChecksumInfo(ChecksumInfo{
|
|
|
|
PartNumber: partNumber,
|
|
|
|
Algorithm: checksumAlgo,
|
|
|
|
Hash: bitrotWriterSum(writers[i]),
|
|
|
|
})
|
|
|
|
}
|
2017-09-29 00:57:19 +02:00
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
// If all disks are having errors, we give up.
|
|
|
|
if disksToHealCount == 0 {
|
|
|
|
return result, fmt.Errorf("all disks had write errors, unable to heal")
|
|
|
|
}
|
2016-10-17 11:10:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
defer er.deleteObject(ctx, minioMetaTmpBucket, tmpID, len(storageDisks)/2+1)
|
2019-04-25 16:33:26 +02:00
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
// Generate and write `xl.meta` generated from other disks.
|
|
|
|
outDatedDisks, err = writeUniqueFileInfo(ctx, outDatedDisks, minioMetaTmpBucket, tmpID,
|
2017-09-29 00:57:19 +02:00
|
|
|
partsMetadata, diskCount(outDatedDisks))
|
2020-06-13 05:04:01 +02:00
|
|
|
if err != nil {
|
|
|
|
return result, toObjectErr(err, bucket, object)
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
|
|
|
|
2016-10-17 11:10:23 +02:00
|
|
|
// Rename from tmp location to the actual location.
|
2018-03-28 03:11:39 +02:00
|
|
|
for _, disk := range outDatedDisks {
|
2020-06-13 05:04:01 +02:00
|
|
|
if disk == OfflineDisk {
|
2016-08-31 20:42:57 +02:00
|
|
|
continue
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
2017-09-29 00:57:19 +02:00
|
|
|
|
2016-10-17 11:10:23 +02:00
|
|
|
// Attempt a rename now from healed data to final location.
|
2020-06-13 05:04:01 +02:00
|
|
|
if err = disk.RenameData(minioMetaTmpBucket, tmpID, latestMeta.DataDir, bucket, object); err != nil {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return result, toObjectErr(err, bucket, object)
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
2018-01-22 23:54:55 +01:00
|
|
|
|
2018-03-28 03:11:39 +02:00
|
|
|
for i, v := range result.Before.Drives {
|
|
|
|
if v.Endpoint == disk.String() {
|
|
|
|
result.After.Drives[i].State = madmin.DriveStateOk
|
2018-02-16 02:45:57 +01:00
|
|
|
}
|
|
|
|
}
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
2018-01-22 23:54:55 +01:00
|
|
|
|
|
|
|
// Set the size of the object in the heal result
|
2020-06-13 05:04:01 +02:00
|
|
|
result.ObjectSize = latestMeta.Size
|
2018-01-22 23:54:55 +01:00
|
|
|
|
|
|
|
return result, nil
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
2016-11-17 01:42:23 +01:00
|
|
|
|
2018-05-11 01:53:42 +02:00
|
|
|
// healObjectDir - heals object directory specifically, this special call
|
|
|
|
// is needed since we do not have a special backend format for directories.
|
2020-06-13 05:04:01 +02:00
|
|
|
func (er erasureObjects) healObjectDir(ctx context.Context, bucket, object string, dryRun bool, remove bool) (hr madmin.HealResultItem, err error) {
|
|
|
|
storageDisks := er.getDisks()
|
|
|
|
storageEndpoints := er.getEndpoints()
|
2018-05-11 01:53:42 +02:00
|
|
|
|
|
|
|
// Initialize heal result object
|
|
|
|
hr = madmin.HealResultItem{
|
|
|
|
Type: madmin.HealItemObject,
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
DiskCount: len(storageDisks),
|
2020-03-31 18:32:16 +02:00
|
|
|
ParityBlocks: getDefaultParityBlocks(len(storageDisks)),
|
|
|
|
DataBlocks: getDefaultDataBlocks(len(storageDisks)),
|
2018-05-11 01:53:42 +02:00
|
|
|
ObjectSize: 0,
|
|
|
|
}
|
|
|
|
|
2019-01-30 19:51:56 +01:00
|
|
|
hr.Before.Drives = make([]madmin.HealDriveInfo, len(storageDisks))
|
|
|
|
hr.After.Drives = make([]madmin.HealDriveInfo, len(storageDisks))
|
|
|
|
|
2019-04-23 23:54:28 +02:00
|
|
|
errs := statAllDirs(ctx, storageDisks, bucket, object)
|
2020-03-30 18:48:24 +02:00
|
|
|
danglingObject := isObjectDirDangling(errs)
|
|
|
|
if danglingObject {
|
|
|
|
if !dryRun && remove {
|
2020-06-13 05:04:01 +02:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
// Remove versions in bulk for each disk
|
|
|
|
for index, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
_ = disk.DeleteFile(bucket, object)
|
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2019-04-23 23:54:28 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-11 01:53:42 +02:00
|
|
|
|
2019-04-23 23:54:28 +02:00
|
|
|
// Prepare object creation in all disks
|
|
|
|
for i, err := range errs {
|
2020-06-11 02:10:31 +02:00
|
|
|
drive := storageEndpoints[i]
|
2019-04-23 23:54:28 +02:00
|
|
|
switch err {
|
2019-08-01 23:13:06 +02:00
|
|
|
case nil:
|
2020-03-30 18:48:24 +02:00
|
|
|
hr.Before.Drives[i] = madmin.HealDriveInfo{Endpoint: drive, State: madmin.DriveStateOk}
|
|
|
|
hr.After.Drives[i] = madmin.HealDriveInfo{Endpoint: drive, State: madmin.DriveStateOk}
|
2019-04-23 23:54:28 +02:00
|
|
|
case errDiskNotFound:
|
|
|
|
hr.Before.Drives[i] = madmin.HealDriveInfo{State: madmin.DriveStateOffline}
|
|
|
|
hr.After.Drives[i] = madmin.HealDriveInfo{State: madmin.DriveStateOffline}
|
2019-08-01 23:13:06 +02:00
|
|
|
case errVolumeNotFound, errFileNotFound:
|
|
|
|
// Bucket or prefix/directory not found
|
2019-04-23 23:54:28 +02:00
|
|
|
hr.Before.Drives[i] = madmin.HealDriveInfo{Endpoint: drive, State: madmin.DriveStateMissing}
|
|
|
|
hr.After.Drives[i] = madmin.HealDriveInfo{Endpoint: drive, State: madmin.DriveStateMissing}
|
|
|
|
default:
|
|
|
|
hr.Before.Drives[i] = madmin.HealDriveInfo{Endpoint: drive, State: madmin.DriveStateCorrupt}
|
|
|
|
hr.After.Drives[i] = madmin.HealDriveInfo{Endpoint: drive, State: madmin.DriveStateCorrupt}
|
|
|
|
}
|
|
|
|
}
|
2020-03-30 18:48:24 +02:00
|
|
|
if dryRun || danglingObject {
|
2019-04-23 23:54:28 +02:00
|
|
|
return hr, nil
|
|
|
|
}
|
|
|
|
for i, err := range errs {
|
2020-03-30 18:48:24 +02:00
|
|
|
if err == errVolumeNotFound || err == errFileNotFound {
|
2019-08-01 23:13:06 +02:00
|
|
|
// Bucket or prefix/directory not found
|
2019-04-23 23:54:28 +02:00
|
|
|
merr := storageDisks[i].MakeVol(pathJoin(bucket, object))
|
|
|
|
switch merr {
|
|
|
|
case nil, errVolumeExists:
|
|
|
|
hr.After.Drives[i].State = madmin.DriveStateOk
|
|
|
|
case errDiskNotFound:
|
|
|
|
hr.After.Drives[i].State = madmin.DriveStateOffline
|
2019-01-30 19:51:56 +01:00
|
|
|
default:
|
2019-04-23 23:54:28 +02:00
|
|
|
logger.LogIf(ctx, merr)
|
|
|
|
hr.After.Drives[i].State = madmin.DriveStateCorrupt
|
2018-05-11 01:53:42 +02:00
|
|
|
}
|
2019-04-23 23:54:28 +02:00
|
|
|
}
|
2018-05-11 01:53:42 +02:00
|
|
|
}
|
|
|
|
return hr, nil
|
|
|
|
}
|
|
|
|
|
2018-10-03 02:13:51 +02:00
|
|
|
// Populates default heal result item entries with possible values when we are returning prematurely.
|
|
|
|
// This is to ensure that in any circumstance we are not returning empty arrays with wrong values.
|
2020-06-13 05:04:01 +02:00
|
|
|
func defaultHealResult(latestFileInfo FileInfo, storageDisks []StorageAPI, storageEndpoints []string, errs []error, bucket, object string) madmin.HealResultItem {
|
2018-10-03 02:13:51 +02:00
|
|
|
// Initialize heal result object
|
|
|
|
result := madmin.HealResultItem{
|
|
|
|
Type: madmin.HealItemObject,
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
DiskCount: len(storageDisks),
|
|
|
|
|
|
|
|
// Initialize object size to -1, so we can detect if we are
|
|
|
|
// unable to reliably find the object size.
|
|
|
|
ObjectSize: -1,
|
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
if latestFileInfo.IsValid() {
|
|
|
|
result.ObjectSize = latestFileInfo.Size
|
2019-03-26 22:57:44 +01:00
|
|
|
}
|
2018-10-03 02:13:51 +02:00
|
|
|
|
|
|
|
for index, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
result.Before.Drives = append(result.Before.Drives, madmin.HealDriveInfo{
|
2020-06-11 02:10:31 +02:00
|
|
|
UUID: "",
|
|
|
|
Endpoint: storageEndpoints[index],
|
|
|
|
State: madmin.DriveStateOffline,
|
2018-10-03 02:13:51 +02:00
|
|
|
})
|
|
|
|
result.After.Drives = append(result.After.Drives, madmin.HealDriveInfo{
|
2020-06-11 02:10:31 +02:00
|
|
|
UUID: "",
|
|
|
|
Endpoint: storageEndpoints[index],
|
|
|
|
State: madmin.DriveStateOffline,
|
2018-10-03 02:13:51 +02:00
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
driveState := madmin.DriveStateCorrupt
|
|
|
|
switch errs[index] {
|
|
|
|
case errFileNotFound, errVolumeNotFound:
|
|
|
|
driveState = madmin.DriveStateMissing
|
|
|
|
}
|
|
|
|
result.Before.Drives = append(result.Before.Drives, madmin.HealDriveInfo{
|
|
|
|
UUID: "",
|
2020-06-11 02:10:31 +02:00
|
|
|
Endpoint: storageEndpoints[index],
|
2018-10-03 02:13:51 +02:00
|
|
|
State: driveState,
|
|
|
|
})
|
|
|
|
result.After.Drives = append(result.After.Drives, madmin.HealDriveInfo{
|
|
|
|
UUID: "",
|
2020-06-11 02:10:31 +02:00
|
|
|
Endpoint: storageEndpoints[index],
|
2018-10-03 02:13:51 +02:00
|
|
|
State: driveState,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
if !latestFileInfo.IsValid() {
|
2019-03-26 22:57:44 +01:00
|
|
|
// Default to most common configuration for erasure blocks.
|
2020-03-31 18:32:16 +02:00
|
|
|
result.ParityBlocks = getDefaultParityBlocks(len(storageDisks))
|
|
|
|
result.DataBlocks = getDefaultDataBlocks(len(storageDisks))
|
2019-03-26 22:57:44 +01:00
|
|
|
} else {
|
2020-06-13 05:04:01 +02:00
|
|
|
result.ParityBlocks = latestFileInfo.Erasure.ParityBlocks
|
|
|
|
result.DataBlocks = latestFileInfo.Erasure.DataBlocks
|
2019-03-26 22:57:44 +01:00
|
|
|
}
|
2018-10-03 02:13:51 +02:00
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2019-04-23 23:54:28 +02:00
|
|
|
// Stat all directories.
|
|
|
|
func statAllDirs(ctx context.Context, storageDisks []StorageAPI, bucket, prefix string) []error {
|
2019-10-14 18:44:51 +02:00
|
|
|
g := errgroup.WithNErrs(len(storageDisks))
|
2019-04-23 23:54:28 +02:00
|
|
|
for index, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 18:44:51 +02:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2020-06-13 05:04:01 +02:00
|
|
|
entries, err := storageDisks[index].ListDir(bucket, prefix, 1)
|
2019-04-23 23:54:28 +02:00
|
|
|
if err != nil {
|
2019-10-14 18:44:51 +02:00
|
|
|
return err
|
2019-04-23 23:54:28 +02:00
|
|
|
}
|
|
|
|
if len(entries) > 0 {
|
2019-10-14 18:44:51 +02:00
|
|
|
return errVolumeNotEmpty
|
2019-04-23 23:54:28 +02:00
|
|
|
}
|
2019-10-14 18:44:51 +02:00
|
|
|
return nil
|
|
|
|
}, index)
|
2019-04-23 23:54:28 +02:00
|
|
|
}
|
|
|
|
|
2019-10-14 18:44:51 +02:00
|
|
|
return g.Wait()
|
2019-04-23 23:54:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ObjectDir is considered dangling/corrupted if any only
|
|
|
|
// if total disks - a combination of corrupted and missing
|
|
|
|
// files is lesser than N/2+1 number of disks.
|
|
|
|
func isObjectDirDangling(errs []error) (ok bool) {
|
2020-03-30 18:48:24 +02:00
|
|
|
var found int
|
|
|
|
var notFound int
|
|
|
|
var foundNotEmpty int
|
|
|
|
var otherFound int
|
2019-04-23 23:54:28 +02:00
|
|
|
for _, readErr := range errs {
|
2020-03-30 18:48:24 +02:00
|
|
|
if readErr == nil {
|
|
|
|
found++
|
|
|
|
} else if readErr == errFileNotFound || readErr == errVolumeNotFound {
|
|
|
|
notFound++
|
|
|
|
} else if readErr == errVolumeNotEmpty {
|
|
|
|
foundNotEmpty++
|
|
|
|
} else {
|
|
|
|
otherFound++
|
2019-04-23 23:54:28 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-30 18:48:24 +02:00
|
|
|
return found+foundNotEmpty+otherFound < notFound
|
2019-04-23 23:54:28 +02:00
|
|
|
}
|
|
|
|
|
2019-02-06 02:58:48 +01:00
|
|
|
// Object is considered dangling/corrupted if any only
|
|
|
|
// if total disks - a combination of corrupted and missing
|
|
|
|
// files is lesser than number of data blocks.
|
2020-06-13 05:04:01 +02:00
|
|
|
func isObjectDangling(metaArr []FileInfo, errs []error, dataErrs []error) (validMeta FileInfo, ok bool) {
|
2019-02-06 02:58:48 +01:00
|
|
|
// We can consider an object data not reliable
|
2020-06-13 05:04:01 +02:00
|
|
|
// when er.meta is not found in read quorum disks.
|
|
|
|
// or when er.meta is not readable in read quorum disks.
|
2020-07-08 05:54:09 +02:00
|
|
|
var notFoundErasureMeta, corruptedErasureMeta int
|
2019-02-06 02:58:48 +01:00
|
|
|
for _, readErr := range errs {
|
2020-07-08 05:54:09 +02:00
|
|
|
if readErr == errFileNotFound || readErr == errFileVersionNotFound {
|
|
|
|
notFoundErasureMeta++
|
2019-02-06 02:58:48 +01:00
|
|
|
} else if readErr == errCorruptedFormat {
|
2020-07-08 05:54:09 +02:00
|
|
|
corruptedErasureMeta++
|
2019-02-06 02:58:48 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-26 22:57:44 +01:00
|
|
|
var notFoundParts int
|
|
|
|
for i := range dataErrs {
|
|
|
|
// Only count part errors, if the error is not
|
2020-06-13 05:04:01 +02:00
|
|
|
// same as er.meta error. This is to avoid
|
|
|
|
// double counting when both parts and er.meta
|
2019-03-26 22:57:44 +01:00
|
|
|
// are not available.
|
|
|
|
if errs[i] != dataErrs[i] {
|
2020-07-08 05:54:09 +02:00
|
|
|
if dataErrs[i] == errFileNotFound || dataErrs[i] == errFileVersionNotFound {
|
2019-03-26 22:57:44 +01:00
|
|
|
notFoundParts++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-06 02:58:48 +01:00
|
|
|
|
|
|
|
for _, m := range metaArr {
|
|
|
|
if !m.IsValid() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
validMeta = m
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-07-08 05:54:09 +02:00
|
|
|
if validMeta.Deleted {
|
|
|
|
return validMeta, false
|
|
|
|
}
|
|
|
|
|
2019-02-06 02:58:48 +01:00
|
|
|
// We couldn't find any valid meta we are indeed corrupted, return true right away.
|
|
|
|
if validMeta.Erasure.DataBlocks == 0 {
|
|
|
|
return validMeta, true
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:57:44 +01:00
|
|
|
// We have valid meta, now verify if we have enough files with parity blocks.
|
2020-07-08 05:54:09 +02:00
|
|
|
return validMeta, corruptedErasureMeta+notFoundErasureMeta+notFoundParts > validMeta.Erasure.ParityBlocks
|
2019-02-06 02:58:48 +01:00
|
|
|
}
|
|
|
|
|
2019-03-26 22:57:44 +01:00
|
|
|
// HealObject - heal the given object, automatically deletes the object if stale/corrupted if `remove` is true.
|
2020-06-13 05:04:01 +02:00
|
|
|
func (er erasureObjects) HealObject(ctx context.Context, bucket, object, versionID string, opts madmin.HealOpts) (hr madmin.HealResultItem, err error) {
|
2018-08-21 01:58:47 +02:00
|
|
|
// Create context that also contains information about the object and bucket.
|
|
|
|
// The top level handler might not have this information.
|
|
|
|
reqInfo := logger.GetReqInfo(ctx)
|
|
|
|
var newReqInfo *logger.ReqInfo
|
|
|
|
if reqInfo != nil {
|
2018-11-19 23:47:03 +01:00
|
|
|
newReqInfo = logger.NewReqInfo(reqInfo.RemoteHost, reqInfo.UserAgent, reqInfo.DeploymentID, reqInfo.RequestID, reqInfo.API, bucket, object)
|
2018-08-21 01:58:47 +02:00
|
|
|
} else {
|
2018-11-19 23:47:03 +01:00
|
|
|
newReqInfo = logger.NewReqInfo("", "", globalDeploymentID, "", "Heal", bucket, object)
|
2018-08-21 01:58:47 +02:00
|
|
|
}
|
2020-04-09 18:30:02 +02:00
|
|
|
healCtx := logger.SetReqInfo(GlobalContext, newReqInfo)
|
2018-08-21 01:58:47 +02:00
|
|
|
|
2018-05-11 01:53:42 +02:00
|
|
|
// Healing directories handle it separately.
|
2019-12-06 08:16:06 +01:00
|
|
|
if HasSuffix(object, SlashSeparator) {
|
2020-06-13 05:04:01 +02:00
|
|
|
return er.healObjectDir(healCtx, bucket, object, opts.DryRun, opts.Remove)
|
2018-05-11 01:53:42 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
storageDisks := er.getDisks()
|
|
|
|
storageEndpoints := er.getEndpoints()
|
2018-10-03 02:13:51 +02:00
|
|
|
|
2017-12-22 12:28:13 +01:00
|
|
|
// Read metadata files from all the disks
|
2020-06-13 05:04:01 +02:00
|
|
|
partsMetadata, errs := readAllFileInfo(healCtx, storageDisks, bucket, object, versionID)
|
2017-12-22 12:28:13 +01:00
|
|
|
|
2019-02-06 02:58:48 +01:00
|
|
|
// Check if the object is dangling, if yes and user requested
|
|
|
|
// remove we simply delete it from namespace.
|
2019-03-26 22:57:44 +01:00
|
|
|
if m, ok := isObjectDangling(partsMetadata, errs, []error{}); ok {
|
2019-02-06 02:58:48 +01:00
|
|
|
writeQuorum := m.Erasure.DataBlocks + 1
|
|
|
|
if m.Erasure.DataBlocks == 0 {
|
2020-03-31 18:32:16 +02:00
|
|
|
writeQuorum = getWriteQuorum(len(storageDisks))
|
2019-02-06 02:58:48 +01:00
|
|
|
}
|
2020-03-19 01:50:00 +01:00
|
|
|
if !opts.DryRun && opts.Remove {
|
2020-07-08 05:54:09 +02:00
|
|
|
if versionID == "" {
|
|
|
|
er.deleteObject(healCtx, bucket, object, writeQuorum)
|
|
|
|
} else {
|
|
|
|
er.deleteObjectVersion(healCtx, bucket, object, writeQuorum, FileInfo{VersionID: versionID})
|
|
|
|
}
|
2019-02-06 02:58:48 +01:00
|
|
|
}
|
2019-11-21 22:18:32 +01:00
|
|
|
err = reduceReadQuorumErrs(ctx, errs, nil, writeQuorum-1)
|
2020-06-13 05:04:01 +02:00
|
|
|
return defaultHealResult(FileInfo{}, storageDisks, storageEndpoints, errs, bucket, object), toObjectErr(err, bucket, object)
|
2019-02-06 02:58:48 +01:00
|
|
|
}
|
|
|
|
|
2020-06-13 05:04:01 +02:00
|
|
|
latestFileInfo, err := getLatestFileInfo(healCtx, partsMetadata, errs)
|
2018-07-31 09:23:29 +02:00
|
|
|
if err != nil {
|
2020-06-13 05:04:01 +02:00
|
|
|
return defaultHealResult(FileInfo{}, storageDisks, storageEndpoints, errs, bucket, object), toObjectErr(err, bucket, object)
|
2018-07-31 09:23:29 +02:00
|
|
|
}
|
2017-12-22 12:28:13 +01:00
|
|
|
|
2019-03-26 22:57:44 +01:00
|
|
|
errCount := 0
|
|
|
|
for _, err := range errs {
|
|
|
|
if err != nil {
|
|
|
|
errCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if errCount == len(errs) {
|
|
|
|
// Only if we get errors from all the disks we return error. Else we need to
|
|
|
|
// continue to return filled madmin.HealResultItem struct which includes info
|
|
|
|
// on what disks the file is available etc.
|
2020-06-13 05:04:01 +02:00
|
|
|
if err = reduceReadQuorumErrs(ctx, errs, nil, latestFileInfo.Erasure.DataBlocks); err != nil {
|
2019-03-26 22:57:44 +01:00
|
|
|
if m, ok := isObjectDangling(partsMetadata, errs, []error{}); ok {
|
|
|
|
writeQuorum := m.Erasure.DataBlocks + 1
|
|
|
|
if m.Erasure.DataBlocks == 0 {
|
2020-03-31 18:32:16 +02:00
|
|
|
writeQuorum = getWriteQuorum(len(storageDisks))
|
2019-03-26 22:57:44 +01:00
|
|
|
}
|
2020-03-19 01:50:00 +01:00
|
|
|
if !opts.DryRun && opts.Remove {
|
2020-07-08 05:54:09 +02:00
|
|
|
if versionID == "" {
|
|
|
|
er.deleteObject(ctx, bucket, object, writeQuorum)
|
|
|
|
} else {
|
|
|
|
er.deleteObjectVersion(ctx, bucket, object, writeQuorum, FileInfo{VersionID: versionID})
|
|
|
|
}
|
2019-03-26 22:57:44 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-13 05:04:01 +02:00
|
|
|
return defaultHealResult(latestFileInfo, storageDisks, storageEndpoints, errs, bucket, object), toObjectErr(err, bucket, object)
|
2019-03-26 22:57:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-17 01:42:23 +01:00
|
|
|
// Heal the object.
|
2020-06-13 05:04:01 +02:00
|
|
|
return er.healObject(healCtx, bucket, object, partsMetadata, errs, latestFileInfo, opts.DryRun, opts.Remove, opts.ScanMode)
|
2016-11-17 01:42:23 +01:00
|
|
|
}
|