mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
code review feedback
This commit is contained in:
@@ -109,10 +109,11 @@ type AllocationMetric struct {
|
||||
ClassExhausted map[string]int
|
||||
DimensionExhausted map[string]int
|
||||
QuotaExhausted []string
|
||||
Scores map[string]float64
|
||||
AllocationTime time.Duration
|
||||
CoalescedFailures int
|
||||
ScoreMetaData []*NodeScoreMeta
|
||||
// Deprecated, replaced with ScoreMetaData
|
||||
Scores map[string]float64
|
||||
AllocationTime time.Duration
|
||||
CoalescedFailures int
|
||||
ScoreMetaData []*NodeScoreMeta
|
||||
}
|
||||
|
||||
// NodeScoreMeta is used to serialize node scoring metadata
|
||||
|
||||
@@ -61,3 +61,16 @@ func (pq *ScoreHeap) Pop() interface{} {
|
||||
pq.items = old[0 : n-1]
|
||||
return item
|
||||
}
|
||||
|
||||
// GetItemsReverse returns the items in this min heap in reverse order
|
||||
// sorted by score descending
|
||||
func (pq *ScoreHeap) GetItemsReverse() []interface{} {
|
||||
ret := make([]interface{}, pq.Len())
|
||||
i := pq.Len() - 1
|
||||
for pq.Len() > 0 {
|
||||
item := heap.Pop(pq)
|
||||
ret[i] = item
|
||||
i--
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -6618,13 +6618,9 @@ func (a *AllocMetric) PopulateScoreMetaData() {
|
||||
if a.ScoreMetaData == nil {
|
||||
a.ScoreMetaData = make([]*NodeScoreMeta, a.topScores.Len())
|
||||
}
|
||||
i := a.topScores.Len() - 1
|
||||
// Pop from the heap and store in reverse to get top K
|
||||
// scoring nodes in descending order
|
||||
for a.topScores.Len() > 0 {
|
||||
item := heap.Pop(a.topScores).(*NodeScoreMeta)
|
||||
a.ScoreMetaData[i] = item
|
||||
i--
|
||||
heapItems := a.topScores.GetItemsReverse()
|
||||
for i, item := range heapItems {
|
||||
a.ScoreMetaData[i] = item.(*NodeScoreMeta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,6 +304,9 @@ func (s *SystemScheduler) computePlacements(place []allocTuple) error {
|
||||
// Store the available nodes by datacenter
|
||||
s.ctx.Metrics().NodesAvailable = s.nodesByDC
|
||||
|
||||
// Compute top K scoring node metadata
|
||||
s.ctx.Metrics().PopulateScoreMetaData()
|
||||
|
||||
// Set fields based on if we found an allocation option
|
||||
if option != nil {
|
||||
// Create an allocation for this
|
||||
|
||||
Reference in New Issue
Block a user