You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
6.2 KiB
191 lines
6.2 KiB
8 years ago
|
/*
|
||
5 years ago
|
* MinIO Cloud Storage, (C) 2016-2019 MinIO, Inc.
|
||
8 years ago
|
*
|
||
|
* 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
|
||
|
|
||
8 years ago
|
import (
|
||
7 years ago
|
"context"
|
||
8 years ago
|
"time"
|
||
7 years ago
|
|
||
6 years ago
|
"github.com/minio/minio/pkg/madmin"
|
||
8 years ago
|
)
|
||
8 years ago
|
|
||
|
// commonTime returns a maximally occurring time from a list of time.
|
||
8 years ago
|
func commonTime(modTimes []time.Time) (modTime time.Time, count int) {
|
||
8 years ago
|
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 {
|
||
5 years ago
|
if time.Equal(timeSentinel) {
|
||
8 years ago
|
continue
|
||
|
}
|
||
|
timeOccurenceMap[time]++
|
||
|
}
|
||
|
// Find the common cardinality from previously collected
|
||
|
// occurrences of elements.
|
||
|
for time, count := range timeOccurenceMap {
|
||
7 years ago
|
if count > maxima || (count == maxima && time.After(modTime)) {
|
||
8 years ago
|
maxima = count
|
||
|
modTime = time
|
||
|
}
|
||
|
}
|
||
|
// Return the collected common uuid.
|
||
8 years ago
|
return modTime, maxima
|
||
8 years ago
|
}
|
||
|
|
||
|
// 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
|
||
|
}
|
||
|
|
||
5 years ago
|
// Extracts list of times from FileInfo slice and returns, skips
|
||
8 years ago
|
// slice elements which have errors.
|
||
5 years ago
|
func listObjectModtimes(partsMetadata []FileInfo, errs []error) (modTimes []time.Time) {
|
||
8 years ago
|
modTimes = bootModtimes(len(partsMetadata))
|
||
|
for index, metadata := range partsMetadata {
|
||
8 years ago
|
if errs[index] != nil {
|
||
|
continue
|
||
8 years ago
|
}
|
||
8 years ago
|
// Once the file is found, save the uuid saved on disk.
|
||
5 years ago
|
modTimes[index] = metadata.ModTime
|
||
8 years ago
|
}
|
||
|
return modTimes
|
||
|
}
|
||
|
|
||
8 years ago
|
// Notes:
|
||
|
// There are 5 possible states a disk could be in,
|
||
5 years ago
|
// 1. __online__ - has the latest copy of xl.meta - returned by listOnlineDisks
|
||
8 years ago
|
//
|
||
|
// 2. __offline__ - err == errDiskNotFound
|
||
|
//
|
||
5 years ago
|
// 3. __availableWithParts__ - has the latest copy of xl.meta and has all
|
||
8 years ago
|
// parts with checksums matching; returned by disksWithAllParts
|
||
|
//
|
||
|
// 4. __outdated__ - returned by outDatedDisk, provided []StorageAPI
|
||
|
// returned by diskWithAllParts is passed for latestDisks.
|
||
5 years ago
|
// - has an old copy of xl.meta
|
||
|
// - doesn't have xl.meta (errFileNotFound)
|
||
|
// - has the latest xl.meta but one or more parts are corrupt
|
||
8 years ago
|
//
|
||
5 years ago
|
// 5. __missingParts__ - has the latest copy of xl.meta but has some parts
|
||
8 years ago
|
// 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
|
||
5 years ago
|
// - a slice of disks where disk having 'older' xl.meta (or nothing)
|
||
8 years ago
|
// are set to nil.
|
||
|
// - latest (in time) of the maximally occurring modTime(s).
|
||
5 years ago
|
func listOnlineDisks(disks []StorageAPI, partsMetadata []FileInfo, errs []error) (onlineDisks []StorageAPI, modTime time.Time) {
|
||
8 years ago
|
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.
|
||
8 years ago
|
modTime, _ = commonTime(modTimes)
|
||
8 years ago
|
|
||
|
// Create a new online disks slice, which have common uuid.
|
||
|
for index, t := range modTimes {
|
||
5 years ago
|
if t.Equal(modTime) {
|
||
8 years ago
|
onlineDisks[index] = disks[index]
|
||
|
} else {
|
||
|
onlineDisks[index] = nil
|
||
|
}
|
||
|
}
|
||
|
return onlineDisks, modTime
|
||
|
}
|
||
|
|
||
5 years ago
|
// Returns the latest updated FileInfo files and error in case of failure.
|
||
|
func getLatestFileInfo(ctx context.Context, partsMetadata []FileInfo, errs []error) (FileInfo, error) {
|
||
6 years ago
|
// There should be atleast half correct entries, if not return failure
|
||
5 years ago
|
if reducedErr := reduceReadQuorumErrs(ctx, errs, objectOpIgnoredErrs, len(partsMetadata)/2); reducedErr != nil {
|
||
5 years ago
|
return FileInfo{}, reducedErr
|
||
6 years ago
|
}
|
||
|
|
||
7 years ago
|
// List all the file commit ids from parts metadata.
|
||
|
modTimes := listObjectModtimes(partsMetadata, errs)
|
||
|
|
||
5 years ago
|
// Count all latest updated FileInfo values
|
||
7 years ago
|
var count int
|
||
5 years ago
|
var latestFileInfo FileInfo
|
||
7 years ago
|
|
||
|
// Reduce list of UUIDs to a single common value - i.e. the last updated Time
|
||
|
modTime, _ := commonTime(modTimes)
|
||
|
|
||
5 years ago
|
// Interate through all the modTimes and count the FileInfo(s) with latest time.
|
||
7 years ago
|
for index, t := range modTimes {
|
||
5 years ago
|
if t.Equal(modTime) && partsMetadata[index].IsValid() {
|
||
|
latestFileInfo = partsMetadata[index]
|
||
7 years ago
|
count++
|
||
|
}
|
||
|
}
|
||
6 years ago
|
if count < len(partsMetadata)/2 {
|
||
5 years ago
|
return FileInfo{}, errErasureReadQuorum
|
||
6 years ago
|
}
|
||
|
|
||
5 years ago
|
return latestFileInfo, nil
|
||
7 years ago
|
}
|
||
|
|
||
8 years ago
|
// disksWithAllParts - This function needs to be called with
|
||
|
// []StorageAPI returned by listOnlineDisks. Returns,
|
||
7 years ago
|
//
|
||
5 years ago
|
// - disks which have all parts specified in the latest xl.meta.
|
||
7 years ago
|
//
|
||
7 years ago
|
// - slice of errors about the state of data files on disk - can have
|
||
|
// a not-found error or a hash-mismatch error.
|
||
5 years ago
|
func disksWithAllParts(ctx context.Context, onlineDisks []StorageAPI, partsMetadata []FileInfo, errs []error, bucket,
|
||
6 years ago
|
object string, scanMode madmin.HealScanMode) ([]StorageAPI, []error) {
|
||
8 years ago
|
availableDisks := make([]StorageAPI, len(onlineDisks))
|
||
7 years ago
|
dataErrs := make([]error, len(onlineDisks))
|
||
7 years ago
|
|
||
7 years ago
|
for i, onlineDisk := range onlineDisks {
|
||
5 years ago
|
if errs[i] != nil {
|
||
6 years ago
|
dataErrs[i] = errs[i]
|
||
8 years ago
|
continue
|
||
|
}
|
||
5 years ago
|
if onlineDisk == nil {
|
||
|
dataErrs[i] = errDiskNotFound
|
||
|
continue
|
||
|
}
|
||
7 years ago
|
|
||
6 years ago
|
switch scanMode {
|
||
|
case madmin.HealDeepScan:
|
||
5 years ago
|
// disk has a valid xl.meta but may not have all the
|
||
6 years ago
|
// parts. This is considered an outdated disk, since
|
||
|
// it needs healing too.
|
||
5 years ago
|
dataErrs[i] = onlineDisk.VerifyFile(bucket, object, partsMetadata[i])
|
||
6 years ago
|
case madmin.HealNormalScan:
|
||
5 years ago
|
dataErrs[i] = onlineDisk.CheckParts(bucket, object, partsMetadata[i])
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
if dataErrs[i] == nil {
|
||
7 years ago
|
// All parts verified, mark it as all data available.
|
||
|
availableDisks[i] = onlineDisk
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
return availableDisks, dataErrs
|
||
8 years ago
|
}
|