2016-05-20 23:48:47 -04:00
|
|
|
/*
|
2018-02-12 04:46:12 -05:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017, 2018 Minio, Inc.
|
2016-05-20 23:48:47 -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.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
import (
|
2018-03-14 15:01:47 -04:00
|
|
|
"context"
|
2016-05-26 17:13:10 -04:00
|
|
|
"sort"
|
2018-01-12 23:34:52 -05:00
|
|
|
"time"
|
2016-05-26 17:13:10 -04:00
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-02-15 20:45:57 -05:00
|
|
|
"github.com/minio/minio/pkg/bpool"
|
2016-05-26 17:13:10 -04:00
|
|
|
"github.com/minio/minio/pkg/disk"
|
2016-05-20 23:48:47 -04:00
|
|
|
)
|
|
|
|
|
2016-05-30 19:51:59 -04:00
|
|
|
// XL constants.
|
2016-05-20 23:48:47 -04:00
|
|
|
const (
|
2016-05-30 19:51:59 -04:00
|
|
|
// XL metadata file carries per object metadata.
|
|
|
|
xlMetaJSONFile = "xl.json"
|
2016-05-20 23:48:47 -04:00
|
|
|
)
|
|
|
|
|
2016-05-30 19:51:59 -04:00
|
|
|
// xlObjects - Implements XL object layer.
|
2016-05-20 23:48:47 -04:00
|
|
|
type xlObjects struct {
|
2018-02-15 20:45:57 -05:00
|
|
|
// name space mutex for object layer.
|
|
|
|
nsMutex *nsLockMap
|
2016-05-30 19:51:59 -04:00
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// getDisks returns list of storageAPIs.
|
|
|
|
getDisks func() []StorageAPI
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// Byte pools used for temporary i/o buffers.
|
|
|
|
bp *bpool.BytePoolCap
|
2018-02-12 04:46:12 -05:00
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// Variable represents bucket policies in memory.
|
|
|
|
bucketPolicies *bucketPolicies
|
2017-01-16 20:05:00 -05:00
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// TODO: Deprecated only kept here for tests, should be removed in future.
|
|
|
|
storageDisks []StorageAPI
|
2017-01-16 20:05:00 -05:00
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// TODO: ListObjects pool management, should be removed in future.
|
|
|
|
listPool *treeWalkPool
|
2017-01-16 20:05:00 -05:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// list of all errors that can be ignored in tree walk operation in XL
|
|
|
|
var xlTreeWalkIgnoredErrs = append(baseIgnoredErrs, errDiskAccessDenied, errVolumeNotFound, errFileNotFound)
|
2016-05-26 17:13:10 -04:00
|
|
|
|
2016-08-15 02:55:48 -04:00
|
|
|
// Shutdown function for object storage interface.
|
2018-03-14 15:01:47 -04:00
|
|
|
func (xl xlObjects) Shutdown(ctx context.Context) error {
|
2016-08-15 02:55:48 -04:00
|
|
|
// Add any object layer shutdown activities here.
|
2018-04-04 00:58:48 -04:00
|
|
|
closeStorageDisks(xl.getDisks())
|
2016-08-15 02:55:48 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-12 23:34:52 -05:00
|
|
|
// Locking operations
|
|
|
|
|
|
|
|
// List namespace locks held in object layer
|
2018-03-14 15:01:47 -04:00
|
|
|
func (xl xlObjects) ListLocks(ctx context.Context, bucket, prefix string, duration time.Duration) ([]VolumeLockInfo, error) {
|
2018-01-12 23:34:52 -05:00
|
|
|
xl.nsMutex.lockMapMutex.Lock()
|
|
|
|
defer xl.nsMutex.lockMapMutex.Unlock()
|
|
|
|
// Fetch current time once instead of fetching system time for every lock.
|
|
|
|
timeNow := UTCNow()
|
|
|
|
volumeLocks := []VolumeLockInfo{}
|
|
|
|
|
|
|
|
for param, debugLock := range xl.nsMutex.debugLockMap {
|
|
|
|
if param.volume != bucket {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// N B empty prefix matches all param.path.
|
|
|
|
if !hasPrefix(param.path, prefix) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
volLockInfo := VolumeLockInfo{
|
|
|
|
Bucket: param.volume,
|
|
|
|
Object: param.path,
|
|
|
|
LocksOnObject: debugLock.counters.total,
|
|
|
|
TotalBlockedLocks: debugLock.counters.blocked,
|
|
|
|
LocksAcquiredOnObject: debugLock.counters.granted,
|
|
|
|
}
|
|
|
|
// Filter locks that are held on bucket, prefix.
|
|
|
|
for opsID, lockInfo := range debugLock.lockInfo {
|
|
|
|
// filter locks that were held for longer than duration.
|
|
|
|
elapsed := timeNow.Sub(lockInfo.since)
|
|
|
|
if elapsed < duration {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Add locks that are held for longer than duration.
|
|
|
|
volLockInfo.LockDetailsOnObject = append(volLockInfo.LockDetailsOnObject,
|
|
|
|
OpsLockState{
|
|
|
|
OperationID: opsID,
|
|
|
|
LockSource: lockInfo.lockSource,
|
|
|
|
LockType: lockInfo.lType,
|
|
|
|
Status: lockInfo.status,
|
|
|
|
Since: lockInfo.since,
|
|
|
|
})
|
|
|
|
volumeLocks = append(volumeLocks, volLockInfo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return volumeLocks, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear namespace locks held in object layer
|
2018-03-14 15:01:47 -04:00
|
|
|
func (xl xlObjects) ClearLocks(ctx context.Context, volLocks []VolumeLockInfo) error {
|
2018-01-12 23:34:52 -05:00
|
|
|
// Remove lock matching bucket/prefix held longer than duration.
|
|
|
|
for _, volLock := range volLocks {
|
|
|
|
xl.nsMutex.ForceUnlock(volLock.Bucket, volLock.Object)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-26 17:13:10 -04:00
|
|
|
// byDiskTotal is a collection satisfying sort.Interface.
|
|
|
|
type byDiskTotal []disk.Info
|
|
|
|
|
|
|
|
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 15:48:07 -04:00
|
|
|
// getDisksInfo - fetch disks info across all other storage API.
|
|
|
|
func getDisksInfo(disks []StorageAPI) (disksInfo []disk.Info, onlineDisks int, offlineDisks int) {
|
2016-10-17 17:31:33 -04:00
|
|
|
disksInfo = make([]disk.Info, len(disks))
|
|
|
|
for i, storageDisk := range disks {
|
2016-09-15 02:53:42 -04:00
|
|
|
if storageDisk == nil {
|
|
|
|
// Storage disk is empty, perhaps ignored disk or not available.
|
2016-10-05 15:48:07 -04:00
|
|
|
offlineDisks++
|
2016-09-15 02:53:42 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-08-25 20:16:34 -04:00
|
|
|
info, err := storageDisk.DiskInfo()
|
2016-05-26 17:13:10 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
logger.LogIf(context.Background(), err)
|
2018-04-10 12:36:37 -04:00
|
|
|
if IsErr(err, baseErrs...) {
|
2016-10-05 15:48:07 -04:00
|
|
|
offlineDisks++
|
2017-01-02 13:43:56 -05:00
|
|
|
continue
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
2016-05-26 17:13:10 -04:00
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
onlineDisks++
|
2016-10-17 17:31:33 -04:00
|
|
|
disksInfo[i] = info
|
2016-05-26 17:13:10 -04:00
|
|
|
}
|
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
// Success.
|
|
|
|
return disksInfo, onlineDisks, offlineDisks
|
|
|
|
}
|
|
|
|
|
2016-10-17 17:31:33 -04: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.
|
|
|
|
func sortValidDisksInfo(disksInfo []disk.Info) []disk.Info {
|
|
|
|
var validDisksInfo []disk.Info
|
|
|
|
for _, diskInfo := range disksInfo {
|
|
|
|
if diskInfo.Total == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
validDisksInfo = append(validDisksInfo, diskInfo)
|
|
|
|
}
|
|
|
|
sort.Sort(byDiskTotal(validDisksInfo))
|
|
|
|
return validDisksInfo
|
|
|
|
}
|
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
// Get an aggregated storage info across all disks.
|
|
|
|
func getStorageInfo(disks []StorageAPI) StorageInfo {
|
|
|
|
disksInfo, onlineDisks, offlineDisks := getDisksInfo(disks)
|
2016-10-17 17:31:33 -04:00
|
|
|
|
|
|
|
// Sort so that the first element is the smallest.
|
|
|
|
validDisksInfo := sortValidDisksInfo(disksInfo)
|
2017-08-03 23:07:22 -04:00
|
|
|
// If there are no valid disks, set total and free disks to 0
|
2016-10-17 17:31:33 -04:00
|
|
|
if len(validDisksInfo) == 0 {
|
2016-09-22 19:35:12 -04:00
|
|
|
return StorageInfo{
|
2017-08-03 23:07:22 -04:00
|
|
|
Total: 0,
|
|
|
|
Free: 0,
|
2016-09-22 19:35:12 -04:00
|
|
|
}
|
|
|
|
}
|
2016-10-17 17:31:33 -04:00
|
|
|
|
2018-01-17 14:25:51 -05: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-27 21:11:39 -04: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)
|
|
|
|
}
|
|
|
|
|
2016-05-26 17:13:10 -04:00
|
|
|
// Return calculated storage info, choose the lowest Total and
|
|
|
|
// Free as the total aggregated values. Total capacity is always
|
|
|
|
// the multiple of smallest disk among the disk list.
|
2016-10-05 15:48:07 -04:00
|
|
|
storageInfo := StorageInfo{
|
2018-01-17 14:25:51 -05:00
|
|
|
Total: validDisksInfo[0].Total * availableDataDisks,
|
|
|
|
Free: validDisksInfo[0].Free * availableDataDisks,
|
2016-05-26 17:13:10 -04:00
|
|
|
}
|
2016-10-17 17:31:33 -04:00
|
|
|
|
2017-02-10 02:26:44 -05:00
|
|
|
storageInfo.Backend.Type = Erasure
|
2016-10-05 15:48:07 -04:00
|
|
|
storageInfo.Backend.OnlineDisks = onlineDisks
|
|
|
|
storageInfo.Backend.OfflineDisks = offlineDisks
|
2017-12-22 06:28:13 -05:00
|
|
|
|
2018-01-17 14:25:51 -05:00
|
|
|
storageInfo.Backend.StandardSCParity = sscParity
|
|
|
|
storageInfo.Backend.RRSCParity = rrscparity
|
2017-12-22 06:28:13 -05:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
return storageInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
// StorageInfo - returns underlying storage statistics.
|
2018-03-14 15:01:47 -04:00
|
|
|
func (xl xlObjects) StorageInfo(ctx context.Context) StorageInfo {
|
2018-02-15 20:45:57 -05:00
|
|
|
return getStorageInfo(xl.getDisks())
|
2016-05-26 17:13:10 -04:00
|
|
|
}
|