Skip to content
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

Fix purging job versions #3056

Merged
merged 2 commits into from
Aug 23, 2017
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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