diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index e9df612c82e..d9207333684 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -2037,6 +2037,7 @@ func (s *StateStore) upsertAllocsImpl(index uint64, allocs []*structs.Allocation if existingPrevAlloc != nil { prevAllocCopy := existingPrevAlloc.Copy() prevAllocCopy.NextAllocation = alloc.ID + prevAllocCopy.ModifyIndex = index if err := txn.Insert("allocs", prevAllocCopy); err != nil { return fmt.Errorf("alloc insert failed: %v", err) } diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index dd085bb9e4e..cf0841e4640 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -4653,6 +4653,15 @@ func TestStateStore_Allocs_PrevAlloc(t *testing.T) { require.Equal(allocs, out) require.False(watchFired(ws)) + + // Insert another alloc, verify index of previous alloc also got updated + alloc := mock.Alloc() + alloc.PreviousAllocation = allocs[0].ID + err = state.UpsertAllocs(1001, []*structs.Allocation{alloc}) + require.Nil(err) + alloc0, err := state.AllocByID(nil, allocs[0].ID) + require.Nil(err) + require.Equal(alloc0.ModifyIndex, uint64(1001)) } func TestStateStore_RestoreAlloc(t *testing.T) {