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. 73
      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 {
if disk == nil { wg.Add(1)
hr.Before.Drives = append(hr.Before.Drives, madmin.HealDriveInfo{ go func(idx int, disk StorageAPI) {
UUID: "", defer wg.Done()
State: madmin.DriveStateOffline, if disk == nil {
}) hr.Before.Drives[idx] = madmin.HealDriveInfo{State: madmin.DriveStateOffline}
hr.After.Drives = append(hr.After.Drives, madmin.HealDriveInfo{ hr.After.Drives[idx] = madmin.HealDriveInfo{State: madmin.DriveStateOffline}
UUID: "", return
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:
hr.Before.Drives[idx].State = madmin.DriveStateMissing
hr.After.Drives[idx].State = madmin.DriveStateMissing
default:
logger.LogIf(ctx, err)
return
}
if !dryRun { if dryRun {
if err := disk.MakeVol(pathJoin(bucket, object)); err != nil && err != errVolumeExists { return
return hr, toObjectErr(err, bucket, object)
} }
for i, v := range hr.Before.Drives { if err := disk.MakeVol(pathJoin(bucket, object)); err == nil || err == errVolumeExists {
if v.Endpoint == drive { hr.After.Drives[idx].State = madmin.DriveStateOk
hr.After.Drives[i].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