Movatterモバイル変換


[0]ホーム

URL:


tsconsensus

package
v1.92.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:24Imported by:0

Details

Repository

github.com/tailscale/tailscale

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

typeBootstrapOptsadded inv1.88.0

type BootstrapOpts struct {TagstringFollowOnlybool}

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)DeleteClusterServeradded inv1.88.0

func (c *Consensus) DeleteClusterServer(idraft.ServerID) (uint64,error)

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)GetClusterConfigurationadded inv1.88.0

func (c *Consensus) GetClusterConfiguration() (raft.Configuration,error)

GetClusterConfiguration returns the result of the underlying raft instance's GetConfiguration

func (*Consensus)Stop

func (c *Consensus) Stop(ctxcontext.Context)error

Stop attempts to gracefully shutdown various components.

typeStreamLayer

type StreamLayer struct {net.Listener// contains filtered or unexported fields}

StreamLayer implements an interface asked for by raft.NetworkTransport.It does the raft interprocess communication via tailscale.

func (StreamLayer)Accept

func (slStreamLayer) Accept() (net.Conn,error)

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.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp