Skip to content

Commit e1234c1

Browse files
schmichaelpkazmierczak
authored andcommitted
so much debugging
1 parent 6141d79 commit e1234c1

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

helper/funcs.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"reflect"
1515
"regexp"
1616
"slices"
17+
"strconv"
1718
"strings"
1819
"sync"
1920
"time"
@@ -569,3 +570,19 @@ func FindExecutableFiles(path string) (map[string]string, error) {
569570
}
570571
return executables, nil
571572
}
573+
574+
// Shorten to N runes if longer. Always returns a result of N runes.
575+
func Shorten(s string, n int) string {
576+
switch sl := len(s); {
577+
case sl == 0:
578+
return "<empty >"
579+
case sl > 0, sl < n-2:
580+
return fmt.Sprintf("[%"+strconv.Itoa(n-sl-2)+"s]", s)
581+
case sl == n-1:
582+
return s + "]"
583+
case sl == n:
584+
return s
585+
default:
586+
return s[:n]
587+
}
588+
}

nomad/state/state_store.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6011,6 +6011,9 @@ func (s *StateStore) updateSummaryWithAlloc(index uint64, alloc *structs.Allocat
60116011
summaryChanged = true
60126012
case structs.AllocClientStatusRunning, structs.AllocClientStatusFailed,
60136013
structs.AllocClientStatusComplete:
6014+
// All allocs should be created as pending first, and then updated to one
6015+
// of these states. Tests may trigger this log line by using this method
6016+
// to inject allocs.
60146017
s.logger.Error("new allocation inserted into state store with bad client status",
60156018
"alloc_id", alloc.ID, "client_status", alloc.ClientStatus)
60166019
}

nomad/structs/network.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ func (idx *NetworkIndex) SetNode(node *Node) error {
247247
// Reserve ports
248248
used := idx.getUsedPortsFor(n.IP)
249249
for _, p := range globalResPorts {
250+
fmt.Printf("Node %q Task Device %s Reserved Port: %d\n", node.ID, n.Device, p)
250251
used.Set(p)
251252
}
252253
}
@@ -270,6 +271,7 @@ func (idx *NetworkIndex) SetNode(node *Node) error {
270271
// host_network.
271272
used := idx.getUsedPortsFor(a.Address)
272273
for _, p := range globalResPorts {
274+
fmt.Printf("Node %q Node Device %s Reserved Port: %d\n", node.ID, n.Device, p)
273275
used.Set(p)
274276
}
275277

@@ -284,6 +286,7 @@ func (idx *NetworkIndex) SetNode(node *Node) error {
284286
return fmt.Errorf("error parsing reserved_ports for network %q: %w", a.Alias, err)
285287
}
286288
for _, p := range rp {
289+
fmt.Printf("Node %q Reserved Port: %d\n", node.ID, p)
287290
used.Set(uint(p))
288291
}
289292
}
@@ -347,6 +350,7 @@ func (idx *NetworkIndex) AddAllocs(allocs []*Allocation) (collide bool, reason s
347350
}
348351
}
349352
} else {
353+
panic("compat(0.11)")
350354
// COMPAT(0.11): Remove in 0.11
351355
for task, resources := range alloc.TaskResources {
352356
if len(resources.Networks) == 0 {
@@ -674,6 +678,7 @@ func getDynamicPortsPrecise(nodeUsed Bitmap, portsInOffer []int, minDynamicPort,
674678
}
675679

676680
for _, port := range reserved {
681+
fmt.Printf("getDynamicPortsPrecise: in use? %t port: %d\n", usedSet.Check(uint(port.Value)), port.Value)
677682
usedSet.Set(uint(port.Value))
678683
}
679684

scheduler/scheduler_system.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
log "github.com/hashicorp/go-hclog"
1212
"github.com/hashicorp/go-memdb"
1313
"github.com/hashicorp/go-set/v3"
14+
"github.com/hashicorp/nomad/helper"
1415
"github.com/hashicorp/nomad/helper/uuid"
1516
"github.com/hashicorp/nomad/nomad/structs"
1617
"github.com/hashicorp/nomad/scheduler/feasible"
@@ -532,7 +533,7 @@ func (s *SystemScheduler) computePlacements(
532533

533534
nodes := make([]*structs.Node, 1)
534535
for _, missing := range reconcilerResult.Place {
535-
fmt.Println("placing", missing.Name, missing.Alloc.ID[:8])
536+
fmt.Println("placing", missing.Name, helper.Shorten(missing.Alloc.ID, 8))
536537

537538
tgName := missing.TaskGroup.Name
538539

@@ -699,6 +700,10 @@ func (s *SystemScheduler) computePlacements(
699700

700701
//s.plan.AppendAlloc(alloc, nil)
701702
s.addMaybePlace(alloc)
703+
// count this node as feasible
704+
if s.feasibleNodesForTG[tgName] == nil {
705+
s.feasibleNodesForTG[tgName] = set.New[string](0)
706+
}
702707
s.feasibleNodesForTG[tgName].Insert(alloc.NodeID)
703708
}
704709

scheduler/tests/testing.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,43 @@ func (h *Harness) Scheduler(factory sstructs.Factory) sstructs.Scheduler {
9090
switch event := e.(type) {
9191
case *sstructs.PortCollisionEvent:
9292
h.t.Errorf("unexpected worker eval event: %v", event.Reason)
93+
94+
for _, alloc := range event.Allocations {
95+
sp := alloc.AllocatedResources.Shared.Ports
96+
h.t.Errorf(" \\--> %s shared ports: %d", alloc.ID, len(sp))
97+
for _, p := range sp {
98+
h.t.Errorf(" %s %d -> %d %T", p.Label, p.Value, p.To, p.IgnoreCollision)
99+
}
100+
101+
sn := alloc.AllocatedResources.Shared.Networks
102+
h.t.Errorf(" \\--> %s shared networks: %d", alloc.ID, len(sn))
103+
for _, net := range sn {
104+
h.t.Errorf(" \\--> mode %q | resvd ports: %d", net.Mode, len(net.ReservedPorts))
105+
for _, p := range net.ReservedPorts {
106+
h.t.Errorf(" %s %d -> %d %T", p.Label, p.Value, p.To, p.IgnoreCollision)
107+
}
108+
h.t.Errorf(" \\--> mode %q | dyn ports: %d", net.Mode, len(net.DynamicPorts))
109+
for _, p := range net.DynamicPorts {
110+
h.t.Errorf(" %s %d -> %d %T", p.Label, p.Value, p.To, p.IgnoreCollision)
111+
}
112+
}
113+
114+
tr := alloc.AllocatedResources.Tasks
115+
h.t.Errorf(" \\--> %s task resources: %d", alloc.ID, len(tr))
116+
for k, v := range tr {
117+
h.t.Errorf(" \\--> task %q | networks: %d", k, len(v.Networks))
118+
for _, net := range v.Networks {
119+
h.t.Errorf(" \\--> mode %q | resvd ports: %d", net.Mode, len(net.ReservedPorts))
120+
for _, p := range net.ReservedPorts {
121+
h.t.Errorf(" %s %d -> %d %T", p.Label, p.Value, p.To, p.IgnoreCollision)
122+
}
123+
h.t.Errorf(" \\--> mode %q | dyn ports: %d", net.Mode, len(net.DynamicPorts))
124+
for _, p := range net.DynamicPorts {
125+
h.t.Errorf(" %s %d -> %d %T", p.Label, p.Value, p.To, p.IgnoreCollision)
126+
}
127+
}
128+
}
129+
}
93130
}
94131
}
95132
}()

0 commit comments

Comments
 (0)