Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2978] Fix handling of reserved allocations where node differs #996

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/scheduler/objects/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ func (sn *Node) RemoveAllocation(allocationKey string) *Allocation {
}
sn.availableResource.AddTo(alloc.GetAllocatedResource())
sn.nodeEvents.SendAllocationRemovedEvent(sn.NodeID, alloc.allocationKey, alloc.GetAllocatedResource())
log.Log(log.SchedNode).Info("node allocation removed",
zap.String("appID", alloc.GetApplicationID()),
zap.String("allocationKey", alloc.GetAllocationKey()),
zap.Stringer("allocatedResource", alloc.GetAllocatedResource()),
zap.Bool("placeholder", alloc.IsPlaceholder()),
zap.String("targetNode", sn.NodeID))
return alloc
}

Expand Down Expand Up @@ -382,6 +388,10 @@ func (sn *Node) UpdateForeignAllocation(alloc *Allocation) *Allocation {
delta := resources.Sub(newResource, existingResource)
delta.Prune()

log.Log(log.SchedNode).Info("node foreign allocation updated",
zap.String("allocationKey", alloc.GetAllocationKey()),
zap.Stringer("deltaResource", delta),
zap.String("targetNode", sn.NodeID))
sn.occupiedResource.AddTo(delta)
sn.occupiedResource.Prune()
sn.refreshAvailableResource()
Expand Down Expand Up @@ -416,6 +426,12 @@ func (sn *Node) addAllocationInternal(alloc *Allocation, force bool) bool {
sn.availableResource.SubFrom(res)
sn.availableResource.Prune()
sn.nodeEvents.SendAllocationAddedEvent(sn.NodeID, alloc.allocationKey, res)
log.Log(log.SchedNode).Info("node allocation processed",
zap.String("appID", alloc.GetApplicationID()),
zap.String("allocationKey", alloc.GetAllocationKey()),
zap.Stringer("allocatedResource", alloc.GetAllocatedResource()),
zap.Bool("placeholder", alloc.IsPlaceholder()),
zap.String("targetNode", sn.NodeID))
result = true
return result
}
Expand All @@ -440,6 +456,12 @@ func (sn *Node) ReplaceAllocation(allocationKey string, replace *Allocation, del
sn.allocatedResource.AddTo(delta)
sn.availableResource.SubFrom(delta)
sn.availableResource.Prune()
log.Log(log.SchedNode).Info("node allocation replaced",
zap.String("appID", replace.GetApplicationID()),
zap.String("allocationKey", replace.GetAllocationKey()),
zap.Stringer("allocatedResource", replace.GetAllocatedResource()),
zap.String("placeholderKey", allocationKey),
zap.String("targetNode", sn.NodeID))
if !before.FitIn(sn.allocatedResource) {
log.Log(log.SchedNode).Warn("unexpected increase in node usage after placeholder replacement",
zap.String("placeholder allocationKey", allocationKey),
Expand Down
38 changes: 24 additions & 14 deletions pkg/scheduler/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,44 +869,54 @@
// find the node make sure it still exists
// if the node was passed in use that ID instead of the one from the allocation
// the node ID is set when a reservation is allocated on a non-reserved node
var nodeID string
alloc := result.Request
targetNodeID := result.NodeID
var srcNodeID string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to reservedNodeID is more logical than srcNodeID
The reserved node is only used if the result is Unreserved or AllocatedReserved This retrieval and the logging should be moved inside that check (line 911) and not clutter the rest of the code.

if result.ReservedNodeID == "" {
nodeID = result.NodeID
srcNodeID = result.NodeID
} else {
nodeID = result.ReservedNodeID
srcNodeID = result.ReservedNodeID
log.Log(log.SchedPartition).Debug("Reservation allocated on different node",
zap.String("current node", result.NodeID),
zap.String("reserved node", nodeID),
zap.String("reserved node", srcNodeID),
zap.String("appID", appID))
}
node := pc.GetNode(nodeID)
if node == nil {
log.Log(log.SchedPartition).Info("Node was removed while allocating",
zap.String("nodeID", nodeID),

targetNode := pc.GetNode(targetNodeID)
if targetNode == nil {
log.Log(log.SchedPartition).Info("Target node was removed while allocating",
zap.String("nodeID", targetNodeID),

Check warning on line 888 in pkg/scheduler/partition.go

View check run for this annotation

Codecov / codecov/patch

pkg/scheduler/partition.go#L887-L888

Added lines #L887 - L888 were not covered by tests
zap.String("appID", appID))

// attempt to deallocate
if alloc.IsAllocated() {
allocKey := alloc.GetAllocationKey()
if _, err := app.DeallocateAsk(allocKey); err != nil {
log.Log(log.SchedPartition).Warn("Failed to unwind allocation",
zap.String("nodeID", nodeID),
zap.String("nodeID", targetNodeID),

Check warning on line 896 in pkg/scheduler/partition.go

View check run for this annotation

Codecov / codecov/patch

pkg/scheduler/partition.go#L896

Added line #L896 was not covered by tests
zap.String("appID", appID),
zap.String("allocationKey", allocKey),
zap.Error(err))
}
}
return nil
}

// reservation
if result.ResultType == objects.Reserved {
pc.reserve(app, node, result.Request)
pc.reserve(app, targetNode, result.Request)
return nil
}
// unreserve
if result.ResultType == objects.Unreserved || result.ResultType == objects.AllocatedReserved {
pc.unReserve(app, node, result.Request)
srcNode := pc.GetNode(srcNodeID)
if srcNode != nil {
pc.unReserve(app, srcNode, result.Request)
} else {
log.Log(log.SchedPartition).Info("Source node was removed while allocating",
zap.String("nodeID", srcNodeID),
zap.String("appID", appID))
}

Check warning on line 919 in pkg/scheduler/partition.go

View check run for this annotation

Codecov / codecov/patch

pkg/scheduler/partition.go#L916-L919

Added lines #L916 - L919 were not covered by tests
if result.ResultType == objects.Unreserved {
return nil
}
Expand All @@ -915,8 +925,8 @@
}

alloc.SetBindTime(time.Now())
alloc.SetNodeID(nodeID)
alloc.SetInstanceType(node.GetInstanceType())
alloc.SetNodeID(targetNodeID)
alloc.SetInstanceType(targetNode.GetInstanceType())

// track the number of allocations
pc.updateAllocationCount(1)
Expand All @@ -929,7 +939,7 @@
zap.String("allocationKey", result.Request.GetAllocationKey()),
zap.Stringer("allocatedResource", result.Request.GetAllocatedResource()),
zap.Bool("placeholder", result.Request.IsPlaceholder()),
zap.String("targetNode", alloc.GetNodeID()))
zap.String("targetNode", targetNodeID))
// pass the allocation result back to the RM via the cluster context
return result
}
Expand Down