2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-06-12 23:04:01 -04:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
2021-03-27 02:24:07 -04:00
|
|
|
"strings"
|
2021-03-16 23:06:57 -04:00
|
|
|
"sync"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
|
2021-05-19 17:38:30 -04:00
|
|
|
"github.com/VividCortex/ewma"
|
2021-05-06 11:52:02 -04:00
|
|
|
"github.com/minio/madmin-go"
|
2021-03-16 23:06:57 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:generate stringer -type=storageMetric -trimprefix=storageMetric $GOFILE
|
|
|
|
|
|
|
|
type storageMetric uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
storageMetricMakeVolBulk storageMetric = iota
|
|
|
|
storageMetricMakeVol
|
|
|
|
storageMetricListVols
|
|
|
|
storageMetricStatVol
|
|
|
|
storageMetricDeleteVol
|
|
|
|
storageMetricWalkDir
|
|
|
|
storageMetricListDir
|
|
|
|
storageMetricReadFile
|
|
|
|
storageMetricAppendFile
|
|
|
|
storageMetricCreateFile
|
|
|
|
storageMetricReadFileStream
|
|
|
|
storageMetricRenameFile
|
|
|
|
storageMetricRenameData
|
|
|
|
storageMetricCheckParts
|
|
|
|
storageMetricDelete
|
|
|
|
storageMetricDeleteVersions
|
|
|
|
storageMetricVerifyFile
|
|
|
|
storageMetricWriteAll
|
|
|
|
storageMetricDeleteVersion
|
|
|
|
storageMetricWriteMetadata
|
2021-04-04 16:32:31 -04:00
|
|
|
storageMetricUpdateMetadata
|
2021-03-16 23:06:57 -04:00
|
|
|
storageMetricReadVersion
|
|
|
|
storageMetricReadAll
|
2021-07-09 14:29:16 -04:00
|
|
|
storageStatInfoFile
|
2021-03-16 23:06:57 -04:00
|
|
|
|
|
|
|
// .... add more
|
|
|
|
|
2021-03-27 02:24:07 -04:00
|
|
|
storageMetricLast
|
2020-06-12 23:04:01 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Detects change in underlying disk.
|
|
|
|
type xlStorageDiskIDCheck struct {
|
2021-04-02 01:12:03 -04:00
|
|
|
// fields position optimized for memory please
|
|
|
|
// do not re-order them, if you add new fields
|
|
|
|
// please use `fieldalignment ./...` to check
|
|
|
|
// if your changes are not causing any problems.
|
|
|
|
storage StorageAPI
|
2021-03-27 02:24:07 -04:00
|
|
|
apiLatencies [storageMetricLast]ewma.MovingAverage
|
2021-04-02 01:12:03 -04:00
|
|
|
diskID string
|
|
|
|
apiCalls [storageMetricLast]uint64
|
2021-03-16 23:06:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *xlStorageDiskIDCheck) getMetrics() DiskMetrics {
|
|
|
|
diskMetric := DiskMetrics{
|
|
|
|
APILatencies: make(map[string]string),
|
|
|
|
APICalls: make(map[string]uint64),
|
|
|
|
}
|
|
|
|
for i, v := range p.apiLatencies {
|
|
|
|
diskMetric.APILatencies[storageMetric(i).String()] = time.Duration(v.Value()).String()
|
|
|
|
}
|
|
|
|
for i := range p.apiCalls {
|
|
|
|
diskMetric.APICalls[storageMetric(i).String()] = atomic.LoadUint64(&p.apiCalls[i])
|
|
|
|
}
|
|
|
|
return diskMetric
|
|
|
|
}
|
|
|
|
|
|
|
|
type lockedSimpleEWMA struct {
|
|
|
|
sync.RWMutex
|
|
|
|
*ewma.SimpleEWMA
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *lockedSimpleEWMA) Add(value float64) {
|
|
|
|
e.Lock()
|
|
|
|
defer e.Unlock()
|
|
|
|
e.SimpleEWMA.Add(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *lockedSimpleEWMA) Set(value float64) {
|
|
|
|
e.Lock()
|
|
|
|
defer e.Unlock()
|
|
|
|
|
|
|
|
e.SimpleEWMA.Set(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *lockedSimpleEWMA) Value() float64 {
|
|
|
|
e.RLock()
|
|
|
|
defer e.RUnlock()
|
|
|
|
return e.SimpleEWMA.Value()
|
|
|
|
}
|
|
|
|
|
|
|
|
func newXLStorageDiskIDCheck(storage *xlStorage) *xlStorageDiskIDCheck {
|
|
|
|
xl := xlStorageDiskIDCheck{
|
|
|
|
storage: storage,
|
|
|
|
}
|
|
|
|
for i := range xl.apiLatencies[:] {
|
|
|
|
xl.apiLatencies[i] = &lockedSimpleEWMA{
|
|
|
|
SimpleEWMA: new(ewma.SimpleEWMA),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &xl
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *xlStorageDiskIDCheck) String() string {
|
|
|
|
return p.storage.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *xlStorageDiskIDCheck) IsOnline() bool {
|
|
|
|
storedDiskID, err := p.storage.GetDiskID()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return storedDiskID == p.diskID
|
|
|
|
}
|
|
|
|
|
2021-05-11 12:19:15 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) LastConn() time.Time {
|
|
|
|
return p.storage.LastConn()
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) IsLocal() bool {
|
|
|
|
return p.storage.IsLocal()
|
|
|
|
}
|
|
|
|
|
2020-09-28 22:39:32 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) Endpoint() Endpoint {
|
|
|
|
return p.storage.Endpoint()
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) Hostname() string {
|
|
|
|
return p.storage.Hostname()
|
|
|
|
}
|
|
|
|
|
2021-03-04 17:36:23 -05:00
|
|
|
func (p *xlStorageDiskIDCheck) Healing() *healingTracker {
|
2020-09-28 22:39:32 -04:00
|
|
|
return p.storage.Healing()
|
|
|
|
}
|
|
|
|
|
2021-05-19 17:38:30 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry) (dataUsageCache, error) {
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return dataUsageCache{}, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return dataUsageCache{}, err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2021-05-19 17:38:30 -04:00
|
|
|
return p.storage.NSScanner(ctx, cache, updates)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2021-03-04 17:36:23 -05:00
|
|
|
func (p *xlStorageDiskIDCheck) GetDiskLoc() (poolIdx, setIdx, diskIdx int) {
|
|
|
|
return p.storage.GetDiskLoc()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *xlStorageDiskIDCheck) SetDiskLoc(poolIdx, setIdx, diskIdx int) {
|
|
|
|
p.storage.SetDiskLoc(poolIdx, setIdx, diskIdx)
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) Close() error {
|
|
|
|
return p.storage.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *xlStorageDiskIDCheck) GetDiskID() (string, error) {
|
|
|
|
return p.storage.GetDiskID()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *xlStorageDiskIDCheck) SetDiskID(id string) {
|
|
|
|
p.diskID = id
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) checkDiskStale() error {
|
2020-06-12 23:04:01 -04:00
|
|
|
if p.diskID == "" {
|
2020-07-13 12:51:07 -04:00
|
|
|
// For empty disk-id we allow the call as the server might be
|
|
|
|
// coming up and trying to read format.json or create format.json
|
|
|
|
return nil
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
storedDiskID, err := p.storage.GetDiskID()
|
2020-07-13 12:51:07 -04:00
|
|
|
if err != nil {
|
|
|
|
// return any error generated while reading `format.json`
|
|
|
|
return err
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
if err == nil && p.diskID == storedDiskID {
|
2020-07-13 12:51:07 -04:00
|
|
|
return nil
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
// not the same disk we remember, take it offline.
|
|
|
|
return errDiskNotFound
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) DiskInfo(ctx context.Context) (info DiskInfo, err error) {
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return DiskInfo{}, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
info, err = p.storage.DiskInfo(ctx)
|
2020-07-13 12:51:07 -04:00
|
|
|
if err != nil {
|
|
|
|
return info, err
|
|
|
|
}
|
2021-03-16 23:06:57 -04:00
|
|
|
|
|
|
|
info.Metrics = p.getMetrics()
|
2020-07-16 10:30:05 -04:00
|
|
|
// check cached diskID against backend
|
|
|
|
// only if its non-empty.
|
|
|
|
if p.diskID != "" {
|
|
|
|
if p.diskID != info.ID {
|
|
|
|
return info, errDiskNotFound
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
return info, nil
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) MakeVolBulk(ctx context.Context, volumes ...string) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricMakeVolBulk, volumes...)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.MakeVolBulk(ctx, volumes...)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) MakeVol(ctx context.Context, volume string) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricMakeVol, volume)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.MakeVol(ctx, volume)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) ListVols(ctx context.Context) ([]VolInfo, error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricListVols, "/")()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return nil, err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.ListVols(ctx)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) StatVol(ctx context.Context, volume string) (vol VolInfo, err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricStatVol, volume)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return VolInfo{}, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return vol, err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.StatVol(ctx, volume)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) DeleteVol(ctx context.Context, volume string, forceDelete bool) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricDeleteVol, volume)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.DeleteVol(ctx, volume, forceDelete)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) ListDir(ctx context.Context, volume, dirPath string, count int) ([]string, error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricListDir, volume, dirPath)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return nil, err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.ListDir(ctx, volume, dirPath, count)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) ReadFile(ctx context.Context, volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricReadFile, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return 0, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return 0, err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.ReadFile(ctx, volume, path, offset, buf, verifier)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) AppendFile(ctx context.Context, volume string, path string, buf []byte) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricAppendFile, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.AppendFile(ctx, volume, path, buf)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) CreateFile(ctx context.Context, volume, path string, size int64, reader io.Reader) error {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricCreateFile, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.CreateFile(ctx, volume, path, size, reader)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) ReadFileStream(ctx context.Context, volume, path string, offset, length int64) (io.ReadCloser, error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricReadFileStream, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return nil, err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.ReadFileStream(ctx, volume, path, offset, length)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string) error {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricRenameFile, srcVolume, srcPath, dstVolume, dstPath)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.RenameFile(ctx, srcVolume, srcPath, dstVolume, dstPath)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2021-04-20 13:44:39 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) RenameData(ctx context.Context, srcVolume, srcPath string, fi FileInfo, dstVolume, dstPath string) error {
|
|
|
|
defer p.updateStorageMetrics(storageMetricRenameData, srcPath, fi.DataDir, dstVolume, dstPath)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2021-04-20 13:44:39 -04:00
|
|
|
return p.storage.RenameData(ctx, srcVolume, srcPath, fi, dstVolume, dstPath)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) CheckParts(ctx context.Context, volume string, path string, fi FileInfo) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricCheckParts, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.CheckParts(ctx, volume, path, fi)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:18:35 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) Delete(ctx context.Context, volume string, path string, recursive bool) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricDelete, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-10-28 12:18:35 -04:00
|
|
|
return p.storage.Delete(ctx, volume, path, recursive)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2021-03-27 02:24:07 -04:00
|
|
|
// DeleteVersions deletes slice of versions, it can be same object
|
|
|
|
// or multiple objects.
|
2021-11-01 13:50:07 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) DeleteVersions(ctx context.Context, volume string, versions []FileInfoVersions) (errs []error) {
|
|
|
|
// Merely for tracing storage
|
2021-03-27 02:24:07 -04:00
|
|
|
path := ""
|
|
|
|
if len(versions) > 0 {
|
|
|
|
path = versions[0].Name
|
|
|
|
}
|
|
|
|
|
|
|
|
defer p.updateStorageMetrics(storageMetricDeleteVersions, volume, path)()
|
|
|
|
|
|
|
|
errs = make([]error, len(versions))
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-16 23:06:57 -04:00
|
|
|
for i := range errs {
|
|
|
|
errs[i] = ctx.Err()
|
|
|
|
}
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
for i := range errs {
|
2020-07-13 12:51:07 -04:00
|
|
|
errs[i] = err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
return errs
|
|
|
|
}
|
2021-03-27 02:24:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.DeleteVersions(ctx, volume, versions)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) VerifyFile(ctx context.Context, volume, path string, fi FileInfo) error {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricVerifyFile, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err := p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.VerifyFile(ctx, volume, path, fi)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-11-02 19:14:31 -05:00
|
|
|
func (p *xlStorageDiskIDCheck) WriteAll(ctx context.Context, volume string, path string, b []byte) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricWriteAll, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-11-02 19:14:31 -05:00
|
|
|
return p.storage.WriteAll(ctx, volume, path, b)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2021-02-03 13:33:43 -05:00
|
|
|
func (p *xlStorageDiskIDCheck) DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricDeleteVersion, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2021-02-03 13:33:43 -05:00
|
|
|
return p.storage.DeleteVersion(ctx, volume, path, fi, forceDelMarker)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo) (err error) {
|
|
|
|
defer p.updateStorageMetrics(storageMetricUpdateMetadata, volume, path)()
|
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-04-04 16:32:31 -04:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.storage.UpdateMetadata(ctx, volume, path, fi)
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) WriteMetadata(ctx context.Context, volume, path string, fi FileInfo) (err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricWriteMetadata, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.WriteMetadata(ctx, volume, path, fi)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
func (p *xlStorageDiskIDCheck) ReadVersion(ctx context.Context, volume, path, versionID string, readData bool) (fi FileInfo, err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricReadVersion, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return fi, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return fi, err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
return p.storage.ReadVersion(ctx, volume, path, versionID, readData)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) ReadAll(ctx context.Context, volume string, path string) (buf []byte, err error) {
|
2021-03-27 02:24:07 -04:00
|
|
|
defer p.updateStorageMetrics(storageMetricReadAll, volume, path)()
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-03-03 21:36:43 -05:00
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
if err = p.checkDiskStale(); err != nil {
|
|
|
|
return nil, err
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
return p.storage.ReadAll(ctx, volume, path)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2021-03-16 23:06:57 -04:00
|
|
|
|
2021-10-01 14:50:00 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) StatInfoFile(ctx context.Context, volume, path string, glob bool) (stat []StatInfo, err error) {
|
2021-07-09 14:29:16 -04:00
|
|
|
defer p.updateStorageMetrics(storageStatInfoFile, volume, path)()
|
|
|
|
|
2021-09-17 17:11:01 -04:00
|
|
|
if contextCanceled(ctx) {
|
2021-10-01 14:50:00 -04:00
|
|
|
return nil, ctx.Err()
|
2021-07-09 14:29:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = p.checkDiskStale(); err != nil {
|
2021-10-01 14:50:00 -04:00
|
|
|
return nil, err
|
2021-07-09 14:29:16 -04:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:50:00 -04:00
|
|
|
return p.storage.StatInfoFile(ctx, volume, path, glob)
|
2021-07-09 14:29:16 -04:00
|
|
|
}
|
|
|
|
|
2021-05-06 11:52:02 -04:00
|
|
|
func storageTrace(s storageMetric, startTime time.Time, duration time.Duration, path string) madmin.TraceInfo {
|
|
|
|
return madmin.TraceInfo{
|
|
|
|
TraceType: madmin.TraceStorage,
|
2021-03-27 02:24:07 -04:00
|
|
|
Time: startTime,
|
|
|
|
NodeName: globalLocalNodeName,
|
2021-03-27 13:07:07 -04:00
|
|
|
FuncName: "storage." + s.String(),
|
2021-05-06 11:52:02 -04:00
|
|
|
StorageStats: madmin.TraceStorageStats{
|
2021-03-27 02:24:07 -04:00
|
|
|
Duration: duration,
|
|
|
|
Path: path,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 23:06:57 -04:00
|
|
|
// Update storage metrics
|
2021-03-27 02:24:07 -04:00
|
|
|
func (p *xlStorageDiskIDCheck) updateStorageMetrics(s storageMetric, paths ...string) func() {
|
2021-03-16 23:06:57 -04:00
|
|
|
startTime := time.Now()
|
2021-03-27 02:24:07 -04:00
|
|
|
trace := globalTrace.NumSubscribers() > 0
|
2021-03-16 23:06:57 -04:00
|
|
|
return func() {
|
2021-03-27 02:24:07 -04:00
|
|
|
duration := time.Since(startTime)
|
|
|
|
|
2021-03-16 23:06:57 -04:00
|
|
|
atomic.AddUint64(&p.apiCalls[s], 1)
|
2021-03-27 02:24:07 -04:00
|
|
|
p.apiLatencies[s].Add(float64(duration))
|
|
|
|
|
|
|
|
if trace {
|
|
|
|
globalTrace.Publish(storageTrace(s, startTime, duration, strings.Join(paths, " ")))
|
|
|
|
}
|
2021-03-16 23:06:57 -04:00
|
|
|
}
|
|
|
|
}
|