Skip to content

Commit

Permalink
Handle error in Raft FSM Apply() and Restore()
Browse files Browse the repository at this point in the history
  • Loading branch information
antw committed Dec 4, 2021
1 parent cc92609 commit ad6c65b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/storage/distributed.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,15 @@ func (f *fsm) Apply(record *raft.Log) interface{} {
return err
}

f.store.Set(req.GetRegister().GetKey(), req.GetRegister().GetValue())
err = f.store.Set(req.GetRegister().GetKey(), req.GetRegister().GetValue())
if err != nil {
return err
}

return &api.SetResponse{}
}

// Snapshot returns an snapshot which represents the store at a point in time.
// Snapshot returns a snapshot which represents the store at a point in time.
//
// For now this is encoded as JSON, but there are likely more efficient ways to encode this data
// (using api.KV, for example).
Expand Down Expand Up @@ -299,7 +302,10 @@ func (f *fsm) Restore(r io.ReadCloser) error {
}

for key, value := range data {
f.store.Set(key, value)
err = f.store.Set(key, value)
if err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit ad6c65b

Please sign in to comment.