This is an automated email from the ASF dual-hosted git repository.
ccondit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/master by this push:
new 7806da59 [YUNIKORN-2285] Don't re-calculate reservationKey (#766)
7806da59 is described below
commit 7806da59fd693562859216b8fcd86f8d38e26b2a
Author: Peter Bacsko <[email protected]>
AuthorDate: Wed Jan 3 12:25:38 2024 -0600
[YUNIKORN-2285] Don't re-calculate reservationKey (#766)
Closes: #766
Signed-off-by: Craig Condit <[email protected]>
---
pkg/scheduler/objects/allocation_ask.go | 21 ++++++++++++++++++++-
pkg/scheduler/objects/allocation_ask_test.go | 1 +
pkg/scheduler/objects/reservation.go | 16 ++++++++++++++--
pkg/scheduler/objects/reservation_test.go | 2 ++
4 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/pkg/scheduler/objects/allocation_ask.go
b/pkg/scheduler/objects/allocation_ask.go
index 98b34f2b..38370aec 100644
--- a/pkg/scheduler/objects/allocation_ask.go
+++ b/pkg/scheduler/objects/allocation_ask.go
@@ -48,12 +48,14 @@ type AllocationAsk struct {
originator bool
tags map[string]string
allocatedResource *resources.Resource
+ resKeyWithoutNode string // the reservation key without node
// Mutable fields which need protection
pendingAskRepeat int32
allocLog map[string]*AllocationLogEntry
preemptionTriggered bool
preemptCheckTime time.Time
+ resKeyPerNode map[string]string // reservation key for a given
node
sync.RWMutex
}
@@ -65,12 +67,15 @@ type AllocationLogEntry struct {
}
func NewAllocationAsk(allocationKey string, applicationID string,
allocatedResource *resources.Resource) *AllocationAsk {
- return &AllocationAsk{
+ aa := &AllocationAsk{
allocationKey: allocationKey,
applicationID: applicationID,
allocatedResource: allocatedResource,
allocLog: make(map[string]*AllocationLogEntry),
+ resKeyPerNode: make(map[string]string),
}
+ aa.resKeyWithoutNode = reservationKeyWithoutNode(applicationID,
allocationKey)
+ return aa
}
func NewAllocationAskFromSI(ask *si.AllocationAsk) *AllocationAsk {
@@ -93,6 +98,7 @@ func NewAllocationAskFromSI(ask *si.AllocationAsk)
*AllocationAsk {
allowPreemptOther:
common.IsAllowPreemptOther(ask.PreemptionPolicy),
originator: ask.Originator,
allocLog: make(map[string]*AllocationLogEntry),
+ resKeyPerNode: make(map[string]string),
}
// this is a safety check placeholder and task group name must be set
as a combo
// order is important as task group can be set without placeholder but
not the other way around
@@ -101,6 +107,7 @@ func NewAllocationAskFromSI(ask *si.AllocationAsk)
*AllocationAsk {
zap.Stringer("SI ask", ask))
return nil
}
+ saa.resKeyWithoutNode = reservationKeyWithoutNode(ask.ApplicationID,
ask.AllocationKey)
return saa
}
@@ -298,3 +305,15 @@ func (aa *AllocationAsk) completedPendingAsk() int {
defer aa.RUnlock()
return int(aa.maxAllocations - aa.pendingAskRepeat)
}
+
+func (aa *AllocationAsk) setReservationKeyForNode(node, resKey string) {
+ aa.Lock()
+ defer aa.Unlock()
+ aa.resKeyPerNode[node] = resKey
+}
+
+func (aa *AllocationAsk) getReservationKeyForNode(node string) string {
+ aa.RLock()
+ defer aa.RUnlock()
+ return aa.resKeyPerNode[node]
+}
diff --git a/pkg/scheduler/objects/allocation_ask_test.go
b/pkg/scheduler/objects/allocation_ask_test.go
index 5f458c1f..df49e87d 100644
--- a/pkg/scheduler/objects/allocation_ask_test.go
+++ b/pkg/scheduler/objects/allocation_ask_test.go
@@ -57,6 +57,7 @@ func TestNewAsk(t *testing.T) {
askStr := ask.String()
expected := "allocationKey ask-1, applicationID app-1, Resource
map[first:10], PendingRepeats 1"
assert.Equal(t, askStr, expected, "Strings should have been equal")
+ assert.Equal(t, "app-1|ask-1", ask.resKeyWithoutNode)
//nolint:staticcheck
}
func TestPendingAskRepeat(t *testing.T) {
diff --git a/pkg/scheduler/objects/reservation.go
b/pkg/scheduler/objects/reservation.go
index b5f26c8d..84958e94 100644
--- a/pkg/scheduler/objects/reservation.go
+++ b/pkg/scheduler/objects/reservation.go
@@ -21,6 +21,7 @@ package objects
import (
"go.uber.org/zap"
+ "github.com/apache/yunikorn-core/pkg/common"
"github.com/apache/yunikorn-core/pkg/log"
)
@@ -69,9 +70,20 @@ func reservationKey(node *Node, app *Application, ask
*AllocationAsk) string {
return ""
}
if node == nil {
- return app.ApplicationID + "|" + ask.GetAllocationKey()
+ return ask.resKeyWithoutNode
}
- return node.NodeID + "|" + ask.GetAllocationKey()
+ key := ask.getReservationKeyForNode(node.NodeID)
+ if key != common.Empty {
+ return key
+ }
+
+ key = node.NodeID + "|" + ask.GetAllocationKey()
+ ask.setReservationKeyForNode(node.NodeID, key)
+ return key
+}
+
+func reservationKeyWithoutNode(appID, allocKey string) string {
+ return appID + "|" + allocKey
}
// Return the reservation key
diff --git a/pkg/scheduler/objects/reservation_test.go
b/pkg/scheduler/objects/reservation_test.go
index 4a04a59d..617ee55a 100644
--- a/pkg/scheduler/objects/reservation_test.go
+++ b/pkg/scheduler/objects/reservation_test.go
@@ -85,6 +85,8 @@ func TestReservationKey(t *testing.T) {
// other cases
reserve = reservationKey(node, nil, ask)
assert.Equal(t, reserve, "node-1|alloc-1", "incorrect node reservation
key")
+ assert.Equal(t, "node-1|alloc-1", ask.resKeyPerNode["node-1"])
+ assert.Equal(t, 1, len(ask.resKeyPerNode))
reserve = reservationKey(nil, app, ask)
assert.Equal(t, reserve, "app-1|alloc-1", "incorrect app reservation
key")
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]