Skip to content

Commit 827436e

Browse files
committed
a NonVoter node should never try to bootstrap
This is a follow-up to #483
1 parent e76e6e4 commit 827436e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

api.go

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ var (
3636
// follower or candidate node.
3737
ErrNotLeader = errors.New("node is not the leader")
3838

39+
// ErrNotVoter is returned when an operation can't be completed on a
40+
// non-voter node.
41+
ErrNotVoter = errors.New("node is not a voter")
42+
3943
// ErrLeadershipLost is returned when a leader fails to commit a log entry
4044
// because it's been deposed in the process.
4145
ErrLeadershipLost = errors.New("leadership lost while committing log")

raft.go

+5
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ func (r *Raft) runFollower() {
233233
// the Raft object's member BootstrapCluster for more details. This must only be
234234
// called on the main thread, and only makes sense in the follower state.
235235
func (r *Raft) liveBootstrap(configuration Configuration) error {
236+
if !hasVote(configuration, r.localID) {
237+
// Reject this operation since we are not a voter
238+
return ErrNotVoter
239+
}
240+
236241
// Use the pre-init API to make the static updates.
237242
cfg := r.config()
238243
err := BootstrapCluster(&cfg, r.logs, r.stable, r.snapshots, r.trans, configuration)

0 commit comments

Comments
 (0)