2019-10-28 13:27:49 -04:00
|
|
|
/*
|
|
|
|
* MinIO Cloud Storage, (C) 2019 MinIO, Inc.
|
|
|
|
*
|
|
|
|
* 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 (
|
|
|
|
"context"
|
2021-02-18 14:06:54 -05:00
|
|
|
"errors"
|
2019-10-28 13:27:49 -04:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/minio/minio/cmd/logger"
|
2021-01-19 05:40:52 -05:00
|
|
|
"github.com/minio/minio/pkg/color"
|
|
|
|
"github.com/minio/minio/pkg/console"
|
2019-10-28 13:27:49 -04:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
bgHealingUUID = "0000-0000-0000-0000"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewBgHealSequence creates a background healing sequence
|
|
|
|
// operation which crawls all objects and heal them.
|
2020-06-29 16:07:26 -04:00
|
|
|
func newBgHealSequence() *healSequence {
|
2019-10-28 13:27:49 -04:00
|
|
|
reqInfo := &logger.ReqInfo{API: "BackgroundHeal"}
|
2020-05-04 01:35:40 -04:00
|
|
|
ctx, cancelCtx := context.WithCancel(logger.SetReqInfo(GlobalContext, reqInfo))
|
2019-10-28 13:27:49 -04:00
|
|
|
|
|
|
|
hs := madmin.HealOpts{
|
|
|
|
// Remove objects that do not have read-quorum
|
|
|
|
Remove: true,
|
|
|
|
ScanMode: madmin.HealNormalScan,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &healSequence{
|
2020-04-01 15:14:00 -04:00
|
|
|
sourceCh: make(chan healSource),
|
2020-04-30 23:23:00 -04:00
|
|
|
respCh: make(chan healResult),
|
2019-10-28 13:27:49 -04:00
|
|
|
startTime: UTCNow(),
|
|
|
|
clientToken: bgHealingUUID,
|
2020-08-07 22:43:06 -04:00
|
|
|
// run-background heal with reserved bucket
|
|
|
|
bucket: minioReservedBucket,
|
|
|
|
settings: hs,
|
2019-10-28 13:27:49 -04:00
|
|
|
currentStatus: healSequenceStatus{
|
|
|
|
Summary: healNotStartedStatus,
|
|
|
|
HealSettings: hs,
|
|
|
|
},
|
2020-05-04 01:35:40 -04:00
|
|
|
cancelCtx: cancelCtx,
|
|
|
|
ctx: ctx,
|
|
|
|
reportProgress: false,
|
|
|
|
scannedItemsMap: make(map[madmin.HealItemType]int64),
|
|
|
|
healedItemsMap: make(map[madmin.HealItemType]int64),
|
|
|
|
healFailedItemsMap: make(map[string]int64),
|
2019-10-28 13:27:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 22:43:06 -04:00
|
|
|
func getLocalBackgroundHealStatus() (madmin.BgHealState, bool) {
|
2020-09-10 12:16:26 -04:00
|
|
|
if globalBackgroundHealState == nil {
|
|
|
|
return madmin.BgHealState{}, false
|
|
|
|
}
|
2020-09-24 18:36:47 -04:00
|
|
|
|
2019-10-28 13:27:49 -04:00
|
|
|
bgSeq, ok := globalBackgroundHealState.getHealSequenceByToken(bgHealingUUID)
|
|
|
|
if !ok {
|
2020-08-07 22:43:06 -04:00
|
|
|
return madmin.BgHealState{}, false
|
2019-10-28 13:27:49 -04:00
|
|
|
}
|
|
|
|
|
2020-09-24 18:36:47 -04:00
|
|
|
var healDisksMap = map[string]struct{}{}
|
|
|
|
for _, ep := range getLocalDisksToHeal() {
|
|
|
|
healDisksMap[ep.String()] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ep := range globalBackgroundHealState.getHealLocalDisks() {
|
|
|
|
if _, ok := healDisksMap[ep.String()]; !ok {
|
|
|
|
healDisksMap[ep.String()] = struct{}{}
|
|
|
|
}
|
2020-09-04 20:09:02 -04:00
|
|
|
}
|
|
|
|
|
2020-08-07 16:22:53 -04:00
|
|
|
var healDisks []string
|
2020-09-24 18:36:47 -04:00
|
|
|
for disk := range healDisksMap {
|
|
|
|
healDisks = append(healDisks, disk)
|
2020-08-07 16:22:53 -04:00
|
|
|
}
|
|
|
|
|
2019-10-28 13:27:49 -04:00
|
|
|
return madmin.BgHealState{
|
2020-03-25 01:40:45 -04:00
|
|
|
ScannedItemsCount: bgSeq.getScannedItemsCount(),
|
2019-10-28 13:27:49 -04:00
|
|
|
LastHealActivity: bgSeq.lastHealActivity,
|
2020-08-07 16:22:53 -04:00
|
|
|
HealDisks: healDisks,
|
2020-08-26 11:53:33 -04:00
|
|
|
NextHealRound: UTCNow(),
|
2020-08-07 22:43:06 -04:00
|
|
|
}, true
|
2019-10-28 13:27:49 -04:00
|
|
|
}
|
|
|
|
|
2020-12-13 14:57:08 -05:00
|
|
|
func mustGetHealSequence(ctx context.Context) *healSequence {
|
2019-10-28 13:27:49 -04:00
|
|
|
// Get background heal sequence to send elements to heal
|
|
|
|
for {
|
2020-12-13 14:57:08 -05:00
|
|
|
globalHealStateLK.RLock()
|
|
|
|
hstate := globalBackgroundHealState
|
|
|
|
globalHealStateLK.RUnlock()
|
|
|
|
|
|
|
|
if hstate == nil {
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
continue
|
2019-10-28 13:27:49 -04:00
|
|
|
}
|
2020-12-13 14:57:08 -05:00
|
|
|
|
|
|
|
bgSeq, ok := hstate.getHealSequenceByToken(bgHealingUUID)
|
|
|
|
if !ok {
|
|
|
|
time.Sleep(time.Second)
|
2020-05-04 01:35:40 -04:00
|
|
|
continue
|
|
|
|
}
|
2020-12-13 14:57:08 -05:00
|
|
|
return bgSeq
|
2019-10-28 13:27:49 -04:00
|
|
|
}
|
2020-12-13 14:57:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// healErasureSet lists and heals all objects in a specific erasure set
|
2021-02-18 14:06:54 -05:00
|
|
|
func (er *erasureObjects) healErasureSet(ctx context.Context, buckets []BucketInfo) error {
|
2020-12-13 14:57:08 -05:00
|
|
|
bgSeq := mustGetHealSequence(ctx)
|
2020-07-17 13:08:04 -04:00
|
|
|
buckets = append(buckets, BucketInfo{
|
|
|
|
Name: pathJoin(minioMetaBucket, minioConfigPrefix),
|
2020-12-13 14:57:08 -05:00
|
|
|
})
|
2020-07-17 13:08:04 -04:00
|
|
|
|
2020-10-24 16:23:08 -04:00
|
|
|
// Try to pro-actively heal backend-encrypted file.
|
2021-02-18 14:06:54 -05:00
|
|
|
if _, err := er.HealObject(ctx, minioMetaBucket, backendEncryptedFile, "", madmin.HealOpts{}); err != nil {
|
2020-12-24 18:02:02 -05:00
|
|
|
if !isErrObjectNotFound(err) && !isErrVersionNotFound(err) {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
}
|
2020-10-24 16:23:08 -04:00
|
|
|
}
|
|
|
|
|
2019-10-28 13:27:49 -04:00
|
|
|
// Heal all buckets with all objects
|
|
|
|
for _, bucket := range buckets {
|
|
|
|
// Heal current bucket
|
2021-02-18 14:06:54 -05:00
|
|
|
if _, err := er.HealBucket(ctx, bucket.Name, madmin.HealOpts{}); err != nil {
|
2020-12-24 18:02:02 -05:00
|
|
|
if !isErrObjectNotFound(err) && !isErrVersionNotFound(err) {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
}
|
2020-04-01 15:14:00 -04:00
|
|
|
}
|
2019-10-28 13:27:49 -04:00
|
|
|
|
2021-01-19 05:40:52 -05:00
|
|
|
if serverDebugLog {
|
2021-02-18 14:06:54 -05:00
|
|
|
console.Debugf(color.Green("healDisk:")+" healing bucket %s content on erasure set %d\n", bucket.Name, er.setNumber+1)
|
2021-01-19 05:40:52 -05:00
|
|
|
}
|
|
|
|
|
2021-02-18 14:06:54 -05:00
|
|
|
disks, _ := er.getOnlineDisksWithHealing()
|
|
|
|
if len(disks) == 0 {
|
|
|
|
return errors.New("healErasureSet: No non-healing disks found")
|
2020-06-09 20:09:19 -04:00
|
|
|
}
|
2021-02-18 14:06:54 -05:00
|
|
|
// Limit listing to 3 drives.
|
|
|
|
if len(disks) > 3 {
|
|
|
|
disks = disks[:3]
|
|
|
|
}
|
|
|
|
healEntry := func(entry metaCacheEntry) {
|
|
|
|
if entry.isDir() {
|
|
|
|
return
|
2020-06-09 20:09:19 -04:00
|
|
|
}
|
2021-02-18 14:06:54 -05:00
|
|
|
fivs, err := entry.fileInfoVersions(bucket.Name)
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
waitForLowHTTPReq(globalHealConfig.IOCount, globalHealConfig.Sleep)
|
|
|
|
for _, version := range fivs.Versions {
|
2021-02-18 18:16:20 -05:00
|
|
|
if _, err := er.HealObject(ctx, bucket.Name, version.Name, version.VersionID, madmin.HealOpts{ScanMode: madmin.HealNormalScan, Remove: healDeleteDangling}); err != nil {
|
2020-12-24 18:02:02 -05:00
|
|
|
if !isErrObjectNotFound(err) && !isErrVersionNotFound(err) {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2021-02-18 14:06:54 -05:00
|
|
|
bgSeq.logHeal(madmin.HealItemObject)
|
2020-04-01 15:14:00 -04:00
|
|
|
}
|
2019-10-28 13:27:49 -04:00
|
|
|
}
|
2021-02-18 14:06:54 -05:00
|
|
|
err := listPathRaw(ctx, listPathRawOptions{
|
|
|
|
disks: disks,
|
|
|
|
bucket: bucket.Name,
|
|
|
|
recursive: true,
|
|
|
|
forwardTo: "", //TODO(klauspost): Set this to last known offset when resuming.
|
|
|
|
minDisks: 1,
|
|
|
|
reportNotFound: false,
|
|
|
|
agreed: healEntry,
|
|
|
|
partial: func(entries metaCacheEntries, nAgreed int, errs []error) {
|
|
|
|
entry, _ := entries.firstFound()
|
|
|
|
if entry != nil && !entry.isDir() {
|
|
|
|
healEntry(*entry)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
finished: nil,
|
|
|
|
})
|
|
|
|
logger.LogIf(ctx, err)
|
2019-10-28 13:27:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-27 13:21:14 -05:00
|
|
|
// healObject heals given object path in deep to fix bitrot.
|
|
|
|
func healObject(bucket, object, versionID string, scan madmin.HealScanMode) {
|
2020-04-01 15:14:00 -04:00
|
|
|
// Get background heal sequence to send elements to heal
|
2020-08-07 22:43:06 -04:00
|
|
|
bgSeq, ok := globalBackgroundHealState.getHealSequenceByToken(bgHealingUUID)
|
|
|
|
if ok {
|
|
|
|
bgSeq.sourceCh <- healSource{
|
|
|
|
bucket: bucket,
|
|
|
|
object: object,
|
|
|
|
versionID: versionID,
|
2020-12-02 14:12:00 -05:00
|
|
|
opts: &madmin.HealOpts{
|
|
|
|
Remove: true, // if found dangling purge it.
|
2021-01-27 13:21:14 -05:00
|
|
|
ScanMode: scan,
|
2020-12-02 14:12:00 -05:00
|
|
|
},
|
2020-08-07 22:43:06 -04:00
|
|
|
}
|
2020-04-01 15:14:00 -04:00
|
|
|
}
|
|
|
|
}
|