Skip to content

Commit 12f1ff5

Browse files
committed
apply more code review changes
1 parent f5ce8a9 commit 12f1ff5

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

.changelog/15068.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
```release-note:bug
2-
scheduler: Fixed a bug that prevented allocations with `max_client_disconnect` set to be updated after they reconnected.
2+
scheduler: Fixed a bug that prevented disconnected allocations to be updated after they reconnect.
33
```
44

55
```release-note:bug
6-
scheduler: Prevent unnecessary placements when allocations with `max_client_disconnect` set reconnect.
6+
scheduler: Prevent unnecessary placements when disconnected allocations reconnect.
77
```

nomad/node_endpoint.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,9 @@ func (n *Node) GetClientAllocs(args *structs.NodeSpecificRequest,
11321132
return n.srv.blockingRPC(&opts)
11331133
}
11341134

1135-
// UpdateAlloc is used to update the client status of an allocation
1135+
// UpdateAlloc is used to update the client status of an allocation. It can
1136+
// only be called by clients.
1137+
//
11361138
// Clients must first register and heartbeat successfully before being able to
11371139
// call this method.
11381140
func (n *Node) UpdateAlloc(args *structs.AllocUpdateRequest, reply *structs.GenericResponse) error {
@@ -1161,6 +1163,10 @@ func (n *Node) UpdateAlloc(args *structs.AllocUpdateRequest, reply *structs.Gene
11611163
// NodeID field in the request.
11621164
nodeID = args.Alloc[0].NodeID
11631165
}
1166+
if nodeID == "" {
1167+
return fmt.Errorf("missing node ID")
1168+
}
1169+
11641170
node, err := n.srv.State().NodeByID(nil, nodeID)
11651171
if err != nil {
11661172
return fmt.Errorf("failed to retrieve node %s: %v", args.NodeID, err)

scheduler/reconcile.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1203,9 +1203,10 @@ func (a *allocReconciler) computeReconnecting(reconnecting allocSet) {
12031203

12041204
// Record the new ClientStatus to indicate to future evals that the
12051205
// alloc has already reconnected.
1206-
alloc.AppendState(structs.AllocStateFieldClientStatus, alloc.ClientStatus)
1207-
1208-
a.result.reconnectUpdates[alloc.ID] = alloc
1206+
// Use a copy to prevent mutating the object from statestore.
1207+
reconnectedAlloc := alloc.Copy()
1208+
reconnectedAlloc.AppendState(structs.AllocStateFieldClientStatus, alloc.ClientStatus)
1209+
a.result.reconnectUpdates[alloc.ID] = reconnectedAlloc
12091210
}
12101211
}
12111212

scheduler/reconcile_util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (a allocSet) filterByTainted(taintedNodes map[string]*structs.Node, serverS
240240
alloc.ClientStatus == structs.AllocClientStatusFailed) {
241241
reconnect = alloc.NeedsToReconnect()
242242
if reconnect {
243-
expired = alloc.Expired(time.Now())
243+
expired = alloc.Expired(now)
244244
}
245245
}
246246

0 commit comments

Comments
 (0)