heal: Fix healing empty directories (#7154)

This commit fixes the computation of Before/After healing state
for empty directories.

Issues before the commit:
- Before state doesn't reflect the real status (no StatVol() called)
- For any MakeVol() error, healObjectDir is exited directly, which is
  wrong.
master
Anis Elleuch 6 years ago committed by kannappanr
parent d3553f8dfc
commit 2d9860e875
  1. 67
      cmd/xl-v1-healing.go

@ -515,44 +515,55 @@ func (xl xlObjects) healObjectDir(ctx context.Context, bucket, object string, dr
ObjectSize: 0, ObjectSize: 0,
} }
hr.Before.Drives = make([]madmin.HealDriveInfo, len(storageDisks))
hr.After.Drives = make([]madmin.HealDriveInfo, len(storageDisks))
var wg sync.WaitGroup
// Prepare object creation in all disks // Prepare object creation in all disks
for _, disk := range storageDisks { for i, d := range storageDisks {
wg.Add(1)
go func(idx int, disk StorageAPI) {
defer wg.Done()
if disk == nil { if disk == nil {
hr.Before.Drives = append(hr.Before.Drives, madmin.HealDriveInfo{ hr.Before.Drives[idx] = madmin.HealDriveInfo{State: madmin.DriveStateOffline}
UUID: "", hr.After.Drives[idx] = madmin.HealDriveInfo{State: madmin.DriveStateOffline}
State: madmin.DriveStateOffline, return
})
hr.After.Drives = append(hr.After.Drives, madmin.HealDriveInfo{
UUID: "",
State: madmin.DriveStateMissing,
})
continue
} }
drive := disk.String() drive := disk.String()
hr.Before.Drives = append(hr.Before.Drives, madmin.HealDriveInfo{ hr.Before.Drives[idx] = madmin.HealDriveInfo{UUID: "", Endpoint: drive, State: madmin.DriveStateOffline}
UUID: "", hr.After.Drives[idx] = madmin.HealDriveInfo{UUID: "", Endpoint: drive, State: madmin.DriveStateOffline}
Endpoint: drive,
State: madmin.DriveStateMissing, _, statErr := disk.StatVol(pathJoin(bucket, object))
}) switch statErr {
hr.After.Drives = append(hr.After.Drives, madmin.HealDriveInfo{ case nil:
UUID: "", hr.Before.Drives[idx].State = madmin.DriveStateOk
Endpoint: drive, hr.After.Drives[idx].State = madmin.DriveStateOk
State: madmin.DriveStateMissing, // Object is fine in this disk, nothing to be done anymore, exiting
}) return
case errVolumeNotFound:
if !dryRun { hr.Before.Drives[idx].State = madmin.DriveStateMissing
if err := disk.MakeVol(pathJoin(bucket, object)); err != nil && err != errVolumeExists { hr.After.Drives[idx].State = madmin.DriveStateMissing
return hr, toObjectErr(err, bucket, object) default:
logger.LogIf(ctx, err)
return
} }
for i, v := range hr.Before.Drives { if dryRun {
if v.Endpoint == drive { return
hr.After.Drives[i].State = madmin.DriveStateOk
}
} }
if err := disk.MakeVol(pathJoin(bucket, object)); err == nil || err == errVolumeExists {
hr.After.Drives[idx].State = madmin.DriveStateOk
} else {
logger.LogIf(ctx, err)
hr.After.Drives[idx].State = madmin.DriveStateOffline
} }
}(i, d)
} }
wg.Wait()
return hr, nil return hr, nil
} }

Loading…
Cancel
Save