Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
61c52a4a
Commit
61c52a4a
authored
3 years ago
by
Michael Schurter
Browse files
Options
Download
Email Patches
Plain Diff
wip alloc copy fixes
parent
71cafc5d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
nomad/structs/funcs.go
+1
-0
nomad/structs/funcs.go
nomad/structs/network.go
+1
-0
nomad/structs/network.go
nomad/structs/structs.go
+38
-10
nomad/structs/structs.go
scheduler/rank.go
+1
-0
scheduler/rank.go
scheduler/util.go
+3
-8
scheduler/util.go
with
44 additions
and
18 deletions
+44
-18
nomad/structs/funcs.go
+
1
-
0
View file @
61c52a4a
...
...
@@ -193,6 +193,7 @@ func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevi
}
// Check if the network is overcommitted
//XXX Remove
if
netIdx
.
Overcommitted
()
{
return
false
,
"bandwidth exceeded"
,
used
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/network.go
+
1
-
0
View file @
61c52a4a
...
...
@@ -216,6 +216,7 @@ func (idx *NetworkIndex) AddReserved(n *NetworkResource) (collide bool) {
for
_
,
port
:=
range
ports
{
// Guard against invalid port
if
port
.
Value
<
0
||
port
.
Value
>=
MaxValidPort
{
//XXX Is it safe to return early here? or should we continue so used is properly updated
return
true
}
if
used
.
Check
(
uint
(
port
.
Value
))
{
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/structs.go
+
38
-
10
View file @
61c52a4a
...
...
@@ -2529,6 +2529,12 @@ func (p AllocatedPorts) Get(label string) (AllocatedPortMapping, bool) {
return
AllocatedPortMapping
{},
false
}
func
(
p
AllocatedPorts
)
Copy
()
AllocatedPorts
{
n
:=
make
(
AllocatedPorts
,
len
(
p
))
copy
(
n
,
p
)
return
n
}
type
Port
struct
{
// Label is the key for HCL port stanzas: port "foo" {}
Label
string
...
...
@@ -3690,7 +3696,7 @@ func (a AllocatedSharedResources) Copy() AllocatedSharedResources {
return
AllocatedSharedResources
{
Networks
:
a
.
Networks
.
Copy
(),
DiskMB
:
a
.
DiskMB
,
Ports
:
a
.
Ports
,
Ports
:
a
.
Ports
.
Copy
()
,
}
}
...
...
@@ -9121,6 +9127,21 @@ type DesiredTransition struct {
ForceReschedule
*
bool
}
// Copy returns a copy of the DesiredTransition
func
(
d
DesiredTransition
)
Copy
()
DesiredTransition
{
cpy
:=
DesiredTransition
{}
if
d
.
Migrate
!=
nil
{
cpy
.
Migrate
=
helper
.
BoolToPtr
(
*
d
.
Migrate
)
}
if
d
.
Reschedule
!=
nil
{
cpy
.
Reschedule
=
helper
.
BoolToPtr
(
*
d
.
Reschedule
)
}
if
d
.
ForceReschedule
!=
nil
{
cpy
.
ForceReschedule
=
helper
.
BoolToPtr
(
*
d
.
ForceReschedule
)
}
return
cpy
}
// Merge merges the two desired transitions, preferring the values from the
// passed in object.
func
(
d
*
DesiredTransition
)
Merge
(
o
*
DesiredTransition
)
{
...
...
@@ -9373,9 +9394,9 @@ func (a *Allocation) copyImpl(job bool) *Allocation {
na
.
Job
=
na
.
Job
.
Copy
()
}
na
.
AllocatedResources
=
n
a
.
AllocatedResources
.
Copy
()
na
.
Resources
=
n
a
.
Resources
.
Copy
()
na
.
SharedResources
=
n
a
.
SharedResources
.
Copy
()
na
.
AllocatedResources
=
a
.
AllocatedResources
.
Copy
()
na
.
Resources
=
a
.
Resources
.
Copy
()
na
.
SharedResources
=
a
.
SharedResources
.
Copy
()
if
a
.
TaskResources
!=
nil
{
tr
:=
make
(
map
[
string
]
*
Resources
,
len
(
na
.
TaskResources
))
...
...
@@ -9385,18 +9406,25 @@ func (a *Allocation) copyImpl(job bool) *Allocation {
na
.
TaskResources
=
tr
}
na
.
Metrics
=
n
a
.
Metrics
.
Copy
()
na
.
De
ploymentStatus
=
n
a
.
De
ploymentStatus
.
Copy
()
na
.
Metrics
=
a
.
Metrics
.
Copy
()
na
.
De
siredTransition
=
a
.
De
siredTransition
.
Copy
()
if
a
.
TaskStates
!=
nil
{
ts
:=
make
(
map
[
string
]
*
TaskState
,
len
(
na
.
TaskStates
))
for
task
,
state
:=
range
na
.
TaskStates
{
ts
[
task
]
=
state
.
Copy
()
na
.
TaskStates
=
make
(
map
[
string
]
*
TaskState
,
len
(
a
.
TaskStates
))
for
task
,
state
:=
range
a
.
TaskStates
{
na
.
TaskStates
[
task
]
=
state
.
Copy
()
}
}
if
a
.
AllocStates
!=
nil
{
na
.
AllocStates
=
make
([]
*
AllocState
,
len
(
a
.
AllocStates
))
for
i
,
s
:=
range
a
.
AllocStates
{
na
.
AllocStates
[
i
]
=
s
}
na
.
TaskStates
=
ts
}
na
.
DeploymentStatus
=
a
.
DeploymentStatus
.
Copy
()
na
.
RescheduleTracker
=
a
.
RescheduleTracker
.
Copy
()
na
.
NetworkStatus
=
a
.
NetworkStatus
.
Copy
()
na
.
PreemptedAllocations
=
helper
.
CopySliceString
(
a
.
PreemptedAllocations
)
return
na
}
...
...
This diff is collapsed.
Click to expand it.
scheduler/rank.go
+
1
-
0
View file @
61c52a4a
...
...
@@ -378,6 +378,7 @@ OUTER:
}
// Reserve this to prevent another task from colliding
//XXX Check return value?!
netIdx
.
AddReserved
(
offer
)
// Update the network ask to the offer
...
...
This diff is collapsed.
Click to expand it.
scheduler/util.go
+
3
-
8
View file @
61c52a4a
...
...
@@ -799,9 +799,8 @@ func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
resources
.
Devices
=
devices
}
// Create a shallow copy
newAlloc
:=
new
(
structs
.
Allocation
)
*
newAlloc
=
*
update
.
Alloc
// Create a copy
newAlloc
:=
update
.
Alloc
.
Copy
()
// Update the allocation
newAlloc
.
EvalID
=
eval
.
ID
...
...
@@ -810,11 +809,7 @@ func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
newAlloc
.
AllocatedResources
=
&
structs
.
AllocatedResources
{
Tasks
:
option
.
TaskResources
,
TaskLifecycles
:
option
.
TaskLifecycles
,
Shared
:
structs
.
AllocatedSharedResources
{
DiskMB
:
int64
(
update
.
TaskGroup
.
EphemeralDisk
.
SizeMB
),
Ports
:
update
.
Alloc
.
AllocatedResources
.
Shared
.
Ports
,
Networks
:
update
.
Alloc
.
AllocatedResources
.
Shared
.
Networks
.
Copy
(),
},
Shared
:
update
.
Alloc
.
AllocatedResources
.
Shared
.
Copy
(),
}
newAlloc
.
Metrics
=
ctx
.
Metrics
()
ctx
.
Plan
()
.
AppendAlloc
(
newAlloc
,
nil
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment