+3
日增长
9,169
stars
1,105
forks
384
watchers
452
prs
289
issues
27
releases
README
raft
====
raft is a Go library that manages a replicated
log and can be used with an FSM to manage replicated state machines. It
is a library for providing consensus).
The use cases for such a library are far-reaching, such as replicated state
machines which are a key component of many distributed systems. They enable
building Consistent, Partition Tolerant (CP) systems, with limited
fault tolerance as well.
Building
If you wish to build raft you'll need Go version 1.16+ installed.
Please check your installation with:
go version
Documentation
For complete documentation, see the associated Godoc.
To prevent complications with cgo, the primary backend MDBStore is in a separate repository,
called raft-mdb. That is the recommended implementation
for the LogStore and StableStore.
A pure Go backend using Bbolt is also available called
raft-boltdb. It can also be used as a LogStore
and StableStore.
Community Contributed Examples
- Raft gRPC Example - Utilizing the Raft repository with gRPC
- Raft-based KV-store Example - Uses Hashicorp Raft to build a distributed key-value store
Tagged Releases
As of September 2017, HashiCorp will start using tags for this library to clearly indicate
major version updates. We recommend you vendor your application's dependency on this library.
v0.1.0 is the original stable version of the library that was in main and has been maintained
with no breaking API changes. This was in use by Consul prior to version 0.7.0.
v1.0.0 takes the changes that were staged in the library-v2-stage-one branch. This version
manages server identities using a UUID, so introduces some breaking API changes. It also versions
the Raft protocol, and requires some special steps when interoperating with Raft servers running
older versions of the library (see the detailed comment in config.go about version compatibility).
You can reference https://github.com/hashicorp/consul/pull/2222 for an idea of what was required
to port Consul to these new interfaces.
This version includes some new features as well, including non voting servers, a new address
provider abstraction in the transport layer, and more resilient snapshots.
Protocol
raft is based on "Raft: In Search of an Understandable Consensus Algorithm"
A high level overview of the Raft protocol is described below, but for details please read the full
Raft paper
followed by the raft source. Any questions about the raft protocol should be sent to the
raft-dev mailing list.
Protocol Description
Raft nodes are always in one of three states: follower, candidate or leader. All
nodes initially start out as a follower. In this state, nodes can accept log entries
from a leader and cast votes. If no entries are received for some time, nodes
self-promote to the candidate state. In the candidate state nodes request votes from
their peers. If a candidate receives a quorum of votes, then it is promoted to a leader.
The leader must accept new log entries and replicTop issues
#128automatic Apply forward to leader?31 comments · 2016-06-29#666asynchronous heartbeat can cause a stale leader to hold lease indefinitely during disk IO stall15 comments · 2026-02-12#472Leadership election stuck in 3 node cluster in Candidate state.14 comments · 2021-09-06#612Leader stopped sending appendEntries to the follower, but heartbeat was working7 comments · 2024-08-25#549Enhancement: persist commit index in LogStore to accelerate recovery7 comments · 2023-03-15#601Make Snapshots streamable by not requiring a known size up front.6 comments · 2024-06-21#695Data divergence (Safety violation) due to Async Heartbeat5 comments · 2026-07-09#586Leader election times seem too long with max current term5 comments · 2024-03-04
Latest release
v1.8.0 v1.8.0 2026-09-16What's Changed This release removes the long-standing compatibiltiy shim between hashicorp/go-metrics and armon/go-metrics. You no longer need to set build tags when consuming this library. If you have other libraries that consume this library, you should upgrade them at the same time as your application. Raft now persists the commit index in the LogStore to accelerate recovery Full Changelog: https://github.com/hashicorp/raft/compare/v1.7.3...v1.8.0