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/>.
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-03-14 15:01:47 -04:00
|
|
|
"context"
|
2018-01-22 17:54:55 -05:00
|
|
|
"encoding/json"
|
2021-08-26 23:32:58 -04:00
|
|
|
"errors"
|
2018-01-22 17:54:55 -05:00
|
|
|
"fmt"
|
2018-11-04 22:24:16 -05:00
|
|
|
"net/http"
|
2020-12-15 20:34:54 -05:00
|
|
|
"sort"
|
2018-01-22 17:54:55 -05:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2023-06-19 20:53:08 -04:00
|
|
|
"github.com/minio/madmin-go/v3"
|
2024-01-28 13:04:17 -05:00
|
|
|
xioutil "github.com/minio/minio/internal/ioutil"
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/logger"
|
2018-01-22 17:54:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// healStatusSummary - overall short summary of a healing sequence
|
|
|
|
type healStatusSummary string
|
|
|
|
|
|
|
|
// healStatusSummary constants
|
|
|
|
const (
|
|
|
|
healNotStartedStatus healStatusSummary = "not started"
|
|
|
|
healRunningStatus = "running"
|
|
|
|
healStoppedStatus = "stopped"
|
|
|
|
healFinishedStatus = "finished"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// a heal sequence with this many un-consumed heal result
|
|
|
|
// items blocks until heal-status consumption resumes or is
|
|
|
|
// aborted due to timeout.
|
|
|
|
maxUnconsumedHealResultItems = 1000
|
|
|
|
|
|
|
|
// if no heal-results are consumed (via the heal-status API)
|
|
|
|
// for this timeout duration, the heal sequence is aborted.
|
|
|
|
healUnconsumedTimeout = 24 * time.Hour
|
|
|
|
|
|
|
|
// time-duration to keep heal sequence state after it
|
|
|
|
// completes.
|
|
|
|
keepHealSeqStateDuration = time.Minute * 10
|
2019-10-28 13:27:49 -04:00
|
|
|
|
|
|
|
// nopHeal is a no operating healing action to
|
|
|
|
// wait for the current healing operation to finish
|
|
|
|
nopHeal = ""
|
2018-01-22 17:54:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-05-04 01:35:40 -04:00
|
|
|
errHealIdleTimeout = fmt.Errorf("healing results were not consumed for too long")
|
|
|
|
errHealStopSignalled = fmt.Errorf("heal stop signaled")
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2018-11-12 14:07:43 -05:00
|
|
|
errFnHealFromAPIErr = func(ctx context.Context, err error) error {
|
2020-07-17 20:41:29 -04:00
|
|
|
apiErr := toAdminAPIErr(ctx, err)
|
2018-01-22 17:54:55 -05:00
|
|
|
return fmt.Errorf("Heal internal error: %s: %s",
|
|
|
|
apiErr.Code, apiErr.Description)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// healSequenceStatus - accumulated status of the heal sequence
|
|
|
|
type healSequenceStatus struct {
|
|
|
|
// summary and detail for failures
|
|
|
|
Summary healStatusSummary `json:"Summary"`
|
|
|
|
FailureDetail string `json:"Detail,omitempty"`
|
|
|
|
StartTime time.Time `json:"StartTime"`
|
|
|
|
|
|
|
|
// settings for the heal sequence
|
|
|
|
HealSettings madmin.HealOpts `json:"Settings"`
|
|
|
|
|
|
|
|
// slice of available heal result records
|
|
|
|
Items []madmin.HealResultItem `json:"Items"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// structure to hold state of all heal sequences in server memory
|
|
|
|
type allHealState struct {
|
2020-09-28 22:39:32 -04:00
|
|
|
sync.RWMutex
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
// map of heal path to heal sequence
|
2022-06-21 10:53:55 -04:00
|
|
|
healSeqMap map[string]*healSequence // Indexed by endpoint
|
|
|
|
// keep track of the healing status of disks in the memory
|
|
|
|
// false: the disk needs to be healed but no healing routine is started
|
|
|
|
// true: the disk is currently healing
|
|
|
|
healLocalDisks map[Endpoint]bool
|
2021-03-04 17:36:23 -05:00
|
|
|
healStatus map[string]healingTracker // Indexed by disk ID
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
2020-06-29 16:07:26 -04:00
|
|
|
// newHealState - initialize global heal state management
|
2022-10-14 06:08:40 -04:00
|
|
|
func newHealState(ctx context.Context, cleanup bool) *allHealState {
|
2020-12-13 14:57:08 -05:00
|
|
|
hstate := &allHealState{
|
2020-09-04 20:09:02 -04:00
|
|
|
healSeqMap: make(map[string]*healSequence),
|
2022-06-21 10:53:55 -04:00
|
|
|
healLocalDisks: make(map[Endpoint]bool),
|
2021-03-04 17:36:23 -05:00
|
|
|
healStatus: make(map[string]healingTracker),
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
2020-12-13 14:57:08 -05:00
|
|
|
if cleanup {
|
2022-10-14 06:08:40 -04:00
|
|
|
go hstate.periodicHealSeqsClean(ctx)
|
2020-12-13 14:57:08 -05:00
|
|
|
}
|
|
|
|
return hstate
|
2018-11-16 17:59:51 -05:00
|
|
|
}
|
|
|
|
|
2021-03-04 17:36:23 -05:00
|
|
|
func (ahs *allHealState) popHealLocalDisks(healLocalDisks ...Endpoint) {
|
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
2020-09-04 20:09:02 -04:00
|
|
|
|
2021-03-04 17:36:23 -05:00
|
|
|
for _, ep := range healLocalDisks {
|
|
|
|
delete(ahs.healLocalDisks, ep)
|
|
|
|
}
|
|
|
|
for id, disk := range ahs.healStatus {
|
|
|
|
for _, ep := range healLocalDisks {
|
|
|
|
if disk.Endpoint == ep.String() {
|
|
|
|
delete(ahs.healStatus, id)
|
|
|
|
}
|
|
|
|
}
|
2020-09-04 20:09:02 -04:00
|
|
|
}
|
2020-08-07 16:22:53 -04:00
|
|
|
}
|
|
|
|
|
2021-03-04 17:36:23 -05:00
|
|
|
// updateHealStatus will update the heal status.
|
|
|
|
func (ahs *allHealState) updateHealStatus(tracker *healingTracker) {
|
2020-08-07 16:22:53 -04:00
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
2024-02-06 11:56:59 -05:00
|
|
|
|
|
|
|
tracker.mu.RLock()
|
|
|
|
t := *tracker
|
|
|
|
t.QueuedBuckets = append(make([]string, 0, len(tracker.QueuedBuckets)), tracker.QueuedBuckets...)
|
|
|
|
t.HealedBuckets = append(make([]string, 0, len(tracker.HealedBuckets)), tracker.HealedBuckets...)
|
|
|
|
ahs.healStatus[tracker.ID] = t
|
|
|
|
tracker.mu.RUnlock()
|
2021-03-04 17:36:23 -05:00
|
|
|
}
|
2020-08-07 16:22:53 -04:00
|
|
|
|
2021-03-04 17:36:23 -05:00
|
|
|
// Sort by zone, set and disk index
|
|
|
|
func sortDisks(disks []madmin.Disk) {
|
|
|
|
sort.Slice(disks, func(i, j int) bool {
|
|
|
|
a, b := &disks[i], &disks[j]
|
|
|
|
if a.PoolIndex != b.PoolIndex {
|
|
|
|
return a.PoolIndex < b.PoolIndex
|
|
|
|
}
|
|
|
|
if a.SetIndex != b.SetIndex {
|
|
|
|
return a.SetIndex < b.SetIndex
|
|
|
|
}
|
|
|
|
return a.DiskIndex < b.DiskIndex
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// getLocalHealingDisks returns local healing disks indexed by endpoint.
|
|
|
|
func (ahs *allHealState) getLocalHealingDisks() map[string]madmin.HealingDisk {
|
|
|
|
ahs.RLock()
|
|
|
|
defer ahs.RUnlock()
|
|
|
|
dst := make(map[string]madmin.HealingDisk, len(ahs.healStatus))
|
|
|
|
for _, v := range ahs.healStatus {
|
|
|
|
dst[v.Endpoint] = v.toHealingDisk()
|
2020-09-04 20:09:02 -04:00
|
|
|
}
|
2021-03-04 17:36:23 -05:00
|
|
|
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2022-06-21 10:53:55 -04:00
|
|
|
// getHealLocalDiskEndpoints() returns the list of disks that need
|
|
|
|
// to be healed but there is no healing routine in progress on them.
|
2021-03-04 17:36:23 -05:00
|
|
|
func (ahs *allHealState) getHealLocalDiskEndpoints() Endpoints {
|
|
|
|
ahs.RLock()
|
|
|
|
defer ahs.RUnlock()
|
|
|
|
|
|
|
|
var endpoints Endpoints
|
2022-06-21 10:53:55 -04:00
|
|
|
for ep, healing := range ahs.healLocalDisks {
|
|
|
|
if !healing {
|
|
|
|
endpoints = append(endpoints, ep)
|
|
|
|
}
|
2021-03-04 17:36:23 -05:00
|
|
|
}
|
|
|
|
return endpoints
|
2020-09-04 20:09:02 -04:00
|
|
|
}
|
|
|
|
|
2023-01-13 18:36:46 -05:00
|
|
|
// Set, in the memory, the state of the disk as currently healing or not
|
|
|
|
func (ahs *allHealState) setDiskHealingStatus(ep Endpoint, healing bool) {
|
2022-06-21 10:53:55 -04:00
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
|
|
|
|
2023-01-13 18:36:46 -05:00
|
|
|
ahs.healLocalDisks[ep] = healing
|
2022-06-21 10:53:55 -04:00
|
|
|
}
|
|
|
|
|
2020-09-04 20:09:02 -04:00
|
|
|
func (ahs *allHealState) pushHealLocalDisks(healLocalDisks ...Endpoint) {
|
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
|
|
|
|
|
|
|
for _, ep := range healLocalDisks {
|
2022-06-21 10:53:55 -04:00
|
|
|
ahs.healLocalDisks[ep] = false
|
2020-09-04 20:09:02 -04:00
|
|
|
}
|
2020-08-07 16:22:53 -04:00
|
|
|
}
|
|
|
|
|
2020-03-18 19:19:29 -04:00
|
|
|
func (ahs *allHealState) periodicHealSeqsClean(ctx context.Context) {
|
2018-11-16 17:59:51 -05:00
|
|
|
// Launch clean-up routine to remove this heal sequence (after
|
|
|
|
// it ends) from the global state after timeout has elapsed.
|
2020-12-17 15:35:02 -05:00
|
|
|
periodicTimer := time.NewTimer(time.Minute * 5)
|
|
|
|
defer periodicTimer.Stop()
|
|
|
|
|
2018-11-16 17:59:51 -05:00
|
|
|
for {
|
|
|
|
select {
|
2020-12-17 15:35:02 -05:00
|
|
|
case <-periodicTimer.C:
|
2018-11-16 17:59:51 -05:00
|
|
|
now := UTCNow()
|
|
|
|
ahs.Lock()
|
|
|
|
for path, h := range ahs.healSeqMap {
|
|
|
|
if h.hasEnded() && h.endTime.Add(keepHealSeqStateDuration).Before(now) {
|
|
|
|
delete(ahs.healSeqMap, path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ahs.Unlock()
|
2022-05-18 01:42:59 -04:00
|
|
|
|
|
|
|
periodicTimer.Reset(time.Minute * 5)
|
2020-03-18 19:19:29 -04:00
|
|
|
case <-ctx.Done():
|
2018-11-16 17:59:51 -05:00
|
|
|
// server could be restarting - need
|
|
|
|
// to exit immediately
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
2019-06-25 19:42:24 -04:00
|
|
|
// getHealSequenceByToken - Retrieve a heal sequence by token. The second
|
|
|
|
// argument returns if a heal sequence actually exists.
|
|
|
|
func (ahs *allHealState) getHealSequenceByToken(token string) (h *healSequence, exists bool) {
|
2022-12-06 11:08:22 -05:00
|
|
|
ahs.RLock()
|
|
|
|
defer ahs.RUnlock()
|
2019-06-25 19:42:24 -04:00
|
|
|
for _, healSeq := range ahs.healSeqMap {
|
|
|
|
if healSeq.clientToken == token {
|
|
|
|
return healSeq, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// getHealSequence - Retrieve a heal sequence by path. The second
|
|
|
|
// argument returns if a heal sequence actually exists.
|
|
|
|
func (ahs *allHealState) getHealSequence(path string) (h *healSequence, exists bool) {
|
2022-12-06 11:08:22 -05:00
|
|
|
ahs.RLock()
|
|
|
|
defer ahs.RUnlock()
|
2018-01-22 17:54:55 -05:00
|
|
|
h, exists = ahs.healSeqMap[path]
|
|
|
|
return h, exists
|
|
|
|
}
|
|
|
|
|
2019-02-12 04:25:52 -05:00
|
|
|
func (ahs *allHealState) stopHealSequence(path string) ([]byte, APIError) {
|
2018-11-04 22:24:16 -05:00
|
|
|
var hsp madmin.HealStopSuccess
|
|
|
|
he, exists := ahs.getHealSequence(path)
|
|
|
|
if !exists {
|
|
|
|
hsp = madmin.HealStopSuccess{
|
2020-07-17 20:41:29 -04:00
|
|
|
ClientToken: "unknown",
|
2018-11-04 22:24:16 -05:00
|
|
|
StartTime: UTCNow(),
|
|
|
|
}
|
|
|
|
} else {
|
2020-07-03 22:27:13 -04:00
|
|
|
clientToken := he.clientToken
|
|
|
|
if globalIsDistErasure {
|
2023-08-11 16:12:35 -04:00
|
|
|
clientToken = fmt.Sprintf("%s:%d", he.clientToken, GetProxyEndpointLocalIndex(globalProxyEndpoints))
|
2020-07-03 22:27:13 -04:00
|
|
|
}
|
|
|
|
|
2018-11-04 22:24:16 -05:00
|
|
|
hsp = madmin.HealStopSuccess{
|
2020-07-03 22:27:13 -04:00
|
|
|
ClientToken: clientToken,
|
2018-11-04 22:24:16 -05:00
|
|
|
ClientAddress: he.clientAddress,
|
|
|
|
StartTime: he.startTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
he.stop()
|
|
|
|
for !he.hasEnded() {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
|
|
|
// Heal sequence explicitly stopped, remove it.
|
|
|
|
delete(ahs.healSeqMap, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := json.Marshal(&hsp)
|
2020-04-09 12:30:02 -04:00
|
|
|
return b, toAdminAPIErr(GlobalContext, err)
|
2018-11-04 22:24:16 -05:00
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// LaunchNewHealSequence - launches a background routine that performs
|
|
|
|
// healing according to the healSequence argument. For each heal
|
|
|
|
// sequence, state is stored in the `globalAllHealState`, which is a
|
|
|
|
// map of the heal path to `healSequence` which holds state about the
|
|
|
|
// heal sequence.
|
|
|
|
//
|
|
|
|
// Heal results are persisted in server memory for
|
|
|
|
// `keepHealSeqStateDuration`. This function also launches a
|
|
|
|
// background routine to clean up heal results after the
|
|
|
|
// aforementioned duration.
|
2020-11-10 12:02:06 -05:00
|
|
|
func (ahs *allHealState) LaunchNewHealSequence(h *healSequence, objAPI ObjectLayer) (
|
2022-01-02 12:15:06 -05:00
|
|
|
respBytes []byte, apiErr APIError, errMsg string,
|
|
|
|
) {
|
2020-07-17 20:41:29 -04:00
|
|
|
if h.forceStarted {
|
|
|
|
_, apiErr = ahs.stopHealSequence(pathJoin(h.bucket, h.object))
|
|
|
|
if apiErr.Code != "" {
|
|
|
|
return respBytes, apiErr, ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
oh, exists := ahs.getHealSequence(pathJoin(h.bucket, h.object))
|
|
|
|
if exists && !oh.hasEnded() {
|
2018-01-22 17:54:55 -05:00
|
|
|
errMsg = "Heal is already running on the given path " +
|
|
|
|
"(use force-start option to stop and start afresh). " +
|
2018-11-04 22:24:16 -05:00
|
|
|
fmt.Sprintf("The heal was started by IP %s at %s, token is %s",
|
|
|
|
h.clientAddress, h.startTime.Format(http.TimeFormat), h.clientToken)
|
2019-02-12 04:25:52 -05:00
|
|
|
return nil, errorCodes.ToAPIErr(ErrHealAlreadyRunning), errMsg
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
|
|
|
|
|
|
|
// Check if new heal sequence to be started overlaps with any
|
|
|
|
// existing, running sequence
|
2020-06-12 23:04:01 -04:00
|
|
|
hpath := pathJoin(h.bucket, h.object)
|
2018-01-22 17:54:55 -05:00
|
|
|
for k, hSeq := range ahs.healSeqMap {
|
2020-06-12 23:04:01 -04:00
|
|
|
if !hSeq.hasEnded() && (HasPrefix(k, hpath) || HasPrefix(hpath, k)) {
|
2018-01-22 17:54:55 -05:00
|
|
|
errMsg = "The provided heal sequence path overlaps with an existing " +
|
|
|
|
fmt.Sprintf("heal path: %s", k)
|
2019-02-12 04:25:52 -05:00
|
|
|
return nil, errorCodes.ToAPIErr(ErrHealOverlappingPaths), errMsg
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add heal state and start sequence
|
2020-06-12 23:04:01 -04:00
|
|
|
ahs.healSeqMap[hpath] = h
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2020-07-03 22:27:13 -04:00
|
|
|
clientToken := h.clientToken
|
|
|
|
if globalIsDistErasure {
|
2023-08-11 16:12:35 -04:00
|
|
|
clientToken = fmt.Sprintf("%s:%d", h.clientToken, GetProxyEndpointLocalIndex(globalProxyEndpoints))
|
2020-07-03 22:27:13 -04:00
|
|
|
}
|
|
|
|
|
2024-04-02 02:48:36 -04:00
|
|
|
if h.clientToken == bgHealingUUID {
|
|
|
|
// For background heal do nothing, do not spawn an unnecessary goroutine.
|
|
|
|
} else {
|
|
|
|
// Launch top-level background heal go-routine
|
|
|
|
go h.healSequenceStart(objAPI)
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
b, err := json.Marshal(madmin.HealStartSuccess{
|
2020-07-03 22:27:13 -04:00
|
|
|
ClientToken: clientToken,
|
2018-03-26 19:36:57 -04:00
|
|
|
ClientAddress: h.clientAddress,
|
|
|
|
StartTime: h.startTime,
|
2018-01-22 17:54:55 -05:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-04-04 08:04:40 -04:00
|
|
|
bugLogIf(h.ctx, err)
|
2020-07-17 20:41:29 -04:00
|
|
|
return nil, toAdminAPIErr(h.ctx, err), ""
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
2019-02-12 04:25:52 -05:00
|
|
|
return b, noError, ""
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// PopHealStatusJSON - Called by heal-status API. It fetches the heal
|
|
|
|
// status results from global state and returns its JSON
|
|
|
|
// representation. The clientToken helps ensure there aren't
|
|
|
|
// conflicting clients fetching status.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (ahs *allHealState) PopHealStatusJSON(hpath string,
|
2022-01-02 12:15:06 -05:00
|
|
|
clientToken string) ([]byte, APIErrorCode,
|
|
|
|
) {
|
2018-01-22 17:54:55 -05:00
|
|
|
// fetch heal state for given path
|
2020-06-12 23:04:01 -04:00
|
|
|
h, exists := ahs.getHealSequence(hpath)
|
2018-01-22 17:54:55 -05:00
|
|
|
if !exists {
|
2020-07-17 20:41:29 -04:00
|
|
|
// heal sequence doesn't exist, must have finished.
|
|
|
|
jbytes, err := json.Marshal(healSequenceStatus{
|
|
|
|
Summary: healFinishedStatus,
|
|
|
|
})
|
|
|
|
return jbytes, toAdminAPIErrCode(GlobalContext, err)
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if client-token is valid
|
|
|
|
if clientToken != h.clientToken {
|
|
|
|
return nil, ErrHealInvalidClientToken
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take lock to access and update the heal-sequence
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Lock()
|
|
|
|
defer h.mutex.Unlock()
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
numItems := len(h.currentStatus.Items)
|
|
|
|
|
|
|
|
// calculate index of most recently available heal result
|
|
|
|
// record.
|
|
|
|
lastResultIndex := h.lastSentResultIndex
|
|
|
|
if numItems > 0 {
|
|
|
|
lastResultIndex = h.currentStatus.Items[numItems-1].ResultIndex
|
|
|
|
}
|
|
|
|
|
2020-05-04 01:35:40 -04:00
|
|
|
h.lastSentResultIndex = lastResultIndex
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
jbytes, err := json.Marshal(h.currentStatus)
|
|
|
|
if err != nil {
|
2020-05-04 01:35:40 -04:00
|
|
|
h.currentStatus.Items = nil
|
|
|
|
|
2024-04-04 08:04:40 -04:00
|
|
|
bugLogIf(h.ctx, err)
|
2018-01-22 17:54:55 -05:00
|
|
|
return nil, ErrInternalError
|
|
|
|
}
|
|
|
|
|
2020-05-04 01:35:40 -04:00
|
|
|
h.currentStatus.Items = nil
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
return jbytes, ErrNone
|
|
|
|
}
|
|
|
|
|
2020-04-01 15:14:00 -04:00
|
|
|
// healSource denotes single entity and heal option.
|
|
|
|
type healSource struct {
|
2020-06-12 23:04:01 -04:00
|
|
|
bucket string
|
|
|
|
object string
|
|
|
|
versionID string
|
2023-01-19 08:20:54 -05:00
|
|
|
noWait bool // a non blocking call, if task queue is full return right away.
|
2020-06-12 23:04:01 -04:00
|
|
|
opts *madmin.HealOpts // optional heal option overrides default setting
|
2020-04-01 15:14:00 -04:00
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// healSequence - state for each heal sequence initiated on the
|
|
|
|
// server.
|
|
|
|
type healSequence struct {
|
2020-06-12 23:04:01 -04:00
|
|
|
// bucket, and object on which heal seq. was initiated
|
|
|
|
bucket, object string
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2020-03-25 01:40:45 -04:00
|
|
|
// Report healing progress
|
2019-06-09 01:14:07 -04:00
|
|
|
reportProgress bool
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// time at which heal sequence was started
|
|
|
|
startTime time.Time
|
|
|
|
|
2018-11-16 17:59:51 -05:00
|
|
|
// time at which heal sequence has ended
|
|
|
|
endTime time.Time
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// Heal client info
|
|
|
|
clientToken, clientAddress string
|
|
|
|
|
|
|
|
// was this heal sequence force started?
|
|
|
|
forceStarted bool
|
|
|
|
|
|
|
|
// heal settings applied to this heal sequence
|
|
|
|
settings madmin.HealOpts
|
|
|
|
|
|
|
|
// current accumulated status of the heal sequence
|
|
|
|
currentStatus healSequenceStatus
|
|
|
|
|
2018-06-28 19:02:02 -04:00
|
|
|
// channel signaled by background routine when traversal has
|
2018-01-22 17:54:55 -05:00
|
|
|
// completed
|
|
|
|
traverseAndHealDoneCh chan error
|
|
|
|
|
2020-05-04 01:35:40 -04:00
|
|
|
// canceler to cancel heal sequence.
|
|
|
|
cancelCtx context.CancelFunc
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
// the last result index sent to client
|
|
|
|
lastSentResultIndex int64
|
2018-03-14 15:01:47 -04:00
|
|
|
|
2020-03-25 01:40:45 -04:00
|
|
|
// Number of total items scanned against item type
|
|
|
|
scannedItemsMap map[madmin.HealItemType]int64
|
|
|
|
|
|
|
|
// Number of total items healed against item type
|
|
|
|
healedItemsMap map[madmin.HealItemType]int64
|
|
|
|
|
|
|
|
// Number of total items where healing failed against endpoint and drive state
|
|
|
|
healFailedItemsMap map[string]int64
|
2019-06-25 19:42:24 -04:00
|
|
|
|
|
|
|
// The time of the last scan/heal activity
|
|
|
|
lastHealActivity time.Time
|
|
|
|
|
2018-03-14 15:01:47 -04:00
|
|
|
// Holds the request-info for logging
|
|
|
|
ctx context.Context
|
2020-03-25 01:40:45 -04:00
|
|
|
|
|
|
|
// used to lock this structure as it is concurrently accessed
|
|
|
|
mutex sync.RWMutex
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHealSequence - creates healSettings, assumes bucket and
|
|
|
|
// objPrefix are already validated.
|
2020-05-04 01:35:40 -04:00
|
|
|
func newHealSequence(ctx context.Context, bucket, objPrefix, clientAddr string,
|
2022-01-02 12:15:06 -05:00
|
|
|
hs madmin.HealOpts, forceStart bool,
|
|
|
|
) *healSequence {
|
2018-04-05 18:04:40 -04:00
|
|
|
reqInfo := &logger.ReqInfo{RemoteHost: clientAddr, API: "Heal", BucketName: bucket}
|
|
|
|
reqInfo.AppendTags("prefix", objPrefix)
|
2020-05-04 01:35:40 -04:00
|
|
|
ctx, cancel := context.WithCancel(logger.SetReqInfo(ctx, reqInfo))
|
2018-03-14 15:01:47 -04:00
|
|
|
|
2020-07-03 14:53:03 -04:00
|
|
|
clientToken := mustGetUUID()
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
return &healSequence{
|
2019-06-09 01:14:07 -04:00
|
|
|
bucket: bucket,
|
2020-06-12 23:04:01 -04:00
|
|
|
object: objPrefix,
|
2019-06-09 01:14:07 -04:00
|
|
|
reportProgress: true,
|
|
|
|
startTime: UTCNow(),
|
2020-07-03 14:53:03 -04:00
|
|
|
clientToken: clientToken,
|
2019-06-09 01:14:07 -04:00
|
|
|
clientAddress: clientAddr,
|
|
|
|
forceStarted: forceStart,
|
|
|
|
settings: hs,
|
2018-01-22 17:54:55 -05:00
|
|
|
currentStatus: healSequenceStatus{
|
|
|
|
Summary: healNotStartedStatus,
|
|
|
|
HealSettings: hs,
|
|
|
|
},
|
|
|
|
traverseAndHealDoneCh: make(chan error),
|
2020-05-04 01:35:40 -04:00
|
|
|
cancelCtx: cancel,
|
2018-03-14 15:01:47 -04:00
|
|
|
ctx: ctx,
|
2020-03-25 01:40:45 -04:00
|
|
|
scannedItemsMap: make(map[madmin.HealItemType]int64),
|
|
|
|
healedItemsMap: make(map[madmin.HealItemType]int64),
|
|
|
|
healFailedItemsMap: make(map[string]int64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// getScannedItemsCount - returns a count of all scanned items
|
|
|
|
func (h *healSequence) getScannedItemsCount() int64 {
|
|
|
|
var count int64
|
|
|
|
h.mutex.RLock()
|
|
|
|
defer h.mutex.RUnlock()
|
|
|
|
|
|
|
|
for _, v := range h.scannedItemsMap {
|
2021-11-16 12:28:29 -05:00
|
|
|
count += v
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
2020-03-25 01:40:45 -04:00
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
|
|
|
// getScannedItemsMap - returns map of all scanned items against type
|
|
|
|
func (h *healSequence) getScannedItemsMap() map[madmin.HealItemType]int64 {
|
|
|
|
h.mutex.RLock()
|
|
|
|
defer h.mutex.RUnlock()
|
|
|
|
|
|
|
|
// Make a copy before returning the value
|
|
|
|
retMap := make(map[madmin.HealItemType]int64, len(h.scannedItemsMap))
|
|
|
|
for k, v := range h.scannedItemsMap {
|
|
|
|
retMap[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return retMap
|
|
|
|
}
|
|
|
|
|
|
|
|
// getHealedItemsMap - returns the map of all healed items against type
|
|
|
|
func (h *healSequence) getHealedItemsMap() map[madmin.HealItemType]int64 {
|
|
|
|
h.mutex.RLock()
|
|
|
|
defer h.mutex.RUnlock()
|
|
|
|
|
|
|
|
// Make a copy before returning the value
|
|
|
|
retMap := make(map[madmin.HealItemType]int64, len(h.healedItemsMap))
|
|
|
|
for k, v := range h.healedItemsMap {
|
|
|
|
retMap[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return retMap
|
|
|
|
}
|
|
|
|
|
2024-04-02 02:48:36 -04:00
|
|
|
// getHealFailedItemsMap - returns map of all items where heal failed against
|
2020-03-25 01:40:45 -04:00
|
|
|
// drive endpoint and status
|
2024-04-02 02:48:36 -04:00
|
|
|
func (h *healSequence) getHealFailedItemsMap() map[string]int64 {
|
2020-03-25 01:40:45 -04:00
|
|
|
h.mutex.RLock()
|
|
|
|
defer h.mutex.RUnlock()
|
|
|
|
|
|
|
|
// Make a copy before returning the value
|
|
|
|
retMap := make(map[string]int64, len(h.healFailedItemsMap))
|
|
|
|
for k, v := range h.healFailedItemsMap {
|
|
|
|
retMap[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return retMap
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
2024-04-02 02:48:36 -04:00
|
|
|
func (h *healSequence) countFailed(res madmin.HealResultItem) {
|
|
|
|
h.mutex.Lock()
|
|
|
|
defer h.mutex.Unlock()
|
|
|
|
|
|
|
|
for _, d := range res.After.Drives {
|
|
|
|
// For failed items we report the endpoint and drive state
|
|
|
|
// This will help users take corrective actions for drives
|
|
|
|
h.healFailedItemsMap[d.Endpoint+","+d.State]++
|
|
|
|
}
|
|
|
|
|
|
|
|
h.lastHealActivity = UTCNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *healSequence) countHeals(healType madmin.HealItemType, healed bool) {
|
|
|
|
h.mutex.Lock()
|
|
|
|
defer h.mutex.Unlock()
|
|
|
|
|
|
|
|
if !healed {
|
|
|
|
h.scannedItemsMap[healType]++
|
|
|
|
} else {
|
|
|
|
h.healedItemsMap[healType]++
|
|
|
|
}
|
|
|
|
|
|
|
|
h.lastHealActivity = UTCNow()
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// isQuitting - determines if the heal sequence is quitting (due to an
|
|
|
|
// external signal)
|
|
|
|
func (h *healSequence) isQuitting() bool {
|
|
|
|
select {
|
2020-05-04 01:35:40 -04:00
|
|
|
case <-h.ctx.Done():
|
2018-01-22 17:54:55 -05:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the heal sequence has ended
|
|
|
|
func (h *healSequence) hasEnded() bool {
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.RLock()
|
2020-08-20 11:48:09 -04:00
|
|
|
defer h.mutex.RUnlock()
|
2020-08-07 22:43:06 -04:00
|
|
|
// background heal never ends
|
|
|
|
if h.clientToken == bgHealingUUID {
|
|
|
|
return false
|
|
|
|
}
|
2020-09-25 13:29:00 -04:00
|
|
|
return !h.endTime.IsZero()
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// stops the heal sequence - safe to call multiple times.
|
|
|
|
func (h *healSequence) stop() {
|
2020-05-04 01:35:40 -04:00
|
|
|
h.cancelCtx()
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// pushHealResultItem - pushes a heal result item for consumption in
|
|
|
|
// the heal-status API. It blocks if there are
|
|
|
|
// maxUnconsumedHealResultItems. When it blocks, the heal sequence
|
|
|
|
// routine is effectively paused - this happens when the server has
|
|
|
|
// accumulated the maximum number of heal records per heal
|
|
|
|
// sequence. When the client consumes further records, the heal
|
|
|
|
// sequence automatically resumes. The return value indicates if the
|
|
|
|
// operation succeeded.
|
|
|
|
func (h *healSequence) pushHealResultItem(r madmin.HealResultItem) error {
|
|
|
|
// start a timer to keep an upper time limit to find an empty
|
|
|
|
// slot to add the given heal result - if no slot is found it
|
|
|
|
// means that the server is holding the maximum amount of
|
|
|
|
// heal-results in memory and the client has not consumed it
|
|
|
|
// for too long.
|
|
|
|
unconsumedTimer := time.NewTimer(healUnconsumedTimeout)
|
2022-05-18 01:42:59 -04:00
|
|
|
defer unconsumedTimer.Stop()
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
var itemsLen int
|
|
|
|
for {
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Lock()
|
2018-01-22 17:54:55 -05:00
|
|
|
itemsLen = len(h.currentStatus.Items)
|
|
|
|
if itemsLen == maxUnconsumedHealResultItems {
|
|
|
|
// wait for a second, or quit if an external
|
|
|
|
// stop signal is received or the
|
|
|
|
// unconsumedTimer fires.
|
|
|
|
select {
|
|
|
|
// Check after a second
|
|
|
|
case <-time.After(time.Second):
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Unlock()
|
2018-01-22 17:54:55 -05:00
|
|
|
continue
|
|
|
|
|
2020-05-04 01:35:40 -04:00
|
|
|
case <-h.ctx.Done():
|
|
|
|
h.mutex.Unlock()
|
2018-01-22 17:54:55 -05:00
|
|
|
// discard result and return.
|
2020-05-04 01:35:40 -04:00
|
|
|
return errHealStopSignalled
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2020-05-04 01:35:40 -04:00
|
|
|
// Timeout if no results consumed for too long.
|
2018-01-22 17:54:55 -05:00
|
|
|
case <-unconsumedTimer.C:
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Unlock()
|
2018-01-22 17:54:55 -05:00
|
|
|
return errHealIdleTimeout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the correct result index for the new result item
|
|
|
|
if itemsLen > 0 {
|
|
|
|
r.ResultIndex = 1 + h.currentStatus.Items[itemsLen-1].ResultIndex
|
|
|
|
} else {
|
|
|
|
r.ResultIndex = 1 + h.lastSentResultIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
// append to results
|
|
|
|
h.currentStatus.Items = append(h.currentStatus.Items, r)
|
|
|
|
|
|
|
|
// release lock
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Unlock()
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// healSequenceStart - this is the top-level background heal
|
|
|
|
// routine. It launches another go-routine that actually traverses
|
|
|
|
// on-disk data, checks and heals according to the selected
|
|
|
|
// settings. This go-routine itself, (1) monitors the traversal
|
|
|
|
// routine for completion, and (2) listens for external stop
|
|
|
|
// signals. When either event happens, it sets the finish status for
|
|
|
|
// the heal-sequence.
|
2020-11-10 12:02:06 -05:00
|
|
|
func (h *healSequence) healSequenceStart(objAPI ObjectLayer) {
|
2018-01-22 17:54:55 -05:00
|
|
|
// Set status as running
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Lock()
|
2018-01-22 17:54:55 -05:00
|
|
|
h.currentStatus.Summary = healRunningStatus
|
|
|
|
h.currentStatus.StartTime = UTCNow()
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Unlock()
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2021-08-26 17:06:04 -04:00
|
|
|
go h.traverseAndHeal(objAPI)
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
select {
|
|
|
|
case err, ok := <-h.traverseAndHealDoneCh:
|
2020-05-04 01:35:40 -04:00
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h.mutex.Lock()
|
2018-11-16 17:59:51 -05:00
|
|
|
h.endTime = UTCNow()
|
2018-01-22 17:54:55 -05:00
|
|
|
// Heal traversal is complete.
|
2020-05-04 01:35:40 -04:00
|
|
|
if err == nil {
|
|
|
|
// heal traversal succeeded.
|
|
|
|
h.currentStatus.Summary = healFinishedStatus
|
|
|
|
} else {
|
2018-01-22 17:54:55 -05:00
|
|
|
// heal traversal had an error.
|
|
|
|
h.currentStatus.Summary = healStoppedStatus
|
|
|
|
h.currentStatus.FailureDetail = err.Error()
|
|
|
|
}
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Unlock()
|
|
|
|
case <-h.ctx.Done():
|
|
|
|
h.mutex.Lock()
|
2018-11-16 17:59:51 -05:00
|
|
|
h.endTime = UTCNow()
|
2020-07-17 20:41:29 -04:00
|
|
|
h.currentStatus.Summary = healFinishedStatus
|
2020-05-04 01:35:40 -04:00
|
|
|
h.mutex.Unlock()
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
// drain traverse channel so the traversal
|
|
|
|
// go-routine does not leak.
|
|
|
|
go func() {
|
|
|
|
// Eventually the traversal go-routine closes
|
|
|
|
// the channel and returns, so this go-routine
|
|
|
|
// itself will not leak.
|
|
|
|
<-h.traverseAndHealDoneCh
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 15:14:00 -04:00
|
|
|
func (h *healSequence) queueHealTask(source healSource, healType madmin.HealItemType) error {
|
2019-06-09 01:14:07 -04:00
|
|
|
// Send heal request
|
2020-04-01 15:14:00 -04:00
|
|
|
task := healTask{
|
2021-08-26 23:32:58 -04:00
|
|
|
bucket: source.bucket,
|
|
|
|
object: source.object,
|
|
|
|
versionID: source.versionID,
|
|
|
|
opts: h.settings,
|
2020-04-01 15:14:00 -04:00
|
|
|
}
|
2020-06-02 12:07:16 -04:00
|
|
|
if source.opts != nil {
|
|
|
|
task.opts = *source.opts
|
2022-03-04 21:25:06 -05:00
|
|
|
} else {
|
2022-04-07 11:10:40 -04:00
|
|
|
task.opts.ScanMode = madmin.HealNormalScan
|
2020-12-25 02:04:03 -05:00
|
|
|
}
|
2020-08-26 11:53:33 -04:00
|
|
|
|
2024-04-02 02:48:36 -04:00
|
|
|
h.countHeals(healType, false)
|
2020-08-26 11:53:33 -04:00
|
|
|
|
2023-01-19 08:20:54 -05:00
|
|
|
if source.noWait {
|
|
|
|
select {
|
|
|
|
case globalBackgroundHealRoutine.tasks <- task:
|
|
|
|
if serverDebugLog {
|
2024-02-15 18:13:30 -05:00
|
|
|
fmt.Printf("Task in the queue: %#v\n", task)
|
2023-01-19 08:20:54 -05:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
// task queue is full, no more workers, we shall move on and heal later.
|
|
|
|
return nil
|
|
|
|
}
|
2023-02-17 12:52:43 -05:00
|
|
|
// Don't wait for result
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// respCh must be set to wait for result.
|
|
|
|
// We make it size 1, so a result can always be written
|
|
|
|
// even if we aren't listening.
|
|
|
|
task.respCh = make(chan healResult, 1)
|
|
|
|
select {
|
|
|
|
case globalBackgroundHealRoutine.tasks <- task:
|
|
|
|
if serverDebugLog {
|
2024-02-15 18:13:30 -05:00
|
|
|
fmt.Printf("Task in the queue: %#v\n", task)
|
2021-12-25 12:01:44 -05:00
|
|
|
}
|
2023-02-17 12:52:43 -05:00
|
|
|
case <-h.ctx.Done():
|
|
|
|
return nil
|
2021-08-26 23:32:58 -04:00
|
|
|
}
|
2020-04-30 23:23:00 -04:00
|
|
|
|
2023-01-19 08:20:54 -05:00
|
|
|
// task queued, now wait for the response.
|
2020-04-30 23:23:00 -04:00
|
|
|
select {
|
2023-02-17 12:52:43 -05:00
|
|
|
case res := <-task.respCh:
|
2020-04-30 23:23:00 -04:00
|
|
|
if !h.reportProgress {
|
2021-08-26 23:32:58 -04:00
|
|
|
if errors.Is(res.err, errSkipFile) { // this is only sent usually by nopHeal
|
|
|
|
return nil
|
|
|
|
}
|
2020-05-04 01:35:40 -04:00
|
|
|
|
|
|
|
// Report caller of any failure
|
|
|
|
return res.err
|
2019-06-09 01:14:07 -04:00
|
|
|
}
|
2020-04-30 23:23:00 -04:00
|
|
|
res.result.Type = healType
|
|
|
|
if res.err != nil {
|
|
|
|
res.result.Detail = res.err.Error()
|
2019-06-09 01:14:07 -04:00
|
|
|
}
|
2020-04-30 23:23:00 -04:00
|
|
|
return h.pushHealResultItem(res.result)
|
|
|
|
case <-h.ctx.Done():
|
|
|
|
return nil
|
2019-06-09 01:14:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 12:02:06 -05:00
|
|
|
func (h *healSequence) healDiskMeta(objAPI ObjectLayer) error {
|
2020-12-13 14:57:08 -05:00
|
|
|
// Start healing the config prefix.
|
|
|
|
return h.healMinioSysMeta(objAPI, minioConfigPrefix)()
|
2020-06-29 16:07:26 -04:00
|
|
|
}
|
|
|
|
|
2020-11-10 12:02:06 -05:00
|
|
|
func (h *healSequence) healItems(objAPI ObjectLayer, bucketsOnly bool) error {
|
2023-04-29 05:05:28 -04:00
|
|
|
if h.clientToken == bgHealingUUID {
|
|
|
|
// For background heal do nothing.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-10 12:02:06 -05:00
|
|
|
if err := h.healDiskMeta(objAPI); err != nil {
|
2019-06-09 01:14:07 -04:00
|
|
|
return err
|
|
|
|
}
|
2018-09-29 04:17:01 -04:00
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// Heal buckets and objects
|
2020-11-10 12:02:06 -05:00
|
|
|
return h.healBuckets(objAPI, bucketsOnly)
|
2019-06-09 01:14:07 -04:00
|
|
|
}
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2019-06-09 01:14:07 -04:00
|
|
|
// traverseAndHeal - traverses on-disk data and performs healing
|
|
|
|
// according to settings. At each "safe" point it also checks if an
|
|
|
|
// external quit signal has been received and quits if so. Since the
|
|
|
|
// healing traversal may be mutating on-disk data when an external
|
|
|
|
// quit signal is received, this routine cannot quit immediately and
|
|
|
|
// has to wait until a safe point is reached, such as between scanning
|
|
|
|
// two objects.
|
2020-11-10 12:02:06 -05:00
|
|
|
func (h *healSequence) traverseAndHeal(objAPI ObjectLayer) {
|
2020-01-15 04:08:39 -05:00
|
|
|
bucketsOnly := false // Heals buckets and objects also.
|
2020-11-10 12:02:06 -05:00
|
|
|
h.traverseAndHealDoneCh <- h.healItems(objAPI, bucketsOnly)
|
2024-01-28 13:04:17 -05:00
|
|
|
xioutil.SafeClose(h.traverseAndHealDoneCh)
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
2019-02-10 22:53:13 -05:00
|
|
|
// healMinioSysMeta - heals all files under a given meta prefix, returns a function
|
|
|
|
// which in-turn heals the respective meta directory path and any files in int.
|
2020-11-10 12:02:06 -05:00
|
|
|
func (h *healSequence) healMinioSysMeta(objAPI ObjectLayer, metaPrefix string) func() error {
|
2019-02-10 22:53:13 -05:00
|
|
|
return func() error {
|
|
|
|
// NOTE: Healing on meta is run regardless
|
|
|
|
// of any bucket being selected, this is to ensure that
|
|
|
|
// meta are always upto date and correct.
|
2023-12-08 15:26:01 -05:00
|
|
|
return objAPI.HealObjects(h.ctx, minioMetaBucket, metaPrefix, h.settings, func(bucket, object, versionID string, scanMode madmin.HealScanMode) error {
|
2019-03-13 20:35:09 -04:00
|
|
|
if h.isQuitting() {
|
|
|
|
return errHealStopSignalled
|
2018-10-01 12:54:26 -04:00
|
|
|
}
|
2019-06-09 01:14:07 -04:00
|
|
|
|
2020-08-24 16:47:01 -04:00
|
|
|
err := h.queueHealTask(healSource{
|
2020-06-12 23:04:01 -04:00
|
|
|
bucket: bucket,
|
|
|
|
object: object,
|
|
|
|
versionID: versionID,
|
|
|
|
}, madmin.HealItemBucketMetadata)
|
2020-08-24 16:47:01 -04:00
|
|
|
return err
|
2019-03-13 20:35:09 -04:00
|
|
|
})
|
2018-09-29 04:17:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// healBuckets - check for all buckets heal or just particular bucket.
|
2020-11-10 12:02:06 -05:00
|
|
|
func (h *healSequence) healBuckets(objAPI ObjectLayer, bucketsOnly bool) error {
|
2018-10-01 12:54:26 -04:00
|
|
|
if h.isQuitting() {
|
|
|
|
return errHealStopSignalled
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// 1. If a bucket was specified, heal only the bucket.
|
|
|
|
if h.bucket != "" {
|
2020-11-10 12:02:06 -05:00
|
|
|
return h.healBucket(objAPI, h.bucket, bucketsOnly)
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
2022-07-25 20:51:32 -04:00
|
|
|
buckets, err := objAPI.ListBuckets(h.ctx, BucketOptions{})
|
2018-01-22 17:54:55 -05:00
|
|
|
if err != nil {
|
2018-11-12 14:07:43 -05:00
|
|
|
return errFnHealFromAPIErr(h.ctx, err)
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
2020-12-15 20:34:54 -05:00
|
|
|
// Heal latest buckets first.
|
|
|
|
sort.Slice(buckets, func(i, j int) bool {
|
|
|
|
return buckets[i].Created.After(buckets[j].Created)
|
|
|
|
})
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
for _, bucket := range buckets {
|
2020-11-10 12:02:06 -05:00
|
|
|
if err = h.healBucket(objAPI, bucket.Name, bucketsOnly); err != nil {
|
2018-01-22 17:54:55 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// healBucket - traverses and heals given bucket
|
2020-11-10 12:02:06 -05:00
|
|
|
func (h *healSequence) healBucket(objAPI ObjectLayer, bucket string, bucketsOnly bool) error {
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := h.queueHealTask(healSource{bucket: bucket}, madmin.HealItemBucket); err != nil {
|
2021-09-02 23:56:13 -04:00
|
|
|
return err
|
2019-02-10 22:53:13 -05:00
|
|
|
}
|
|
|
|
|
2020-01-15 04:08:39 -05:00
|
|
|
if bucketsOnly {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
if !h.settings.Recursive {
|
2020-06-12 23:04:01 -04:00
|
|
|
if h.object != "" {
|
2023-12-08 15:26:01 -05:00
|
|
|
if err := h.healObject(bucket, h.object, "", h.settings.ScanMode); err != nil {
|
2023-04-19 10:47:42 -04:00
|
|
|
return err
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-10 12:02:06 -05:00
|
|
|
if err := objAPI.HealObjects(h.ctx, bucket, h.object, h.settings, h.healObject); err != nil {
|
2021-09-02 23:56:13 -04:00
|
|
|
return errFnHealFromAPIErr(h.ctx, err)
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// healObject - heal the given object and record result
|
2023-12-08 15:26:01 -05:00
|
|
|
func (h *healSequence) healObject(bucket, object, versionID string, scanMode madmin.HealScanMode) error {
|
2020-01-29 01:35:44 -05:00
|
|
|
if h.isQuitting() {
|
|
|
|
return errHealStopSignalled
|
|
|
|
}
|
|
|
|
|
2020-08-24 16:47:01 -04:00
|
|
|
err := h.queueHealTask(healSource{
|
2020-06-12 23:04:01 -04:00
|
|
|
bucket: bucket,
|
|
|
|
object: object,
|
|
|
|
versionID: versionID,
|
2021-12-25 12:01:44 -05:00
|
|
|
opts: &h.settings,
|
2020-06-12 23:04:01 -04:00
|
|
|
}, madmin.HealItemObject)
|
2021-08-25 20:46:20 -04:00
|
|
|
|
|
|
|
// Wait and proceed if there are active requests
|
|
|
|
waitForLowHTTPReq()
|
|
|
|
|
2020-08-24 16:47:01 -04:00
|
|
|
return err
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|