raft

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHeartbeatTimeout = 300 * time.Millisecond
	DefaultElectionTimeout  = 300 * time.Millisecond
	DefaultLeaderLease      = 200 * time.Millisecond
)

Raft and consensus related parameters.

Variables

View Source
var DefaultConfig = Config{
	HeartbeatTimeout: DefaultHeartbeatTimeout,
	ElectionTimeout:  DefaultElectionTimeout,
	LeaderLease:      DefaultLeaderLease,
}

DefaultConfig represents the default settings for the raft handler.

Functions

This section is empty.

Types

type Config

type Config struct {
	Callbacks []FSMProcessFunc // Callback functions to be invoked by the FSM after execution is done.

	HeartbeatTimeout time.Duration // How often a consensus cluster leader should ping its followers.
	ElectionTimeout  time.Duration // How long does a consensus cluster node wait for a leader before it triggers an election.
	LeaderLease      time.Duration // How long does a leader remain a leader if it cannot contact a quorum of cluster nodes.
}

type FSMLogEntry

type FSMLogEntry struct {
	RequestID string          `json:"request_id,omitempty"`
	Origin    peer.ID         `json:"origin,omitempty"`
	Execute   execute.Request `json:"execute,omitempty"`
}

type FSMProcessFunc

type FSMProcessFunc func(req FSMLogEntry, res execute.Result)

type Option

type Option func(*Config)

Option can be used to set Raft configuration options.

func WithCallbacks

func WithCallbacks(callbacks ...FSMProcessFunc) Option

func WithElectionTimeout

func WithElectionTimeout(d time.Duration) Option

WithElectionTimeout sets the election timeout for the consensus cluster.

func WithHeartbeatTimeout

func WithHeartbeatTimeout(d time.Duration) Option

WithHeartbeatTimeout sets the heartbeat timeout for the consensus cluster.

func WithLeaderLease

func WithLeaderLease(d time.Duration) Option

WithLeaderLease sets the leader lease for the consensus cluster leader.

type Replica

type Replica struct {
	*raft.Raft
	// contains filtered or unexported fields
}

func New

func New(log zerolog.Logger, host *host.Host, workspace string, requestID string, executor blockless.Executor, peers []peer.ID, options ...Option) (*Replica, error)

New creates a new raft replica, bootstraps the cluster and waits until a first leader is elected. We do this because only after the election the cluster is really operational and ready to process requests.

func (*Replica) Consensus

func (r *Replica) Consensus() consensus.Type

func (*Replica) Execute

func (r *Replica) Execute(from peer.ID, requestID string, timestamp time.Time, req execute.Request) (codes.Code, execute.Result, error)

func (*Replica) Shutdown

func (r *Replica) Shutdown() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL