Skip to content

Commit

Permalink
Merge pull request #14413 from tbg/raft-single-voter
Browse files Browse the repository at this point in the history
raft: don't emit unstable CommittedEntries
  • Loading branch information
ahrtr authored Sep 22, 2022
2 parents 0267944 + d56676c commit 31d9664
Show file tree
Hide file tree
Showing 17 changed files with 705 additions and 365 deletions.
2 changes: 1 addition & 1 deletion raft/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func mustTemp(pre, body string) string {
}

func ltoa(l *raftLog) string {
s := fmt.Sprintf("committed: %d\n", l.committed)
s := fmt.Sprintf("lastIndex: %d\n", l.lastIndex())
s += fmt.Sprintf("applied: %d\n", l.applied)
for i, e := range l.allEntries() {
s += fmt.Sprintf("#%d: %+v\n", i, e)
Expand Down
16 changes: 10 additions & 6 deletions raft/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ type Peer struct {
Context []byte
}

// StartNode returns a new Node given configuration and a list of raft peers.
// It appends a ConfChangeAddNode entry for each given peer to the initial log.
//
// Peers must not be zero length; call RestartNode in that case.
func StartNode(c *Config, peers []Peer) Node {
func setupNode(c *Config, peers []Peer) *node {
if len(peers) == 0 {
panic("no peers given; use RestartNode instead")
}
Expand All @@ -229,9 +225,17 @@ func StartNode(c *Config, peers []Peer) Node {
}

n := newNode(rn)
return &n
}

// StartNode returns a new Node given configuration and a list of raft peers.
// It appends a ConfChangeAddNode entry for each given peer to the initial log.
//
// Peers must not be zero length; call RestartNode in that case.
func StartNode(c *Config, peers []Peer) Node {
n := setupNode(c, peers)
go n.run()
return &n
return n
}

// RestartNode is similar to StartNode but does not take a list of peers.
Expand Down
Loading

0 comments on commit 31d9664

Please sign in to comment.