2018-01-22 17:54:55 -05:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2017 MinIO, Inc.
|
2018-01-22 17:54:55 -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"
|
2018-01-22 17:54:55 -05:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2018-11-04 22:24:16 -05:00
|
|
|
"net/http"
|
2018-01-22 17:54:55 -05:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2018-03-14 15:01:47 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-01-22 17:54:55 -05:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
sync.Mutex
|
|
|
|
|
|
|
|
// map of heal path to heal sequence
|
2020-08-07 16:22:53 -04:00
|
|
|
healSeqMap map[string]*healSequence
|
|
|
|
healLocalDisks []Endpoints
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
2020-06-29 16:07:26 -04:00
|
|
|
// newHealState - initialize global heal state management
|
|
|
|
func newHealState() *allHealState {
|
2019-06-09 01:14:07 -04:00
|
|
|
healState := &allHealState{
|
2018-01-22 17:54:55 -05:00
|
|
|
healSeqMap: make(map[string]*healSequence),
|
|
|
|
}
|
2018-11-16 17:59:51 -05:00
|
|
|
|
2020-03-18 19:19:29 -04:00
|
|
|
go healState.periodicHealSeqsClean(GlobalContext)
|
2019-06-09 01:14:07 -04:00
|
|
|
|
|
|
|
return healState
|
2018-11-16 17:59:51 -05:00
|
|
|
}
|
|
|
|
|
2020-08-07 16:22:53 -04:00
|
|
|
func (ahs *allHealState) getHealLocalDisks() []Endpoints {
|
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
|
|
|
|
|
|
|
healLocalDisks := make([]Endpoints, len(ahs.healLocalDisks))
|
|
|
|
copy(healLocalDisks, ahs.healLocalDisks)
|
|
|
|
return healLocalDisks
|
|
|
|
}
|
|
|
|
|
2020-08-07 22:43:06 -04:00
|
|
|
func (ahs *allHealState) updateHealLocalDisks(healLocalDisks []Endpoints) {
|
2020-08-07 16:22:53 -04:00
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
|
|
|
|
2020-08-07 22:43:06 -04:00
|
|
|
ahs.healLocalDisks = healLocalDisks
|
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.
|
|
|
|
for {
|
|
|
|
select {
|
2020-05-04 01:35:40 -04:00
|
|
|
case <-time.After(time.Minute * 5):
|
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()
|
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) {
|
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
|
|
|
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) {
|
|
|
|
ahs.Lock()
|
|
|
|
defer ahs.Unlock()
|
|
|
|
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 {
|
|
|
|
clientToken = fmt.Sprintf("%s@%d", he.clientToken, GetProxyEndpointLocalIndex(globalProxyEndpoints))
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
func (ahs *allHealState) LaunchNewHealSequence(h *healSequence) (
|
2019-02-12 04:25:52 -05:00
|
|
|
respBytes []byte, apiErr APIError, errMsg string) {
|
2018-01-22 17:54:55 -05:00
|
|
|
|
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
|
|
|
|
|
|
|
// Launch top-level background heal go-routine
|
|
|
|
go h.healSequenceStart()
|
|
|
|
|
2020-07-03 22:27:13 -04:00
|
|
|
clientToken := h.clientToken
|
|
|
|
if globalIsDistErasure {
|
|
|
|
clientToken = fmt.Sprintf("%s@%d", h.clientToken, GetProxyEndpointLocalIndex(globalProxyEndpoints))
|
|
|
|
}
|
|
|
|
|
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 {
|
2018-11-12 14:07:43 -05:00
|
|
|
logger.LogIf(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,
|
2018-01-22 17:54:55 -05:00
|
|
|
clientToken string) ([]byte, APIErrorCode) {
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2018-11-12 14:07:43 -05:00
|
|
|
logger.LogIf(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
|
|
|
|
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-04-30 23:23:00 -04:00
|
|
|
// A channel of entities (format, buckets, objects) to heal
|
2020-04-01 15:14:00 -04:00
|
|
|
sourceCh chan healSource
|
2019-06-09 01:14:07 -04:00
|
|
|
|
2020-04-30 23:23:00 -04:00
|
|
|
// A channel of entities with heal result
|
|
|
|
respCh chan healResult
|
|
|
|
|
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,
|
2020-06-29 16:07:26 -04:00
|
|
|
hs madmin.HealOpts, forceStart bool) *healSequence {
|
2018-01-22 17:54:55 -05:00
|
|
|
|
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{
|
2020-04-30 23:23:00 -04:00
|
|
|
respCh: make(chan healResult),
|
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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// resetHealStatusCounters - reset the healSequence status counters between
|
|
|
|
// each monthly background heal scanning activity.
|
|
|
|
// This is used only in case of Background healing scenario, where
|
|
|
|
// we use a single long running healSequence which reactively heals
|
|
|
|
// objects passed to the SourceCh.
|
|
|
|
func (h *healSequence) resetHealStatusCounters() {
|
|
|
|
h.mutex.Lock()
|
|
|
|
defer h.mutex.Unlock()
|
|
|
|
|
|
|
|
h.currentStatus.Items = []madmin.HealResultItem{}
|
|
|
|
h.lastSentResultIndex = 0
|
|
|
|
h.scannedItemsMap = make(map[madmin.HealItemType]int64)
|
|
|
|
h.healedItemsMap = make(map[madmin.HealItemType]int64)
|
|
|
|
h.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 {
|
|
|
|
count = 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
|
|
|
|
}
|
|
|
|
|
|
|
|
// gethealFailedItemsMap - returns map of all items where heal failed against
|
|
|
|
// drive endpoint and status
|
|
|
|
func (h *healSequence) gethealFailedItemsMap() map[string]int64 {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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-08-20 11:48:09 -04:00
|
|
|
return len(h.currentStatus.Items) == 0 || h.currentStatus.Summary == healStoppedStatus || h.currentStatus.Summary == healFinishedStatus
|
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)
|
|
|
|
defer func() {
|
|
|
|
// stop the timeout timer so it is garbage collected.
|
|
|
|
if !unconsumedTimer.Stop() {
|
|
|
|
<-unconsumedTimer.C
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
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.
|
|
|
|
func (h *healSequence) healSequenceStart() {
|
|
|
|
// 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
|
|
|
|
2019-06-09 01:14:07 -04:00
|
|
|
if h.sourceCh == nil {
|
|
|
|
go h.traverseAndHeal()
|
|
|
|
} else {
|
|
|
|
go h.healFromSourceCh()
|
|
|
|
}
|
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{
|
2020-06-12 23:04:01 -04:00
|
|
|
bucket: source.bucket,
|
|
|
|
object: source.object,
|
|
|
|
versionID: source.versionID,
|
2020-04-01 15:14:00 -04:00
|
|
|
opts: h.settings,
|
2020-04-30 23:23:00 -04:00
|
|
|
responseCh: h.respCh,
|
2020-04-01 15:14:00 -04:00
|
|
|
}
|
2020-06-02 12:07:16 -04:00
|
|
|
if source.opts != nil {
|
|
|
|
task.opts = *source.opts
|
2020-04-01 15:14:00 -04:00
|
|
|
}
|
2020-08-26 11:53:33 -04:00
|
|
|
|
|
|
|
h.mutex.Lock()
|
|
|
|
h.scannedItemsMap[healType]++
|
|
|
|
h.lastHealActivity = UTCNow()
|
|
|
|
h.mutex.Unlock()
|
|
|
|
|
2020-04-01 15:14:00 -04:00
|
|
|
globalBackgroundHealRoutine.queueHealTask(task)
|
2020-04-30 23:23:00 -04:00
|
|
|
|
|
|
|
select {
|
|
|
|
case res := <-h.respCh:
|
|
|
|
if !h.reportProgress {
|
2020-05-04 01:35:40 -04:00
|
|
|
// Object might have been deleted, by the time heal
|
|
|
|
// was attempted, we should ignore this object and
|
2020-08-24 16:47:01 -04:00
|
|
|
// return the error and not calculate this object
|
|
|
|
// as part of the metrics.
|
2020-07-02 19:17:27 -04:00
|
|
|
if isErrObjectNotFound(res.err) || isErrVersionNotFound(res.err) {
|
2020-08-24 16:47:01 -04:00
|
|
|
// Return the error so that caller can handle it.
|
|
|
|
return res.err
|
2020-05-04 01:35:40 -04:00
|
|
|
}
|
|
|
|
|
2020-04-30 23:23:00 -04:00
|
|
|
h.mutex.Lock()
|
|
|
|
defer h.mutex.Unlock()
|
|
|
|
|
|
|
|
// Progress is not reported in case of background heal processing.
|
|
|
|
// Instead we increment relevant counter based on the heal result
|
|
|
|
// for prometheus reporting.
|
2020-05-04 01:35:40 -04:00
|
|
|
if res.err != nil {
|
2020-04-30 23:23:00 -04:00
|
|
|
for _, d := range res.result.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]++
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Only object type reported for successful healing
|
|
|
|
h.healedItemsMap[res.result.Type]++
|
2020-03-25 01:40:45 -04:00
|
|
|
}
|
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 {
|
|
|
|
// Object might have been deleted, by the time heal
|
|
|
|
// was attempted, we should ignore this object and return success.
|
2020-07-02 19:17:27 -04:00
|
|
|
if isErrObjectNotFound(res.err) || isErrVersionNotFound(res.err) {
|
2020-04-30 23:23:00 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// Only report object error
|
|
|
|
if healType != madmin.HealItemObject {
|
|
|
|
return res.err
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *healSequence) healItemsFromSourceCh() error {
|
2020-01-10 05:35:06 -05:00
|
|
|
for {
|
|
|
|
select {
|
2020-05-04 01:35:40 -04:00
|
|
|
case source, ok := <-h.sourceCh:
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-10 05:35:06 -05:00
|
|
|
var itemType madmin.HealItemType
|
|
|
|
switch {
|
2020-06-12 23:04:01 -04:00
|
|
|
case source.bucket == nopHeal:
|
2020-01-10 05:35:06 -05:00
|
|
|
continue
|
2020-06-12 23:04:01 -04:00
|
|
|
case source.bucket == SlashSeparator:
|
2020-01-10 05:35:06 -05:00
|
|
|
itemType = madmin.HealItemMetadata
|
2020-06-12 23:04:01 -04:00
|
|
|
case source.bucket != "" && source.object == "":
|
2020-01-10 05:35:06 -05:00
|
|
|
itemType = madmin.HealItemBucket
|
|
|
|
default:
|
|
|
|
itemType = madmin.HealItemObject
|
|
|
|
}
|
2019-12-12 09:02:37 -05:00
|
|
|
|
2020-04-01 15:14:00 -04:00
|
|
|
if err := h.queueHealTask(source, itemType); err != nil {
|
2020-07-17 13:08:04 -04:00
|
|
|
switch err.(type) {
|
|
|
|
case ObjectExistsAsDirectory:
|
2020-08-24 16:47:01 -04:00
|
|
|
case ObjectNotFound:
|
|
|
|
case VersionNotFound:
|
2020-07-17 13:08:04 -04:00
|
|
|
default:
|
|
|
|
logger.LogIf(h.ctx, fmt.Errorf("Heal attempt failed for %s: %w",
|
|
|
|
pathJoin(source.bucket, source.object), err))
|
|
|
|
}
|
2020-01-10 05:35:06 -05:00
|
|
|
}
|
2020-03-18 19:19:29 -04:00
|
|
|
case <-h.ctx.Done():
|
2020-01-10 05:35:06 -05:00
|
|
|
return nil
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
}
|
2019-06-09 01:14:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *healSequence) healFromSourceCh() {
|
2019-10-15 21:35:41 -04:00
|
|
|
h.healItemsFromSourceCh()
|
2019-06-09 01:14:07 -04:00
|
|
|
}
|
|
|
|
|
2020-06-29 16:07:26 -04:00
|
|
|
func (h *healSequence) healDiskMeta() error {
|
2018-01-22 17:54:55 -05:00
|
|
|
// Start with format healing
|
2019-06-09 01:14:07 -04:00
|
|
|
if err := h.healDiskFormat(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2019-02-10 22:53:13 -05:00
|
|
|
// Start healing the config prefix.
|
2019-06-09 01:14:07 -04:00
|
|
|
if err := h.healMinioSysMeta(minioConfigPrefix)(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-02-10 22:53:13 -05:00
|
|
|
|
|
|
|
// Start healing the bucket config prefix.
|
2020-06-29 16:07:26 -04:00
|
|
|
return h.healMinioSysMeta(bucketConfigPrefix)()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *healSequence) healItems(bucketsOnly bool) error {
|
|
|
|
if err := h.healDiskMeta(); 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-01-15 04:08:39 -05:00
|
|
|
return h.healBuckets(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.
|
|
|
|
func (h *healSequence) traverseAndHeal() {
|
2020-01-15 04:08:39 -05:00
|
|
|
bucketsOnly := false // Heals buckets and objects also.
|
2020-05-04 01:35:40 -04:00
|
|
|
h.traverseAndHealDoneCh <- h.healItems(bucketsOnly)
|
2018-01-22 17:54:55 -05:00
|
|
|
close(h.traverseAndHealDoneCh)
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
func (h *healSequence) healMinioSysMeta(metaPrefix string) func() error {
|
|
|
|
return func() error {
|
|
|
|
// Get current object layer instance.
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-02-10 22:53:13 -05:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
2018-09-29 04:17:01 -04:00
|
|
|
}
|
2018-10-01 12:54:26 -04:00
|
|
|
|
2019-02-10 22:53:13 -05:00
|
|
|
// NOTE: Healing on meta is run regardless
|
|
|
|
// of any bucket being selected, this is to ensure that
|
|
|
|
// meta are always upto date and correct.
|
2020-06-12 23:04:01 -04:00
|
|
|
return objectAPI.HealObjects(h.ctx, minioMetaBucket, metaPrefix, h.settings, func(bucket, object, versionID string) 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)
|
2019-03-13 20:35:09 -04:00
|
|
|
// Object might have been deleted, by the time heal
|
|
|
|
// was attempted we ignore this object an move on.
|
2020-08-24 16:47:01 -04:00
|
|
|
if isErrObjectNotFound(err) || isErrVersionNotFound(err) {
|
2019-03-13 20:35:09 -04:00
|
|
|
return nil
|
2018-10-01 12:54:26 -04:00
|
|
|
}
|
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
|
|
|
// healDiskFormat - heals format.json, return value indicates if a
|
|
|
|
// failure error occurred.
|
|
|
|
func (h *healSequence) healDiskFormat() error {
|
2018-10-01 12:54:26 -04:00
|
|
|
if h.isQuitting() {
|
|
|
|
return errHealStopSignalled
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// Get current object layer instance.
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-01-22 17:54:55 -05:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
return h.queueHealTask(healSource{bucket: SlashSeparator}, madmin.HealItemMetadata)
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// healBuckets - check for all buckets heal or just particular bucket.
|
2020-01-15 04:08:39 -05:00
|
|
|
func (h *healSequence) healBuckets(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-01-15 04:08:39 -05:00
|
|
|
return h.healBucket(h.bucket, bucketsOnly)
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get current object layer instance.
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-01-22 17:54:55 -05:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
2018-03-14 15:01:47 -04:00
|
|
|
buckets, err := objectAPI.ListBucketsHeal(h.ctx)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
for _, bucket := range buckets {
|
2020-01-15 04:08:39 -05:00
|
|
|
if err = h.healBucket(bucket.Name, bucketsOnly); err != nil {
|
2018-01-22 17:54:55 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// healBucket - traverses and heals given bucket
|
2020-01-15 04:08:39 -05:00
|
|
|
func (h *healSequence) healBucket(bucket string, bucketsOnly bool) error {
|
2018-01-22 17:54:55 -05:00
|
|
|
// Get current object layer instance.
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-01-22 17:54:55 -05:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := h.queueHealTask(healSource{bucket: bucket}, madmin.HealItemBucket); err != nil {
|
2020-08-26 11:53:33 -04:00
|
|
|
if !isErrObjectNotFound(err) && !isErrVersionNotFound(err) {
|
|
|
|
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 != "" {
|
2018-01-22 17:54:55 -05:00
|
|
|
// Check if an object named as the objPrefix exists,
|
|
|
|
// and if so heal it.
|
2020-08-17 11:25:44 -04:00
|
|
|
oi, err := objectAPI.GetObjectInfo(h.ctx, bucket, h.object, ObjectOptions{})
|
2018-01-22 17:54:55 -05:00
|
|
|
if err == nil {
|
2020-08-17 11:25:44 -04:00
|
|
|
if err = h.healObject(bucket, h.object, oi.VersionID); err != nil {
|
2020-08-26 11:53:33 -04:00
|
|
|
if isErrObjectNotFound(err) || isErrVersionNotFound(err) {
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-22 17:54:55 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := objectAPI.HealObjects(h.ctx, bucket, h.object, h.settings, h.healObject); err != nil {
|
2020-08-26 11:53:33 -04:00
|
|
|
// Object might have been deleted, by the time heal
|
|
|
|
// was attempted we ignore this object an move on.
|
|
|
|
if !isErrObjectNotFound(err) && !isErrVersionNotFound(err) {
|
|
|
|
return errFnHealFromAPIErr(h.ctx, err)
|
|
|
|
}
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// healObject - heal the given object and record result
|
2020-06-12 23:04:01 -04:00
|
|
|
func (h *healSequence) healObject(bucket, object, versionID string) error {
|
2018-01-22 17:54:55 -05:00
|
|
|
// Get current object layer instance.
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-01-22 17:54:55 -05:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}, madmin.HealItemObject)
|
2020-08-24 16:47:01 -04:00
|
|
|
return err
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|