309 Commits

Author SHA1 Message Date
siddontang
c6f2db2e92 raft: support learner 2017-11-11 10:38:21 +08:00
Xiang
9801fd7297 raft: ensure CheckQuorum is enabled when readonlyoption is lease based 2017-09-17 10:46:12 -07:00
gladiator
58b98c6a14 raft: check leader request when becomeFollower 2017-09-15 08:23:18 +08:00
gladiator
3740793b42 raft: reset votes when becomePreCandidate 2017-08-01 22:42:09 +08:00
irfan sharif
a92ceeec25 raft: introduce/fix TestNodeWithSmallerTermCanCompleteElection
TestNodeWithSmallerTermCanCompleteElection tests the scenario where a
node that has been partitioned away (and fallen behind) rejoins the
cluster at about the same time the leader node gets partitioned away.
Previously the cluster would come to a standstill when run with PreVote
enabled.

When responding to Msg{Pre,}Vote messages we now include the term from
the message, not the local term. To see why consider the case where a
single node was previously partitioned away and it's local term is now
of date. If we include the local term (recall that for pre-votes we
don't update the local term), the (pre-)campaigning node on the other
end will proceed to ignore the message (it ignores all out of date
messages).
The term in the original message and current local term are the same in
the case of regular votes, but different for pre-votes.

NB: Had to change TestRecvMsgVote to include pb.Message.Term when
sending MsgVote messages. The new sanity checks on MsgVoteResp
(m.Term != 0) would panic with the old test as raft.Term would be equal
to 0 when responding with MsgVoteResp messages.
2017-07-21 02:26:02 -04:00
smetro
e461017ac5 raft: add DisableProposalForwarding option
this allows users to disable followers from forwarding proposals to the
leader.
2017-06-21 14:58:28 -07:00
Aaron Lehmann
52613b262b raft: Set the RecentActive flag for newly added nodes
I found that enabling the CheckQuorum flag led to spurious leader
elections when new nodes joined. It looks like in the time between a new
node joining the cluster, and that node first communicating with the
leader, the quorum check could fail because the new node looks inactive.
To solve this, set the RecentActive flag when nodes are first added.
This gives a grace period for the node to communicate before it causes
the quorum check to fail.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-27 11:19:29 -07:00
Dylan.Wen
9342647e0c raft: fix read index request for #7331 2017-02-17 09:45:41 +08:00
Xiang Li
b940e0d514 Merge pull request #7042 from petermattis/pmattis/resume-after-heartbeat-resp
raft: resume paused followers on receipt of MsgHeartbeatResp
2016-12-27 21:15:53 -08:00
Peter Mattis
e625400f1d raft: resume paused followers on receipt of MsgHeartbeatResp
Previously, paused followers were resumed upon sending a MsgHearbeat.

Fixes #7037
2016-12-20 08:22:09 -05:00
Ben Darnell
f60a5d6025 raft: Export Progress.IsPaused
CockroachDB would like to use this method for monitoring.
2016-12-04 13:14:08 +08:00
Vincent Lee
4401d88546 raft: add node should reset the pendingConf state
After add node conf proposed twice with the same node id, the pending state is not reset because
the addNode returned without setting the pending state at the second
time and the pending state will always be true unless other conf changed. During this we
can not add any new node because the propose will be ignored since the
pending state is true.
2016-11-17 15:50:13 +08:00
Ben Darnell
2f34547d39 raft: Check promotable() in MsgTimeoutNow handling
If MsgTimeoutNow arrived after a node was removed, the node could start
and win an election, then panic in becomeLeader (see
cockroachdb/cockroach#8535)
2016-11-07 20:02:21 +08:00
Gyu-Ho Lee
cb5c92f69b raft: do not attach term to MsgReadIndex
Fix https://github.com/coreos/etcd/issues/6744.

MsgReadIndex, as MsgProp, is to be forwarded to leader.
So we should treat it as local message.
2016-10-28 22:12:25 -07:00
Ben Darnell
22aa710c1f raft: Improve comments and formatting for PreVote change 2016-10-24 22:29:33 +09:00
Ben Darnell
cf93a74aa8 raft: Refactor vote handling
Move all vote handling from the per-state step functions to the
top-level Step(). This wasn't necessary before because MsgVote would
cause us to become a follower, but MsgPreVote needs to be handled
without changing the node's current state.
2016-10-19 19:35:21 +08:00
Ben Darnell
73cae7abd0 raft: Implement the PreVote RPC described in thesis section 9.6
This prevents disruption when a node that has been partitioned
away rejoins the cluster.

Fixes #6522
2016-10-19 19:35:20 +08:00
Xiang Li
cfe717e926 Merge pull request #6275 from xiang90/raft_l
raft: support safe readonly request
2016-09-13 01:36:04 -05:00
Xiang Li
710b14ce56 raft: support safe readonly request
Implement raft readonly request described in raft thesis 6.4
along with the existing clock/lease based approach.
2016-09-12 15:13:52 +08:00
Peter Mattis
4a33aa3917 raft: use a singleton global rand
rand.NewSource creates a 4872 byte object. With a small number of raft
groups in a process this isn't a problem. With 10k raft groups we'd use
46MB for these random sources. The only usage is in
raft.resetRandomizedElectionTimeout which isn't performance critical.

Fixes #6347.
2016-09-05 09:03:18 -04:00
Ben Darnell
a7a867c1e6 raft: Allow an election immediately after start with checkQuorum
Previously, the checkQuorum flag required an election timeout to
expire before a node could cast its first vote. This change permits
the node to cast a vote at any time when the leader is not known,
including immediately after startup.
2016-08-30 08:28:41 +08:00
Gyu-Ho Lee
f4141f0f51 raft: handle 'MsgTransferLeader' in follower 2016-08-10 16:24:29 -07:00
Xiang Li
5f0c122496 raft: fix getting unapplied log entries 2016-08-08 10:44:02 -07:00
Xiang Li
484f579905 raft: hide Campaign rules on applying all entries 2016-07-25 15:53:39 -07:00
Xiang Li
1c5754f02d raft: fix readindex 2016-07-19 15:00:58 -07:00
Xiang Li
7432e9fbe9 Merge pull request #5809 from swingbach/master
raft: make leader transferring workable when quorum check is on
2016-07-12 09:46:18 -07:00
swingbach@gmail.com
c36a40ca15 raft: introduce top-level context in message struct 2016-07-12 16:14:06 +08:00
Gyu-Ho Lee
6f3a40cb53 raft: set leader id in stepFollower
Follower has already set its leader ID from
previous append messages from the leader, but
to be consistent,  this adds a line to set its
leader id from leader snapshot message.
2016-07-11 16:37:31 -07:00
swingbach@gmail.com
0d9b6ba0ab raft: fix a few problems 2016-07-11 14:59:53 +08:00
Gyu-Ho Lee
c396b6aaaa raft: remove unnecessary type-cast, else-clause 2016-07-09 22:01:19 -07:00
swingbach@gmail.com
e020b2a228 raft: make leader transferring workable when quorum check is on 2016-06-29 18:24:58 +08:00
Xiang Li
5f1c763993 Merge pull request #5553 from swingbach/master
raft: implemented read-only query when quorum check is on
2016-06-28 12:47:43 -07:00
swingbach@gmail.com
0faae33ace raft: implemented read-only query when quorum check is on 2016-06-28 10:52:53 +08:00
Gyu-Ho Lee
33f7e7583b raft: fix comment,method name to needSnapshotAbort
And 'maybeSnapshotAbort' does not 'unset'
the pendingSnapshot. 'resetState', which is called after this
metho, is the one that unsets pendingSnapshot. So this changes
the method name.
2016-06-24 07:54:10 -07:00
swingbach@gmail.com
337ef64ed5 raft: implemented leader lease when quorum check is on 2016-06-02 06:17:27 +08:00
Xiang Li
910781ef5b raft: do not panic when removing all the nodes from cluster 2016-05-16 10:04:17 -07:00
Xiang Li
4d2424210f Merge pull request #5313 from xiang90/fix_raft_abort
raft: simplify leadership transfer
2016-05-13 09:26:01 -07:00
Gyu-Ho Lee
fe884f8209 raft: update LICENSE header 2016-05-12 20:49:15 -07:00
Xiang Li
82a6de8b69 raft: simplify leadership transfer 2016-05-10 20:03:42 -07:00
Gyu-Ho Lee
9108af9046 *: clean up from go vet, misspell 2016-04-10 23:16:56 -07:00
Xiang Li
4997ed36b4 Merge pull request #5011 from xiang90/r_c
raft: fix issues reported by golint
2016-04-08 11:46:12 -07:00
es-chow
ac059eb8cb raft: transfer leader feature 2016-04-08 16:56:32 +08:00
Xiang Li
1b41ee9c99 raft: fix issues reported by golint 2016-04-07 22:14:56 -07:00
Gyu-Ho Lee
6e6d64fb9b *: clean up unused vars, functions
With help from https://github.com/dominikh/go-unused.
IsNetTimeoutError seems useful, so moved to pkg/netutil.
2016-04-06 21:33:55 -07:00
Tamir Duberstein
68db18667a raft: correct doc comment 2016-04-06 08:43:42 -04:00
Tamir Duberstein
5250784b09 raft: use rand.Intn instead of rand.Int and mod
This provides a better random distribution and is easier to read.
2016-04-06 08:43:42 -04:00
Xiang Li
5d431b4782 raft: lower split vote rate 2016-04-01 12:11:03 -07:00
Peter Bourgon
aedf2c5876 raft: Config: comment wrapping @ 80col 2016-03-01 09:54:58 +01:00
Peter Bourgon
6c1b3a71db raft: clarify Heartbeat/ElectionTick comments
Avoid other, ambiguous interpretations.
2016-03-01 09:52:14 +01:00
Anthony Romano
c5b51946eb *: exported godoc fixups 2016-02-21 20:36:44 -08:00