xl: Fix locking in xl HealObject (#8455)

Move locking to the correct location, before loading
object data.
master
Anis Elleuch 5 years ago committed by Harshavardhana
parent 38e6d911ea
commit 8cc5ecec23
  1. 15
      cmd/xl-v1-healing.go

@ -679,6 +679,14 @@ func (xl xlObjects) HealObject(ctx context.Context, bucket, object string, dryRu
}
healCtx := logger.SetReqInfo(context.Background(), newReqInfo)
// Lock the object before healing. Use read lock since healing
// will only regenerate parts & xl.json of outdated disks.
objectLock := xl.nsMutex.NewNSLock(ctx, bucket, object)
if lerr := objectLock.GetRLock(globalHealingTimeout); lerr != nil {
return madmin.HealResultItem{}, lerr
}
defer objectLock.RUnlock()
// Healing directories handle it separately.
if hasSuffix(object, SlashSeparator) {
return xl.healObjectDir(healCtx, bucket, object, dryRun)
@ -707,13 +715,6 @@ func (xl xlObjects) HealObject(ctx context.Context, bucket, object string, dryRu
return defaultHealResult(xlMetaV1{}, storageDisks, errs, bucket, object), toObjectErr(err, bucket, object)
}
// Lock the object before healing.
objectLock := xl.nsMutex.NewNSLock(ctx, bucket, object)
if lerr := objectLock.GetRLock(globalHealingTimeout); lerr != nil {
return defaultHealResult(latestXLMeta, storageDisks, errs, bucket, object), lerr
}
defer objectLock.RUnlock()
errCount := 0
for _, err := range errs {
if err != nil {

Loading…
Cancel
Save