modulepackage
0.0.0-20240402192949-3f8f888dc8af
Repository: https://github.com/nats-io/graft.git
Documentation: pkg.go.dev
# README
Graft
A RAFT Election implementation in Go. More information on RAFT can be found in this research paper and this video.
Overview
RAFT is a consensus based algorithm that produces consistent state through replicated logs and leader elections.
Example usage of the election algorithm is to produce guaranteed leaders for N-wise scalability and elimination of SPOF (Single Point of Failure) within a system.
Example Usage
ci := graft.ClusterInfo{Name: "health_manager", Size: 3}
rpc, err := graft.NewNatsRpc(&nats.DefaultOptions)
errChan := make(chan error)
stateChangeChan := make(chan StateChange)
handler := graft.NewChanHandler(stateChangeChan, errChan)
node, err := graft.New(ci, handler, rpc, "/tmp/graft.log");
// ...
if node.State() == graft.LEADER {
// Process as a LEADER
}
select {
case sc := <- stateChangeChan:
// Process a state change
case err := <- errChan:
// Process an error, log etc.
}
License
Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.
# Packages
No description provided by the author
# Functions
New will create a new Graft node.
NewChanHandler returns a Handler implementation which uses channels for handling errors and state changes.
NewChanHandlerWithStateMachine returns a Handler implementation which uses channels for handling errors and state changes and a StateMachineHandler for hooking into external state.
No description provided by the author
NewNatsRpc creates a new instance of the driver.
NewNatsRpcFromConn creates a new instance of the driver using an existing NATS connection.
# Constants
Allowable states for a Graft node.
Allowable states for a Graft node.
Allowable states for a Graft node.
Membership designations for split network simulations.
Membership designations for split network simulations.
Heartbeat tick for LEADERS.
The subject space for the nats rpc driver is based on the cluster name, which is filled in below on the heartbeats and vote requests.
Allowable states for a Graft node.
No description provided by the author
Election timeout MIN and MAX per RAFT spec suggestion.
No description provided by the author
Membership designations for split network simulations.
No description provided by the author
No description provided by the author
The subject space for the nats rpc driver is based on the cluster name, which is filled in below on the heartbeats and vote requests.
The subject space for the nats rpc driver is based on the cluster name, which is filled in below on the heartbeats and vote requests.
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
ChanHandler is a convenience handler when a user wants to simply use channels for the async handling of errors and state changes.
ClusterInfo expresses the name and expected size of the cluster.
No description provided by the author
NatsRpcDriver is an implementation of the RPCDriver using NATS.
No description provided by the author
StateChange captures "from" and "to" States for the ChanHandler.
# Interfaces
A Handler can process async callbacks from a Graft node.
An RPCDriver allows multiple transports to be utilized for the RAFT protocol RPCs.
StateMachineHandler is used to interrogate an external state machine.
# Type aliases
No description provided by the author