2016-05-21 03:48:47 +00:00
|
|
|
/*
|
2018-02-12 09:46:12 +00:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017, 2018 Minio, Inc.
|
2016-05-21 03:48:47 +00: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-18 23:23:42 +00:00
|
|
|
package cmd
|
2016-05-21 03:48:47 +00:00
|
|
|
|
|
|
|
import (
|
2018-03-14 19:01:47 +00:00
|
|
|
"context"
|
2016-05-26 21:13:10 +00:00
|
|
|
"sort"
|
|
|
|
|
2018-04-05 22:04:40 +00:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-02-16 01:45:57 +00:00
|
|
|
"github.com/minio/minio/pkg/bpool"
|
2016-05-21 03:48:47 +00:00
|
|
|
)
|
|
|
|
|
2016-05-30 23:51:59 +00:00
|
|
|
// XL constants.
|
2016-05-21 03:48:47 +00:00
|
|
|
const (
|
2016-05-30 23:51:59 +00:00
|
|
|
// XL metadata file carries per object metadata.
|
|
|
|
xlMetaJSONFile = "xl.json"
|
2016-05-21 03:48:47 +00:00
|
|
|
)
|
|
|
|
|
2018-08-24 06:35:37 +00:00
|
|
|
// OfflineDisk represents an unavailable disk.
|
|
|
|
var OfflineDisk StorageAPI // zero value is nil
|
|
|
|
|
2016-05-30 23:51:59 +00:00
|
|
|
// xlObjects - Implements XL object layer.
|
2016-05-21 03:48:47 +00:00
|
|
|
type xlObjects struct {
|
2018-02-16 01:45:57 +00:00
|
|
|
// name space mutex for object layer.
|
|
|
|
nsMutex *nsLockMap
|
2016-05-30 23:51:59 +00:00
|
|
|
|
2018-02-16 01:45:57 +00:00
|
|
|
// getDisks returns list of storageAPIs.
|
|
|
|
getDisks func() []StorageAPI
|
2016-05-21 03:48:47 +00:00
|
|
|
|
2018-02-16 01:45:57 +00:00
|
|
|
// Byte pools used for temporary i/o buffers.
|
|
|
|
bp *bpool.BytePoolCap
|
2018-02-12 09:46:12 +00:00
|
|
|
|
2018-02-16 01:45:57 +00:00
|
|
|
// TODO: Deprecated only kept here for tests, should be removed in future.
|
|
|
|
storageDisks []StorageAPI
|
2017-01-17 01:05:00 +00:00
|
|
|
|
2018-02-16 01:45:57 +00:00
|
|
|
// TODO: ListObjects pool management, should be removed in future.
|
|
|
|
listPool *treeWalkPool
|
2017-01-17 01:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 06:55:48 +00:00
|
|
|
// Shutdown function for object storage interface.
|
2018-03-14 19:01:47 +00:00
|
|
|
func (xl xlObjects) Shutdown(ctx context.Context) error {
|
2016-08-15 06:55:48 +00:00
|
|
|
// Add any object layer shutdown activities here.
|
2018-04-04 04:58:48 +00:00
|
|
|
closeStorageDisks(xl.getDisks())
|
2016-08-15 06:55:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-26 21:13:10 +00:00
|
|
|
// byDiskTotal is a collection satisfying sort.Interface.
|
2018-05-23 10:11:29 +00:00
|
|
|
type byDiskTotal []DiskInfo
|
2016-05-26 21:13:10 +00:00
|
|
|
|
|
|
|
func (d byDiskTotal) Len() int { return len(d) }
|
|
|
|
func (d byDiskTotal) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
|
|
|
|
func (d byDiskTotal) Less(i, j int) bool {
|
|
|
|
return d[i].Total < d[j].Total
|
|
|
|
}
|
|
|
|
|
2016-10-05 19:48:07 +00:00
|
|
|
// getDisksInfo - fetch disks info across all other storage API.
|
2018-05-23 10:11:29 +00:00
|
|
|
func getDisksInfo(disks []StorageAPI) (disksInfo []DiskInfo, onlineDisks int, offlineDisks int) {
|
|
|
|
disksInfo = make([]DiskInfo, len(disks))
|
2016-10-17 21:31:33 +00:00
|
|
|
for i, storageDisk := range disks {
|
2016-09-15 06:53:42 +00:00
|
|
|
if storageDisk == nil {
|
|
|
|
// Storage disk is empty, perhaps ignored disk or not available.
|
2016-10-05 19:48:07 +00:00
|
|
|
offlineDisks++
|
2016-09-15 06:53:42 +00:00
|
|
|
continue
|
|
|
|
}
|
2016-08-26 00:16:34 +00:00
|
|
|
info, err := storageDisk.DiskInfo()
|
2016-05-26 21:13:10 +00:00
|
|
|
if err != nil {
|
2018-09-14 04:42:50 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
logger.GetReqInfo(ctx).AppendTags("disk", storageDisk.String())
|
|
|
|
logger.LogIf(ctx, err)
|
2018-04-10 16:36:37 +00:00
|
|
|
if IsErr(err, baseErrs...) {
|
2016-10-05 19:48:07 +00:00
|
|
|
offlineDisks++
|
2017-01-02 18:43:56 +00:00
|
|
|
continue
|
2016-10-05 19:48:07 +00:00
|
|
|
}
|
2016-05-26 21:13:10 +00:00
|
|
|
}
|
2016-10-05 19:48:07 +00:00
|
|
|
onlineDisks++
|
2016-10-17 21:31:33 +00:00
|
|
|
disksInfo[i] = info
|
2016-05-26 21:13:10 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 19:48:07 +00:00
|
|
|
// Success.
|
|
|
|
return disksInfo, onlineDisks, offlineDisks
|
|
|
|
}
|
|
|
|
|
2016-10-17 21:31:33 +00:00
|
|
|
// returns sorted disksInfo slice which has only valid entries.
|
|
|
|
// i.e the entries where the total size of the disk is not stated
|
|
|
|
// as 0Bytes, this means that the disk is not online or ignored.
|
2018-05-23 10:11:29 +00:00
|
|
|
func sortValidDisksInfo(disksInfo []DiskInfo) []DiskInfo {
|
|
|
|
var validDisksInfo []DiskInfo
|
2016-10-17 21:31:33 +00:00
|
|
|
for _, diskInfo := range disksInfo {
|
|
|
|
if diskInfo.Total == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
validDisksInfo = append(validDisksInfo, diskInfo)
|
|
|
|
}
|
|
|
|
sort.Sort(byDiskTotal(validDisksInfo))
|
|
|
|
return validDisksInfo
|
|
|
|
}
|
|
|
|
|
2016-10-05 19:48:07 +00:00
|
|
|
// Get an aggregated storage info across all disks.
|
|
|
|
func getStorageInfo(disks []StorageAPI) StorageInfo {
|
|
|
|
disksInfo, onlineDisks, offlineDisks := getDisksInfo(disks)
|
2016-10-17 21:31:33 +00:00
|
|
|
|
|
|
|
// Sort so that the first element is the smallest.
|
|
|
|
validDisksInfo := sortValidDisksInfo(disksInfo)
|
2017-08-04 03:07:22 +00:00
|
|
|
// If there are no valid disks, set total and free disks to 0
|
2016-10-17 21:31:33 +00:00
|
|
|
if len(validDisksInfo) == 0 {
|
2018-05-24 00:30:25 +00:00
|
|
|
return StorageInfo{}
|
2016-09-22 23:35:12 +00:00
|
|
|
}
|
2016-10-17 21:31:33 +00:00
|
|
|
|
2018-01-17 19:25:51 +00:00
|
|
|
_, sscParity := getRedundancyCount(standardStorageClass, len(disks))
|
|
|
|
_, rrscparity := getRedundancyCount(reducedRedundancyStorageClass, len(disks))
|
|
|
|
|
|
|
|
// Total number of online data drives available
|
|
|
|
// This is the number of drives we report free and total space for
|
|
|
|
availableDataDisks := uint64(onlineDisks - sscParity)
|
|
|
|
|
2018-03-28 01:11:39 +00:00
|
|
|
// Available data disks can be zero when onlineDisks is equal to parity,
|
|
|
|
// at that point we simply choose online disks to calculate the size.
|
|
|
|
if availableDataDisks == 0 {
|
|
|
|
availableDataDisks = uint64(onlineDisks)
|
|
|
|
}
|
|
|
|
|
2018-05-24 00:30:25 +00:00
|
|
|
storageInfo := StorageInfo{}
|
2016-10-17 21:31:33 +00:00
|
|
|
|
2018-05-23 10:11:29 +00:00
|
|
|
// Combine all disks to get total usage.
|
|
|
|
var used uint64
|
|
|
|
for _, di := range validDisksInfo {
|
|
|
|
used = used + di.Used
|
|
|
|
}
|
|
|
|
storageInfo.Used = used
|
|
|
|
|
2018-08-24 06:35:37 +00:00
|
|
|
storageInfo.Backend.Type = BackendErasure
|
2016-10-05 19:48:07 +00:00
|
|
|
storageInfo.Backend.OnlineDisks = onlineDisks
|
|
|
|
storageInfo.Backend.OfflineDisks = offlineDisks
|
2017-12-22 11:28:13 +00:00
|
|
|
|
2018-01-17 19:25:51 +00:00
|
|
|
storageInfo.Backend.StandardSCParity = sscParity
|
|
|
|
storageInfo.Backend.RRSCParity = rrscparity
|
2017-12-22 11:28:13 +00:00
|
|
|
|
2016-10-05 19:48:07 +00:00
|
|
|
return storageInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
// StorageInfo - returns underlying storage statistics.
|
2018-03-14 19:01:47 +00:00
|
|
|
func (xl xlObjects) StorageInfo(ctx context.Context) StorageInfo {
|
2018-02-16 01:45:57 +00:00
|
|
|
return getStorageInfo(xl.getDisks())
|
2016-05-26 21:13:10 +00:00
|
|
|
}
|