diff --git a/.changelog/25799.txt b/.changelog/25799.txt new file mode 100644 index 000000000..59b632c26 --- /dev/null +++ b/.changelog/25799.txt @@ -0,0 +1,3 @@ +```release-note:bug +reconnecting client: fix issue where reconcile strategy was sometimes ignored +``` diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index f53924155..1f8fcce24 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -4185,6 +4185,11 @@ func (s *StateStore) upsertAllocsImpl(index uint64, allocs []*structs.Allocation alloc.ModifyIndex = index alloc.AllocModifyIndex = index + // Carry over NextAllocation from existing + if exist.NextAllocation != "" { + alloc.NextAllocation = exist.NextAllocation + } + // Keep the clients task states alloc.TaskStates = exist.TaskStates diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 36b431757..2b11c8ec7 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -6587,6 +6587,31 @@ func TestStateStore_UpsertAlloc_ChildJob(t *testing.T) { require.False(t, watchFired(ws)) } +func TestStateStore_UpsertAlloc_NextAllocation(t *testing.T) { + ci.Parallel(t) + + state := testStateStore(t) + + alloc1 := mock.Alloc() + alloc2 := mock.Alloc() + alloc2.PreviousAllocation = alloc1.ID + + err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2}) + must.NoError(t, err) + + // alloc1 should have the correct NextAllocation + actual, err := state.AllocByID(nil, alloc1.ID) + must.Eq(t, actual.NextAllocation, alloc2.ID) + + err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc2, alloc1}) + must.NoError(t, err) + + // upsert in a different order, alloc1 should still have the correct NextAllocation + actual, err = state.AllocByID(nil, alloc1.ID) + must.NoError(t, err) + must.Eq(t, actual.NextAllocation, alloc2.ID) +} + func TestStateStore_UpdateAlloc_Alloc(t *testing.T) { ci.Parallel(t)