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/>.
|
2016-05-30 19:51:59 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-05-30 19:51:59 -04:00
|
|
|
|
2017-09-25 17:47:58 -04:00
|
|
|
import (
|
2018-04-05 18:04:40 -04:00
|
|
|
"context"
|
2023-07-14 05:25:40 -04:00
|
|
|
"math/rand"
|
2020-09-29 12:54:41 -04:00
|
|
|
"sync"
|
2023-07-14 05:25:40 -04:00
|
|
|
"time"
|
2017-09-25 17:47:58 -04:00
|
|
|
)
|
2016-05-30 19:51:59 -04:00
|
|
|
|
2022-01-10 12:07:49 -05:00
|
|
|
func (er erasureObjects) getOnlineDisks() (newDisks []StorageAPI) {
|
|
|
|
disks := er.getDisks()
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var mu sync.Mutex
|
2023-07-14 05:25:40 -04:00
|
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
for _, i := range r.Perm(len(disks)) {
|
2022-01-10 12:07:49 -05:00
|
|
|
i := i
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
2023-07-14 05:25:40 -04:00
|
|
|
if disks[i] == nil {
|
2022-01-10 12:07:49 -05:00
|
|
|
return
|
|
|
|
}
|
2024-01-25 15:45:46 -05:00
|
|
|
di, err := disks[i].DiskInfo(context.Background(), DiskInfoOptions{})
|
2022-01-10 12:07:49 -05:00
|
|
|
if err != nil || di.Healing {
|
|
|
|
// - Do not consume disks which are not reachable
|
|
|
|
// unformatted or simply not accessible for some reason.
|
|
|
|
//
|
|
|
|
// - Do not consume disks which are being healed
|
|
|
|
//
|
|
|
|
// - Future: skip busy disks
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
mu.Lock()
|
2023-07-14 05:25:40 -04:00
|
|
|
newDisks = append(newDisks, disks[i])
|
2022-01-10 12:07:49 -05:00
|
|
|
mu.Unlock()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
return newDisks
|
|
|
|
}
|
|
|
|
|
2023-10-25 02:33:25 -04:00
|
|
|
func (er erasureObjects) getOnlineLocalDisks() (newDisks []StorageAPI) {
|
|
|
|
disks := er.getOnlineDisks()
|
|
|
|
|
|
|
|
// Based on the random shuffling return back randomized disks.
|
|
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
|
|
|
|
for _, i := range r.Perm(len(disks)) {
|
|
|
|
if disks[i] != nil && disks[i].IsLocal() {
|
|
|
|
newDisks = append(newDisks, disks[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newDisks
|
|
|
|
}
|
|
|
|
|
|
|
|
func (er erasureObjects) getLocalDisks() (newDisks []StorageAPI) {
|
2020-08-26 22:29:35 -04:00
|
|
|
disks := er.getDisks()
|
|
|
|
// Based on the random shuffling return back randomized disks.
|
2023-07-14 05:25:40 -04:00
|
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
for _, i := range r.Perm(len(disks)) {
|
|
|
|
if disks[i] != nil && disks[i].IsLocal() {
|
|
|
|
newDisks = append(newDisks, disks[i])
|
2020-08-26 22:29:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return newDisks
|
|
|
|
}
|