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

better way to handle error not found from StableStore #10

Open
komuw opened this issue Apr 10, 2018 · 0 comments
Open

better way to handle error not found from StableStore #10

komuw opened this issue Apr 10, 2018 · 0 comments

Comments

@komuw
Copy link
Owner

komuw commented Apr 10, 2018

  • Most implementations[1][2] of raft StableStore interface; when you do a get for a key and the value returned happens to be a nil []byte, then they return an error.
  • Since we are using StableStore interface to persist (ballots and state), we need to check if the state exists(ie do a get). But instead of throwing an error if state is nil []byte, we need to 'catch' it and set it to nil.
state, err := a.acceptorStore.Get(key)
if err != nil && err.Error() == "not found" {
    state, err = nil, nil
}
if err != nil {
    return acceptorState{}, errors.Wrap(err, fmt.Sprintf("unable to get state for key:%v from acceptor:%v", key, a.ID))
}
  • it looks hideous and should be replaced with something better.

ref:

  1. https://github.com/hashicorp/raft-boltdb/blob/6e5ba93211eaf8d9a2ad7e41ffad8c6f160f9fe3/bolt_store.go#L243-L245
  2. https://github.com/hashicorp/raft-mdb/blob/55f29473b9e604b3678b93a8433a6cf089e70f76/mdb_store.go#L328-L329
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant