Skip to content

Commit

Permalink
Merge pull request #3056 from hashicorp/b-auto-revert
Browse files Browse the repository at this point in the history
Fix purging job versions
  • Loading branch information
dadgar committed Aug 23, 2017
2 parents 47b8c18 + 33d7b37 commit 815cd92
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ IMPROVEMENTS:
deregistering from Consul [GH-3043]

BUG FIXES:
* core: Fix purging of job versions [GH-3056]
* core: Fix race creating EvalFuture [GH-3051]
* core: Fix panic occuring from improper bitmap size [GH-3023]
* core: Fix restoration of parameterized, periodic jobs [GH-2959]
Expand Down
2 changes: 1 addition & 1 deletion nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ func (s *StateStore) deleteJobVersions(index uint64, job *structs.Job, txn *memd
continue
}

if _, err = txn.DeleteAll("job_version", "id", job.ID, job.Version); err != nil {
if _, err = txn.DeleteAll("job_version", "id", j.ID, j.Version); err != nil {
return fmt.Errorf("deleting job versions failed: %v", err)
}
}
Expand Down
56 changes: 56 additions & 0 deletions nomad/state/state_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/assert"
)

func testStateStore(t *testing.T) *StateStore {
Expand Down Expand Up @@ -1307,6 +1308,61 @@ func TestStateStore_DeleteJob_Job(t *testing.T) {
}
}

func TestStateStore_DeleteJob_MultipleVersions(t *testing.T) {
state := testStateStore(t)
assert := assert.New(t)

// Create a job and mark it as stable
job := mock.Job()
job.Stable = true
job.Priority = 0

// Create a watchset so we can test that upsert fires the watch
ws := memdb.NewWatchSet()
_, err := state.JobVersionsByID(ws, job.ID)
assert.Nil(err)
assert.Nil(state.UpsertJob(1000, job))
assert.True(watchFired(ws))

var finalJob *structs.Job
for i := 1; i < 20; i++ {
finalJob = mock.Job()
finalJob.ID = job.ID
finalJob.Priority = i
assert.Nil(state.UpsertJob(uint64(1000+i), finalJob))
}

assert.Nil(state.DeleteJob(1001, job.ID))
assert.True(watchFired(ws))

ws = memdb.NewWatchSet()
out, err := state.JobByID(ws, job.ID)
assert.Nil(err)
assert.Nil(out)

index, err := state.Index("jobs")
assert.Nil(err)
assert.EqualValues(1001, index)

summary, err := state.JobSummaryByID(ws, job.ID)
assert.Nil(err)
assert.Nil(summary)

index, err = state.Index("job_summary")
assert.Nil(err)
assert.EqualValues(1001, index)

versions, err := state.JobVersionsByID(ws, job.ID)
assert.Nil(err)
assert.Len(versions, 0)

index, err = state.Index("job_summary")
assert.Nil(err)
assert.EqualValues(1001, index)

assert.False(watchFired(ws))
}

func TestStateStore_DeleteJob_ChildJob(t *testing.T) {
state := testStateStore(t)

Expand Down

0 comments on commit 815cd92

Please sign in to comment.