2016-10-17 05:10:23 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016, 2017 MinIO, Inc.
|
2016-10-17 05:10:23 -04: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2017-03-04 17:53:28 -05:00
|
|
|
import (
|
2018-04-05 18:04:40 -04:00
|
|
|
"context"
|
2018-07-29 05:30:37 -04:00
|
|
|
"strings"
|
2017-03-04 17:53:28 -05:00
|
|
|
"time"
|
2017-11-25 14:58:29 -05:00
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2019-03-14 16:08:51 -04:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2017-03-04 17:53:28 -05:00
|
|
|
)
|
2016-10-17 05:10:23 -04:00
|
|
|
|
|
|
|
// commonTime returns a maximally occurring time from a list of time.
|
2017-01-17 13:02:58 -05:00
|
|
|
func commonTime(modTimes []time.Time) (modTime time.Time, count int) {
|
2016-10-17 05:10:23 -04:00
|
|
|
var maxima int // Counter for remembering max occurrence of elements.
|
|
|
|
timeOccurenceMap := make(map[time.Time]int)
|
|
|
|
// Ignore the uuid sentinel and count the rest.
|
|
|
|
for _, time := range modTimes {
|
|
|
|
if time == timeSentinel {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
timeOccurenceMap[time]++
|
|
|
|
}
|
|
|
|
// Find the common cardinality from previously collected
|
|
|
|
// occurrences of elements.
|
|
|
|
for time, count := range timeOccurenceMap {
|
2018-01-22 17:54:55 -05:00
|
|
|
if count > maxima || (count == maxima && time.After(modTime)) {
|
2016-10-17 05:10:23 -04:00
|
|
|
maxima = count
|
|
|
|
modTime = time
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Return the collected common uuid.
|
2017-01-17 13:02:58 -05:00
|
|
|
return modTime, maxima
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Beginning of unix time is treated as sentinel value here.
|
|
|
|
var timeSentinel = time.Unix(0, 0).UTC()
|
|
|
|
|
|
|
|
// Boot modTimes up to disk count, setting the value to time sentinel.
|
|
|
|
func bootModtimes(diskCount int) []time.Time {
|
|
|
|
modTimes := make([]time.Time, diskCount)
|
|
|
|
// Boots up all the modtimes.
|
|
|
|
for i := range modTimes {
|
|
|
|
modTimes[i] = timeSentinel
|
|
|
|
}
|
|
|
|
return modTimes
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extracts list of times from xlMetaV1 slice and returns, skips
|
2017-03-04 17:53:28 -05:00
|
|
|
// slice elements which have errors.
|
2016-10-17 05:10:23 -04:00
|
|
|
func listObjectModtimes(partsMetadata []xlMetaV1, errs []error) (modTimes []time.Time) {
|
|
|
|
modTimes = bootModtimes(len(partsMetadata))
|
|
|
|
for index, metadata := range partsMetadata {
|
2017-03-04 17:53:28 -05:00
|
|
|
if errs[index] != nil {
|
|
|
|
continue
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
2017-03-04 17:53:28 -05:00
|
|
|
// Once the file is found, save the uuid saved on disk.
|
|
|
|
modTimes[index] = metadata.Stat.ModTime
|
2016-10-17 05:10:23 -04:00
|
|
|
}
|
|
|
|
return modTimes
|
|
|
|
}
|
|
|
|
|
2017-03-04 17:53:28 -05:00
|
|
|
// Notes:
|
|
|
|
// There are 5 possible states a disk could be in,
|
|
|
|
// 1. __online__ - has the latest copy of xl.json - returned by listOnlineDisks
|
|
|
|
//
|
|
|
|
// 2. __offline__ - err == errDiskNotFound
|
|
|
|
//
|
|
|
|
// 3. __availableWithParts__ - has the latest copy of xl.json and has all
|
|
|
|
// parts with checksums matching; returned by disksWithAllParts
|
|
|
|
//
|
|
|
|
// 4. __outdated__ - returned by outDatedDisk, provided []StorageAPI
|
|
|
|
// returned by diskWithAllParts is passed for latestDisks.
|
|
|
|
// - has an old copy of xl.json
|
|
|
|
// - doesn't have xl.json (errFileNotFound)
|
|
|
|
// - has the latest xl.json but one or more parts are corrupt
|
|
|
|
//
|
|
|
|
// 5. __missingParts__ - has the latest copy of xl.json but has some parts
|
|
|
|
// missing. This is identified separately since this may need manual
|
|
|
|
// inspection to understand the root cause. E.g, this could be due to
|
|
|
|
// backend filesystem corruption.
|
|
|
|
|
|
|
|
// listOnlineDisks - returns
|
|
|
|
// - a slice of disks where disk having 'older' xl.json (or nothing)
|
|
|
|
// are set to nil.
|
|
|
|
// - latest (in time) of the maximally occurring modTime(s).
|
2016-10-17 05:10:23 -04:00
|
|
|
func listOnlineDisks(disks []StorageAPI, partsMetadata []xlMetaV1, errs []error) (onlineDisks []StorageAPI, modTime time.Time) {
|
|
|
|
onlineDisks = make([]StorageAPI, len(disks))
|
|
|
|
|
|
|
|
// List all the file commit ids from parts metadata.
|
|
|
|
modTimes := listObjectModtimes(partsMetadata, errs)
|
|
|
|
|
|
|
|
// Reduce list of UUIDs to a single common value.
|
2017-01-17 13:02:58 -05:00
|
|
|
modTime, _ = commonTime(modTimes)
|
2016-10-17 05:10:23 -04:00
|
|
|
|
|
|
|
// Create a new online disks slice, which have common uuid.
|
|
|
|
for index, t := range modTimes {
|
|
|
|
if t == modTime {
|
|
|
|
onlineDisks[index] = disks[index]
|
|
|
|
} else {
|
|
|
|
onlineDisks[index] = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return onlineDisks, modTime
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:23:29 -04:00
|
|
|
// Returns the latest updated xlMeta files and error in case of failure.
|
|
|
|
func getLatestXLMeta(ctx context.Context, partsMetadata []xlMetaV1, errs []error) (xlMetaV1, error) {
|
|
|
|
|
|
|
|
// There should be atleast half correct entries, if not return failure
|
|
|
|
if reducedErr := reduceReadQuorumErrs(ctx, errs, objectOpIgnoredErrs, globalXLSetDriveCount/2); reducedErr != nil {
|
|
|
|
return xlMetaV1{}, reducedErr
|
|
|
|
}
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
// List all the file commit ids from parts metadata.
|
|
|
|
modTimes := listObjectModtimes(partsMetadata, errs)
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// Count all latest updated xlMeta values
|
2017-12-22 06:28:13 -05:00
|
|
|
var count int
|
|
|
|
var latestXLMeta xlMetaV1
|
|
|
|
|
|
|
|
// Reduce list of UUIDs to a single common value - i.e. the last updated Time
|
|
|
|
modTime, _ := commonTime(modTimes)
|
|
|
|
|
|
|
|
// Interate through all the modTimes and count the xlMeta(s) with latest time.
|
|
|
|
for index, t := range modTimes {
|
|
|
|
if t == modTime && partsMetadata[index].IsValid() {
|
|
|
|
latestXLMeta = partsMetadata[index]
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
2018-07-31 03:23:29 -04:00
|
|
|
if count < len(partsMetadata)/2 {
|
|
|
|
return xlMetaV1{}, errXLReadQuorum
|
|
|
|
}
|
|
|
|
|
|
|
|
return latestXLMeta, nil
|
2017-12-22 06:28:13 -05:00
|
|
|
}
|
|
|
|
|
2017-03-04 17:53:28 -05:00
|
|
|
// disksWithAllParts - This function needs to be called with
|
|
|
|
// []StorageAPI returned by listOnlineDisks. Returns,
|
2017-09-28 18:57:19 -04:00
|
|
|
//
|
2017-03-04 17:53:28 -05:00
|
|
|
// - disks which have all parts specified in the latest xl.json.
|
2017-09-28 18:57:19 -04:00
|
|
|
//
|
2018-01-22 17:54:55 -05:00
|
|
|
// - slice of errors about the state of data files on disk - can have
|
|
|
|
// a not-found error or a hash-mismatch error.
|
2018-04-05 18:04:40 -04:00
|
|
|
func disksWithAllParts(ctx context.Context, onlineDisks []StorageAPI, partsMetadata []xlMetaV1, errs []error, bucket,
|
2019-03-14 16:08:51 -04:00
|
|
|
object string, scanMode madmin.HealScanMode) ([]StorageAPI, []error) {
|
2017-03-04 17:53:28 -05:00
|
|
|
availableDisks := make([]StorageAPI, len(onlineDisks))
|
2018-01-22 17:54:55 -05:00
|
|
|
dataErrs := make([]error, len(onlineDisks))
|
2017-08-14 21:08:42 -04:00
|
|
|
|
2017-09-28 18:57:19 -04:00
|
|
|
for i, onlineDisk := range onlineDisks {
|
2018-01-22 17:54:55 -05:00
|
|
|
if onlineDisk == nil {
|
2019-03-26 17:57:44 -04:00
|
|
|
dataErrs[i] = errs[i]
|
2017-03-04 17:53:28 -05:00
|
|
|
continue
|
|
|
|
}
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2019-03-14 16:08:51 -04:00
|
|
|
switch scanMode {
|
|
|
|
case madmin.HealDeepScan:
|
|
|
|
erasureInfo := partsMetadata[i].Erasure
|
|
|
|
erasure, err := NewErasure(ctx, erasureInfo.DataBlocks, erasureInfo.ParityBlocks, erasureInfo.BlockSize)
|
2019-01-17 07:58:18 -05:00
|
|
|
if err != nil {
|
|
|
|
dataErrs[i] = err
|
2019-03-14 16:08:51 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// disk has a valid xl.json but may not have all the
|
|
|
|
// parts. This is considered an outdated disk, since
|
|
|
|
// it needs healing too.
|
|
|
|
for _, part := range partsMetadata[i].Parts {
|
|
|
|
checksumInfo := erasureInfo.GetChecksumInfo(part.Name)
|
2019-07-08 16:51:18 -04:00
|
|
|
err = onlineDisk.VerifyFile(bucket, pathJoin(object, part.Name), checksumInfo.Algorithm, checksumInfo.Hash, erasure.ShardSize())
|
2019-03-14 16:08:51 -04:00
|
|
|
if err != nil {
|
|
|
|
isCorrupt := strings.HasPrefix(err.Error(), "Bitrot verification mismatch - expected ")
|
|
|
|
if !isCorrupt && err != errFileNotFound && err != errVolumeNotFound {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
}
|
|
|
|
dataErrs[i] = err
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case madmin.HealNormalScan:
|
|
|
|
for _, part := range partsMetadata[i].Parts {
|
|
|
|
_, err := onlineDisk.StatFile(bucket, pathJoin(object, part.Name))
|
|
|
|
if err != nil {
|
|
|
|
dataErrs[i] = err
|
|
|
|
break
|
|
|
|
}
|
2017-03-04 17:53:28 -05:00
|
|
|
}
|
2017-09-28 18:57:19 -04:00
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
if dataErrs[i] == nil {
|
2017-09-28 18:57:19 -04:00
|
|
|
// All parts verified, mark it as all data available.
|
|
|
|
availableDisks[i] = onlineDisk
|
2017-03-04 17:53:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:13:51 -04:00
|
|
|
return availableDisks, dataErrs
|
2017-03-04 17:53:28 -05:00
|
|
|
}
|