From d267d152ba77221b7508d994b3e77f5233722765 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Wed, 7 Apr 2021 19:39:48 +0200 Subject: [PATCH] healing: re-read metadata after lock (#12004) Do no use potentially wrong metadata from before acquiring lock. Plus remove unused NoLock option. --- cmd/erasure-healing.go | 19 ++++++++++--------- pkg/madmin/heal-commands.go | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/erasure-healing.go b/cmd/erasure-healing.go index 47f51f4cb..062c49183 100644 --- a/cmd/erasure-healing.go +++ b/cmd/erasure-healing.go @@ -231,7 +231,7 @@ func shouldHealObjectOnDisk(erErr, dataErr error, meta FileInfo, quorumModTime t } // Heals an object by re-writing corrupt/missing erasure blocks. -func (er erasureObjects) healObject(ctx context.Context, bucket string, object string, versionID string, partsMetadata []FileInfo, errs []error, opts madmin.HealOpts) (result madmin.HealResultItem, err error) { +func (er erasureObjects) healObject(ctx context.Context, bucket string, object string, versionID string, opts madmin.HealOpts) (result madmin.HealResultItem, err error) { dryRun := opts.DryRun scanMode := opts.ScanMode @@ -249,13 +249,14 @@ func (er erasureObjects) healObject(ctx context.Context, bucket string, object s DataBlocks: len(storageDisks) - er.defaultParityCount, } - if !opts.NoLock { - lk := er.NewNSLock(bucket, object) - if ctx, err = lk.GetLock(ctx, globalOperationTimeout); err != nil { - return result, err - } - defer lk.Unlock() + lk := er.NewNSLock(bucket, object) + if ctx, err = lk.GetLock(ctx, globalOperationTimeout); err != nil { + return result, err } + defer lk.Unlock() + + // Re-read when we have lock... + partsMetadata, errs := readAllFileInfo(ctx, storageDisks, bucket, object, versionID, true) // List of disks having latest version of the object er.meta // (by modtime). @@ -857,7 +858,7 @@ func (er erasureObjects) HealObject(ctx context.Context, bucket, object, version versionID = nullVersionID } - partsMetadata, errs := readAllFileInfo(healCtx, storageDisks, bucket, object, versionID, true) + partsMetadata, errs := readAllFileInfo(healCtx, storageDisks, bucket, object, versionID, false) if isAllNotFound(errs) { err = toObjectErr(errFileNotFound, bucket, object) @@ -874,5 +875,5 @@ func (er erasureObjects) HealObject(ctx context.Context, bucket, object, version } // Heal the object. - return er.healObject(healCtx, bucket, object, versionID, partsMetadata, errs, opts) + return er.healObject(healCtx, bucket, object, versionID, opts) } diff --git a/pkg/madmin/heal-commands.go b/pkg/madmin/heal-commands.go index 21455a05d..0fea8ad07 100644 --- a/pkg/madmin/heal-commands.go +++ b/pkg/madmin/heal-commands.go @@ -48,7 +48,6 @@ type HealOpts struct { DryRun bool `json:"dryRun"` Remove bool `json:"remove"` Recreate bool `json:"recreate"` // only used when bucket needs to be healed - NoLock bool `json:"-"` // only used internally. ScanMode HealScanMode `json:"scanMode"` }