From 2718b09079a3c0792cc68763df3482eaf7f0286f Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Thu, 3 May 2018 17:03:58 -0500 Subject: [PATCH] Update ModifyIndex of alloc when setting NextAllocation value --- nomad/state/state_store.go | 1 + nomad/state/state_store_test.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index e9df612c8..d92073336 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 dd085bb9e..cf0841e46 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) {