Pure Python implementation of the RAFT concencous algorithm
Project description
pyraftlog is a RAFT consensus algorithm implementation that provides direct access to the consensus log.
Consensus Nodes can be instantiated into defined mode, but can also have its mode changed via an RPC. There are three modes a node can be in:
- Active
A fully-fledged consensus node which will attempt to take leadership of the cluster if a leadership timeout is reached.
- Reluctant
A consensus node which will reluctantly take leadership of the cluster while there is no eligible candidate. As soon as there is an eligible active node a reluctant node will rescind its leadership.
- Passive
A consensus node which that will respond to all vote requests but will never convert itself to a candidate. This mode can be useful in testing or development environments but shouldn’t be used in production.
Consensus Nodes can enable log reduction, this can be useful in certain situations where a complete history of actions is not required or would take considerable storage to retain. If log_reduction is set to True in the state then the cluster will automatically reduce the log to the most recent last_applied index that is shared across the cluster. Have log reduction set to True would make it difficult to add additional nodes to the cluster.
Mock Server
There is a mock server that can be run by calling pyraftlog-mock:
usage: pyraftlog-mock [-h] [-t {active,reluctant,passive}] -n NODE -b NEIGHBOURS [NEIGHBOURS ...] [-p PORT] [-r] [-l {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [-f FILE] Run a mock localhost pyraftlog server optional arguments: -h, --help show this help message and exit -t {active,reluctant,passive}, --type {active,reluctant,passive} Type of the node -n NODE, --node NODE (host:)?port of this node. e.g. 7001 or node:7001 -b NEIGHBOURS [NEIGHBOURS ...], --neighbours NEIGHBOURS [NEIGHBOURS ...] Port(s) of neighbour -p PORT, --port PORT Port for receiving commands -r, --log-reduction Set log reduction to True -l {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL} Logging level -f FILE, --file FILE Storage filename
Create SSL certs (for mock)
The following set of commands (performed in ./certs/) will create a set a CA and device certificate for running the mock cluster on localhost:
# Only do once: generate the root CA key: > openssl genrsa -out transport-ca.key 4096 # Generate the root CA certificate: ## Country Name (2 letter code) []:GB ## State or Province Name (full name) []:. ## Locality Name (eg, city) []:. ## Organization Name (eg, company) []:. ## Organizational Unit Name (eg, section) []:. ## Common Name (eg, fully qualified host name) []:PyRaftLog ## Email Address []:. > openssl req -x509 -new -nodes -key transport-ca.key -sha256 -days 1024 -out transport-ca.pem # Generate device certificates # Only do once: generate device key: > openssl genrsa -out transport-consensus.key 4096 # Generate device certificate signing request: ## Country Name (2 letter code) []:GB ## State or Province Name (full name) []:. ## Locality Name (eg, city) []:. ## Organization Name (eg, company) []:. ## Organizational Unit Name (eg, section) []:. ## Common Name (eg, fully qualified host name) []:localhost ## Email Address []:. > openssl req -new -key transport-consensus.key -out transport-consensus.csr # Generate a signed device certificate: > openssl x509 -req -in transport-consensus.csr -CA transport-ca.pem -CAkey transport-ca.key -CAcreateserial -out transport-consensus.crt -days 500 -sha256
Also See
Raft lecture (Raft user study)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.