2016-06-17 20:57:51 +02: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-05-26 01:42:31 +02:00
|
|
|
package main
|
|
|
|
|
2016-07-13 00:20:31 +02:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
2016-05-26 01:42:31 +02:00
|
|
|
|
2016-07-13 00:20:31 +02:00
|
|
|
// commonTime returns a maximally occurring time from a list of time.
|
|
|
|
func commonTime(modTimes []time.Time) (modTime time.Time) {
|
|
|
|
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 {
|
|
|
|
if count > maxima {
|
|
|
|
maxima = count
|
|
|
|
modTime = time
|
2016-05-26 01:42:31 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-13 00:20:31 +02:00
|
|
|
// Return the collected common uuid.
|
|
|
|
return modTime
|
|
|
|
}
|
|
|
|
|
2016-07-13 08:21:18 +02:00
|
|
|
// Beginning of unix time is treated as sentinel value here.
|
2016-07-13 00:20:31 +02:00
|
|
|
var timeSentinel = time.Unix(0, 0).UTC()
|
|
|
|
|
2016-07-13 08:21:18 +02:00
|
|
|
// Boot modTimes up to disk count, setting the value to time sentinel.
|
2016-07-13 00:20:31 +02:00
|
|
|
func bootModtimes(diskCount int) []time.Time {
|
|
|
|
modTimes := make([]time.Time, diskCount)
|
2016-07-13 08:21:18 +02:00
|
|
|
// Boots up all the modtimes.
|
2016-07-13 00:20:31 +02:00
|
|
|
for i := range modTimes {
|
|
|
|
modTimes[i] = timeSentinel
|
|
|
|
}
|
|
|
|
return modTimes
|
2016-05-26 01:42:31 +02:00
|
|
|
}
|
|
|
|
|
2016-07-13 00:20:31 +02:00
|
|
|
// Extracts list of times from xlMetaV1 slice and returns, skips
|
|
|
|
// slice elements which have errors. As a special error
|
|
|
|
// errFileNotFound is treated as a initial good condition.
|
|
|
|
func listObjectModtimes(partsMetadata []xlMetaV1, errs []error) (modTimes []time.Time) {
|
|
|
|
modTimes = bootModtimes(len(partsMetadata))
|
|
|
|
// Set a new time value, specifically set when
|
|
|
|
// error == errFileNotFound (this is needed when this is a
|
|
|
|
// fresh PutObject).
|
|
|
|
timeNow := time.Now().UTC()
|
2016-05-26 01:42:31 +02:00
|
|
|
for index, metadata := range partsMetadata {
|
|
|
|
if errs[index] == nil {
|
2016-07-13 00:20:31 +02:00
|
|
|
// Once the file is found, save the uuid saved on disk.
|
|
|
|
modTimes[index] = metadata.Stat.ModTime
|
2016-06-17 20:57:51 +02:00
|
|
|
} else if errs[index] == errFileNotFound {
|
2016-07-13 00:20:31 +02:00
|
|
|
// Once the file is not found then the epoch is current time.
|
|
|
|
modTimes[index] = timeNow
|
2016-05-26 01:42:31 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-13 00:20:31 +02:00
|
|
|
return modTimes
|
2016-05-26 01:42:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (xl xlObjects) shouldHeal(onlineDisks []StorageAPI) (heal bool) {
|
|
|
|
onlineDiskCount := diskCount(onlineDisks)
|
|
|
|
// If online disks count is lesser than configured disks, most
|
|
|
|
// probably we need to heal the file, additionally verify if the
|
|
|
|
// count is lesser than readQuorum, if not we throw an error.
|
|
|
|
if onlineDiskCount < len(xl.storageDisks) {
|
|
|
|
// Online disks lesser than total storage disks, needs to be
|
|
|
|
// healed. unless we do not have readQuorum.
|
|
|
|
heal = true
|
|
|
|
// Verify if online disks count are lesser than readQuorum
|
|
|
|
// threshold, return an error.
|
|
|
|
if onlineDiskCount < xl.readQuorum {
|
2016-06-03 01:34:15 +02:00
|
|
|
errorIf(errXLReadQuorum, "Unable to establish read quorum, disks are offline.")
|
2016-05-26 01:42:31 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return heal
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns slice of online disks needed.
|
|
|
|
// - slice returing readable disks.
|
2016-07-14 23:59:01 +02:00
|
|
|
// - modTime of the Object
|
|
|
|
func listOnlineDisks(disks []StorageAPI, partsMetadata []xlMetaV1, errs []error) (onlineDisks []StorageAPI, modTime time.Time) {
|
|
|
|
onlineDisks = make([]StorageAPI, len(disks))
|
2016-06-17 20:57:51 +02:00
|
|
|
|
2016-07-13 00:20:31 +02:00
|
|
|
// List all the file commit ids from parts metadata.
|
|
|
|
modTimes := listObjectModtimes(partsMetadata, errs)
|
2016-05-26 01:42:31 +02:00
|
|
|
|
2016-07-13 00:20:31 +02:00
|
|
|
// Reduce list of UUIDs to a single common value.
|
|
|
|
modTime = commonTime(modTimes)
|
2016-05-26 01:42:31 +02:00
|
|
|
|
2016-07-13 00:20:31 +02:00
|
|
|
// Create a new online disks slice, which have common uuid.
|
|
|
|
for index, t := range modTimes {
|
|
|
|
if t == modTime {
|
2016-07-14 23:59:01 +02:00
|
|
|
onlineDisks[index] = disks[index]
|
2016-05-26 01:42:31 +02:00
|
|
|
} else {
|
|
|
|
onlineDisks[index] = nil
|
|
|
|
}
|
|
|
|
}
|
2016-07-13 00:20:31 +02:00
|
|
|
return onlineDisks, modTime
|
2016-05-26 01:42:31 +02:00
|
|
|
}
|