tsconsensus
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package tsconsensus implements a consensus algorithm for a group of tsnet.Servers
The Raft consensus algorithm relies on you implementing a state machine that will give the sameresult to a given command as long as the same logs have been applied in the same order.
tsconsensus uses the hashicorp/raft library to implement leader elections and log application.
tsconsensus provides:
- cluster peer discovery based on tailscale tags
- executing a command on the leader
- communication between cluster peers over tailscale using tsnet
Users implement a state machine that satisfies the raft.FSM interface, with the business logic they desire.When changes to state are needed any node may
- create a Command instance with serialized Args.
- call ExecuteCommand with the Command instancethis will propagate the command to the leader,and then from the reader to every node via raft.
- the state machine then can implement raft.Apply, and dispatch commands via the Command.Namereturning a CommandResult with an Err or a serialized Result.
Index¶
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeBootstrapOpts¶added inv1.88.0
typeCommand¶
type Command struct {// The Name can be used to dispatch the command when received.Namestring// The Args are serialized for transport.Argsjson.RawMessage}A Command is a representation of a state machine action.
typeCommandResult¶
type CommandResult struct {// Err is any error that occurred on the node that tried to execute the command,// including any error from the underlying operation and deserialization problems etc.Errerror// Result is serialized for transport.Resultjson.RawMessage}A CommandResult is a representation of the result of a statemachine action.
typeConfig¶
type Config struct {CommandPortuint16RaftPortuint16MonitorPortuint16Raft *raft.ConfigMaxConnPoolintConnTimeouttime.DurationServeDebugMonitorboolStateDirPathstring}A Config holds configurable values such as ports and timeouts.Use DefaultConfig to get a useful Config.
funcDefaultConfig¶
func DefaultConfig()Config
DefaultConfig returns a Config populated with default values ready for use.
typeConsensus¶
type Consensus struct {// contains filtered or unexported fields}A Consensus is the consensus algorithm for a tsnet.ServerIt wraps a raft.Raft instance and performs the peer discoveryand command execution on the leader.
funcStart¶
func Start(ctxcontext.Context, ts *tsnet.Server, fsmraft.FSM, bootstrapOptsBootstrapOpts, cfgConfig) (*Consensus,error)
Start returns a pointer to a running Consensus instance.Calling it with a *tsnet.Server will cause that server to join or start a consensus clusterwith other nodes on the tailnet tagged with the clusterTag. The *tsnet.Server will run the statemachine defined by the raft.FSM also provided, and keep it in sync with the other cluster members'state machines using Raft.
func (*Consensus)DeleteClusterServer¶added inv1.88.0
DeleteClusterServer returns the result of the underlying raft instance's RemoveServer
func (*Consensus)ExecuteCommand¶
func (c *Consensus) ExecuteCommand(cmdCommand) (CommandResult,error)
ExecuteCommand propagates a Command to be executed on the leader. Whichuses raft to Apply it to the followers.
func (*Consensus)GetClusterConfiguration¶added inv1.88.0
func (c *Consensus) GetClusterConfiguration() (raft.Configuration,error)
GetClusterConfiguration returns the result of the underlying raft instance's GetConfiguration
typeStreamLayer¶
StreamLayer implements an interface asked for by raft.NetworkTransport.It does the raft interprocess communication via tailscale.
func (StreamLayer)Dial¶
func (slStreamLayer) Dial(addressraft.ServerAddress, timeouttime.Duration) (net.Conn,error)
Dial implements the raft.StreamLayer interface with the tsnet.Server's Dial.