mirror of
https://github.com/pgsty/minio.git
synced 2026-11-09 17:21:51 +03:00
fix(decom): preserve cancellation during finalization
Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -182,7 +182,9 @@ func (p *poolMeta) returnResumablePools() []PoolStatus {
|
||||
}
|
||||
|
||||
func (p *poolMeta) DecommissionComplete(idx int) bool {
|
||||
if p.Pools[idx].Decommission != nil && !p.Pools[idx].Decommission.Complete {
|
||||
if p.Pools[idx].Decommission != nil &&
|
||||
!p.Pools[idx].Decommission.Complete &&
|
||||
!p.Pools[idx].Decommission.Canceled {
|
||||
p.Pools[idx].LastUpdate = UTCNow()
|
||||
p.Pools[idx].Decommission.Complete = true
|
||||
p.Pools[idx].Decommission.Failed = false
|
||||
@@ -193,7 +195,9 @@ func (p *poolMeta) DecommissionComplete(idx int) bool {
|
||||
}
|
||||
|
||||
func (p *poolMeta) DecommissionFailed(idx int) bool {
|
||||
if p.Pools[idx].Decommission != nil && !p.Pools[idx].Decommission.Failed {
|
||||
if p.Pools[idx].Decommission != nil &&
|
||||
!p.Pools[idx].Decommission.Failed &&
|
||||
!p.Pools[idx].Decommission.Canceled {
|
||||
p.Pools[idx].LastUpdate = UTCNow()
|
||||
p.Pools[idx].Decommission.StartTime = time.Time{}
|
||||
p.Pools[idx].Decommission.Complete = false
|
||||
|
||||
@@ -197,3 +197,29 @@ func TestPoolMetaValidate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPoolMetaDecommissionCancellationIsTerminal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
canceled := poolMeta{Pools: []PoolStatus{{Decommission: &PoolDecommissionInfo{}}}}
|
||||
if !canceled.DecommissionCancel(0) {
|
||||
t.Fatal("failed to record cancellation")
|
||||
}
|
||||
if canceled.DecommissionFailed(0) {
|
||||
t.Fatal("a canceled decommission was changed to failed")
|
||||
}
|
||||
if canceled.DecommissionComplete(0) {
|
||||
t.Fatal("a canceled decommission was changed to complete")
|
||||
}
|
||||
if got := canceled.returnResumablePools(); len(got) != 0 {
|
||||
t.Fatalf("canceled decommission is resumable: %+v", got)
|
||||
}
|
||||
|
||||
failed := poolMeta{Pools: []PoolStatus{{Decommission: &PoolDecommissionInfo{}}}}
|
||||
if !failed.DecommissionFailed(0) {
|
||||
t.Fatal("failed to record failure")
|
||||
}
|
||||
if got := failed.returnResumablePools(); len(got) != 1 {
|
||||
t.Fatalf("failed decommission is not resumable: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user