Skip to content

Commit

Permalink
Merge pull request #165 from aaronlehmann/isleader-atomicity
Browse files Browse the repository at this point in the history
raft: Use IsLeader method to avoid race detector complaint
  • Loading branch information
vieux committed Mar 18, 2016
2 parents 7c07b48 + 67ebfdb commit 4b054cb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions manager/state/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type Node struct {
wal *wal.WAL
snapshotter *snap.Snapshotter
stateDir string
isLeader bool
wasLeader bool

ticker *time.Ticker
stopCh chan struct{}
Expand Down Expand Up @@ -312,11 +312,11 @@ func (n *Node) Start() (errCh <-chan error) {
// if that happens we will apply them as any
// follower would.
if rd.SoftState != nil {
if n.isLeader && rd.SoftState.RaftState != raft.StateLeader {
n.isLeader = false
if n.wasLeader && rd.SoftState.RaftState != raft.StateLeader {
n.wasLeader = false
n.wait.cancelAll()
} else if !n.isLeader && rd.SoftState.RaftState == raft.StateLeader {
n.isLeader = true
} else if !n.wasLeader && rd.SoftState.RaftState == raft.StateLeader {
n.wasLeader = true
}
}

Expand Down Expand Up @@ -592,7 +592,7 @@ func (n *Node) processInternalRaftRequest(ctx context.Context, r *api.InternalRa
ch := n.wait.register(r.ID)

// Do this check after calling register to avoid a race.
if !n.isLeader {
if !n.IsLeader() {
n.wait.trigger(r.ID, nil)
return nil, ErrLostLeadership
}
Expand Down

0 comments on commit 4b054cb

Please sign in to comment.