Skip to content

Commit

Permalink
ignore delete events for now
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Oct 7, 2020
1 parent 384c008 commit df3ca7f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
7 changes: 4 additions & 3 deletions nomad/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package nomad

import (
"bytes"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -3249,11 +3248,13 @@ func TestFSM_SnapshotRestore_Events_WithDurability(t *testing.T) {

pub, err := state2.EventPublisher()
require.NoError(t, err)

testutil.WaitForResult(func() (bool, error) {
if pub.Len() == 2 {
plen := pub.Len()
if plen == 4 {
return true, nil
}
return false, errors.New("expected publisher to be populated")
return false, fmt.Errorf("expected publisher to have len 2 got: %d", plen)
}, func(err error) {
require.Fail(t, err.Error())
})
Expand Down
2 changes: 1 addition & 1 deletion nomad/node_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ func TestClientEndpoint_GetClientAllocs_Blocking_GC(t *testing.T) {
if time.Since(start) < 100*time.Millisecond {
t.Fatalf("too fast")
}
assert.EqualValues(200, resp3.Index)
assert.EqualValues(200, int(resp3.Index))
if assert.Len(resp3.Allocs, 1) {
assert.EqualValues(100, resp3.Allocs[alloc1.ID])
}
Expand Down
12 changes: 12 additions & 0 deletions nomad/state/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func GenericEventsFromChanges(tx ReadTxn, changes Changes) (*structs.Events, err
for _, change := range changes.Changes {
switch change.Table {
case "evals":
if change.Deleted() {
return nil, nil
}
after, ok := change.After.(*structs.Evaluation)
if !ok {
return nil, fmt.Errorf("transaction change was not an Evaluation")
Expand All @@ -127,6 +130,9 @@ func GenericEventsFromChanges(tx ReadTxn, changes Changes) (*structs.Events, err
events = append(events, event)

case "allocs":
if change.Deleted() {
return nil, nil
}
after, ok := change.After.(*structs.Allocation)
if !ok {
return nil, fmt.Errorf("transaction change was not an Allocation")
Expand All @@ -148,6 +154,9 @@ func GenericEventsFromChanges(tx ReadTxn, changes Changes) (*structs.Events, err

events = append(events, event)
case "jobs":
if change.Deleted() {
return nil, nil
}
after, ok := change.After.(*structs.Job)
if !ok {
return nil, fmt.Errorf("transaction change was not an Allocation")
Expand All @@ -165,6 +174,9 @@ func GenericEventsFromChanges(tx ReadTxn, changes Changes) (*structs.Events, err

events = append(events, event)
case "nodes":
if change.Deleted() {
return nil, nil
}
after, ok := change.After.(*structs.Node)
if !ok {
return nil, fmt.Errorf("transaction change was not a Node")
Expand Down
14 changes: 7 additions & 7 deletions nomad/state/state_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (tx *txn) Commit() error {
return err
}

if tx.persistChanges {
if tx.persistChanges && events != nil {
// persist events after processing changes
err := tx.Txn.Insert("events", events)
if err != nil {
Expand Down Expand Up @@ -224,12 +224,12 @@ func processDBChanges(tx ReadTxn, changes Changes) (*structs.Events, error) {
case structs.AllocUpdateRequestType:
// TODO(drew) test
return GenericEventsFromChanges(tx, changes)
case structs.JobDeregisterRequestType:
// TODO(drew) test
return GenericEventsFromChanges(tx, changes)
case structs.JobBatchDeregisterRequestType:
// TODO(drew) test
return GenericEventsFromChanges(tx, changes)
// case structs.JobDeregisterRequestType:
// TODO(drew) test / handle delete
// return GenericEventsFromChanges(tx, changes)
// case structs.JobBatchDeregisterRequestType:
// TODO(drew) test & handle delete
// return GenericEventsFromChanges(tx, changes)
case structs.AllocUpdateDesiredTransitionRequestType:
// TODO(drew) drain
return GenericEventsFromChanges(tx, changes)
Expand Down
3 changes: 1 addition & 2 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2950,8 +2950,7 @@ func (s *StateStore) DeleteEval(index uint64, evals []string, allocs []string) e
return fmt.Errorf("setting job status failed: %v", err)
}

txn.Commit()
return nil
return txn.Commit()
}

// EvalByID is used to lookup an eval by its ID
Expand Down

0 comments on commit df3ca7f

Please sign in to comment.