service

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FollowerState  nodeState = "follower"
	CandidateState nodeState = "candidate"
	LeaderState    nodeState = "leader"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	GetRequestVoteTimeout() time.Duration
	GetAppendEntriesTimeout() time.Duration

	GetStartDelay() time.Duration
	GetCommitPeriod() time.Duration
	GetElectionTimeout() time.Duration

	GetLeaderStalePeriod() time.Duration
	GetLeaderHeartbeatPeriod() time.Duration
	GetLeaderHeartbeatBatchSize() uint64
}

type EntryStore

type EntryStore interface {
	AppendEntries(ctx context.Context, entries ...*core.Entry) (err error)
	Last(ctx context.Context) (entry *core.Entry, err error)
	At(ctx context.Context, index uint64) (entry *core.Entry, err error)
	Range(ctx context.Context, from uint64, to uint64) (entries []*core.Entry, err error)
}

type KVStore

type KVStore interface {
	Get(ctx context.Context, key string) (value string, err error)
	Set(ctx context.Context, key, value string) (err error)
	Del(ctx context.Context, key string) (err error)
}

type Raft

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

func NewRaftState

func NewRaftState(
	ctx context.Context,
	config Config,
	raftID core.ServerID,
	cluster []core.Node,
	entryStore EntryStore,
	stateStore StateStore,
	kvStore KVStore,
) (*Raft, error)

func (*Raft) AppendEntries

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

func (*Raft) Close

func (r *Raft) Close() error

func (*Raft) Del

func (r *Raft) Del(ctx context.Context, key string) error

func (*Raft) Get

func (r *Raft) Get(ctx context.Context, key string) (string, error)

func (*Raft) Info

func (*Raft) RequestVote

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

func (*Raft) Run

func (r *Raft) Run()

func (*Raft) Set

func (r *Raft) Set(ctx context.Context, key string, value string) error

type StateStore

type StateStore interface {
	GetTerm(ctx context.Context) (term uint64, err error)
	SetTerm(ctx context.Context, term uint64) (err error)

	GetCommit(ctx context.Context) (commitIndex uint64, err error)
	SetCommit(ctx context.Context, commitIndex uint64) (err error)

	GetLastApplied(ctx context.Context) (lastApplied uint64, err error)
	SetLastApplied(ctx context.Context, lastApplied uint64) (err error)

	GetVotedFor(ctx context.Context) (votedFor uint64, err error)
	SetVotedFor(ctx context.Context, votedFor uint64) (err error)
}

Jump to

Keyboard shortcuts

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