diff --git a/nomad/node_endpoint.go b/nomad/node_endpoint.go index 9dbd7f871..7f4265fb9 100644 --- a/nomad/node_endpoint.go +++ b/nomad/node_endpoint.go @@ -820,12 +820,13 @@ func (n *Node) UpdateAlloc(args *structs.AllocUpdateRequest, reply *structs.Gene return fmt.Errorf("must update at least one allocation") } - // Add this to the batch - n.updatesLock.Lock() + // Update modified timestamp for client initiated allocation updates now := time.Now().UTC().UnixNano() for _, alloc := range args.Alloc { alloc.ModifyTime = now } + // Add this to the batch + n.updatesLock.Lock() n.updates = append(n.updates, args.Alloc...) // Start a new batch if none diff --git a/nomad/plan_apply.go b/nomad/plan_apply.go index fe2ed2e5c..5d2c29bcf 100644 --- a/nomad/plan_apply.go +++ b/nomad/plan_apply.go @@ -149,9 +149,8 @@ func (s *Server) applyPlan(plan *structs.Plan, result *structs.PlanResult, snap for _, alloc := range req.Alloc { if alloc.CreateTime == 0 { alloc.CreateTime = now - } else { - alloc.ModifyTime = now } + alloc.ModifyTime = now } // Dispatch the Raft transaction diff --git a/nomad/plan_apply_test.go b/nomad/plan_apply_test.go index 6bf7181b9..7d3195d92 100644 --- a/nomad/plan_apply_test.go +++ b/nomad/plan_apply_test.go @@ -147,6 +147,16 @@ func TestPlanApply_applyPlan(t *testing.T) { t.Fatalf("missing alloc") } + if out.CreateTime <= 0 { + t.Fatalf("invalid create time %v", out.CreateTime) + } + if out.ModifyTime <= 0 { + t.Fatalf("invalid modify time %v", out.CreateTime) + } + if out.CreateTime != out.ModifyTime { + t.Fatalf("create time %v modify time %v must be equal", out.CreateTime, out.ModifyTime) + } + // Lookup the new deployment dout, err := fsmState.DeploymentByID(ws, plan.Deployment.ID) if err != nil {