transport

package
v1.12.1-0...-676f45f Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package transport provides grpc transport layer for raft. All methods are non-blocking.

Index

Constants

View Source
const (
	// GRPCMaxMsgSize is the max allowed gRPC message size for raft messages.
	GRPCMaxMsgSize = 4 << 20
)

Variables

View Source
var ErrIsNotFound = errors.New("peer not found")

ErrIsNotFound indicates that peer was never added to transport.

Functions

This section is empty.

Types

type Config

type Config struct {
	HeartbeatInterval time.Duration
	SendTimeout       time.Duration
	Credentials       credentials.TransportCredentials
	RaftID            string

	Raft
}

Config for Transport

type Raft

type Raft interface {
	ReportUnreachable(id uint64)
	ReportSnapshot(id uint64, status raft.SnapshotStatus)
	IsIDRemoved(id uint64) bool
	UpdateNode(id uint64, addr string)

	NodeRemoved()
}

Raft is interface which represents Raft API for transport package.

type Transport

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

Transport is structure which manages remote raft peers and sends messages to them.

func New

func New(cfg *Config) *Transport

New returns new Transport with specified Config.

func (*Transport) Active

func (t *Transport) Active(id uint64) bool

Active returns true if node was recently active and false otherwise.

func (*Transport) AddPeer

func (t *Transport) AddPeer(id uint64, addr string) error

AddPeer adds new peer with id and address addr to Transport. If there is already peer with such id in Transport it will return error if address is different (UpdatePeer should be used) or nil otherwise.

func (*Transport) HealthCheck

func (t *Transport) HealthCheck(ctx context.Context, id uint64) error

HealthCheck checks health of particular peer.

func (*Transport) LongestActive

func (t *Transport) LongestActive() (uint64, error)

LongestActive returns the ID of the peer that has been active for the longest length of time.

func (*Transport) PeerAddr

func (t *Transport) PeerAddr(id uint64) (string, error)

PeerAddr returns address of peer with id.

func (*Transport) PeerConn

func (t *Transport) PeerConn(id uint64) (*grpc.ClientConn, error)

PeerConn returns raw grpc connection to peer.

func (*Transport) RemovePeer

func (t *Transport) RemovePeer(id uint64) error

RemovePeer removes peer from Transport and wait for it to stop.

func (*Transport) Send

func (t *Transport) Send(m raftpb.Message) error

Send sends raft message to remote peers.

func (*Transport) Stop

func (t *Transport) Stop()

Stop stops transport and waits until it finished

func (*Transport) UpdatePeer

func (t *Transport) UpdatePeer(id uint64, addr string) error

UpdatePeer updates peer with new address. It replaces connection immediately.

func (*Transport) UpdatePeerAddr

func (t *Transport) UpdatePeerAddr(id uint64, addr string) error

UpdatePeerAddr updates peer with new address, but delays connection creation. New address won't be used until first failure on old address.

Jump to

Keyboard shortcuts

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