Update ModifyIndex of alloc when setting NextAllocation value

This commit is contained in:
Preetha Appan
2018-05-03 17:03:58 -05:00
parent 86093d1a51
commit 2718b09079
2 changed files with 10 additions and 0 deletions

View File

@@ -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)
}

View File

@@ -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) {