Pure Python implementation of the RAFT consensus 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.
Source Distribution
Built Distribution
File details
Details for the file pyraftlog-3.0.0.tar.gz
.
File metadata
- Download URL: pyraftlog-3.0.0.tar.gz
- Upload date:
- Size: 30.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee75a4f08daa1b450ffb26bbdc2ad71214b8f99fb999f7cf8ed69801a07b2d9a |
|
MD5 | ecdbdf70a20c7aa9a3725f8f10a9b444 |
|
BLAKE2b-256 | 3d6e759e81b9aec136f68666d753a8a609370b8f2ac13a5cd09abb6e3853fcc0 |
File details
Details for the file pyraftlog-3.0.0-py3-none-any.whl
.
File metadata
- Download URL: pyraftlog-3.0.0-py3-none-any.whl
- Upload date:
- Size: 33.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 813f65b95a026c292ca95b30b1b3b9a34af6de1bf0dc3d34b1d23b01c6e91e7f |
|
MD5 | 023b7c22903e056ab1851857c0032885 |
|
BLAKE2b-256 | 781be32e70799f0b268739857f487d7626fd02c92400b164acb7cd9b86c682e7 |