Skip to content

Commit

Permalink
Revert "Improve error handling - remove hardcoded values (#370)" (#382)
Browse files Browse the repository at this point in the history
This reverts commit ba08237. #370
  • Loading branch information
catsby committed Jan 16, 2020
1 parent da7af57 commit 2bd0dfb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
8 changes: 0 additions & 8 deletions .gitignore
Expand Up @@ -21,11 +21,3 @@ _testmain.go

*.exe
*.test

# MacOS
.DS_Store
.AppleDouble
.LSOverride

# IDE specific
.vscode/*
8 changes: 4 additions & 4 deletions api.go
Expand Up @@ -52,7 +52,7 @@ var (
ErrEnqueueTimeout = errors.New("timed out enqueuing operation")

// ErrNothingNewToSnapshot is returned when trying to create a snapshot
// but there's nothing new committed to the FSM since we started.
// but there's nothing new commited to the FSM since we started.
ErrNothingNewToSnapshot = errors.New("nothing new to snapshot")

// ErrUnsupportedProtocol is returned when an operation is attempted
Expand Down Expand Up @@ -412,7 +412,7 @@ func HasExistingState(logs LogStore, stable StableStore, snaps SnapshotStore) (b
return true, nil
}
} else {
if err != ErrKeyNotFound {
if err.Error() != "not found" {
return false, fmt.Errorf("failed to read current term: %v", err)
}
}
Expand Down Expand Up @@ -466,7 +466,7 @@ func NewRaft(conf *Config, fsm FSM, logs LogStore, stable StableStore, snaps Sna

// Try to restore the current term.
currentTerm, err := stable.GetUint64(keyCurrentTerm)
if err != nil && err != ErrKeyNotFound {
if err != nil && err.Error() != "not found" {
return nil, fmt.Errorf("failed to load current term: %v", err)
}

Expand Down Expand Up @@ -705,7 +705,7 @@ func (r *Raft) ApplyLog(log Log, timeout time.Duration) ApplyFuture {
}
}

// Barrier is used to issue a command that blocks until all preceding
// Barrier is used to issue a command that blocks until all preceeding
// operations have been applied to the FSM. It can be used to ensure the
// FSM reflects all queued writes. An optional timeout can be provided to
// limit the amount of time we wait for the command to be started. This
Expand Down
7 changes: 1 addition & 6 deletions inmem_store.go
Expand Up @@ -5,11 +5,6 @@ import (
"sync"
)

var (
// ErrKeyNotFound is returned when a key does not exist in collection.
ErrKeyNotFound = errors.New("not found")
)

// InmemStore implements the LogStore and StableStore interface.
// It should NOT EVER be used for production. It is used only for
// unit tests. Use the MDBStore implementation instead.
Expand Down Expand Up @@ -114,7 +109,7 @@ func (i *InmemStore) Get(key []byte) ([]byte, error) {
defer i.l.RUnlock()
val := i.kv[string(key)]
if val == nil {
return nil, ErrKeyNotFound
return nil, errors.New("not found")
}
return val, nil
}
Expand Down
6 changes: 3 additions & 3 deletions raft.go
Expand Up @@ -256,7 +256,7 @@ func (r *Raft) runCandidate() {
// Make sure the leadership transfer flag is reset after each run. Having this
// flag will set the field LeadershipTransfer in a RequestVoteRequst to true,
// which will make other servers vote even though they have a leader already.
// It is important to reset that flag, because this privilege could be abused
// It is important to reset that flag, because this priviledge could be abused
// otherwise.
defer func() { r.candidateFromLeadershipTransfer = false }()

Expand Down Expand Up @@ -1437,12 +1437,12 @@ func (r *Raft) requestVote(rpc RPC, req *RequestVoteRequest) {

// Check if we have voted yet
lastVoteTerm, err := r.stable.GetUint64(keyLastVoteTerm)
if err != nil && err != ErrKeyNotFound {
if err != nil && err.Error() != "not found" {
r.logger.Error("failed to get last vote term", "error", err)
return
}
lastVoteCandBytes, err := r.stable.Get(keyLastVoteCand)
if err != nil && err != ErrKeyNotFound {
if err != nil && err.Error() != "not found" {
r.logger.Error("failed to get last vote candidate", "error", err)
return
}
Expand Down

0 comments on commit 2bd0dfb

Please sign in to comment.