From 46de9ac03eece18d0152c0484141c4b9c6cdcecc Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Tue, 3 May 2022 21:36:08 +0100 Subject: [PATCH] Decom: Easily restart decommission when it is done (#14855) When a decommission task is successfully completed, failed, or canceled, this commit allows restarting the decommission again. Restarting is not allowed when there is an ongoing decommission task. --- cmd/erasure-server-pool-decom.go | 47 +++++++++++--------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/cmd/erasure-server-pool-decom.go b/cmd/erasure-server-pool-decom.go index ce66b9dfa..0889ebfa6 100644 --- a/cmd/erasure-server-pool-decom.go +++ b/cmd/erasure-server-pool-decom.go @@ -242,39 +242,24 @@ func (p *poolMeta) Decommission(idx int, pi poolSpaceInfo) error { } } + // Return an error when there is decommission on going - the user needs + // to explicitly cancel it first in order to restart decommissioning again. + if p.Pools[idx].Decommission != nil && + !p.Pools[idx].Decommission.Complete && + !p.Pools[idx].Decommission.Failed && + !p.Pools[idx].Decommission.Canceled { + return errDecommissionAlreadyRunning + } + now := UTCNow() - if p.Pools[idx].Decommission == nil { - p.Pools[idx].LastUpdate = now - p.Pools[idx].Decommission = &PoolDecommissionInfo{ - StartTime: now, - StartSize: pi.Free, - CurrentSize: pi.Free, - TotalSize: pi.Total, - } - return nil + p.Pools[idx].LastUpdate = now + p.Pools[idx].Decommission = &PoolDecommissionInfo{ + StartTime: now, + StartSize: pi.Free, + CurrentSize: pi.Free, + TotalSize: pi.Total, } - - // Completed pool doesn't need to be decommissioned again. - if p.Pools[idx].Decommission.Complete { - return errDecommissionComplete - } - - // Canceled or Failed decommission can be triggered again. - if p.Pools[idx].Decommission.StartTime.IsZero() { - if p.Pools[idx].Decommission.Canceled || p.Pools[idx].Decommission.Failed { - p.Pools[idx].LastUpdate = now - p.Pools[idx].Decommission = &PoolDecommissionInfo{ - StartTime: now, - StartSize: pi.Free, - CurrentSize: pi.Free, - TotalSize: pi.Total, - } - return nil - } - } // In-progress pool doesn't need to be decommissioned again. - - // In all other scenarios an active decommissioning is in progress. - return errDecommissionAlreadyRunning + return nil } func (p poolMeta) IsSuspended(idx int) bool {