Packages
ra
0.9.2
3.1.9
3.1.8
3.1.7
3.1.6
3.1.5
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.2
3.0.1
3.0.0
3.0.0-beta.1
2.17.3
2.17.2
2.17.1
2.17.0
2.16.13
2.16.12
2.16.11
2.16.10
2.16.9
2.16.8
2.16.7
2.16.6
2.16.5
2.16.4
2.16.3
2.16.2
2.16.1
2.16.0
2.16.0-pre.12
2.16.0-pre.11
2.16.0-pre.10
2.16.0-pre.9
2.16.0-pre.8
2.16.0-pre.7
2.16.0-pre.6
2.16.0-pre.5
2.16.0-pre.4
2.16.0-pre.3
2.16.0-pre.2
2.16.0-pre.1
2.15.4
2.15.3
2.15.2
2.15.1
2.15.0
2.14.0
2.13.6
2.13.5
2.13.4
2.13.3
2.13.2
2.13.1
2.13.0
2.13.0-pre.1
2.12.0
2.11.0
2.11.0-pre.1
2.10.2-pre.2
2.10.2-pre.1
2.10.1
2.10.0
2.10.0-pre.3
2.10.0-pre.2
2.10.0-pre.1
2.9.10-pre.1
2.9.1
2.9.1-pre.2
2.9.1-pre.1
2.9.0
2.8.0
retired
2.7.3
2.7.2
2.7.1
2.7.0
2.7.0-pre.3
2.7.0-pre.2
2.7.0-pre.1
2.6.3
2.6.2
2.6.1
2.6.0-pre.1
2.5.1
2.5.1-pre.1
2.5.0
2.4.9
2.4.8
2.4.7
2.4.6
2.4.5
2.4.4
2.4.3
2.4.2
retired
2.4.1
2.4.0
2.3.0
2.2.0
2.1.0
2.0.13
2.0.12
2.0.11
2.0.10
2.0.9
2.0.8
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.9.6
0.9.5
0.9.4
0.9.2
0.3.3
retired
0.3.2
retired
0.3.1
retired
Raft library
Current section
Files
Jump to
Current section
Files
README.md
# Ra: a Raft Implementation for Erlang and Elixir[](https://travis-ci.org/rabbitmq/ra)## What is ThisRa is a [Raft](https://ramcloud.stanford.edu/~ongaro/thesis.pdf) implementationby Team RabbitMQ. It is not tied to RabbitMQ and can be used in any Erlang or Elixirproject. It is, however, heavily inspired by and geared towards RabbitMQ needs.Ra (by virtue of being a Raft implementation) is a library that allows users to implement [persistent, fault-tolerant and replicated state machines](https://en.wikipedia.org/wiki/State_machine_replication).## Project MaturityThis library is maturing and is currently in a pre-1.0 phase. This means thatthe primary APIs (`ra`, `ra_machine` modules) and on disk formats are unlikelyto change significantly until 1.0 is tagged but _may_ need to be if deemednecessary.### StatusThe following Raft features are implemented: * Leader election * Log replication * Cluster membership changes: one server (member) at a time * Log compaction (with limitations and RabbitMQ-specific extensions) * Snapshot installation## Supported Erlang/OTP VersionsRa requires Erlang/OTP 20.3 or later.## Quick start```erlang%% All servers in a Ra cluster are named processes.%% Create some Server Ids to pass to the configurationErlangNodes = [ra@node1, ra@node2, ra@node3]ServerIds = [{quick_start, N} || N <- ErlangNodes]%% start a simple distributed addition state machine with an initial state of 0{ok, ServersStarted, ServersNotStarted} = ra:start_cluster(quick_start, {simple, fun erlang:'+'/2, 0}, ServerIds),%% Add a number to the state machine%% Simple state machines always return the full state after each operation{ok, StateMachineResult, LeaderId} = ra:process_command(hd(ServersStarted), 5),%% use the leader id from the last command result for the next{ok, 12, LeaderId1} = ra:process_command(LeaderId, 7),```"Simple" state machines like the above can only take you so far. See [Ra state machine tutorial](docs/internals/STATE_MACHINE_TUTORIAL.md)for how to write a state machine by implementing the `ra_machine` behaviour.## Design Goals * Low footprint: use as few resources as possible, avoid process tree explosion * Able to run thousands of `ra` clusters within an Erlang node * Provide adequate performance for use as a basis for a distributed data service## Use CasesThis library is primarily developed as the foundation for replication layer forreplicated queues in a future version of RabbitMQ. The design it aims to replace usesa variant of [Chain Based Replication](https://www.cs.cornell.edu/home/rvr/papers/OSDI04.pdf)which has two major shortcomings: * Replication algorithm is linear * Failure recovery procedure requires expensive topology changes## Documentation* API docs: https://rabbitmq.github.io/ra/* How to write a Ra state machine: [Ra state machine tutorial](docs/internals/STATE_MACHINE_TUTORIAL.md)* Design and implementation details: [Ra internals guide](docs/internals/INTERNALS.md)## Configuration* `data_dir`:A directory name where `ra` will store it's data.* `wal_max_size_bytes`:The maximum size of the WAL (Write Ahead Log). Default: 128Mb.* `wal_compute_checksums`:Indicate whether the wal should compute and validate checksums. Default: true* `wal_write_strategy`: - `default`: The default. Actual `write(2)` system calls are delayed until a buffer is due to be flushed. Then it writes all the data in a single call then fsyncs. Fastest but incurs some additional memory use. - `do_sync`: Like `default` but will try to open the file with `O_SYNC` and thus wont need the additional `fsync(2)` system call. If it fails to open the file with this flag this mode falls back to `default`Example:```[{data_dir, "/tmp/ra-data"}, {wal_max_size_bytes, 134217728}, {wal_compute_checksums, true}, {wal_write_strategy, default},]```## Copyright and License(c) 2017-2018, Pivotal Software Inc.Double licensed under the ASL2 and MPL1.1.See [LICENSE](./LICENSE) for details.