• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..11-Oct-2018-

LICENSEH A D11-Oct-201815.6 KiB355256

MakefileH A D11-Oct-2018410 2114

README.mdH A D11-Oct-20185.6 KiB10881

api.goH A D11-Oct-201833.1 KiB1,009601

commands.goH A D11-Oct-20183.5 KiB15271

commitment.goH A D11-Oct-20183.2 KiB10266

config.goH A D11-Oct-201811.5 KiB25990

configuration.goH A D11-Oct-201810.8 KiB344231

discard_snapshot.goH A D11-Oct-20181.2 KiB5032

file_snapshot.goH A D11-Oct-201813 KiB529370

fsm.goH A D11-Oct-20183.5 KiB13781

future.goH A D11-Oct-20186.7 KiB290178

inmem_snapshot.goH A D11-Oct-20182.5 KiB10778

inmem_store.goH A D11-Oct-20182.7 KiB12697

inmem_transport.goH A D11-Oct-20187.5 KiB323244

log.goH A D11-Oct-20182.2 KiB7324

log_cache.goH A D11-Oct-20181.7 KiB8053

membership.mdH A D11-Oct-20187 KiB8467

net_transport.goH A D11-Oct-201818.4 KiB736497

observer.goH A D11-Oct-20183.6 KiB12369

peersjson.goH A D11-Oct-20182.8 KiB9963

raft.goH A D11-Oct-201843.4 KiB1,4711,013

replication.goH A D11-Oct-201816.8 KiB569372

snapshot.goH A D11-Oct-20187.5 KiB240136

stable.goH A D11-Oct-2018443 167

state.goH A D11-Oct-20183.8 KiB172113

tag.shH A D11-Oct-2018399 179

tcp_transport.goH A D11-Oct-20183 KiB11786

transport.goH A D11-Oct-20184.5 KiB12552

util.goH A D11-Oct-20182.9 KiB13497

README.md

1raft [![Build Status](https://travis-ci.org/hashicorp/raft.png)](https://travis-ci.org/hashicorp/raft)
2====
3
4raft is a [Go](http://www.golang.org) library that manages a replicated
5log and can be used with an FSM to manage replicated state machines. It
6is a library for providing [consensus](http://en.wikipedia.org/wiki/Consensus_(computer_science)).
7
8The use cases for such a library are far-reaching as replicated state
9machines are a key component of many distributed systems. They enable
10building Consistent, Partition Tolerant (CP) systems, with limited
11fault tolerance as well.
12
13## Building
14
15If you wish to build raft you'll need Go version 1.2+ installed.
16
17Please check your installation with:
18
19```
20go version
21```
22
23## Documentation
24
25For complete documentation, see the associated [Godoc](http://godoc.org/github.com/hashicorp/raft).
26
27To prevent complications with cgo, the primary backend `MDBStore` is in a separate repository,
28called [raft-mdb](http://github.com/hashicorp/raft-mdb). That is the recommended implementation
29for the `LogStore` and `StableStore`.
30
31A pure Go backend using [BoltDB](https://github.com/boltdb/bolt) is also available called
32[raft-boltdb](https://github.com/hashicorp/raft-boltdb). It can also be used as a `LogStore`
33and `StableStore`.
34
35## Tagged Releases
36
37As of September 2017, Hashicorp will start using tags for this library to clearly indicate
38major version updates. We recommend you vendor your application's dependency on this library.
39
40* v0.1.0 is the original stable version of the library that was in master and has been maintained
41with no breaking API changes. This was in use by Consul prior to version 0.7.0.
42
43* v1.0.0 takes the changes that were staged in the library-v2-stage-one branch. This version
44manages server identities using a UUID, so introduces some breaking API changes. It also versions
45the Raft protocol, and requires some special steps when interoperating with Raft servers running
46older versions of the library (see the detailed comment in config.go about version compatibility).
47You can reference https://github.com/hashicorp/consul/pull/2222 for an idea of what was required
48to port Consul to these new interfaces.
49
50    This version includes some new features as well, including non voting servers, a new address
51    provider abstraction in the transport layer, and more resilient snapshots.
52
53## Protocol
54
55raft is based on ["Raft: In Search of an Understandable Consensus Algorithm"](https://ramcloud.stanford.edu/wiki/download/attachments/11370504/raft.pdf)
56
57A high level overview of the Raft protocol is described below, but for details please read the full
58[Raft paper](https://ramcloud.stanford.edu/wiki/download/attachments/11370504/raft.pdf)
59followed by the raft source. Any questions about the raft protocol should be sent to the
60[raft-dev mailing list](https://groups.google.com/forum/#!forum/raft-dev).
61
62### Protocol Description
63
64Raft nodes are always in one of three states: follower, candidate or leader. All
65nodes initially start out as a follower. In this state, nodes can accept log entries
66from a leader and cast votes. If no entries are received for some time, nodes
67self-promote to the candidate state. In the candidate state nodes request votes from
68their peers. If a candidate receives a quorum of votes, then it is promoted to a leader.
69The leader must accept new log entries and replicate to all the other followers.
70In addition, if stale reads are not acceptable, all queries must also be performed on
71the leader.
72
73Once a cluster has a leader, it is able to accept new log entries. A client can
74request that a leader append a new log entry, which is an opaque binary blob to
75Raft. The leader then writes the entry to durable storage and attempts to replicate
76to a quorum of followers. Once the log entry is considered *committed*, it can be
77*applied* to a finite state machine. The finite state machine is application specific,
78and is implemented using an interface.
79
80An obvious question relates to the unbounded nature of a replicated log. Raft provides
81a mechanism by which the current state is snapshotted, and the log is compacted. Because
82of the FSM abstraction, restoring the state of the FSM must result in the same state
83as a replay of old logs. This allows Raft to capture the FSM state at a point in time,
84and then remove all the logs that were used to reach that state. This is performed automatically
85without user intervention, and prevents unbounded disk usage as well as minimizing
86time spent replaying logs.
87
88Lastly, there is the issue of updating the peer set when new servers are joining
89or existing servers are leaving. As long as a quorum of nodes is available, this
90is not an issue as Raft provides mechanisms to dynamically update the peer set.
91If a quorum of nodes is unavailable, then this becomes a very challenging issue.
92For example, suppose there are only 2 peers, A and B. The quorum size is also
932, meaning both nodes must agree to commit a log entry. If either A or B fails,
94it is now impossible to reach quorum. This means the cluster is unable to add,
95or remove a node, or commit any additional log entries. This results in *unavailability*.
96At this point, manual intervention would be required to remove either A or B,
97and to restart the remaining node in bootstrap mode.
98
99A Raft cluster of 3 nodes can tolerate a single node failure, while a cluster
100of 5 can tolerate 2 node failures. The recommended configuration is to either
101run 3 or 5 raft servers. This maximizes availability without
102greatly sacrificing performance.
103
104In terms of performance, Raft is comparable to Paxos. Assuming stable leadership,
105committing a log entry requires a single round trip to half of the cluster.
106Thus performance is bound by disk I/O and network latency.
107
108