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.
758 lines
21 KiB
758 lines
21 KiB
9 years ago
|
/*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
9 years ago
|
import (
|
||
|
"encoding/json"
|
||
9 years ago
|
"errors"
|
||
9 years ago
|
"fmt"
|
||
9 years ago
|
"reflect"
|
||
9 years ago
|
"sync"
|
||
8 years ago
|
)
|
||
|
|
||
|
const (
|
||
|
// Represents XL backend.
|
||
|
formatBackendXL = "xl"
|
||
|
|
||
7 years ago
|
// formatXLV1.XL.Version
|
||
|
formatXLVersionV1 = "1"
|
||
|
)
|
||
8 years ago
|
|
||
7 years ago
|
// Represents the current backend disk structure
|
||
|
// version under `.minio.sys` and actual data namespace.
|
||
|
// formatXLV1 - structure holds format config version '1'.
|
||
|
type formatXLV1 struct {
|
||
|
formatMetaV1
|
||
|
XL struct {
|
||
|
Version string `json:"version"` // Version of 'xl' format.
|
||
|
Disk string `json:"disk"` // Disk field carries assigned disk uuid.
|
||
|
// JBOD field carries the input disk order generated the first
|
||
|
// time when fresh disks were supplied.
|
||
|
JBOD []string `json:"jbod"`
|
||
|
} `json:"xl"` // XL field holds xl format.
|
||
8 years ago
|
}
|
||
|
|
||
9 years ago
|
/*
|
||
|
|
||
|
All disks online
|
||
|
-----------------
|
||
|
- All Unformatted - format all and return success.
|
||
|
- Some Unformatted - format all and return success.
|
||
|
- Any JBOD inconsistent - return failure // Requires deep inspection, phase2.
|
||
|
- Some are corrupt (missing format.json) - return failure // Requires deep inspection, phase2.
|
||
|
- Any unrecognized disks - return failure
|
||
|
|
||
|
Some disks are offline and we have quorum.
|
||
|
-----------------
|
||
|
- Some unformatted - no heal, return success.
|
||
|
- Any JBOD inconsistent - return failure // Requires deep inspection, phase2.
|
||
|
- Some are corrupt (missing format.json) - return failure // Requires deep inspection, phase2.
|
||
|
- Any unrecognized disks - return failure
|
||
|
|
||
|
No read quorum
|
||
|
-----------------
|
||
|
failure for all cases.
|
||
|
|
||
|
// Pseudo code for managing `format.json`.
|
||
|
|
||
|
// Generic checks.
|
||
|
if (no quorum) return error
|
||
|
if (any disk is corrupt) return error // phase2
|
||
|
if (jbod inconsistent) return error // phase2
|
||
|
if (disks not recognized) // Always error.
|
||
|
|
||
|
// Specific checks.
|
||
|
if (all disks online)
|
||
|
if (all disks return format.json)
|
||
|
if (jbod consistent)
|
||
|
if (all disks recognized)
|
||
|
return
|
||
|
else
|
||
|
if (all disks return format.json not found)
|
||
|
(initialize format)
|
||
|
return
|
||
|
else (some disks return format.json not found)
|
||
|
(heal format)
|
||
|
return
|
||
|
fi
|
||
|
fi
|
||
|
else // No healing at this point forward, some disks are offline or dead.
|
||
|
if (some disks return format.json not found)
|
||
|
if (with force)
|
||
|
// Offline disks are marked as dead.
|
||
|
(heal format) // Offline disks should be marked as dead.
|
||
|
return success
|
||
|
else (without force)
|
||
|
// --force is necessary to heal few drives, because some drives
|
||
|
// are offline. Offline disks will be marked as dead.
|
||
|
return error
|
||
|
fi
|
||
|
fi
|
||
|
*/
|
||
|
|
||
9 years ago
|
// error returned when some disks are offline.
|
||
9 years ago
|
var errSomeDiskOffline = errors.New("some disks are offline")
|
||
|
|
||
9 years ago
|
// errDiskOrderMismatch - returned when disk UUID is not in consistent JBOD order.
|
||
|
var errDiskOrderMismatch = errors.New("disk order mismatch")
|
||
|
|
||
7 years ago
|
// formatErrsSummary - summarizes errors into different classes
|
||
|
func formatErrsSummary(errs []error) (formatCount, unformattedDiskCount,
|
||
|
diskNotFoundCount, corruptedFormatCount, otherErrCount int) {
|
||
|
|
||
|
for _, err := range errs {
|
||
|
switch err {
|
||
|
case errDiskNotFound:
|
||
|
diskNotFoundCount++
|
||
|
case errUnformattedDisk:
|
||
|
unformattedDiskCount++
|
||
|
case errCorruptedFormat:
|
||
|
corruptedFormatCount++
|
||
|
case nil:
|
||
|
// implies that format is not nil
|
||
|
formatCount++
|
||
|
default:
|
||
|
otherErrCount++
|
||
|
}
|
||
|
}
|
||
|
return
|
||
9 years ago
|
}
|
||
|
|
||
|
// loadAllFormats - load all format config from all input disks in parallel.
|
||
7 years ago
|
func loadAllFormats(bootstrapDisks []StorageAPI) ([]*formatXLV1, []error) {
|
||
9 years ago
|
// Initialize sync waitgroup.
|
||
|
var wg = &sync.WaitGroup{}
|
||
|
|
||
|
// Initialize list of errors.
|
||
|
var sErrs = make([]error, len(bootstrapDisks))
|
||
|
|
||
|
// Initialize format configs.
|
||
7 years ago
|
var formats = make([]*formatXLV1, len(bootstrapDisks))
|
||
9 years ago
|
|
||
|
// Make a volume entry on all underlying storage disks.
|
||
|
for index, disk := range bootstrapDisks {
|
||
9 years ago
|
if disk == nil {
|
||
|
sErrs[index] = errDiskNotFound
|
||
|
continue
|
||
|
}
|
||
9 years ago
|
wg.Add(1)
|
||
|
// Make a volume inside a go-routine.
|
||
|
go func(index int, disk StorageAPI) {
|
||
|
defer wg.Done()
|
||
7 years ago
|
format, lErr := loadFormat(disk)
|
||
9 years ago
|
if lErr != nil {
|
||
|
sErrs[index] = lErr
|
||
|
return
|
||
|
}
|
||
7 years ago
|
formats[index] = format
|
||
9 years ago
|
}(index, disk)
|
||
|
}
|
||
|
|
||
|
// Wait for all make vol to finish.
|
||
|
wg.Wait()
|
||
|
|
||
|
for _, err := range sErrs {
|
||
|
if err != nil {
|
||
|
// Return all formats and errors.
|
||
7 years ago
|
return formats, sErrs
|
||
9 years ago
|
}
|
||
|
}
|
||
|
// Return all formats and nil
|
||
7 years ago
|
return formats, sErrs
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
// genericFormatCheckXL - validates and returns error.
|
||
9 years ago
|
// if (no quorum) return error
|
||
|
// if (any disk is corrupt) return error // phase2
|
||
|
// if (jbod inconsistent) return error // phase2
|
||
|
// if (disks not recognized) // Always error.
|
||
7 years ago
|
func genericFormatCheckXL(formats []*formatXLV1, sErrs []error) (err error) {
|
||
9 years ago
|
// Calculate the errors.
|
||
|
var (
|
||
|
errCorruptFormatCount = 0
|
||
|
errCount = 0
|
||
|
)
|
||
|
|
||
|
// Through all errors calculate the actual errors.
|
||
|
for _, lErr := range sErrs {
|
||
|
if lErr == nil {
|
||
|
continue
|
||
|
}
|
||
|
// These errors are good conditions, means disk is online.
|
||
|
if lErr == errUnformattedDisk || lErr == errVolumeNotFound {
|
||
|
continue
|
||
|
}
|
||
|
if lErr == errCorruptedFormat {
|
||
|
errCorruptFormatCount++
|
||
|
} else {
|
||
|
errCount++
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Calculate read quorum.
|
||
7 years ago
|
readQuorum := len(formats) / 2
|
||
9 years ago
|
|
||
8 years ago
|
// Validate the err count under read quorum.
|
||
7 years ago
|
if errCount > len(formats)-readQuorum {
|
||
9 years ago
|
return errXLReadQuorum
|
||
|
}
|
||
|
|
||
8 years ago
|
// Check if number of corrupted format under read quorum
|
||
7 years ago
|
if errCorruptFormatCount > len(formats)-readQuorum {
|
||
9 years ago
|
return errCorruptedFormat
|
||
|
}
|
||
|
|
||
|
// Validates if format and JBOD are consistent across all disks.
|
||
7 years ago
|
if err = checkFormatXL(formats); err != nil {
|
||
9 years ago
|
return err
|
||
|
}
|
||
|
|
||
|
// Success..
|
||
|
return nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// isSavedUUIDInOrder - validates if disk uuid is present and valid in all
|
||
|
// available format config JBOD. This function also validates if the disk UUID
|
||
|
// is always available on all JBOD under the same order.
|
||
7 years ago
|
func isSavedUUIDInOrder(uuid string, formats []*formatXLV1) bool {
|
||
9 years ago
|
var orderIndexes []int
|
||
|
// Validate each for format.json for relevant uuid.
|
||
7 years ago
|
for _, format := range formats {
|
||
|
if format == nil {
|
||
9 years ago
|
continue
|
||
|
}
|
||
|
// Validate if UUID is present in JBOD.
|
||
7 years ago
|
uuidIndex := findDiskIndex(uuid, format.XL.JBOD)
|
||
9 years ago
|
if uuidIndex == -1 {
|
||
|
// UUID not found.
|
||
|
errorIf(errDiskNotFound, "Disk %s not found in JBOD list", uuid)
|
||
|
return false
|
||
|
}
|
||
|
// Save the position of UUID present in JBOD.
|
||
|
orderIndexes = append(orderIndexes, uuidIndex+1)
|
||
|
}
|
||
|
// Once uuid is found, verify if the uuid
|
||
|
// present in same order across all format configs.
|
||
|
prevOrderIndex := orderIndexes[0]
|
||
|
for _, orderIndex := range orderIndexes {
|
||
|
if prevOrderIndex != orderIndex {
|
||
|
errorIf(errDiskOrderMismatch, "Disk %s is in wrong order wanted %d, saw %d ", uuid, prevOrderIndex, orderIndex)
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
// Returns success, when we have verified if uuid
|
||
|
// is consistent and valid across all format configs.
|
||
|
return true
|
||
|
}
|
||
|
|
||
9 years ago
|
// checkDisksConsistency - checks if all disks are consistent with all JBOD entries on all disks.
|
||
7 years ago
|
func checkDisksConsistency(formats []*formatXLV1) error {
|
||
|
var disks = make([]string, len(formats))
|
||
9 years ago
|
// Collect currently available disk uuids.
|
||
7 years ago
|
for index, format := range formats {
|
||
|
if format == nil {
|
||
9 years ago
|
disks[index] = ""
|
||
9 years ago
|
continue
|
||
|
}
|
||
7 years ago
|
disks[index] = format.XL.Disk
|
||
9 years ago
|
}
|
||
|
// Validate collected uuids and verify JBOD.
|
||
9 years ago
|
for _, uuid := range disks {
|
||
9 years ago
|
if uuid == "" {
|
||
|
continue
|
||
|
}
|
||
9 years ago
|
// Is uuid present on all JBOD ?.
|
||
7 years ago
|
if !isSavedUUIDInOrder(uuid, formats) {
|
||
9 years ago
|
return fmt.Errorf("%s disk not found in JBOD", uuid)
|
||
9 years ago
|
}
|
||
|
}
|
||
|
return nil
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// checkJBODConsistency - validate xl jbod order if they are consistent.
|
||
7 years ago
|
func checkJBODConsistency(formats []*formatXLV1) error {
|
||
9 years ago
|
var sentinelJBOD []string
|
||
9 years ago
|
// Extract first valid JBOD.
|
||
7 years ago
|
for _, format := range formats {
|
||
9 years ago
|
if format == nil {
|
||
|
continue
|
||
|
}
|
||
9 years ago
|
sentinelJBOD = format.XL.JBOD
|
||
9 years ago
|
break
|
||
|
}
|
||
7 years ago
|
for _, format := range formats {
|
||
9 years ago
|
if format == nil {
|
||
|
continue
|
||
|
}
|
||
9 years ago
|
currentJBOD := format.XL.JBOD
|
||
|
if !reflect.DeepEqual(sentinelJBOD, currentJBOD) {
|
||
8 years ago
|
return errors.New("Inconsistent JBOD found")
|
||
9 years ago
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
// findDiskIndex returns position of disk in JBOD.
|
||
|
func findDiskIndex(disk string, jbod []string) int {
|
||
9 years ago
|
for index, uuid := range jbod {
|
||
|
if uuid == disk {
|
||
|
return index
|
||
|
}
|
||
|
}
|
||
|
return -1
|
||
|
}
|
||
|
|
||
7 years ago
|
// reorderDisks - reorder disks in JBOD order, and return reference
|
||
|
// format-config. If assignUUIDs is true, it assigns UUIDs to disks
|
||
|
// with missing format configurations in the reference configuration.
|
||
|
func reorderDisks(bootstrapDisks []StorageAPI,
|
||
7 years ago
|
formats []*formatXLV1, assignUUIDs bool) (*formatXLV1,
|
||
7 years ago
|
[]StorageAPI, error) {
|
||
|
|
||
|
// Pick first non-nil format-cfg as reference
|
||
7 years ago
|
var refCfg *formatXLV1
|
||
|
for _, format := range formats {
|
||
|
if format != nil {
|
||
|
refCfg = format
|
||
7 years ago
|
break
|
||
9 years ago
|
}
|
||
|
}
|
||
7 years ago
|
if refCfg == nil {
|
||
|
return nil, nil, fmt.Errorf("could not find any valid config")
|
||
|
}
|
||
|
refJBOD := refCfg.XL.JBOD
|
||
|
|
||
|
// construct reordered disk slice
|
||
9 years ago
|
var newDisks = make([]StorageAPI, len(bootstrapDisks))
|
||
7 years ago
|
for fIndex, format := range formats {
|
||
9 years ago
|
if format == nil {
|
||
|
continue
|
||
|
}
|
||
7 years ago
|
jIndex := findDiskIndex(format.XL.Disk, refJBOD)
|
||
9 years ago
|
if jIndex == -1 {
|
||
7 years ago
|
return nil, nil, errors.New("Unrecognized uuid " + format.XL.Disk + " found")
|
||
9 years ago
|
}
|
||
|
newDisks[jIndex] = bootstrapDisks[fIndex]
|
||
|
}
|
||
7 years ago
|
|
||
|
if assignUUIDs {
|
||
|
// Based on orderedDisks generate new UUIDs in the ref. config
|
||
|
// for disks without format-configs.
|
||
|
for index, disk := range newDisks {
|
||
|
if disk == nil {
|
||
|
refCfg.XL.JBOD[index] = mustGetUUID()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return refCfg, newDisks, nil
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// loadFormat - loads format.json from disk.
|
||
7 years ago
|
func loadFormat(disk StorageAPI) (format *formatXLV1, err error) {
|
||
9 years ago
|
buf, err := disk.ReadAll(minioMetaBucket, formatConfigFile)
|
||
|
if err != nil {
|
||
9 years ago
|
// 'file not found' and 'volume not found' as
|
||
|
// same. 'volume not found' usually means its a fresh disk.
|
||
|
if err == errFileNotFound || err == errVolumeNotFound {
|
||
|
var vols []VolInfo
|
||
|
vols, err = disk.ListVols()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(vols) > 1 {
|
||
|
// 'format.json' not found, but we found user data.
|
||
|
return nil, errCorruptedFormat
|
||
|
}
|
||
|
// No other data found, its a fresh disk.
|
||
|
return nil, errUnformattedDisk
|
||
|
}
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
// Try to decode format json into formatConfigV1 struct.
|
||
7 years ago
|
format = &formatXLV1{}
|
||
9 years ago
|
if err = json.Unmarshal(buf, format); err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
// Success.
|
||
9 years ago
|
return format, nil
|
||
|
}
|
||
|
|
||
7 years ago
|
// collectNSaveNewFormatConfigs - creates new format configs based on
|
||
|
// the reference config and saves it on all disks, this is to be
|
||
|
// called from healFormatXL* functions.
|
||
7 years ago
|
func collectNSaveNewFormatConfigs(referenceConfig *formatXLV1,
|
||
7 years ago
|
orderedDisks []StorageAPI) error {
|
||
9 years ago
|
|
||
9 years ago
|
// Collect new format configs that need to be written.
|
||
7 years ago
|
var newFormatConfigs = make([]*formatXLV1, len(orderedDisks))
|
||
9 years ago
|
for index := range orderedDisks {
|
||
|
// New configs are generated since we are going
|
||
|
// to re-populate across all disks.
|
||
7 years ago
|
config := &formatXLV1{}
|
||
|
config.Version = referenceConfig.Version
|
||
|
config.Format = referenceConfig.Format
|
||
|
config.XL.Version = referenceConfig.XL.Version
|
||
|
config.XL.Disk = referenceConfig.XL.JBOD[index]
|
||
|
config.XL.JBOD = referenceConfig.XL.JBOD
|
||
9 years ago
|
newFormatConfigs[index] = config
|
||
|
}
|
||
|
|
||
7 years ago
|
// Initialize meta volume, if volume already exists ignores it.
|
||
|
if err := initMetaVolume(orderedDisks); err != nil {
|
||
|
return fmt.Errorf("Unable to initialize '.minio.sys' meta volume, %s", err)
|
||
|
}
|
||
|
|
||
|
// Save new `format.json` across all disks, in JBOD order.
|
||
|
return saveFormatXL(orderedDisks, newFormatConfigs)
|
||
|
}
|
||
|
|
||
|
// Heals any missing format.json on the drives. Returns error only for
|
||
|
// unexpected errors as regular errors can be ignored since there
|
||
|
// might be enough quorum to be operational. Heals only fresh disks.
|
||
|
func healFormatXLFreshDisks(storageDisks []StorageAPI,
|
||
7 years ago
|
formats []*formatXLV1) error {
|
||
7 years ago
|
|
||
|
// Reorder the disks based on the JBOD order.
|
||
|
referenceConfig, orderedDisks, err := reorderDisks(storageDisks,
|
||
7 years ago
|
formats, true)
|
||
7 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
9 years ago
|
// Fill in the missing disk back from format configs.
|
||
|
// We need to make sure we have kept the previous order
|
||
|
// and allowed fresh disks to be arranged anywhere.
|
||
|
// Following block facilitates to put fresh disks.
|
||
7 years ago
|
for index, format := range formats {
|
||
9 years ago
|
// Format is missing so we go through ordered disks.
|
||
9 years ago
|
if format == nil {
|
||
9 years ago
|
// At this point when disk is missing the fresh disk
|
||
|
// in the stack get it back from storageDisks.
|
||
|
for oIndex, disk := range orderedDisks {
|
||
|
if disk == nil {
|
||
|
orderedDisks[oIndex] = storageDisks[index]
|
||
|
break
|
||
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
|
}
|
||
9 years ago
|
|
||
7 years ago
|
// apply new format config and save to all disks
|
||
|
return collectNSaveNewFormatConfigs(referenceConfig, orderedDisks)
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
// collectUnAssignedDisks - collect disks unassigned to orderedDisks
|
||
|
// from storageDisks and return them.
|
||
|
func collectUnAssignedDisks(storageDisks, orderedDisks []StorageAPI) (
|
||
|
uDisks []StorageAPI) {
|
||
|
|
||
|
// search for each disk from storageDisks in orderedDisks
|
||
9 years ago
|
for i := range storageDisks {
|
||
|
found := false
|
||
|
for j := range orderedDisks {
|
||
|
if storageDisks[i] == orderedDisks[j] {
|
||
|
found = true
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
if !found {
|
||
7 years ago
|
// append not found disk to result
|
||
|
uDisks = append(uDisks, storageDisks[i])
|
||
9 years ago
|
}
|
||
|
}
|
||
7 years ago
|
return uDisks
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
// Inspect the content of all disks to guess the right order according
|
||
|
// to the format files. The right order is represented in orderedDisks
|
||
|
func reorderDisksByInspection(orderedDisks, storageDisks []StorageAPI,
|
||
7 years ago
|
formats []*formatXLV1) ([]StorageAPI, error) {
|
||
7 years ago
|
|
||
7 years ago
|
for index, format := range formats {
|
||
9 years ago
|
if format != nil {
|
||
|
continue
|
||
|
}
|
||
|
vols, err := storageDisks[index].ListVols()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(vols) == 0 {
|
||
|
continue
|
||
|
}
|
||
8 years ago
|
volName := ""
|
||
7 years ago
|
// Avoid picking minioMetaBucket because ListVols()
|
||
|
// returns a non ordered list
|
||
8 years ago
|
for i := range vols {
|
||
|
if vols[i].Name != minioMetaBucket {
|
||
|
volName = vols[i].Name
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
if volName == "" {
|
||
|
continue
|
||
|
}
|
||
|
objects, err := storageDisks[index].ListDir(volName, "")
|
||
9 years ago
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(objects) == 0 {
|
||
|
continue
|
||
|
}
|
||
8 years ago
|
xlData, err := readXLMeta(storageDisks[index], volName, objects[0])
|
||
9 years ago
|
if err != nil {
|
||
|
if err == errFileNotFound {
|
||
|
continue
|
||
|
}
|
||
|
return nil, err
|
||
|
}
|
||
|
diskIndex := -1
|
||
|
for i, d := range xlData.Erasure.Distribution {
|
||
|
if d == xlData.Erasure.Index {
|
||
|
diskIndex = i
|
||
|
}
|
||
|
}
|
||
|
// Check for found results
|
||
|
if diskIndex == -1 || orderedDisks[diskIndex] != nil {
|
||
|
// Some inconsistent data are found, exit immediately.
|
||
|
return nil, errCorruptedFormat
|
||
|
}
|
||
|
orderedDisks[diskIndex] = storageDisks[index]
|
||
|
}
|
||
|
return orderedDisks, nil
|
||
|
}
|
||
|
|
||
|
// Heals corrupted format json in all disks
|
||
7 years ago
|
func healFormatXLCorruptedDisks(storageDisks []StorageAPI,
|
||
7 years ago
|
formats []*formatXLV1) error {
|
||
9 years ago
|
|
||
|
// Reorder the disks based on the JBOD order.
|
||
7 years ago
|
referenceConfig, orderedDisks, err := reorderDisks(storageDisks,
|
||
7 years ago
|
formats, true)
|
||
9 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
7 years ago
|
// For disks with corrupted formats, inspect the disks
|
||
|
// contents to guess the disks order
|
||
|
orderedDisks, err = reorderDisksByInspection(orderedDisks, storageDisks,
|
||
7 years ago
|
formats)
|
||
9 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
7 years ago
|
// At this stage, all disks with corrupted formats but with
|
||
|
// objects inside found their way. Now take care of
|
||
|
// unformatted disks, which are the `unAssignedDisks`
|
||
|
unAssignedDisks := collectUnAssignedDisks(storageDisks, orderedDisks)
|
||
9 years ago
|
|
||
|
// Assign unassigned disks to nil elements in orderedDisks
|
||
|
for i, disk := range orderedDisks {
|
||
|
if disk == nil && len(unAssignedDisks) > 0 {
|
||
|
orderedDisks[i] = unAssignedDisks[0]
|
||
|
unAssignedDisks = unAssignedDisks[1:]
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
// apply new format config and save to all disks
|
||
|
return collectNSaveNewFormatConfigs(referenceConfig, orderedDisks)
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// loadFormatXL - loads XL `format.json` and returns back properly
|
||
|
// ordered storage slice based on `format.json`.
|
||
8 years ago
|
func loadFormatXL(bootstrapDisks []StorageAPI, readQuorum int) (disks []StorageAPI, err error) {
|
||
9 years ago
|
var unformattedDisksFoundCnt = 0
|
||
|
var diskNotFoundCount = 0
|
||
8 years ago
|
var corruptedDisksFoundCnt = 0
|
||
7 years ago
|
formats := make([]*formatXLV1, len(bootstrapDisks))
|
||
9 years ago
|
|
||
9 years ago
|
// Try to load `format.json` bootstrap disks.
|
||
9 years ago
|
for index, disk := range bootstrapDisks {
|
||
9 years ago
|
if disk == nil {
|
||
|
diskNotFoundCount++
|
||
|
continue
|
||
|
}
|
||
7 years ago
|
var formatXL *formatXLV1
|
||
9 years ago
|
formatXL, err = loadFormat(disk)
|
||
|
if err != nil {
|
||
|
if err == errUnformattedDisk {
|
||
|
unformattedDisksFoundCnt++
|
||
|
continue
|
||
|
} else if err == errDiskNotFound {
|
||
|
diskNotFoundCount++
|
||
|
continue
|
||
8 years ago
|
} else if err == errCorruptedFormat {
|
||
|
corruptedDisksFoundCnt++
|
||
|
continue
|
||
9 years ago
|
}
|
||
|
return nil, err
|
||
|
}
|
||
|
// Save valid formats.
|
||
7 years ago
|
formats[index] = formatXL
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
// If all disks indicate that 'format.json' is not available return 'errUnformattedDisk'.
|
||
8 years ago
|
if unformattedDisksFoundCnt > len(bootstrapDisks)-readQuorum {
|
||
9 years ago
|
return nil, errUnformattedDisk
|
||
8 years ago
|
} else if corruptedDisksFoundCnt > len(bootstrapDisks)-readQuorum {
|
||
|
return nil, errCorruptedFormat
|
||
9 years ago
|
} else if diskNotFoundCount == len(bootstrapDisks) {
|
||
|
return nil, errDiskNotFound
|
||
8 years ago
|
} else if diskNotFoundCount > len(bootstrapDisks)-readQuorum {
|
||
9 years ago
|
return nil, errXLReadQuorum
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
// Validate the format configs read are correct.
|
||
7 years ago
|
if err = checkFormatXL(formats); err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
7 years ago
|
// Erasure code requires disks to be presented in the same
|
||
|
// order each time.
|
||
7 years ago
|
_, orderedDisks, err := reorderDisks(bootstrapDisks, formats,
|
||
7 years ago
|
false)
|
||
|
return orderedDisks, err
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
func checkFormatXLValue(formatXL *formatXLV1) error {
|
||
8 years ago
|
// Validate format version and format type.
|
||
7 years ago
|
if formatXL.Version != formatMetaVersionV1 {
|
||
8 years ago
|
return fmt.Errorf("Unsupported version of backend format [%s] found", formatXL.Version)
|
||
|
}
|
||
8 years ago
|
if formatXL.Format != formatBackendXL {
|
||
8 years ago
|
return fmt.Errorf("Unsupported backend format [%s] found", formatXL.Format)
|
||
|
}
|
||
7 years ago
|
if formatXL.XL.Version != formatXLVersionV1 {
|
||
8 years ago
|
return fmt.Errorf("Unsupported XL backend format found [%s]", formatXL.XL.Version)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
7 years ago
|
func checkFormatXLValues(formats []*formatXLV1) (int, error) {
|
||
|
for i, formatXL := range formats {
|
||
9 years ago
|
if formatXL == nil {
|
||
|
continue
|
||
|
}
|
||
8 years ago
|
if err := checkFormatXLValue(formatXL); err != nil {
|
||
|
return i, err
|
||
9 years ago
|
}
|
||
7 years ago
|
if len(formats) != len(formatXL.XL.JBOD) {
|
||
8 years ago
|
return i, fmt.Errorf("Number of disks %d did not match the backend format %d",
|
||
7 years ago
|
len(formats), len(formatXL.XL.JBOD))
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
8 years ago
|
return -1, nil
|
||
8 years ago
|
}
|
||
|
|
||
|
// checkFormatXL - verifies if format.json format is intact.
|
||
7 years ago
|
func checkFormatXL(formats []*formatXLV1) error {
|
||
|
if _, err := checkFormatXLValues(formats); err != nil {
|
||
8 years ago
|
return err
|
||
|
}
|
||
7 years ago
|
if err := checkJBODConsistency(formats); err != nil {
|
||
9 years ago
|
return err
|
||
|
}
|
||
7 years ago
|
return checkDisksConsistency(formats)
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// saveFormatXL - populates `format.json` on disks in its order.
|
||
7 years ago
|
func saveFormatXL(storageDisks []StorageAPI, formats []*formatXLV1) error {
|
||
9 years ago
|
var errs = make([]error, len(storageDisks))
|
||
|
var wg = &sync.WaitGroup{}
|
||
|
// Write `format.json` to all disks.
|
||
9 years ago
|
for index, disk := range storageDisks {
|
||
9 years ago
|
if disk == nil {
|
||
|
continue
|
||
9 years ago
|
}
|
||
9 years ago
|
wg.Add(1)
|
||
7 years ago
|
go func(index int, disk StorageAPI, format *formatXLV1) {
|
||
9 years ago
|
defer wg.Done()
|
||
|
|
||
|
// Marshal and write to disk.
|
||
|
formatBytes, err := json.Marshal(format)
|
||
|
if err != nil {
|
||
|
errs[index] = err
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// Purge any existing temporary file, okay to ignore errors here.
|
||
|
disk.DeleteFile(minioMetaBucket, formatConfigFileTmp)
|
||
|
|
||
|
// Append file `format.json.tmp`.
|
||
|
if err = disk.AppendFile(minioMetaBucket, formatConfigFileTmp, formatBytes); err != nil {
|
||
|
errs[index] = err
|
||
|
return
|
||
|
}
|
||
|
// Rename file `format.json.tmp` --> `format.json`.
|
||
|
if err = disk.RenameFile(minioMetaBucket, formatConfigFileTmp, minioMetaBucket, formatConfigFile); err != nil {
|
||
|
errs[index] = err
|
||
|
return
|
||
9 years ago
|
}
|
||
9 years ago
|
}(index, disk, formats[index])
|
||
|
}
|
||
|
|
||
|
// Wait for the routines to finish.
|
||
|
wg.Wait()
|
||
|
|
||
|
// Validate if we encountered any errors, return quickly.
|
||
|
for _, err := range errs {
|
||
|
if err != nil {
|
||
|
// Failure.
|
||
9 years ago
|
return err
|
||
|
}
|
||
9 years ago
|
}
|
||
|
|
||
|
// Success.
|
||
|
return nil
|
||
|
}
|
||
|
|
||
7 years ago
|
// Return a slice of format, to be used to format uninitialized disks.
|
||
|
func newFormatXLV1(diskCount int) []*formatXLV1 {
|
||
|
var jbod = make([]string, diskCount)
|
||
9 years ago
|
|
||
7 years ago
|
var formats = make([]*formatXLV1, diskCount)
|
||
9 years ago
|
|
||
7 years ago
|
for i := 0; i < diskCount; i++ {
|
||
|
format := &formatXLV1{}
|
||
|
format.Version = formatMetaVersionV1
|
||
|
format.Format = formatBackendXL
|
||
|
format.XL.Version = formatXLVersionV1
|
||
|
format.XL.Disk = mustGetUUID()
|
||
|
formats[i] = format
|
||
|
jbod[i] = formats[i].XL.Disk
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
// Update the jbod entries.
|
||
7 years ago
|
for i := 0; i < diskCount; i++ {
|
||
|
formats[i].XL.JBOD = jbod
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
7 years ago
|
return formats
|
||
|
}
|
||
|
|
||
|
// initFormatXL - save XL format configuration on all disks.
|
||
|
func initFormatXL(storageDisks []StorageAPI) (err error) {
|
||
8 years ago
|
// Initialize meta volume, if volume already exists ignores it.
|
||
|
if err := initMetaVolume(storageDisks); err != nil {
|
||
8 years ago
|
return fmt.Errorf("Unable to initialize '.minio.sys' meta volume, %s", err)
|
||
8 years ago
|
}
|
||
|
|
||
9 years ago
|
// Save formats `format.json` across all disks.
|
||
7 years ago
|
return saveFormatXL(storageDisks, newFormatXLV1(len(storageDisks)))
|
||
9 years ago
|
}
|