Skip to content

Commit

Permalink
Merge pull request #55 from xiangli-cmu/master
Browse files Browse the repository at this point in the history
when candidate stepdown it should break the loop; gofmt
  • Loading branch information
benbjohnson committed Jul 7, 2013
2 parents 7845ebd + d3787f6 commit 347a27e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Log struct {
// The results of the applying a log entry.
type logResult struct {
returnValue interface{}
err error
err error
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -172,7 +172,7 @@ func (l *Log) open(path string) error {

// Apply the command.
returnValue, err := l.ApplyFunc(entry.Command)
l.results = append(l.results, &logResult{returnValue:returnValue, err:err})
l.results = append(l.results, &logResult{returnValue: returnValue, err: err})

lastIndex += n
}
Expand Down Expand Up @@ -277,7 +277,7 @@ func (l *Log) getEntryResult(entry *LogEntry, clear bool) (interface{}, error) {
if clear {
result.returnValue = nil
}

return result.returnValue, result.err
}
}
Expand Down Expand Up @@ -374,7 +374,7 @@ func (l *Log) setCommitIndex(index uint64) error {

// Apply the changes to the state machine and store the error code.
returnValue, err := l.ApplyFunc(entry.Command)
l.results[entryIndex] = &logResult{returnValue:returnValue, err:err}
l.results[entryIndex] = &logResult{returnValue: returnValue, err: err}
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions log_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
// A log entry stores a single item in the log.
type LogEntry struct {
log *Log
Index uint64 `json:"index"`
Term uint64 `json:"term"`
Command Command `json:"command"`
commit chan bool `json:"-"`
Index uint64 `json:"index"`
Term uint64 `json:"term"`
Command Command `json:"command"`
commit chan bool `json:"-"`
}

// A temporary interface used for unmarshaling log entries.
Expand Down
9 changes: 7 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (s *Server) setCurrentTerm(term uint64, leaderName string, append bool) {
s.leader = leaderName
s.votedFor = ""
return
}
}

// discover new leader
if term == s.currentTerm && s.state == Candidate && append {
Expand Down Expand Up @@ -392,7 +392,7 @@ func (s *Server) loop() {

for {
state := s.State()

s.debugln("server.loop.run ", state)
switch state {
case Follower:
Expand Down Expand Up @@ -520,6 +520,11 @@ func (s *Server) candidateLoop() {
// Callback to event.
e.c <- err

// both process AER and RVR can make the server to follower
if s.State() == Follower {
break
}

case <-timeoutChan:
break
}
Expand Down

0 comments on commit 347a27e

Please sign in to comment.