raft

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	HeartbeatTimeout  time.Duration
	ElectionTimeout   time.Duration
	HeartbeatInterval time.Duration
}

type Peer

type Peer interface {
	pb.RaftClient
}

Peer provides an interface to allow Raft to commnuncate with other nodes

type Persister

type Persister interface {
	SaveRaftState(raftState []byte) error
	LoadRaftState() ([]byte, error)
}

type Raft

type Raft struct {
	pb.UnimplementedRaftServer
	// contains filtered or unexported fields
}

func NewRaft

func NewRaft(id uint32, peers map[uint32]Peer, persister Persister, config *Config, logger *zap.Logger) *Raft

func (*Raft) AppendEntries

func (r *Raft) AppendEntries(ctx context.Context, req *pb.AppendEntriesRequest) (*pb.AppendEntriesResponse, error)

func (*Raft) ApplyCh

func (r *Raft) ApplyCh() <-chan *pb.Entry

func (*Raft) ApplyCommand

func (r *Raft) ApplyCommand(ctx context.Context, req *pb.ApplyCommandRequest) (*pb.ApplyCommandResponse, error)

func (*Raft) RequestVote

func (r *Raft) RequestVote(ctx context.Context, req *pb.RequestVoteRequest) (*pb.RequestVoteResponse, error)

func (*Raft) Run

func (r *Raft) Run(ctx context.Context)

type RaftState

type RaftState uint32
const (
	Follower RaftState = iota
	Candidate
	Leader
)

func (RaftState) String

func (s RaftState) String() string

Jump to

Keyboard shortcuts

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