Skip to content

Commit

Permalink
SKS-2227: Fix deleting a PG might create multiple deletion tasks at t…
Browse files Browse the repository at this point in the history
…he same time (#164)
  • Loading branch information
haijianyang committed Dec 13, 2023
1 parent a30b311 commit 5e75d87
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/service/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@ func (svr *TowerVMService) DeleteVMPlacementGroupsByNamePrefix(ctx goctx.Context
},
}

if _, err := svr.Session.VMPlacementGroup.DeleteVMPlacementGroup(deleteVMPlacementGroupParams); err != nil {
deleteVMPlacementGroupResp, err := svr.Session.VMPlacementGroup.DeleteVMPlacementGroup(deleteVMPlacementGroupParams)
if err != nil {
return nil, err
}

Expand All @@ -956,6 +957,25 @@ func (svr *TowerVMService) DeleteVMPlacementGroupsByNamePrefix(ctx goctx.Context
pgNames[i] = *getVMPlacementGroupsResp.Payload[i].Name
}

if len(deleteVMPlacementGroupResp.Payload) == 0 {
return pgNames, nil
}

// With consecutive calls to DeleteVMPlacementGroupsByNamePrefix (e.g. a short reconcile interval),
// Tower may create duplicate tasks for deleting placement groups.
// Wait for the first deletion task to complete or timeout,
// can increase the interval between calls to DeleteVMPlacementGroupsByNamePrefix
// to reduce the probability of duplicate deletion tasks.
taskID := *deleteVMPlacementGroupResp.Payload[0].TaskID
withLatestStatusTask, err := svr.WaitTask(ctx, taskID, config.WaitTaskTimeoutForPlacementGroupOperation, config.WaitTaskInterval)
if err != nil {
return pgNames, errors.Wrapf(err, "failed to wait for placement groups with name prefix %s deleting task to complete in %s: taskID %s", namePrefix, config.WaitTaskTimeoutForPlacementGroupOperation, taskID)
}

if *withLatestStatusTask.Status == models.TaskStatusFAILED {
return pgNames, errors.Errorf("failed to delete placement groups with name prefix %s in task %s", namePrefix, *withLatestStatusTask.ID)
}

return pgNames, nil
}

Expand Down

0 comments on commit 5e75d87

Please sign in to comment.