Skip to content

state store: persist NextAllocation correctly when upserting allocations #25799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/25799.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
reconnecting client: fix issue where reconcile strategy was sometimes ignored
```
5 changes: 5 additions & 0 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions nomad/state/state_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading