Move topk and delay heap to separate packages under lib

This commit is contained in:
Preetha Appan 2018-08-17 19:26:43 -05:00
parent 9bc0962527
commit 4f8e925b54
No known key found for this signature in database
GPG Key ID: 9F7C19990A50EAFC
7 changed files with 27 additions and 22 deletions

View File

@ -254,14 +254,20 @@ func TestAllocStatusCommand_ScoreMetrics(t *testing.T) {
mockNode1 := mock.Node()
mockNode2 := mock.Node()
a.Metrics = &structs.AllocMetric{
ScoreMetaData: map[string][]*structs.NodeScoreMeta{
"binpack": {
{NodeID: mockNode1.ID, Score: 0.77},
{NodeID: mockNode2.ID, Score: 0.75},
ScoreMetaData: []*structs.NodeScoreMeta{
{
NodeID: mockNode1.ID,
Scores: map[string]float64{
"binpack": 0.77,
"node-affinity": 0.5,
},
},
"node-affinity": {
{NodeID: mockNode1.ID, Score: 0.5},
{NodeID: mockNode2.ID, Score: 0.33},
{
NodeID: mockNode2.ID,
Scores: map[string]float64{
"binpack": 0.75,
"node-affinity": 0.33,
},
},
},
}
@ -272,10 +278,9 @@ func TestAllocStatusCommand_ScoreMetrics(t *testing.T) {
}
out := ui.OutputWriter.String()
require.Contains(out, "Placement Metrics")
require.Contains(out, fmt.Sprintf("Scorer %q, Node %q", "binpack", mockNode1.ID))
require.Contains(out, fmt.Sprintf("Scorer %q, Node %q", "binpack", mockNode2.ID))
require.Contains(out, fmt.Sprintf("Scorer %q, Node %q", "node-affinity", mockNode1.ID))
require.Contains(out, fmt.Sprintf("Scorer %q, Node %q", "binpack", mockNode2.ID))
require.Contains(out, mockNode1.ID)
require.Contains(out, mockNode2.ID)
require.Contains(out, "Final Score")
}
func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) {

View File

@ -1,4 +1,4 @@
package lib
package delayheap
import (
"container/heap"

View File

@ -1,4 +1,4 @@
package lib
package delayheap
import (
"testing"

View File

@ -1,4 +1,4 @@
package lib
package kheap
import (
"container/heap"

View File

@ -1,4 +1,4 @@
package lib
package kheap
import (
"container/heap"

View File

@ -12,7 +12,7 @@ import (
"github.com/armon/go-metrics"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/lib"
"github.com/hashicorp/nomad/lib/delayheap"
"github.com/hashicorp/nomad/nomad/structs"
)
@ -86,7 +86,7 @@ type EvalBroker struct {
// delayHeap is a heap used to track incoming evaluations that are
// not eligible to enqueue until their WaitTime
delayHeap *lib.DelayHeap
delayHeap *delayheap.DelayHeap
// delayedEvalsUpdateCh is used to trigger notifications for updates
// to the delayHeap
@ -142,7 +142,7 @@ func NewEvalBroker(timeout, initialNackDelay, subsequentNackDelay time.Duration,
timeWait: make(map[string]*time.Timer),
initialNackDelay: initialNackDelay,
subsequentNackDelay: subsequentNackDelay,
delayHeap: lib.NewDelayHeap(),
delayHeap: delayheap.NewDelayHeap(),
delayedEvalsUpdateCh: make(chan struct{}, 1),
}
b.stats.ByScheduler = make(map[string]*SchedulerStats)
@ -719,7 +719,7 @@ func (b *EvalBroker) flush() {
b.ready = make(map[string]PendingEvaluations)
b.unack = make(map[string]*unackEval)
b.timeWait = make(map[string]*time.Timer)
b.delayHeap = lib.NewDelayHeap()
b.delayHeap = delayheap.NewDelayHeap()
}
// evalWrapper satisfies the HeapNode interface

View File

@ -34,8 +34,8 @@ import (
"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/args"
"github.com/hashicorp/nomad/helper/lib"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/lib/kheap"
"github.com/mitchellh/copystructure"
"github.com/ugorji/go/codec"
@ -6510,7 +6510,7 @@ type AllocMetric struct {
// topScores is used to maintain a heap of the top K nodes with
// the highest normalized score
topScores *lib.ScoreHeap
topScores *kheap.ScoreHeap
// AllocationTime is a measure of how long the allocation
// attempt took. This can affect performance and SLAs.
@ -6599,7 +6599,7 @@ func (a *AllocMetric) ScoreNode(node *Node, name string, score float64) {
// Create the heap if its not there already
if a.topScores == nil {
a.topScores = lib.NewScoreHeap(MaxRetainedNodeScores)
a.topScores = kheap.NewScoreHeap(MaxRetainedNodeScores)
}
heap.Push(a.topScores, a.nodeScoreMeta)