consensus

package
v0.0.0-...-0194b68 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExecRequest RequestType = iota

	// RaftRPC is given at the start of connection to signify that raft should handle that connection.
	RaftRPC int = 1
)

Variables

View Source
var (
	// ErrNotLeader defines a project-wide not leader error
	ErrNotLeader = errors.New("not raft leader")

	// ErrJoinSelf happens when a node tries to join itself.
	ErrJoinSelf = errors.New("trying to join self")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Raft struct {
		raft.Config
		Bootstrap         bool
		SnapshotThreshold uint64
	}
	Transport *Transport
}

Config configures parts of raft and also transport that is used.

type Consensus

type Consensus struct {
	// contains filtered or unexported fields
}

func NewDB

func NewDB(dataDir string, config *Config) (*Consensus, error)

func (*Consensus) Apply

func (c *Consensus) Apply(record *raft.Log) interface{}

func (*Consensus) Close

func (c *Consensus) Close() error

Close closes the raft node and it also closes the database connections

func (*Consensus) Exec

func (c *Consensus) Exec(req *pb.Request) ([]*pb.ExecRes, error)

func (*Consensus) GetServers

func (c *Consensus) GetServers() ([]*pb.Server, error)

func (*Consensus) IsLeader

func (c *Consensus) IsLeader() bool

func (*Consensus) Join

func (c *Consensus) Join(id, addr string) error

func (*Consensus) LeaderAddr

func (c *Consensus) LeaderAddr() string

func (*Consensus) Leave

func (c *Consensus) Leave(id string) error

func (*Consensus) Metrics

func (c *Consensus) Metrics() (map[string]any, error)

func (*Consensus) Query

func (c *Consensus) Query(q *pb.QueryReq) ([]*pb.QueryRes, error)

func (*Consensus) Restore

func (c *Consensus) Restore(rc io.ReadCloser) error

func (*Consensus) Snapshot

func (c *Consensus) Snapshot() (raft.FSMSnapshot, error)

func (*Consensus) WaitForIndex

func (c *Consensus) WaitForIndex(idx uint64, timeout time.Duration) (uint64, error)

func (*Consensus) WaitForLeader

func (c *Consensus) WaitForLeader(timeout time.Duration) error

type RequestType

type RequestType uint8

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport handles communications between different raft nodes.

func NewTLSTransport

func NewTLSTransport(ln net.Listener, servertls *tls.Config, peertls *tls.Config) *Transport

NewTLSTransport creates a transport instance with the tls fields populated.

func NewTransport

func NewTransport(ln net.Listener) *Transport

NewTransport creates a new transport instance.

func (*Transport) Accept

func (tn *Transport) Accept() (net.Conn, error)

Accept acceps a given dial and checks that the RaftRPC identifier is defined at the start; if not then just return an error.

func (*Transport) Addr

func (tn *Transport) Addr() net.Addr

Addr returns a net.Addr representing the address Transport is listening on.

func (*Transport) Close

func (tn *Transport) Close() error

Close closes the listener

func (*Transport) Dial

func (tn *Transport) Dial(addr raft.ServerAddress, timeout time.Duration) (net.Conn, error)

Dial creates a connection to a given address. This function appends the RaftRPC identifier (1) to the request's beginning such that raft requests can be properly identified.

Jump to

Keyboard shortcuts

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