2018-02-15 20:45:57 -05:00
|
|
|
/*
|
2019-10-21 17:43:04 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2018-2019 MinIO, Inc.
|
2018-02-15 20:45:57 -05: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-03-14 15:01:47 -04:00
|
|
|
"context"
|
2020-08-18 17:37:26 -04:00
|
|
|
"errors"
|
2018-02-15 20:45:57 -05:00
|
|
|
"fmt"
|
|
|
|
"hash/crc32"
|
|
|
|
"io"
|
2018-09-20 22:22:09 -04:00
|
|
|
"net/http"
|
2020-05-06 17:25:05 -04:00
|
|
|
"sort"
|
2018-02-15 20:45:57 -05:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
"github.com/dchest/siphash"
|
|
|
|
"github.com/google/uuid"
|
2020-07-14 12:38:05 -04:00
|
|
|
"github.com/minio/minio-go/v7/pkg/tags"
|
2019-10-07 01:50:24 -04:00
|
|
|
"github.com/minio/minio/cmd/config/storageclass"
|
2019-12-06 02:16:06 -05:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-02-15 20:45:57 -05:00
|
|
|
"github.com/minio/minio/pkg/bpool"
|
2019-11-13 15:17:45 -05:00
|
|
|
"github.com/minio/minio/pkg/dsync"
|
2018-02-15 20:45:57 -05:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
|
|
|
"github.com/minio/minio/pkg/sync/errgroup"
|
|
|
|
)
|
|
|
|
|
2019-11-13 15:17:45 -05:00
|
|
|
// setsDsyncLockers is encapsulated type for Close()
|
|
|
|
type setsDsyncLockers [][]dsync.NetLocker
|
|
|
|
|
2020-01-15 21:30:32 -05:00
|
|
|
// Information of a new disk connection
|
|
|
|
type diskConnectInfo struct {
|
|
|
|
setIndex int
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// erasureSets implements ObjectLayer combining a static list of erasure coded
|
2018-02-15 20:45:57 -05:00
|
|
|
// object sets. NOTE: There is no dynamic scaling allowed or intended in
|
|
|
|
// current design.
|
2020-06-12 23:04:01 -04:00
|
|
|
type erasureSets struct {
|
2020-05-19 16:53:54 -04:00
|
|
|
GatewayUnsupported
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
sets []*erasureObjects
|
2018-02-15 20:45:57 -05:00
|
|
|
|
|
|
|
// Reference format.
|
2020-06-12 23:04:01 -04:00
|
|
|
format *formatErasureV3
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// erasureDisks mutex to lock erasureDisks.
|
|
|
|
erasureDisksMu sync.RWMutex
|
2018-02-15 20:45:57 -05:00
|
|
|
|
|
|
|
// Re-ordered list of disks per set.
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks [][]StorageAPI
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2019-11-13 15:17:45 -05:00
|
|
|
// Distributed locker clients.
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureLockers setsDsyncLockers
|
2019-11-13 15:17:45 -05:00
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// List of endpoints provided on the command line.
|
2019-11-19 20:42:27 -05:00
|
|
|
endpoints Endpoints
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2020-03-24 21:53:24 -04:00
|
|
|
// String version of all the endpoints, an optimization
|
|
|
|
// to avoid url.String() conversion taking CPU on
|
|
|
|
// large disk setups.
|
|
|
|
endpointStrings []string
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// Total number of sets and the number of disks per set.
|
|
|
|
setCount, drivesPerSet int
|
|
|
|
|
2020-01-15 21:30:32 -05:00
|
|
|
disksConnectEvent chan diskConnectInfo
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// Done channel to control monitoring loop.
|
|
|
|
disksConnectDoneCh chan struct{}
|
|
|
|
|
|
|
|
// Distribution algorithm of choice.
|
|
|
|
distributionAlgo string
|
2020-06-12 23:04:01 -04:00
|
|
|
deploymentID [16]byte
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2020-05-26 15:52:24 -04:00
|
|
|
disksStorageInfoCache timedValue
|
|
|
|
|
2019-05-14 16:49:10 -04:00
|
|
|
// Merge tree walk
|
2020-06-12 23:04:01 -04:00
|
|
|
pool *MergeWalkPool
|
|
|
|
poolSplunk *MergeWalkPool
|
|
|
|
poolVersions *MergeWalkVersionsPool
|
2020-01-15 21:30:32 -05:00
|
|
|
|
2020-06-29 16:07:26 -04:00
|
|
|
mrfMU sync.Mutex
|
|
|
|
mrfOperations map[healSource]int
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2020-03-25 02:26:13 -04:00
|
|
|
func isEndpointConnected(diskMap map[string]StorageAPI, endpoint string) bool {
|
|
|
|
disk := diskMap[endpoint]
|
|
|
|
if disk == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return disk.IsOnline()
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) getDiskMap() map[string]StorageAPI {
|
2020-03-25 02:26:13 -04:00
|
|
|
diskMap := make(map[string]StorageAPI)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisksMu.RLock()
|
|
|
|
defer s.erasureDisksMu.RUnlock()
|
2018-02-15 20:45:57 -05:00
|
|
|
|
|
|
|
for i := 0; i < s.setCount; i++ {
|
|
|
|
for j := 0; j < s.drivesPerSet; j++ {
|
2020-06-12 23:04:01 -04:00
|
|
|
disk := s.erasureDisks[i][j]
|
2020-03-25 02:26:13 -04:00
|
|
|
if disk == nil {
|
2018-02-15 20:45:57 -05:00
|
|
|
continue
|
|
|
|
}
|
2020-03-25 02:26:13 -04:00
|
|
|
if !disk.IsOnline() {
|
2018-02-15 20:45:57 -05:00
|
|
|
continue
|
|
|
|
}
|
2020-03-25 02:26:13 -04:00
|
|
|
diskMap[disk.String()] = disk
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
}
|
2020-03-25 02:26:13 -04:00
|
|
|
return diskMap
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initializes a new StorageAPI from the endpoint argument, returns
|
|
|
|
// StorageAPI and also `format` which exists on the disk.
|
2020-06-12 23:04:01 -04:00
|
|
|
func connectEndpoint(endpoint Endpoint) (StorageAPI, *formatErasureV3, error) {
|
2018-02-15 20:45:57 -05:00
|
|
|
disk, err := newStorageAPI(endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
format, err := loadFormatErasure(disk)
|
2018-02-15 20:45:57 -05:00
|
|
|
if err != nil {
|
2018-04-04 00:58:48 -04:00
|
|
|
// Close the internal connection to avoid connection leaks.
|
2018-02-15 20:45:57 -05:00
|
|
|
disk.Close()
|
2020-08-18 17:37:26 -04:00
|
|
|
if errors.Is(err, errUnformattedDisk) {
|
|
|
|
info, derr := disk.DiskInfo()
|
|
|
|
if derr != nil && info.RootDisk {
|
|
|
|
return nil, nil, fmt.Errorf("Disk: %s returned %w but its a root disk refusing to use it",
|
|
|
|
disk, derr) // make sure to '%w' to wrap the error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil, fmt.Errorf("Disk: %s returned %w", disk, err) // make sure to '%w' to wrap the error
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return disk, format, nil
|
|
|
|
}
|
|
|
|
|
2020-03-27 17:48:30 -04:00
|
|
|
// findDiskIndex - returns the i,j'th position of the input `diskID` against the reference
|
|
|
|
// format, after successful validation.
|
|
|
|
// - i'th position is the set index
|
|
|
|
// - j'th position is the disk index in the current set
|
2020-06-12 23:04:01 -04:00
|
|
|
func findDiskIndexByDiskID(refFormat *formatErasureV3, diskID string) (int, int, error) {
|
2020-03-27 17:48:30 -04:00
|
|
|
if diskID == offlineDiskUUID {
|
|
|
|
return -1, -1, fmt.Errorf("diskID: %s is offline", diskID)
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
for i := 0; i < len(refFormat.Erasure.Sets); i++ {
|
|
|
|
for j := 0; j < len(refFormat.Erasure.Sets[0]); j++ {
|
|
|
|
if refFormat.Erasure.Sets[i][j] == diskID {
|
2020-03-27 17:48:30 -04:00
|
|
|
return i, j, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1, -1, fmt.Errorf("diskID: %s not found", diskID)
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// findDiskIndex - returns the i,j'th position of the input `format` against the reference
|
|
|
|
// format, after successful validation.
|
2020-01-15 21:30:32 -05:00
|
|
|
// - i'th position is the set index
|
|
|
|
// - j'th position is the disk index in the current set
|
2020-06-12 23:04:01 -04:00
|
|
|
func findDiskIndex(refFormat, format *formatErasureV3) (int, int, error) {
|
|
|
|
if err := formatErasureV3Check(refFormat, format); err != nil {
|
2018-02-15 20:45:57 -05:00
|
|
|
return 0, 0, err
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if format.Erasure.This == offlineDiskUUID {
|
|
|
|
return -1, -1, fmt.Errorf("diskID: %s is offline", format.Erasure.This)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
for i := 0; i < len(refFormat.Erasure.Sets); i++ {
|
|
|
|
for j := 0; j < len(refFormat.Erasure.Sets[0]); j++ {
|
|
|
|
if refFormat.Erasure.Sets[i][j] == format.Erasure.This {
|
2018-02-15 20:45:57 -05:00
|
|
|
return i, j, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
return -1, -1, fmt.Errorf("diskID: %s not found", format.Erasure.This)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2020-01-10 05:35:06 -05:00
|
|
|
// connectDisks - attempt to connect all the endpoints, loads format
|
2018-03-27 21:11:39 -04:00
|
|
|
// and re-arranges the disks in proper position.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) connectDisks() {
|
2020-03-25 02:26:13 -04:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
diskMap := s.getDiskMap()
|
2020-06-10 20:10:31 -04:00
|
|
|
for _, endpoint := range s.endpoints {
|
2020-06-11 11:05:25 -04:00
|
|
|
diskPath := endpoint.String()
|
|
|
|
if endpoint.IsLocal {
|
|
|
|
diskPath = endpoint.Path
|
|
|
|
}
|
|
|
|
if isEndpointConnected(diskMap, diskPath) {
|
2018-03-27 21:11:39 -04:00
|
|
|
continue
|
|
|
|
}
|
2020-03-25 02:26:13 -04:00
|
|
|
wg.Add(1)
|
|
|
|
go func(endpoint Endpoint) {
|
|
|
|
defer wg.Done()
|
|
|
|
disk, format, err := connectEndpoint(endpoint)
|
|
|
|
if err != nil {
|
2020-07-17 13:08:04 -04:00
|
|
|
printEndpointError(endpoint, err, true)
|
2020-03-25 02:26:13 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
setIndex, diskIndex, err := findDiskIndex(s.format, format)
|
|
|
|
if err != nil {
|
|
|
|
// Close the internal connection to avoid connection leaks.
|
|
|
|
disk.Close()
|
2020-07-17 13:08:04 -04:00
|
|
|
printEndpointError(endpoint, err, false)
|
2020-03-25 02:26:13 -04:00
|
|
|
return
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
disk.SetDiskID(format.Erasure.This)
|
|
|
|
s.erasureDisksMu.Lock()
|
|
|
|
if s.erasureDisks[setIndex][diskIndex] != nil {
|
|
|
|
s.erasureDisks[setIndex][diskIndex].Close()
|
2020-04-03 21:06:31 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisks[setIndex][diskIndex] = disk
|
2020-06-10 20:10:31 -04:00
|
|
|
s.endpointStrings[setIndex*s.drivesPerSet+diskIndex] = disk.String()
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisksMu.Unlock()
|
2020-03-25 02:26:13 -04:00
|
|
|
go func(setIndex int) {
|
|
|
|
// Send a new disk connect event with a timeout
|
|
|
|
select {
|
|
|
|
case s.disksConnectEvent <- diskConnectInfo{setIndex: setIndex}:
|
|
|
|
case <-time.After(100 * time.Millisecond):
|
|
|
|
}
|
|
|
|
}(setIndex)
|
|
|
|
}(endpoint)
|
2018-03-27 21:11:39 -04:00
|
|
|
}
|
2020-03-25 02:26:13 -04:00
|
|
|
wg.Wait()
|
2018-03-27 21:11:39 -04:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// monitorAndConnectEndpoints this is a monitoring loop to keep track of disconnected
|
|
|
|
// endpoints by reconnecting them and making sure to place them into right position in
|
|
|
|
// the set topology, this monitoring happens at a given monitoring interval.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) monitorAndConnectEndpoints(ctx context.Context, monitorInterval time.Duration) {
|
2018-02-15 20:45:57 -05:00
|
|
|
for {
|
|
|
|
select {
|
2020-03-18 19:19:29 -04:00
|
|
|
case <-ctx.Done():
|
2018-04-09 13:25:41 -04:00
|
|
|
return
|
|
|
|
case <-s.disksConnectDoneCh:
|
2018-02-15 20:45:57 -05:00
|
|
|
return
|
2020-03-24 21:53:24 -04:00
|
|
|
case <-time.After(monitorInterval):
|
2020-01-10 05:35:06 -05:00
|
|
|
s.connectDisks()
|
2019-11-13 15:17:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetLockers(setIndex int) func() []dsync.NetLocker {
|
2019-11-13 15:17:45 -05:00
|
|
|
return func() []dsync.NetLocker {
|
|
|
|
lockers := make([]dsync.NetLocker, s.drivesPerSet)
|
2020-06-12 23:04:01 -04:00
|
|
|
copy(lockers, s.erasureLockers[setIndex])
|
2019-11-13 15:17:45 -05:00
|
|
|
return lockers
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetEndpoints(setIndex int) func() []string {
|
2020-06-10 20:10:31 -04:00
|
|
|
return func() []string {
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisksMu.RLock()
|
|
|
|
defer s.erasureDisksMu.RUnlock()
|
2020-06-10 20:10:31 -04:00
|
|
|
|
|
|
|
eps := make([]string, s.drivesPerSet)
|
|
|
|
for i := 0; i < s.drivesPerSet; i++ {
|
|
|
|
eps[i] = s.endpointStrings[setIndex*s.drivesPerSet+i]
|
|
|
|
}
|
|
|
|
return eps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// GetDisks returns a closure for a given set, which provides list of disks per set.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetDisks(setIndex int) func() []StorageAPI {
|
2018-02-15 20:45:57 -05:00
|
|
|
return func() []StorageAPI {
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisksMu.RLock()
|
|
|
|
defer s.erasureDisksMu.RUnlock()
|
2018-02-15 20:45:57 -05:00
|
|
|
disks := make([]StorageAPI, s.drivesPerSet)
|
2020-06-12 23:04:01 -04:00
|
|
|
copy(disks, s.erasureDisks[setIndex])
|
2018-02-15 20:45:57 -05:00
|
|
|
return disks
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultMonitorConnectEndpointInterval = time.Second * 10 // Set to 10 secs.
|
|
|
|
|
|
|
|
// Initialize new set of erasure coded sets.
|
2020-06-12 23:04:01 -04:00
|
|
|
func newErasureSets(ctx context.Context, endpoints Endpoints, storageDisks []StorageAPI, format *formatErasureV3) (*erasureSets, error) {
|
|
|
|
setCount := len(format.Erasure.Sets)
|
|
|
|
drivesPerSet := len(format.Erasure.Sets[0])
|
2020-04-27 17:39:57 -04:00
|
|
|
|
2020-06-10 20:10:31 -04:00
|
|
|
endpointStrings := make([]string, len(endpoints))
|
2020-06-12 23:04:01 -04:00
|
|
|
// Initialize the erasure sets instance.
|
|
|
|
s := &erasureSets{
|
|
|
|
sets: make([]*erasureObjects, setCount),
|
|
|
|
erasureDisks: make([][]StorageAPI, setCount),
|
|
|
|
erasureLockers: make([][]dsync.NetLocker, setCount),
|
|
|
|
endpoints: endpoints,
|
|
|
|
endpointStrings: endpointStrings,
|
2018-02-15 20:45:57 -05:00
|
|
|
setCount: setCount,
|
|
|
|
drivesPerSet: drivesPerSet,
|
|
|
|
format: format,
|
2020-01-15 21:30:32 -05:00
|
|
|
disksConnectEvent: make(chan diskConnectInfo),
|
2018-02-15 20:45:57 -05:00
|
|
|
disksConnectDoneCh: make(chan struct{}),
|
2020-06-12 23:04:01 -04:00
|
|
|
distributionAlgo: format.Erasure.DistributionAlgo,
|
|
|
|
deploymentID: uuid.MustParse(format.ID),
|
2019-05-14 16:49:10 -04:00
|
|
|
pool: NewMergeWalkPool(globalMergeLookupTimeout),
|
2020-03-22 22:23:47 -04:00
|
|
|
poolSplunk: NewMergeWalkPool(globalMergeLookupTimeout),
|
2020-06-12 23:04:01 -04:00
|
|
|
poolVersions: NewMergeWalkVersionsPool(globalMergeLookupTimeout),
|
2020-06-29 16:07:26 -04:00
|
|
|
mrfOperations: make(map[healSource]int),
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
mutex := newNSLock(globalIsDistErasure)
|
2018-06-01 19:41:23 -04:00
|
|
|
|
|
|
|
// Initialize byte pool once for all sets, bpool size is set to
|
|
|
|
// setCount * drivesPerSet with each memory upto blockSizeV1.
|
|
|
|
bp := bpool.NewBytePoolCap(setCount*drivesPerSet, blockSizeV1, blockSizeV1*2)
|
|
|
|
|
2020-03-27 17:48:30 -04:00
|
|
|
for i := 0; i < setCount; i++ {
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisks[i] = make([]StorageAPI, drivesPerSet)
|
|
|
|
s.erasureLockers[i] = make([]dsync.NetLocker, drivesPerSet)
|
2020-04-29 16:42:37 -04:00
|
|
|
}
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2020-04-29 16:42:37 -04:00
|
|
|
for i := 0; i < setCount; i++ {
|
2020-03-04 19:18:32 -05:00
|
|
|
for j := 0; j < drivesPerSet; j++ {
|
2020-06-10 20:10:31 -04:00
|
|
|
endpoint := endpoints[i*drivesPerSet+j]
|
2020-03-27 17:48:30 -04:00
|
|
|
// Rely on endpoints list to initialize, init lockers and available disks.
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureLockers[i][j] = newLockAPI(endpoint)
|
2020-04-03 21:06:31 -04:00
|
|
|
disk := storageDisks[i*drivesPerSet+j]
|
|
|
|
if disk == nil {
|
2020-03-27 17:48:30 -04:00
|
|
|
continue
|
|
|
|
}
|
2020-04-03 21:06:31 -04:00
|
|
|
diskID, derr := disk.GetDiskID()
|
|
|
|
if derr != nil {
|
|
|
|
disk.Close()
|
|
|
|
continue
|
2020-03-27 17:48:30 -04:00
|
|
|
}
|
2020-04-03 21:06:31 -04:00
|
|
|
m, n, err := findDiskIndexByDiskID(format, diskID)
|
|
|
|
if err != nil {
|
|
|
|
disk.Close()
|
|
|
|
continue
|
|
|
|
}
|
2020-06-10 20:10:31 -04:00
|
|
|
s.endpointStrings[m*drivesPerSet+n] = disk.String()
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisks[m][n] = disk
|
2020-03-04 19:18:32 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Initialize erasure objects for a given set.
|
|
|
|
s.sets[i] = &erasureObjects{
|
2020-06-10 20:10:31 -04:00
|
|
|
getDisks: s.GetDisks(i),
|
|
|
|
getLockers: s.GetLockers(i),
|
|
|
|
getEndpoints: s.GetEndpoints(i),
|
|
|
|
nsMutex: mutex,
|
|
|
|
bp: bp,
|
2020-06-29 16:07:26 -04:00
|
|
|
mrfOpCh: make(chan partialOperation, 10000),
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
2020-08-22 00:39:54 -04:00
|
|
|
|
|
|
|
go s.sets[i].cleanupStaleMultipartUploads(ctx,
|
|
|
|
GlobalMultipartCleanupInterval, GlobalMultipartExpiry)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start the disk monitoring and connect routine.
|
2020-04-14 20:52:38 -04:00
|
|
|
go s.monitorAndConnectEndpoints(ctx, defaultMonitorConnectEndpointInterval)
|
2020-01-15 21:30:32 -05:00
|
|
|
go s.maintainMRFList()
|
|
|
|
go s.healMRFRoutine()
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
2019-11-13 15:17:45 -05:00
|
|
|
// NewNSLock - initialize a new namespace RWLocker instance.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) NewNSLock(ctx context.Context, bucket string, objects ...string) RWLocker {
|
2020-02-21 00:59:57 -05:00
|
|
|
if len(objects) == 1 {
|
|
|
|
return s.getHashedSet(objects[0]).NewNSLock(ctx, bucket, objects...)
|
|
|
|
}
|
|
|
|
return s.getHashedSet("").NewNSLock(ctx, bucket, objects...)
|
2019-11-13 15:17:45 -05:00
|
|
|
}
|
|
|
|
|
2020-08-05 16:31:12 -04:00
|
|
|
// SetDriveCount returns the current drives per set.
|
|
|
|
func (s *erasureSets) SetDriveCount() int {
|
|
|
|
return s.drivesPerSet
|
|
|
|
}
|
|
|
|
|
2020-05-28 16:03:04 -04:00
|
|
|
// StorageUsageInfo - combines output of StorageInfo across all erasure coded object sets.
|
|
|
|
// This only returns disk usage info for Zones to perform placement decision, this call
|
|
|
|
// is not implemented in Object interface and is not meant to be used by other object
|
|
|
|
// layer implementations.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) StorageUsageInfo(ctx context.Context) StorageInfo {
|
2020-05-28 16:03:04 -04:00
|
|
|
storageUsageInfo := func() StorageInfo {
|
|
|
|
var storageInfo StorageInfo
|
|
|
|
storageInfos := make([]StorageInfo, len(s.sets))
|
|
|
|
storageInfo.Backend.Type = BackendErasure
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(s.sets))
|
|
|
|
for index := range s.sets {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
// ignoring errors on purpose
|
|
|
|
storageInfos[index], _ = s.sets[index].StorageInfo(ctx, false)
|
|
|
|
return nil
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for the go routines.
|
|
|
|
g.Wait()
|
|
|
|
|
|
|
|
for _, lstorageInfo := range storageInfos {
|
2020-07-13 12:51:07 -04:00
|
|
|
storageInfo.Disks = append(storageInfo.Disks, lstorageInfo.Disks...)
|
2020-05-28 16:03:04 -04:00
|
|
|
storageInfo.Backend.OnlineDisks = storageInfo.Backend.OnlineDisks.Merge(lstorageInfo.Backend.OnlineDisks)
|
|
|
|
storageInfo.Backend.OfflineDisks = storageInfo.Backend.OfflineDisks.Merge(lstorageInfo.Backend.OfflineDisks)
|
|
|
|
}
|
|
|
|
|
|
|
|
return storageInfo
|
|
|
|
}
|
|
|
|
|
2020-05-26 15:52:24 -04:00
|
|
|
s.disksStorageInfoCache.Once.Do(func() {
|
|
|
|
s.disksStorageInfoCache.TTL = time.Second
|
|
|
|
s.disksStorageInfoCache.Update = func() (interface{}, error) {
|
2020-05-28 16:03:04 -04:00
|
|
|
return storageUsageInfo(), nil
|
2020-05-26 15:52:24 -04:00
|
|
|
}
|
|
|
|
})
|
2020-05-28 16:03:04 -04:00
|
|
|
|
2020-05-26 15:52:24 -04:00
|
|
|
v, _ := s.disksStorageInfoCache.Get()
|
|
|
|
return v.(StorageInfo)
|
|
|
|
}
|
|
|
|
|
2020-05-28 16:03:04 -04:00
|
|
|
// StorageInfo - combines output of StorageInfo across all erasure coded object sets.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) StorageInfo(ctx context.Context, local bool) (StorageInfo, []error) {
|
2018-02-15 20:45:57 -05:00
|
|
|
var storageInfo StorageInfo
|
2019-08-22 23:02:40 -04:00
|
|
|
|
|
|
|
storageInfos := make([]StorageInfo, len(s.sets))
|
2020-05-28 16:03:04 -04:00
|
|
|
storageInfoErrs := make([][]error, len(s.sets))
|
2018-08-24 02:35:37 -04:00
|
|
|
storageInfo.Backend.Type = BackendErasure
|
2019-10-14 12:44:51 -04:00
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(s.sets))
|
|
|
|
for index := range s.sets {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2020-05-28 16:03:04 -04:00
|
|
|
storageInfos[index], storageInfoErrs[index] = s.sets[index].StorageInfo(ctx, local)
|
2019-10-14 12:44:51 -04:00
|
|
|
return nil
|
|
|
|
}, index)
|
2019-08-22 23:02:40 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
|
2019-08-22 23:02:40 -04:00
|
|
|
// Wait for the go routines.
|
2019-10-14 12:44:51 -04:00
|
|
|
g.Wait()
|
2019-08-22 23:02:40 -04:00
|
|
|
|
|
|
|
for _, lstorageInfo := range storageInfos {
|
2020-07-13 12:51:07 -04:00
|
|
|
storageInfo.Disks = append(storageInfo.Disks, lstorageInfo.Disks...)
|
2019-10-23 00:01:14 -04:00
|
|
|
storageInfo.Backend.OnlineDisks = storageInfo.Backend.OnlineDisks.Merge(lstorageInfo.Backend.OnlineDisks)
|
|
|
|
storageInfo.Backend.OfflineDisks = storageInfo.Backend.OfflineDisks.Merge(lstorageInfo.Backend.OfflineDisks)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
scParity := globalStorageClass.GetParityForSC(storageclass.STANDARD)
|
2019-10-07 01:50:24 -04:00
|
|
|
if scParity == 0 {
|
|
|
|
scParity = s.drivesPerSet / 2
|
|
|
|
}
|
|
|
|
storageInfo.Backend.StandardSCData = s.drivesPerSet - scParity
|
2018-02-15 20:45:57 -05:00
|
|
|
storageInfo.Backend.StandardSCParity = scParity
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
rrSCParity := globalStorageClass.GetParityForSC(storageclass.RRS)
|
2019-10-07 01:50:24 -04:00
|
|
|
storageInfo.Backend.RRSCData = s.drivesPerSet - rrSCParity
|
|
|
|
storageInfo.Backend.RRSCParity = rrSCParity
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2020-03-22 15:16:36 -04:00
|
|
|
if local {
|
2020-05-28 16:03:04 -04:00
|
|
|
// if local is true, we are not interested in the drive UUID info.
|
|
|
|
// this is called primarily by prometheus
|
|
|
|
return storageInfo, nil
|
2020-03-22 15:16:36 -04:00
|
|
|
}
|
|
|
|
|
2020-05-28 16:03:04 -04:00
|
|
|
var errs []error
|
|
|
|
for i := range s.sets {
|
|
|
|
errs = append(errs, storageInfoErrs[i]...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return storageInfo, errs
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) CrawlAndGetDataUsage(ctx context.Context, bf *bloomFilter, updates chan<- DataUsageInfo) error {
|
2020-04-27 13:06:21 -04:00
|
|
|
// Use the zone-level implementation instead.
|
2020-06-12 23:04:01 -04:00
|
|
|
return NotImplemented{API: "CrawlAndGetDataUsage"}
|
2020-01-21 17:07:49 -05:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// Shutdown shutsdown all erasure coded sets in parallel
|
|
|
|
// returns error upon first error.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) Shutdown(ctx context.Context) error {
|
2018-02-15 20:45:57 -05:00
|
|
|
g := errgroup.WithNErrs(len(s.sets))
|
|
|
|
|
|
|
|
for index := range s.sets {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2018-03-14 15:01:47 -04:00
|
|
|
return s.sets[index].Shutdown(ctx)
|
2018-02-15 20:45:57 -05:00
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:20:42 -04:00
|
|
|
// MakeBucketLocation - creates a new bucket across all sets simultaneously,
|
|
|
|
// then return the first encountered error
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) MakeBucketWithLocation(ctx context.Context, bucket string, opts BucketOptions) error {
|
2018-02-15 20:45:57 -05:00
|
|
|
g := errgroup.WithNErrs(len(s.sets))
|
|
|
|
|
|
|
|
// Create buckets in parallel across all sets.
|
|
|
|
for index := range s.sets {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2020-06-12 23:04:01 -04:00
|
|
|
return s.sets[index].MakeBucketWithLocation(ctx, bucket, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
errs := g.Wait()
|
2020-05-12 18:20:42 -04:00
|
|
|
|
|
|
|
// Return the first encountered error
|
2018-02-15 20:45:57 -05:00
|
|
|
for _, err := range errs {
|
2018-02-16 23:16:48 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// hashes the key returning an integer based on the input algorithm.
|
|
|
|
// This function currently supports
|
|
|
|
// - CRCMOD
|
2020-06-12 23:04:01 -04:00
|
|
|
// - SIPMOD
|
2018-02-15 20:45:57 -05:00
|
|
|
// - all new algos.
|
2020-06-12 23:04:01 -04:00
|
|
|
func sipHashMod(key string, cardinality int, id [16]byte) int {
|
|
|
|
if cardinality <= 0 {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
sip := siphash.New(id[:])
|
|
|
|
sip.Write([]byte(key))
|
|
|
|
return int(sip.Sum64() % uint64(cardinality))
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
func crcHashMod(key string, cardinality int) int {
|
|
|
|
if cardinality <= 0 {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
keyCrc := crc32.Checksum([]byte(key), crc32.IEEETable)
|
|
|
|
return int(keyCrc % uint32(cardinality))
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func hashKey(algo string, key string, cardinality int, id [16]byte) int {
|
2018-02-15 20:45:57 -05:00
|
|
|
switch algo {
|
2020-06-12 23:04:01 -04:00
|
|
|
case formatErasureVersionV2DistributionAlgoLegacy:
|
2018-02-15 20:45:57 -05:00
|
|
|
return crcHashMod(key, cardinality)
|
2020-06-12 23:04:01 -04:00
|
|
|
case formatErasureVersionV3DistributionAlgo:
|
|
|
|
return sipHashMod(key, cardinality, id)
|
2018-08-06 13:26:40 -04:00
|
|
|
default:
|
|
|
|
// Unknown algorithm returns -1, also if cardinality is lesser than 0.
|
|
|
|
return -1
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-13 15:25:49 -04:00
|
|
|
// Returns always a same erasure coded set for a given input.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) getHashedSetIndex(input string) int {
|
|
|
|
return hashKey(s.distributionAlgo, input, len(s.sets), s.deploymentID)
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// Returns always a same erasure coded set for a given input.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) getHashedSet(input string) (set *erasureObjects) {
|
2019-05-13 15:25:49 -04:00
|
|
|
return s.sets[s.getHashedSetIndex(input)]
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBucketInfo - returns bucket info from one of the erasure coded set.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetBucketInfo(ctx context.Context, bucket string) (bucketInfo BucketInfo, err error) {
|
2019-11-19 20:42:27 -05:00
|
|
|
return s.getHashedSet("").GetBucketInfo(ctx, bucket)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListObjectsV2 lists all objects in bucket filtered by prefix
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) ListObjectsV2(ctx context.Context, bucket, prefix, continuationToken, delimiter string, maxKeys int, fetchOwner bool, startAfter string) (result ListObjectsV2Info, err error) {
|
|
|
|
return result, NotImplemented{}
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsNotificationSupported returns whether bucket notification is applicable for this layer.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) IsNotificationSupported() bool {
|
2018-02-15 20:45:57 -05:00
|
|
|
return s.getHashedSet("").IsNotificationSupported()
|
|
|
|
}
|
|
|
|
|
2020-07-20 15:52:49 -04:00
|
|
|
// IsListenSupported returns whether listen bucket notification is applicable for this layer.
|
|
|
|
func (s *erasureSets) IsListenSupported() bool {
|
2018-12-05 17:03:42 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-01-05 17:16:43 -05:00
|
|
|
// IsEncryptionSupported returns whether server side encryption is implemented for this layer.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) IsEncryptionSupported() bool {
|
2018-02-15 20:45:57 -05:00
|
|
|
return s.getHashedSet("").IsEncryptionSupported()
|
|
|
|
}
|
|
|
|
|
2018-09-27 23:36:17 -04:00
|
|
|
// IsCompressionSupported returns whether compression is applicable for this layer.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) IsCompressionSupported() bool {
|
2018-09-27 23:36:17 -04:00
|
|
|
return s.getHashedSet("").IsCompressionSupported()
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) IsTaggingSupported() bool {
|
2020-05-23 14:09:35 -04:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// DeleteBucket - deletes a bucket on all sets simultaneously,
|
|
|
|
// even if one of the sets fail to delete buckets, we proceed to
|
|
|
|
// undo a successful operation.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) DeleteBucket(ctx context.Context, bucket string, forceDelete bool) error {
|
2018-02-15 20:45:57 -05:00
|
|
|
g := errgroup.WithNErrs(len(s.sets))
|
|
|
|
|
|
|
|
// Delete buckets in parallel across all sets.
|
|
|
|
for index := range s.sets {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2020-03-28 00:52:59 -04:00
|
|
|
return s.sets[index].DeleteBucket(ctx, bucket, forceDelete)
|
2018-02-15 20:45:57 -05:00
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
errs := g.Wait()
|
2020-04-27 17:18:02 -04:00
|
|
|
// For any failure, we attempt undo all the delete buckets operation
|
|
|
|
// by creating buckets again on all sets which were successfully deleted.
|
2018-02-15 20:45:57 -05:00
|
|
|
for _, err := range errs {
|
2018-02-16 23:16:48 -05:00
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
undoDeleteBucketSets(ctx, bucket, s.sets, errs)
|
2018-02-16 23:16:48 -05:00
|
|
|
return err
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete all bucket metadata.
|
2020-05-19 16:53:54 -04:00
|
|
|
deleteBucketMetadata(ctx, s, bucket)
|
2018-02-15 20:45:57 -05:00
|
|
|
|
|
|
|
// Success.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is used to undo a successful DeleteBucket operation.
|
2020-06-12 23:04:01 -04:00
|
|
|
func undoDeleteBucketSets(ctx context.Context, bucket string, sets []*erasureObjects, errs []error) {
|
2018-02-15 20:45:57 -05:00
|
|
|
g := errgroup.WithNErrs(len(sets))
|
|
|
|
|
|
|
|
// Undo previous delete bucket on all underlying sets.
|
|
|
|
for index := range sets {
|
|
|
|
index := index
|
2019-10-14 12:44:51 -04:00
|
|
|
g.Go(func() error {
|
|
|
|
if errs[index] == nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return sets[index].MakeBucketWithLocation(ctx, bucket, BucketOptions{})
|
2019-10-14 12:44:51 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}, index)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
g.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// List all buckets from one of the set, we are not doing merge
|
|
|
|
// sort here just for simplification. As per design it is assumed
|
|
|
|
// that all buckets are present on all sets.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) ListBuckets(ctx context.Context) (buckets []BucketInfo, err error) {
|
2018-02-15 20:45:57 -05:00
|
|
|
// Always lists from the same set signified by the empty string.
|
2018-03-14 15:01:47 -04:00
|
|
|
return s.getHashedSet("").ListBuckets(ctx)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- Object Operations ---
|
|
|
|
|
2018-09-20 22:22:09 -04:00
|
|
|
// GetObjectNInfo - returns object info and locked object ReadCloser
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (gr *GetObjectReader, err error) {
|
2018-09-27 06:06:45 -04:00
|
|
|
return s.getHashedSet(object).GetObjectNInfo(ctx, bucket, object, rs, h, lockType, opts)
|
2018-09-20 22:22:09 -04:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// GetObject - reads an object from the hashedSet based on the object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetObject(ctx context.Context, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string, opts ObjectOptions) error {
|
2018-09-10 12:42:43 -04:00
|
|
|
return s.getHashedSet(object).GetObject(ctx, bucket, object, startOffset, length, writer, etag, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutObject - writes an object to hashedSet based on the object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) PutObject(ctx context.Context, bucket string, object string, data *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error) {
|
2019-02-09 00:31:06 -05:00
|
|
|
return s.getHashedSet(object).PutObject(ctx, bucket, object, data, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetObjectInfo - reads object metadata from the hashedSet based on the object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetObjectInfo(ctx context.Context, bucket, object string, opts ObjectOptions) (objInfo ObjectInfo, err error) {
|
2018-09-10 12:42:43 -04:00
|
|
|
return s.getHashedSet(object).GetObjectInfo(ctx, bucket, object, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObject - deletes an object from the hashedSet based on the object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) DeleteObject(ctx context.Context, bucket string, object string, opts ObjectOptions) (objInfo ObjectInfo, err error) {
|
|
|
|
return s.getHashedSet(object).DeleteObject(ctx, bucket, object, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2019-05-13 15:25:49 -04:00
|
|
|
// DeleteObjects - bulk delete of objects
|
|
|
|
// Bulk delete is only possible within one set. For that purpose
|
|
|
|
// objects are group by set first, and then bulk delete is invoked
|
|
|
|
// for each set, the error response of each delete will be returned
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) DeleteObjects(ctx context.Context, bucket string, objects []ObjectToDelete, opts ObjectOptions) ([]DeletedObject, []error) {
|
2019-05-13 15:25:49 -04:00
|
|
|
type delObj struct {
|
|
|
|
// Set index associated to this object
|
|
|
|
setIndex int
|
|
|
|
// Original index from the list of arguments
|
|
|
|
// where this object is passed
|
|
|
|
origIndex int
|
2020-06-12 23:04:01 -04:00
|
|
|
// object to delete
|
|
|
|
object ObjectToDelete
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transform []delObj to the list of object names
|
2020-06-12 23:04:01 -04:00
|
|
|
toNames := func(delObjs []delObj) []ObjectToDelete {
|
|
|
|
objs := make([]ObjectToDelete, len(delObjs))
|
2019-05-13 15:25:49 -04:00
|
|
|
for i, obj := range delObjs {
|
2020-06-12 23:04:01 -04:00
|
|
|
objs[i] = obj.object
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
return objs
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The result of delete operation on all passed objects
|
|
|
|
var delErrs = make([]error, len(objects))
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// The result of delete objects
|
|
|
|
var delObjects = make([]DeletedObject, len(objects))
|
|
|
|
|
2019-05-13 15:25:49 -04:00
|
|
|
// A map between a set and its associated objects
|
|
|
|
var objSetMap = make(map[int][]delObj)
|
|
|
|
|
|
|
|
// Group objects by set index
|
|
|
|
for i, object := range objects {
|
2020-06-12 23:04:01 -04:00
|
|
|
index := s.getHashedSetIndex(object.ObjectName)
|
|
|
|
objSetMap[index] = append(objSetMap[index], delObj{setIndex: index, origIndex: i, object: object})
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Invoke bulk delete on objects per set and save
|
|
|
|
// the result of the delete operation
|
|
|
|
for _, objsGroup := range objSetMap {
|
2020-06-12 23:04:01 -04:00
|
|
|
dobjects, errs := s.getHashedSet(objsGroup[0].object.ObjectName).DeleteObjects(ctx, bucket, toNames(objsGroup), opts)
|
2019-05-13 15:25:49 -04:00
|
|
|
for i, obj := range objsGroup {
|
|
|
|
delErrs[obj.origIndex] = errs[i]
|
2020-06-12 23:04:01 -04:00
|
|
|
if delErrs[obj.origIndex] == nil {
|
|
|
|
delObjects[obj.origIndex] = dobjects[i]
|
|
|
|
}
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
return delObjects, delErrs
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// CopyObject - copies objects from one hashedSet to another hashedSet, on server side.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) CopyObject(ctx context.Context, srcBucket, srcObject, dstBucket, dstObject string, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (objInfo ObjectInfo, err error) {
|
2018-02-15 20:45:57 -05:00
|
|
|
srcSet := s.getHashedSet(srcObject)
|
2020-05-28 17:36:38 -04:00
|
|
|
dstSet := s.getHashedSet(dstObject)
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2020-08-03 19:21:10 -04:00
|
|
|
cpSrcDstSame := srcSet == dstSet
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// Check if this request is only metadata update.
|
2020-08-03 19:21:10 -04:00
|
|
|
if cpSrcDstSame && srcInfo.metadataOnly {
|
2020-06-19 11:44:51 -04:00
|
|
|
if dstOpts.VersionID != "" && srcOpts.VersionID == dstOpts.VersionID {
|
|
|
|
return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts)
|
|
|
|
}
|
|
|
|
if !dstOpts.Versioned && srcOpts.VersionID == "" {
|
|
|
|
return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts)
|
|
|
|
}
|
2020-08-03 19:21:10 -04:00
|
|
|
// CopyObject optimization where we don't create an entire copy
|
|
|
|
// of the content, instead we add a reference, we disallow legacy
|
|
|
|
// objects to be self referenced in this manner so make sure
|
|
|
|
// that we actually create a new dataDir for legacy objects.
|
|
|
|
if dstOpts.Versioned && srcOpts.VersionID != dstOpts.VersionID && !srcInfo.Legacy {
|
|
|
|
srcInfo.versionOnly = true
|
|
|
|
return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts)
|
|
|
|
}
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 14:13:41 -04:00
|
|
|
putOpts := ObjectOptions{
|
|
|
|
ServerSideEncryption: dstOpts.ServerSideEncryption,
|
|
|
|
UserDefined: srcInfo.UserDefined,
|
|
|
|
Versioned: dstOpts.Versioned,
|
|
|
|
VersionID: dstOpts.VersionID,
|
|
|
|
}
|
2020-06-19 11:44:51 -04:00
|
|
|
|
2020-05-28 17:36:38 -04:00
|
|
|
return dstSet.putObject(ctx, dstBucket, dstObject, srcInfo.PutObjReader, putOpts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// FileInfoVersionsCh - file info versions channel
|
|
|
|
type FileInfoVersionsCh struct {
|
|
|
|
Ch chan FileInfoVersions
|
|
|
|
Prev FileInfoVersions
|
|
|
|
Valid bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop - pops a cached entry if any, or from the cached channel.
|
|
|
|
func (f *FileInfoVersionsCh) Pop() (fi FileInfoVersions, ok bool) {
|
|
|
|
if f.Valid {
|
|
|
|
f.Valid = false
|
|
|
|
return f.Prev, true
|
|
|
|
} // No cached entries found, read from channel
|
|
|
|
f.Prev, ok = <-f.Ch
|
|
|
|
return f.Prev, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push - cache an entry, for Pop() later.
|
|
|
|
func (f *FileInfoVersionsCh) Push(fi FileInfoVersions) {
|
|
|
|
f.Prev = fi
|
|
|
|
f.Valid = true
|
|
|
|
}
|
|
|
|
|
2019-05-14 16:49:10 -04:00
|
|
|
// FileInfoCh - file info channel
|
|
|
|
type FileInfoCh struct {
|
|
|
|
Ch chan FileInfo
|
|
|
|
Prev FileInfo
|
|
|
|
Valid bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop - pops a cached entry if any, or from the cached channel.
|
|
|
|
func (f *FileInfoCh) Pop() (fi FileInfo, ok bool) {
|
|
|
|
if f.Valid {
|
|
|
|
f.Valid = false
|
|
|
|
return f.Prev, true
|
|
|
|
} // No cached entries found, read from channel
|
|
|
|
f.Prev, ok = <-f.Ch
|
|
|
|
return f.Prev, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push - cache an entry, for Pop() later.
|
|
|
|
func (f *FileInfoCh) Push(fi FileInfo) {
|
|
|
|
f.Prev = fi
|
|
|
|
f.Valid = true
|
|
|
|
}
|
|
|
|
|
2020-07-11 01:21:04 -04:00
|
|
|
// Calculate lexically least entry across multiple FileInfo channels,
|
|
|
|
// returns the lexically common entry and the total number of times
|
|
|
|
// we found this entry. Additionally also returns a boolean
|
|
|
|
// to indicate if the caller needs to call this function
|
|
|
|
// again to list the next entry. It is callers responsibility
|
|
|
|
// if the caller wishes to list N entries to call lexicallySortedEntry
|
|
|
|
// N times until this boolean is 'false'.
|
|
|
|
func lexicallySortedEntry(entryChs []FileInfoCh, entries []FileInfo, entriesValid []bool) (FileInfo, int, bool) {
|
|
|
|
for i := range entryChs {
|
|
|
|
entries[i], entriesValid[i] = entryChs[i].Pop()
|
|
|
|
}
|
|
|
|
|
|
|
|
var isTruncated = false
|
|
|
|
for _, valid := range entriesValid {
|
|
|
|
if !valid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
isTruncated = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
var lentry FileInfo
|
|
|
|
var found bool
|
|
|
|
for i, valid := range entriesValid {
|
|
|
|
if !valid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
lentry = entries[i]
|
|
|
|
found = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if entries[i].Name < lentry.Name {
|
|
|
|
lentry = entries[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We haven't been able to find any lexically least entry,
|
|
|
|
// this would mean that we don't have valid entry.
|
|
|
|
if !found {
|
|
|
|
return lentry, 0, isTruncated
|
|
|
|
}
|
|
|
|
|
|
|
|
lexicallySortedEntryCount := 0
|
|
|
|
for i, valid := range entriesValid {
|
|
|
|
if !valid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Entries are duplicated across disks,
|
|
|
|
// we should simply skip such entries.
|
|
|
|
if lentry.Name == entries[i].Name && lentry.ModTime.Equal(entries[i].ModTime) {
|
|
|
|
lexicallySortedEntryCount++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push all entries which are lexically higher
|
|
|
|
// and will be returned later in Pop()
|
|
|
|
entryChs[i].Push(entries[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return lentry, lexicallySortedEntryCount, isTruncated
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate lexically least entry across multiple FileInfo channels,
|
|
|
|
// returns the lexically common entry and the total number of times
|
2019-09-16 20:38:37 -04:00
|
|
|
// we found this entry. Additionally also returns a boolean
|
|
|
|
// to indicate if the caller needs to call this function
|
|
|
|
// again to list the next entry. It is callers responsibility
|
2020-06-09 20:09:19 -04:00
|
|
|
// if the caller wishes to list N entries to call lexicallySortedEntry
|
2019-09-16 20:38:37 -04:00
|
|
|
// N times until this boolean is 'false'.
|
2020-06-12 23:04:01 -04:00
|
|
|
func lexicallySortedEntryVersions(entryChs []FileInfoVersionsCh, entries []FileInfoVersions, entriesValid []bool) (FileInfoVersions, int, bool) {
|
2019-09-16 20:38:37 -04:00
|
|
|
for i := range entryChs {
|
|
|
|
entries[i], entriesValid[i] = entryChs[i].Pop()
|
2019-05-14 16:49:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var isTruncated = false
|
|
|
|
for _, valid := range entriesValid {
|
|
|
|
if !valid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
isTruncated = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
var lentry FileInfoVersions
|
2019-05-14 16:49:10 -04:00
|
|
|
var found bool
|
|
|
|
for i, valid := range entriesValid {
|
|
|
|
if !valid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
lentry = entries[i]
|
|
|
|
found = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if entries[i].Name < lentry.Name {
|
|
|
|
lentry = entries[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-11 01:21:04 -04:00
|
|
|
// We haven't been able to find any lexically least entry,
|
2019-09-16 20:38:37 -04:00
|
|
|
// this would mean that we don't have valid entry.
|
2019-05-14 16:49:10 -04:00
|
|
|
if !found {
|
2019-09-16 20:38:37 -04:00
|
|
|
return lentry, 0, isTruncated
|
2019-05-14 16:49:10 -04:00
|
|
|
}
|
|
|
|
|
2020-06-09 20:09:19 -04:00
|
|
|
lexicallySortedEntryCount := 0
|
2019-05-14 16:49:10 -04:00
|
|
|
for i, valid := range entriesValid {
|
|
|
|
if !valid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Entries are duplicated across disks,
|
|
|
|
// we should simply skip such entries.
|
2020-06-12 23:04:01 -04:00
|
|
|
if lentry.Name == entries[i].Name && lentry.LatestModTime.Equal(entries[i].LatestModTime) {
|
2020-06-09 20:09:19 -04:00
|
|
|
lexicallySortedEntryCount++
|
2019-05-14 16:49:10 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push all entries which are lexically higher
|
|
|
|
// and will be returned later in Pop()
|
2019-09-16 20:38:37 -04:00
|
|
|
entryChs[i].Push(entries[i])
|
2019-05-14 16:49:10 -04:00
|
|
|
}
|
|
|
|
|
2020-06-09 20:09:19 -04:00
|
|
|
return lentry, lexicallySortedEntryCount, isTruncated
|
2019-05-14 16:49:10 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) startMergeWalks(ctx context.Context, bucket, prefix, marker string, recursive bool, endWalkCh <-chan struct{}) []FileInfoCh {
|
|
|
|
return s.startMergeWalksN(ctx, bucket, prefix, marker, recursive, endWalkCh, -1)
|
2019-09-16 20:38:37 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) startMergeWalksVersions(ctx context.Context, bucket, prefix, marker string, recursive bool, endWalkCh <-chan struct{}) []FileInfoVersionsCh {
|
|
|
|
return s.startMergeWalksVersionsN(ctx, bucket, prefix, marker, recursive, endWalkCh, -1)
|
2020-03-22 19:33:49 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Starts a walk versions channel across N number of disks and returns a slice.
|
|
|
|
// FileInfoCh which can be read from.
|
|
|
|
func (s *erasureSets) startMergeWalksVersionsN(ctx context.Context, bucket, prefix, marker string, recursive bool, endWalkCh <-chan struct{}, ndisks int) []FileInfoVersionsCh {
|
|
|
|
var entryChs []FileInfoVersionsCh
|
2020-03-22 19:33:49 -04:00
|
|
|
var success int
|
2019-04-17 12:52:08 -04:00
|
|
|
for _, set := range s.sets {
|
2020-03-22 19:33:49 -04:00
|
|
|
// Reset for the next erasure set.
|
|
|
|
success = ndisks
|
|
|
|
for _, disk := range set.getLoadBalancedDisks() {
|
2019-05-14 16:49:10 -04:00
|
|
|
if disk == nil {
|
|
|
|
// Disk can be offline
|
|
|
|
continue
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
entryCh, err := disk.WalkVersions(bucket, prefix, marker, recursive, endWalkCh)
|
2019-05-14 16:49:10 -04:00
|
|
|
if err != nil {
|
2020-07-02 13:29:50 -04:00
|
|
|
logger.LogIf(ctx, err)
|
2019-05-14 16:49:10 -04:00
|
|
|
// Disk walk returned error, ignore it.
|
|
|
|
continue
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
entryChs = append(entryChs, FileInfoVersionsCh{
|
2019-05-14 16:49:10 -04:00
|
|
|
Ch: entryCh,
|
|
|
|
})
|
2020-03-22 19:33:49 -04:00
|
|
|
success--
|
|
|
|
if success == 0 {
|
|
|
|
break
|
|
|
|
}
|
2019-05-14 16:49:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return entryChs
|
2020-03-22 22:23:47 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Starts a walk channel across n number of disks and returns a slice of
|
|
|
|
// FileInfoCh which can be read from.
|
|
|
|
func (s *erasureSets) startMergeWalksN(ctx context.Context, bucket, prefix, marker string, recursive bool, endWalkCh <-chan struct{}, ndisks int) []FileInfoCh {
|
2020-03-22 22:23:47 -04:00
|
|
|
var entryChs []FileInfoCh
|
|
|
|
var success int
|
|
|
|
for _, set := range s.sets {
|
|
|
|
// Reset for the next erasure set.
|
|
|
|
success = ndisks
|
|
|
|
for _, disk := range set.getLoadBalancedDisks() {
|
|
|
|
if disk == nil {
|
|
|
|
// Disk can be offline
|
|
|
|
continue
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
entryCh, err := disk.Walk(bucket, prefix, marker, recursive, endWalkCh)
|
2020-03-22 22:23:47 -04:00
|
|
|
if err != nil {
|
|
|
|
// Disk walk returned error, ignore it.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
entryChs = append(entryChs, FileInfoCh{
|
|
|
|
Ch: entryCh,
|
|
|
|
})
|
|
|
|
success--
|
|
|
|
if success == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entryChs
|
2019-05-14 16:49:10 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Starts a walk channel across n number of disks and returns a slice of
|
|
|
|
// FileInfo channels which can be read from.
|
|
|
|
func (s *erasureSets) startSplunkMergeWalksN(ctx context.Context, bucket, prefix, marker string, endWalkCh <-chan struct{}, ndisks int) []FileInfoCh {
|
|
|
|
var entryChs []FileInfoCh
|
|
|
|
var success int
|
|
|
|
for _, set := range s.sets {
|
|
|
|
// Reset for the next erasure set.
|
|
|
|
success = ndisks
|
|
|
|
for _, disk := range set.getLoadBalancedDisks() {
|
|
|
|
if disk == nil {
|
|
|
|
// Disk can be offline
|
|
|
|
continue
|
2019-07-05 17:06:12 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
entryCh, err := disk.WalkSplunk(bucket, prefix, marker, endWalkCh)
|
|
|
|
if err != nil {
|
|
|
|
// Disk walk returned error, ignore it.
|
2019-07-05 17:06:12 -04:00
|
|
|
continue
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
entryChs = append(entryChs, FileInfoCh{
|
|
|
|
Ch: entryCh,
|
|
|
|
})
|
|
|
|
success--
|
|
|
|
if success == 0 {
|
|
|
|
break
|
2019-07-05 17:06:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
return entryChs
|
2019-07-05 17:06:12 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// ListObjectVersions - implements listing of objects across disks, each disk is indepenently
|
2019-05-14 16:49:10 -04:00
|
|
|
// walked and merged at this layer. Resulting value through the merge process sends
|
|
|
|
// the data in lexically sorted order.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) ListObjectVersions(ctx context.Context, bucket, prefix, marker, versionIDMarker, delimiter string, maxKeys int) (loi ListObjectVersionsInfo, err error) {
|
|
|
|
// Shouldn't be called directly, caller Zones already has an implementation
|
|
|
|
return loi, NotImplemented{}
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2019-06-09 01:14:07 -04:00
|
|
|
// ListObjects - implements listing of objects across disks, each disk is indepenently
|
|
|
|
// walked and merged at this layer. Resulting value through the merge process sends
|
|
|
|
// the data in lexically sorted order.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) ListObjects(ctx context.Context, bucket, prefix, marker, delimiter string, maxKeys int) (loi ListObjectsInfo, err error) {
|
|
|
|
// Shouldn't be called directly, caller Zones already has an implementation
|
|
|
|
return loi, NotImplemented{}
|
2019-06-09 01:14:07 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) ListMultipartUploads(ctx context.Context, bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result ListMultipartsInfo, err error) {
|
2018-02-15 20:45:57 -05:00
|
|
|
// In list multipart uploads we are going to treat input prefix as the object,
|
|
|
|
// this means that we are not supporting directory navigation.
|
2018-03-14 15:01:47 -04:00
|
|
|
return s.getHashedSet(prefix).ListMultipartUploads(ctx, bucket, prefix, keyMarker, uploadIDMarker, delimiter, maxUploads)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initiate a new multipart upload on a hashedSet based on object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) NewMultipartUpload(ctx context.Context, bucket, object string, opts ObjectOptions) (uploadID string, err error) {
|
2019-02-09 00:31:06 -05:00
|
|
|
return s.getHashedSet(object).NewMultipartUpload(ctx, bucket, object, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copies a part of an object from source hashedSet to destination hashedSet.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) CopyObjectPart(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, uploadID string, partID int,
|
2018-09-10 12:42:43 -04:00
|
|
|
startOffset int64, length int64, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (partInfo PartInfo, err error) {
|
2018-02-15 20:45:57 -05:00
|
|
|
destSet := s.getHashedSet(destObject)
|
|
|
|
|
2018-11-14 20:36:41 -05:00
|
|
|
return destSet.PutObjectPart(ctx, destBucket, destObject, uploadID, partID, NewPutObjReader(srcInfo.Reader, nil, nil), dstOpts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutObjectPart - writes part of an object to hashedSet based on the object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) PutObjectPart(ctx context.Context, bucket, object, uploadID string, partID int, data *PutObjReader, opts ObjectOptions) (info PartInfo, err error) {
|
2018-09-10 12:42:43 -04:00
|
|
|
return s.getHashedSet(object).PutObjectPart(ctx, bucket, object, uploadID, partID, data, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2020-05-28 15:36:20 -04:00
|
|
|
// GetMultipartInfo - return multipart metadata info uploaded at hashedSet.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetMultipartInfo(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) (result MultipartInfo, err error) {
|
2020-05-28 15:36:20 -04:00
|
|
|
return s.getHashedSet(object).GetMultipartInfo(ctx, bucket, object, uploadID, opts)
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// ListObjectParts - lists all uploaded parts to an object in hashedSet.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) ListObjectParts(ctx context.Context, bucket, object, uploadID string, partNumberMarker int, maxParts int, opts ObjectOptions) (result ListPartsInfo, err error) {
|
2019-01-05 17:16:43 -05:00
|
|
|
return s.getHashedSet(object).ListObjectParts(ctx, bucket, object, uploadID, partNumberMarker, maxParts, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Aborts an in-progress multipart operation on hashedSet based on the object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string) error {
|
2018-03-14 15:01:47 -04:00
|
|
|
return s.getHashedSet(object).AbortMultipartUpload(ctx, bucket, object, uploadID)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// CompleteMultipartUpload - completes a pending multipart transaction, on hashedSet based on object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, uploadedParts []CompletePart, opts ObjectOptions) (objInfo ObjectInfo, err error) {
|
2018-11-14 20:36:41 -05:00
|
|
|
return s.getHashedSet(object).CompleteMultipartUpload(ctx, bucket, object, uploadID, uploadedParts, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
All disks online
|
|
|
|
-----------------
|
|
|
|
- All Unformatted - format all and return success.
|
|
|
|
- Some Unformatted - format all and return success.
|
|
|
|
- Any JBOD inconsistent - return failure
|
|
|
|
- Some are corrupt (missing format.json) - return failure
|
|
|
|
- Any unrecognized disks - return failure
|
|
|
|
|
|
|
|
Some disks are offline and we have quorum.
|
|
|
|
-----------------
|
|
|
|
- Some unformatted - format all and return success,
|
|
|
|
treat disks offline as corrupted.
|
|
|
|
- Any JBOD inconsistent - return failure
|
|
|
|
- Some are corrupt (missing format.json)
|
|
|
|
- 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 // Always error
|
|
|
|
if (jbod inconsistent) return error // Always error.
|
|
|
|
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)
|
|
|
|
return error
|
|
|
|
else (some disks return format.json not found)
|
|
|
|
(heal format)
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if (some disks return format.json not found)
|
|
|
|
// Offline disks are marked as dead.
|
|
|
|
(heal format) // Offline disks should be marked as dead.
|
|
|
|
return success
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
*/
|
|
|
|
|
2020-07-13 12:51:07 -04:00
|
|
|
func formatsToDrivesInfo(endpoints Endpoints, formats []*formatErasureV3, sErrs []error) (beforeDrives []madmin.HealDriveInfo) {
|
|
|
|
beforeDrives = make([]madmin.HealDriveInfo, len(endpoints))
|
2018-02-15 20:45:57 -05:00
|
|
|
// Existing formats are available (i.e. ok), so save it in
|
|
|
|
// result, also populate disks to be healed.
|
|
|
|
for i, format := range formats {
|
|
|
|
drive := endpoints.GetString(i)
|
2019-08-30 17:11:18 -04:00
|
|
|
var state = madmin.DriveStateCorrupt
|
2018-02-15 20:45:57 -05:00
|
|
|
switch {
|
|
|
|
case format != nil:
|
2019-08-30 17:11:18 -04:00
|
|
|
state = madmin.DriveStateOk
|
2018-02-15 20:45:57 -05:00
|
|
|
case sErrs[i] == errUnformattedDisk:
|
2019-08-30 17:11:18 -04:00
|
|
|
state = madmin.DriveStateMissing
|
2019-08-02 15:17:26 -04:00
|
|
|
case sErrs[i] == errDiskNotFound:
|
2019-08-30 17:11:18 -04:00
|
|
|
state = madmin.DriveStateOffline
|
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
beforeDrives[i] = madmin.HealDriveInfo{
|
2019-08-30 17:11:18 -04:00
|
|
|
UUID: func() string {
|
|
|
|
if format != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return format.Erasure.This
|
2019-08-30 17:11:18 -04:00
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}(),
|
|
|
|
Endpoint: drive,
|
|
|
|
State: state,
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return beforeDrives
|
|
|
|
}
|
|
|
|
|
2018-04-09 13:25:41 -04:00
|
|
|
// Reloads the format from the disk, usually called by a remote peer notifier while
|
|
|
|
// healing in a distributed setup.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) ReloadFormat(ctx context.Context, dryRun bool) (err error) {
|
2019-09-27 19:47:12 -04:00
|
|
|
storageDisks, errs := initStorageDisksWithErrors(s.endpoints)
|
|
|
|
for i, err := range errs {
|
|
|
|
if err != nil && err != errDiskNotFound {
|
|
|
|
return fmt.Errorf("Disk %s: %w", s.endpoints[i], err)
|
|
|
|
}
|
2018-04-09 13:25:41 -04:00
|
|
|
}
|
|
|
|
defer func(storageDisks []StorageAPI) {
|
|
|
|
if err != nil {
|
|
|
|
closeStorageDisks(storageDisks)
|
|
|
|
}
|
|
|
|
}(storageDisks)
|
|
|
|
|
2020-08-03 21:17:48 -04:00
|
|
|
formats, _ := loadFormatErasureAll(storageDisks, false)
|
2020-06-12 23:04:01 -04:00
|
|
|
if err = checkFormatErasureValues(formats, s.drivesPerSet); err != nil {
|
2018-04-09 13:25:41 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
refFormat, err := getFormatErasureInQuorum(formats)
|
2018-04-09 13:25:41 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// kill the monitoring loop such that we stop writing
|
|
|
|
// to indicate that we will re-initialize everything
|
|
|
|
// with new format.
|
|
|
|
s.disksConnectDoneCh <- struct{}{}
|
|
|
|
|
2020-03-27 17:48:30 -04:00
|
|
|
// Replace with new reference format.
|
2018-04-09 13:25:41 -04:00
|
|
|
s.format = refFormat
|
|
|
|
|
2020-01-10 05:35:06 -05:00
|
|
|
// Close all existing disks and reconnect all the disks.
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisksMu.Lock()
|
2020-03-27 17:48:30 -04:00
|
|
|
for _, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
diskID, err := disk.GetDiskID()
|
|
|
|
if err != nil {
|
2020-04-03 21:06:31 -04:00
|
|
|
disk.Close()
|
2020-03-27 17:48:30 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
m, n, err := findDiskIndexByDiskID(refFormat, diskID)
|
|
|
|
if err != nil {
|
2020-04-03 21:06:31 -04:00
|
|
|
disk.Close()
|
2020-03-27 17:48:30 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if s.erasureDisks[m][n] != nil {
|
|
|
|
s.erasureDisks[m][n].Close()
|
2020-03-27 17:48:30 -04:00
|
|
|
}
|
|
|
|
|
2020-06-10 20:10:31 -04:00
|
|
|
s.endpointStrings[m*s.drivesPerSet+n] = disk.String()
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisks[m][n] = disk
|
2020-03-27 17:48:30 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisksMu.Unlock()
|
2018-04-09 13:25:41 -04:00
|
|
|
|
|
|
|
// Restart monitoring loop to monitor reformatted disks again.
|
2020-03-18 19:19:29 -04:00
|
|
|
go s.monitorAndConnectEndpoints(GlobalContext, defaultMonitorConnectEndpointInterval)
|
2018-04-09 13:25:41 -04:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// If it is a single node Erasure and all disks are root disks, it is most likely a test setup, else it is a production setup.
|
2019-02-06 14:44:19 -05:00
|
|
|
// On a test setup we allow creation of format.json on root disks to help with dev/testing.
|
|
|
|
func isTestSetup(infos []DiskInfo, errs []error) bool {
|
|
|
|
rootDiskCount := 0
|
|
|
|
for i := range errs {
|
2020-07-16 10:30:05 -04:00
|
|
|
if errs[i] != nil && errs[i] != errUnformattedDisk {
|
|
|
|
// On any error which is not unformatted disk
|
|
|
|
// it is safer to reject healing.
|
2019-02-06 14:44:19 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if infos[i].RootDisk {
|
|
|
|
rootDiskCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// It is a test setup if all disks are root disks.
|
|
|
|
return rootDiskCount == len(infos)
|
|
|
|
}
|
|
|
|
|
2020-08-18 17:37:26 -04:00
|
|
|
func getHealDiskInfos(storageDisks []StorageAPI, errs []error) ([]DiskInfo, []error) {
|
2019-02-06 14:44:19 -05:00
|
|
|
infos := make([]DiskInfo, len(storageDisks))
|
2019-10-14 12:44:51 -04:00
|
|
|
g := errgroup.WithNErrs(len(storageDisks))
|
|
|
|
for index := range storageDisks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2020-08-18 17:37:26 -04:00
|
|
|
if errs[index] != nil && errs[index] != errUnformattedDisk {
|
|
|
|
return errs[index]
|
|
|
|
}
|
|
|
|
if storageDisks[index] == nil {
|
|
|
|
return errDiskNotFound
|
2019-10-14 12:44:51 -04:00
|
|
|
}
|
2020-08-18 17:37:26 -04:00
|
|
|
var err error
|
|
|
|
infos[index], err = storageDisks[index].DiskInfo()
|
2019-10-14 12:44:51 -04:00
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
return infos, g.Wait()
|
2019-02-06 14:44:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark root disks as down so as not to heal them.
|
2020-08-18 17:37:26 -04:00
|
|
|
func markRootDisksAsDown(storageDisks []StorageAPI, errs []error) {
|
|
|
|
var infos []DiskInfo
|
|
|
|
infos, errs = getHealDiskInfos(storageDisks, errs)
|
|
|
|
if !isTestSetup(infos, errs) {
|
|
|
|
for i := range storageDisks {
|
|
|
|
if storageDisks[i] != nil && infos[i].RootDisk {
|
|
|
|
// We should not heal on root disk. i.e in a situation where the minio-administrator has unmounted a
|
|
|
|
// defective drive we should not heal a path on the root disk.
|
|
|
|
logger.Info("Disk `%s` is a root disk. Please ensure the disk is mounted properly, refusing to use root disk.",
|
|
|
|
storageDisks[i].String())
|
|
|
|
storageDisks[i] = nil
|
|
|
|
}
|
2019-02-06 14:44:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 23:37:39 -04:00
|
|
|
// HealFormat - heals missing `format.json` on fresh unformatted disks.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) HealFormat(ctx context.Context, dryRun bool) (res madmin.HealResultItem, err error) {
|
2019-09-27 19:47:12 -04:00
|
|
|
storageDisks, errs := initStorageDisksWithErrors(s.endpoints)
|
|
|
|
for i, derr := range errs {
|
|
|
|
if derr != nil && derr != errDiskNotFound {
|
|
|
|
return madmin.HealResultItem{}, fmt.Errorf("Disk %s: %w", s.endpoints[i], derr)
|
|
|
|
}
|
2018-04-04 00:58:48 -04:00
|
|
|
}
|
2018-04-09 13:25:41 -04:00
|
|
|
|
|
|
|
defer func(storageDisks []StorageAPI) {
|
|
|
|
if err != nil {
|
|
|
|
closeStorageDisks(storageDisks)
|
|
|
|
}
|
|
|
|
}(storageDisks)
|
2018-04-04 00:58:48 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
formats, sErrs := loadFormatErasureAll(storageDisks, true)
|
|
|
|
if err = checkFormatErasureValues(formats, s.drivesPerSet); err != nil {
|
2018-02-15 20:45:57 -05:00
|
|
|
return madmin.HealResultItem{}, err
|
|
|
|
}
|
|
|
|
|
2020-08-18 17:37:26 -04:00
|
|
|
// Mark all root disks down
|
|
|
|
markRootDisksAsDown(storageDisks, sErrs)
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// Prepare heal-result
|
2018-04-09 13:25:41 -04:00
|
|
|
res = madmin.HealResultItem{
|
2018-02-15 20:45:57 -05:00
|
|
|
Type: madmin.HealItemMetadata,
|
|
|
|
Detail: "disk-format",
|
|
|
|
DiskCount: s.setCount * s.drivesPerSet,
|
|
|
|
SetCount: s.setCount,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch all the drive info status.
|
|
|
|
beforeDrives := formatsToDrivesInfo(s.endpoints, formats, sErrs)
|
|
|
|
|
|
|
|
res.After.Drives = make([]madmin.HealDriveInfo, len(beforeDrives))
|
|
|
|
res.Before.Drives = make([]madmin.HealDriveInfo, len(beforeDrives))
|
|
|
|
// Copy "after" drive state too from before.
|
|
|
|
for k, v := range beforeDrives {
|
2019-02-13 07:59:36 -05:00
|
|
|
res.Before.Drives[k] = madmin.HealDriveInfo(v)
|
|
|
|
res.After.Drives[k] = madmin.HealDriveInfo(v)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2019-09-24 21:47:26 -04:00
|
|
|
if countErrs(sErrs, errUnformattedDisk) == 0 {
|
2018-04-30 23:37:39 -04:00
|
|
|
// No unformatted disks found disks are either offline
|
|
|
|
// or online, no healing is required.
|
|
|
|
return res, errNoHealRequired
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
refFormat, err := getFormatErasureInQuorum(formats)
|
2018-02-15 20:45:57 -05:00
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark all UUIDs which might be offline, use list
|
|
|
|
// of formats to mark them appropriately.
|
|
|
|
markUUIDsOffline(refFormat, formats)
|
|
|
|
|
|
|
|
// Initialize a new set of set formats which will be written to disk.
|
|
|
|
newFormatSets := newHealFormatSets(refFormat, s.setCount, s.drivesPerSet, formats, sErrs)
|
|
|
|
|
|
|
|
// Look for all offline/unformatted disks in our reference format,
|
|
|
|
// such that we can fill them up with new UUIDs, this looping also
|
|
|
|
// ensures that the replaced disks allocated evenly across all sets.
|
|
|
|
// Making sure that the redundancy is not lost.
|
2020-06-12 23:04:01 -04:00
|
|
|
for i := range refFormat.Erasure.Sets {
|
|
|
|
for j := range refFormat.Erasure.Sets[i] {
|
|
|
|
if refFormat.Erasure.Sets[i][j] == offlineDiskUUID {
|
2018-02-15 20:45:57 -05:00
|
|
|
for l := range newFormatSets[i] {
|
|
|
|
if newFormatSets[i][l] == nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
if newFormatSets[i][l].Erasure.This == "" {
|
|
|
|
newFormatSets[i][l].Erasure.This = mustGetUUID()
|
|
|
|
refFormat.Erasure.Sets[i][j] = newFormatSets[i][l].Erasure.This
|
2018-02-15 20:45:57 -05:00
|
|
|
for m, v := range res.After.Drives {
|
|
|
|
if v.Endpoint == s.endpoints.GetString(i*s.drivesPerSet+l) {
|
2020-06-12 23:04:01 -04:00
|
|
|
res.After.Drives[m].UUID = newFormatSets[i][l].Erasure.This
|
2018-02-15 20:45:57 -05:00
|
|
|
res.After.Drives[m].State = madmin.DriveStateOk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !dryRun {
|
2020-06-12 23:04:01 -04:00
|
|
|
var tmpNewFormats = make([]*formatErasureV3, s.setCount*s.drivesPerSet)
|
2018-02-15 20:45:57 -05:00
|
|
|
for i := range newFormatSets {
|
|
|
|
for j := range newFormatSets[i] {
|
|
|
|
if newFormatSets[i][j] == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
tmpNewFormats[i*s.drivesPerSet+j] = newFormatSets[i][j]
|
2020-06-12 23:04:01 -04:00
|
|
|
tmpNewFormats[i*s.drivesPerSet+j].Erasure.Sets = refFormat.Erasure.Sets
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save formats `format.json` across all disks.
|
2020-06-12 23:04:01 -04:00
|
|
|
if err = saveFormatErasureAll(ctx, storageDisks, tmpNewFormats); err != nil {
|
2018-02-15 20:45:57 -05:00
|
|
|
return madmin.HealResultItem{}, err
|
|
|
|
}
|
|
|
|
|
2020-08-07 16:22:53 -04:00
|
|
|
refFormat, err = getFormatErasureInQuorum(tmpNewFormats)
|
|
|
|
if err != nil {
|
|
|
|
return madmin.HealResultItem{}, err
|
|
|
|
}
|
|
|
|
|
2018-04-09 13:25:41 -04:00
|
|
|
// kill the monitoring loop such that we stop writing
|
|
|
|
// to indicate that we will re-initialize everything
|
|
|
|
// with new format.
|
|
|
|
s.disksConnectDoneCh <- struct{}{}
|
|
|
|
|
|
|
|
// Replace with new reference format.
|
2018-02-15 20:45:57 -05:00
|
|
|
s.format = refFormat
|
2018-03-27 21:11:39 -04:00
|
|
|
|
2019-11-13 15:17:45 -05:00
|
|
|
// Disconnect/relinquish all existing disks, lockers and reconnect the disks, lockers.
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisksMu.Lock()
|
2020-03-27 17:48:30 -04:00
|
|
|
for _, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
diskID, err := disk.GetDiskID()
|
|
|
|
if err != nil {
|
2020-04-03 21:06:31 -04:00
|
|
|
disk.Close()
|
2020-03-27 17:48:30 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
m, n, err := findDiskIndexByDiskID(refFormat, diskID)
|
|
|
|
if err != nil {
|
2020-04-03 21:06:31 -04:00
|
|
|
disk.Close()
|
2020-03-27 17:48:30 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if s.erasureDisks[m][n] != nil {
|
|
|
|
s.erasureDisks[m][n].Close()
|
2020-03-27 17:48:30 -04:00
|
|
|
}
|
|
|
|
|
2020-06-10 20:10:31 -04:00
|
|
|
s.endpointStrings[m*s.drivesPerSet+n] = disk.String()
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisks[m][n] = disk
|
2020-03-27 17:48:30 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
s.erasureDisksMu.Unlock()
|
2018-04-09 13:25:41 -04:00
|
|
|
|
|
|
|
// Restart our monitoring loop to start monitoring newly formatted disks.
|
2020-03-18 19:19:29 -04:00
|
|
|
go s.monitorAndConnectEndpoints(GlobalContext, defaultMonitorConnectEndpointInterval)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// HealBucket - heals inconsistent buckets and bucket metadata on all sets.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) HealBucket(ctx context.Context, bucket string, dryRun, remove bool) (result madmin.HealResultItem, err error) {
|
2018-02-15 20:45:57 -05:00
|
|
|
// Initialize heal result info
|
2019-02-10 22:53:13 -05:00
|
|
|
result = madmin.HealResultItem{
|
2018-02-15 20:45:57 -05:00
|
|
|
Type: madmin.HealItemBucket,
|
|
|
|
Bucket: bucket,
|
|
|
|
DiskCount: s.setCount * s.drivesPerSet,
|
|
|
|
SetCount: s.setCount,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range s.sets {
|
2019-02-10 22:53:13 -05:00
|
|
|
var healResult madmin.HealResultItem
|
|
|
|
healResult, err = s.HealBucket(ctx, bucket, dryRun, remove)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
2019-02-13 07:59:36 -05:00
|
|
|
result.Before.Drives = append(result.Before.Drives, healResult.Before.Drives...)
|
|
|
|
result.After.Drives = append(result.After.Drives, healResult.After.Drives...)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we had quorum to write, if not return an appropriate error.
|
2019-02-10 22:53:13 -05:00
|
|
|
_, afterDriveOnline := result.GetOnlineCounts()
|
2018-03-26 19:36:57 -04:00
|
|
|
if afterDriveOnline < ((s.setCount*s.drivesPerSet)/2)+1 {
|
2020-06-12 23:04:01 -04:00
|
|
|
return result, toObjectErr(errErasureWriteQuorum, bucket)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
2019-02-10 22:53:13 -05:00
|
|
|
return result, nil
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// HealObject - heals inconsistent object on a hashedSet based on object name.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) HealObject(ctx context.Context, bucket, object, versionID string, opts madmin.HealOpts) (madmin.HealResultItem, error) {
|
|
|
|
return s.getHashedSet(object).HealObject(ctx, bucket, object, versionID, opts)
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lists all buckets which need healing.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) ListBucketsHeal(ctx context.Context) ([]BucketInfo, error) {
|
2020-05-06 17:25:05 -04:00
|
|
|
var listBuckets []BucketInfo
|
2020-06-12 23:04:01 -04:00
|
|
|
var healBuckets = map[string]VolInfo{}
|
2018-02-15 20:45:57 -05:00
|
|
|
for _, set := range s.sets {
|
2020-05-06 17:25:05 -04:00
|
|
|
// lists all unique buckets across drives.
|
|
|
|
if err := listAllBuckets(set.getDisks(), healBuckets); err != nil {
|
2018-02-15 20:45:57 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2020-05-06 17:25:05 -04:00
|
|
|
for _, v := range healBuckets {
|
|
|
|
listBuckets = append(listBuckets, BucketInfo(v))
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
2020-05-06 17:25:05 -04:00
|
|
|
sort.Sort(byBucketName(listBuckets))
|
2018-02-15 20:45:57 -05:00
|
|
|
return listBuckets, nil
|
|
|
|
}
|
|
|
|
|
2020-02-25 10:52:28 -05:00
|
|
|
// Walk a bucket, optionally prefix recursively, until we have returned
|
|
|
|
// all the content to objectInfo channel, it is callers responsibility
|
|
|
|
// to allocate a receive channel for ObjectInfo, upon any unhandled
|
|
|
|
// error walker returns error. Optionally if context.Done() is received
|
|
|
|
// then Walk() stops the walker.
|
2020-07-11 01:21:04 -04:00
|
|
|
func (s *erasureSets) Walk(ctx context.Context, bucket, prefix string, results chan<- ObjectInfo, opts ObjectOptions) error {
|
2020-02-25 10:52:28 -05:00
|
|
|
if err := checkListObjsArgs(ctx, bucket, prefix, "", s); err != nil {
|
2020-02-25 22:58:58 -05:00
|
|
|
// Upon error close the channel.
|
|
|
|
close(results)
|
2020-02-25 10:52:28 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-11 01:21:04 -04:00
|
|
|
if opts.WalkVersions {
|
|
|
|
entryChs := s.startMergeWalksVersions(ctx, bucket, prefix, "", true, ctx.Done())
|
|
|
|
|
|
|
|
entriesValid := make([]bool, len(entryChs))
|
|
|
|
entries := make([]FileInfoVersions, len(entryChs))
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer close(results)
|
|
|
|
|
|
|
|
for {
|
|
|
|
entry, quorumCount, ok := lexicallySortedEntryVersions(entryChs, entries, entriesValid)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if quorumCount >= s.drivesPerSet/2 {
|
|
|
|
// Read quorum exists proceed
|
|
|
|
for _, version := range entry.Versions {
|
|
|
|
results <- version.ToObjectInfo(bucket, version.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// skip entries which do not have quorum
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
entryChs := s.startMergeWalks(ctx, bucket, prefix, "", true, ctx.Done())
|
2020-02-25 10:52:28 -05:00
|
|
|
|
|
|
|
entriesValid := make([]bool, len(entryChs))
|
2020-07-11 01:21:04 -04:00
|
|
|
entries := make([]FileInfo, len(entryChs))
|
2020-02-25 10:52:28 -05:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer close(results)
|
|
|
|
|
|
|
|
for {
|
2020-07-11 01:21:04 -04:00
|
|
|
entry, quorumCount, ok := lexicallySortedEntry(entryChs, entries, entriesValid)
|
2020-02-25 10:52:28 -05:00
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-18 23:56:07 -04:00
|
|
|
if quorumCount >= s.drivesPerSet/2 {
|
2020-06-12 23:04:01 -04:00
|
|
|
// Read quorum exists proceed
|
2020-07-11 01:21:04 -04:00
|
|
|
results <- entry.ToObjectInfo(bucket, entry.Name)
|
2020-02-25 10:52:28 -05:00
|
|
|
}
|
2020-03-18 23:56:07 -04:00
|
|
|
// skip entries which do not have quorum
|
2020-02-25 10:52:28 -05:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-13 20:35:09 -04:00
|
|
|
// HealObjects - Heal all objects recursively at a specified prefix, any
|
|
|
|
// dangling objects deleted as well automatically.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) HealObjects(ctx context.Context, bucket, prefix string, opts madmin.HealOpts, healObject HealObjectFn) error {
|
2020-01-29 01:35:44 -05:00
|
|
|
endWalkCh := make(chan struct{})
|
|
|
|
defer close(endWalkCh)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
entryChs := s.startMergeWalksVersions(ctx, bucket, prefix, "", true, endWalkCh)
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2020-01-29 01:35:44 -05:00
|
|
|
entriesValid := make([]bool, len(entryChs))
|
2020-06-12 23:04:01 -04:00
|
|
|
entries := make([]FileInfoVersions, len(entryChs))
|
2019-03-13 20:35:09 -04:00
|
|
|
for {
|
2020-06-12 23:04:01 -04:00
|
|
|
entry, quorumCount, ok := lexicallySortedEntryVersions(entryChs, entries, entriesValid)
|
2020-01-29 01:35:44 -05:00
|
|
|
if !ok {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-03-18 20:50:00 -04:00
|
|
|
if quorumCount == s.drivesPerSet && opts.ScanMode == madmin.HealNormalScan {
|
2020-01-29 01:35:44 -05:00
|
|
|
// Skip good entries.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
for _, version := range entry.Versions {
|
2020-08-24 16:47:01 -04:00
|
|
|
// Wait and proceed if there are active requests
|
|
|
|
waitForLowHTTPReq(int32(s.drivesPerSet), time.Second)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := healObject(bucket, version.Name, version.VersionID); err != nil {
|
|
|
|
return toObjectErr(err, bucket, version.Name)
|
|
|
|
}
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 20:35:09 -04:00
|
|
|
return nil
|
2018-02-15 20:45:57 -05:00
|
|
|
}
|
2019-06-09 01:14:07 -04:00
|
|
|
|
2020-05-23 14:09:35 -04:00
|
|
|
// PutObjectTags - replace or add tags to an existing object
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) PutObjectTags(ctx context.Context, bucket, object string, tags string, opts ObjectOptions) error {
|
|
|
|
return s.getHashedSet(object).PutObjectTags(ctx, bucket, object, tags, opts)
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
|
|
|
|
2020-05-23 14:09:35 -04:00
|
|
|
// DeleteObjectTags - delete object tags from an existing object
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) DeleteObjectTags(ctx context.Context, bucket, object string, opts ObjectOptions) error {
|
|
|
|
return s.getHashedSet(object).DeleteObjectTags(ctx, bucket, object, opts)
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
|
|
|
|
2020-05-23 14:09:35 -04:00
|
|
|
// GetObjectTags - get object tags from an existing object
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetObjectTags(ctx context.Context, bucket, object string, opts ObjectOptions) (*tags.Tags, error) {
|
|
|
|
return s.getHashedSet(object).GetObjectTags(ctx, bucket, object, opts)
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
|
|
|
|
2019-12-06 02:16:06 -05:00
|
|
|
// GetMetrics - no op
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) GetMetrics(ctx context.Context) (*Metrics, error) {
|
2019-12-06 02:16:06 -05:00
|
|
|
logger.LogIf(ctx, NotImplemented{})
|
|
|
|
return &Metrics{}, NotImplemented{}
|
|
|
|
}
|
2019-12-28 11:54:43 -05:00
|
|
|
|
2020-07-20 21:31:22 -04:00
|
|
|
// Health shouldn't be called directly - will panic
|
|
|
|
func (s *erasureSets) Health(ctx context.Context, _ HealthOptions) HealthResult {
|
|
|
|
logger.CriticalIf(ctx, NotImplemented{})
|
|
|
|
return HealthResult{}
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2020-01-15 21:30:32 -05:00
|
|
|
// maintainMRFList gathers the list of successful partial uploads
|
2020-06-12 23:04:01 -04:00
|
|
|
// from all underlying er.sets and puts them in a global map which
|
2020-01-15 21:30:32 -05:00
|
|
|
// should not have more than 10000 entries.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) maintainMRFList() {
|
2020-06-29 16:07:26 -04:00
|
|
|
var agg = make(chan partialOperation, 10000)
|
2020-06-12 23:04:01 -04:00
|
|
|
for i, er := range s.sets {
|
2020-06-29 16:07:26 -04:00
|
|
|
go func(c <-chan partialOperation, setIndex int) {
|
2020-01-15 21:30:32 -05:00
|
|
|
for msg := range c {
|
|
|
|
msg.failedSet = setIndex
|
|
|
|
select {
|
|
|
|
case agg <- msg:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
2020-06-29 16:07:26 -04:00
|
|
|
}(er.mrfOpCh, i)
|
2020-01-15 21:30:32 -05:00
|
|
|
}
|
|
|
|
|
2020-06-29 16:07:26 -04:00
|
|
|
for fOp := range agg {
|
2020-01-15 21:30:32 -05:00
|
|
|
s.mrfMU.Lock()
|
2020-06-29 16:07:26 -04:00
|
|
|
if len(s.mrfOperations) > 10000 {
|
2020-01-15 21:30:32 -05:00
|
|
|
s.mrfMU.Unlock()
|
|
|
|
continue
|
|
|
|
}
|
2020-06-29 16:07:26 -04:00
|
|
|
s.mrfOperations[healSource{
|
|
|
|
bucket: fOp.bucket,
|
|
|
|
object: fOp.object,
|
|
|
|
versionID: fOp.versionID,
|
|
|
|
}] = fOp.failedSet
|
2020-01-15 21:30:32 -05:00
|
|
|
s.mrfMU.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// healMRFRoutine monitors new disks connection, sweep the MRF list
|
|
|
|
// to find objects related to the new disk that needs to be healed.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (s *erasureSets) healMRFRoutine() {
|
2020-01-15 21:30:32 -05:00
|
|
|
// Wait until background heal state is initialized
|
|
|
|
var bgSeq *healSequence
|
|
|
|
for {
|
2020-03-18 19:19:29 -04:00
|
|
|
if globalBackgroundHealState == nil {
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
continue
|
|
|
|
}
|
2020-01-15 21:30:32 -05:00
|
|
|
var ok bool
|
|
|
|
bgSeq, ok = globalBackgroundHealState.getHealSequenceByToken(bgHealingUUID)
|
|
|
|
if ok {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
for e := range s.disksConnectEvent {
|
2020-06-12 23:04:01 -04:00
|
|
|
// Get the list of objects related the er.set
|
2020-01-15 21:30:32 -05:00
|
|
|
// to which the connected disk belongs.
|
2020-06-29 16:07:26 -04:00
|
|
|
var mrfOperations []healSource
|
2020-01-15 21:30:32 -05:00
|
|
|
s.mrfMU.Lock()
|
2020-06-29 16:07:26 -04:00
|
|
|
for k, v := range s.mrfOperations {
|
2020-01-15 21:30:32 -05:00
|
|
|
if v == e.setIndex {
|
2020-06-29 16:07:26 -04:00
|
|
|
mrfOperations = append(mrfOperations, k)
|
2020-01-15 21:30:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
s.mrfMU.Unlock()
|
|
|
|
|
|
|
|
// Heal objects
|
2020-06-29 16:07:26 -04:00
|
|
|
for _, u := range mrfOperations {
|
2020-01-15 21:30:32 -05:00
|
|
|
// Send an object to be healed with a timeout
|
|
|
|
select {
|
2020-06-12 23:04:01 -04:00
|
|
|
case bgSeq.sourceCh <- u:
|
2020-01-15 21:30:32 -05:00
|
|
|
case <-time.After(100 * time.Millisecond):
|
|
|
|
}
|
|
|
|
|
|
|
|
s.mrfMU.Lock()
|
2020-06-29 16:07:26 -04:00
|
|
|
delete(s.mrfOperations, u)
|
2020-01-15 21:30:32 -05:00
|
|
|
s.mrfMU.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|