state store: persist NextAllocation correctly when upserting allocations (#25799)

---------

Co-authored-by: Tim Gross <tgross@hashicorp.com>
This commit is contained in:
Michael Smithhisler
2025-05-19 15:45:04 -04:00
committed by GitHub
parent 456d95a19e
commit 979d34a461
3 changed files with 33 additions and 0 deletions

3
.changelog/25799.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
reconnecting client: fix issue where reconcile strategy was sometimes ignored
```

View File

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

View File

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