From dfeee61df8c999a71a5bfe8dbdf11b109748de7e Mon Sep 17 00:00:00 2001 From: qzhu Date: Mon, 19 Aug 2024 10:29:22 -0500 Subject: [PATCH] [YUNIKORN-2816] Clean up AllocationReleaseRequest logic (#895) Closes: #895 Signed-off-by: Craig Condit --- pkg/cache/task.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/cache/task.go b/pkg/cache/task.go index c77739659..eccab00a7 100644 --- a/pkg/cache/task.go +++ b/pkg/cache/task.go @@ -482,7 +482,7 @@ func (task *Task) beforeTaskCompleted() { "Task %s is completed", task.alias) } -// releaseAllocation sends the release request for the Allocation or the AllocationAsk to the core. +// releaseAllocation sends the release request for the Allocation to the core. func (task *Task) releaseAllocation() { // scheduler api might be nil in some tests if task.context.apiProvider.GetAPIs().SchedulerAPI != nil { @@ -494,25 +494,31 @@ func (task *Task) releaseAllocation() { zap.String("task", task.GetTaskState()), zap.String("terminationType", task.terminationType)) - // The message depends on current task state, generate requests accordingly. - // If allocated send an AllocationReleaseRequest, - // If not allocated yet send an AllocationAskReleaseRequest + // send an AllocationReleaseRequest var releaseRequest *si.AllocationRequest s := TaskStates() - switch task.GetTaskState() { - case s.New, s.Pending, s.Scheduling, s.Rejected: - releaseRequest = common.CreateReleaseRequestForTask(task.applicationID, task.taskID, task.application.partition, task.terminationType) - default: + + // check if the task is in a state where it has not been allocated yet + if task.GetTaskState() != s.New && task.GetTaskState() != s.Pending && + task.GetTaskState() != s.Scheduling && task.GetTaskState() != s.Rejected { + // task is in a state where it might have been allocated if task.allocationKey == "" { log.Log(log.ShimCacheTask).Warn("BUG: task allocationKey is empty on release", zap.String("applicationID", task.applicationID), zap.String("taskID", task.taskID), zap.String("taskAlias", task.alias), - zap.String("task", task.GetTaskState())) + zap.String("taskState", task.GetTaskState())) } - releaseRequest = common.CreateReleaseRequestForTask(task.applicationID, task.taskID, task.application.partition, task.terminationType) } + // create the release request + releaseRequest = common.CreateReleaseRequestForTask( + task.applicationID, + task.taskID, + task.application.partition, + task.terminationType, + ) + if releaseRequest.Releases != nil { log.Log(log.ShimCacheTask).Info("releasing allocations", zap.Int("numOfAllocationsToRelease", len(releaseRequest.Releases.AllocationsToRelease)))