raftgorums

package
v0.0.0-...-ef52421 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const BufferSize = 10000

BufferSize is the initial buffer size used for maps and buffered channels that directly depend on the number of requests being serviced.

View Source
const None = 0

None represents no server.

View Source
const TCPConnect = 50000

TCPConnect specifies how long the manager will attempt to establish a connection to all servers.

Variables

This section is empty.

Functions

This section is empty.

Types

type AEQueue

type AEQueue []*pb.AppendEntriesRequest

AEQueue implements the heap interface

func InitAEQueue

func InitAEQueue(conf *Config) *AEQueue

func (*AEQueue) Empty

func (aeq *AEQueue) Empty()

func (AEQueue) Len

func (aeq AEQueue) Len() int

func (AEQueue) Less

func (aeq AEQueue) Less(i, j int) bool

func (*AEQueue) Pop

func (aeq *AEQueue) Pop() interface{}

func (*AEQueue) Push

func (aeq *AEQueue) Push(x interface{})

func (AEQueue) Swap

func (aeq AEQueue) Swap(i, j int)

type Config

type Config struct {
	ID uint64

	Servers []string
	// IDs of server which forms the initial cluster. IDs start at 1, which
	// refers to the first server in Servers.
	InitialCluster []uint64

	Storage raft.Storage

	Batch            bool
	ElectionTimeout  time.Duration
	HeartbeatTimeout time.Duration

	EntriesPerMsg uint64
	// CatchupMultiplier is how many times more EntriesPerMsg we are allowed
	// to use when doing a catch up, i.e., EntriesPerMsg*CatchupMultiplier.
	CatchupMultiplier uint64
	// Catchup will be sent if this many committed entries are missing from the log
	MaxMissingCommit uint64
	// Maximum number of out of order append entry requests buffered, before sending catchup
	MaxAEBuffer uint64

	Logger         logrus.FieldLogger
	CheckQuorum    bool
	MetricsEnabled bool
}

Config contains the configuration needed to start an instance of Raft.

type Raft

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

Raft represents an instance of the Raft algorithm.

func NewRaft

func NewRaft(sm raft.StateMachine, cfg *Config, lat *raft.Latency, event *raft.Event, leaderOut chan struct{}) *Raft

NewRaft returns a new Raft given a configuration.

func (*Raft) AppendEntries

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

AppendEntries implements gorums.RaftServer.

func (*Raft) CatchMeUp

func (r *Raft) CatchMeUp(ctx context.Context, req *pb.CatchMeUpRequest) (res *pb.Empty, err error)

CatchMeUp implements gorums.RaftServer.

func (*Raft) HandleAppendEntriesRequest

func (r *Raft) HandleAppendEntriesRequest(req *pb.AppendEntriesRequest) *pb.AppendEntriesResponse

HandleAppendEntriesRequest must be called when receiving a AppendEntriesRequest, the return value must be delivered to the requester.

func (*Raft) HandleAppendEntriesResponse

func (r *Raft) HandleAppendEntriesResponse(response *pb.AppendEntriesQFResponse, maxIndex uint64)

HandleAppendEntriesResponse must be invoked when receiving an AppendEntriesResponse.

func (*Raft) HandleInstallSnapshotRequest

func (r *Raft) HandleInstallSnapshotRequest(snapshot *commonpb.Snapshot) (res *pb.InstallSnapshotResponse)

func (*Raft) HandleInstallSnapshotResponse

func (r *Raft) HandleInstallSnapshotResponse(res *pb.InstallSnapshotResponse) bool

func (*Raft) HandleRequestVoteRequest

func (r *Raft) HandleRequestVoteRequest(req *pb.RequestVoteRequest) *pb.RequestVoteResponse

HandleRequestVoteRequest must be called when receiving a RequestVoteRequest, the return value must be delivered to the requester.

func (*Raft) HandleRequestVoteResponse

func (r *Raft) HandleRequestVoteResponse(response *pb.RequestVoteResponse)

HandleRequestVoteResponse must be invoked when receiving a RequestVoteResponse.

func (*Raft) InstallSnapshot

func (r *Raft) InstallSnapshot(ctx context.Context, snapshot *commonpb.Snapshot) (*pb.InstallSnapshotResponse, error)

InstallSnapshot implements gorums.RaftServer.

func (*Raft) ProposeCmd

func (r *Raft) ProposeCmd(ctx context.Context, cmd []byte) (raft.Future, error)

ProposeCmd implements raft.Raft.

func (*Raft) ProposeConf

func (r *Raft) ProposeConf(ctx context.Context, req *commonpb.ReconfRequest) (raft.Future, error)

ProposeConf implements raft.Raft.

func (*Raft) ReadCmd

func (r *Raft) ReadCmd(ctx context.Context, cmd []byte) (raft.Future, error)

ReadCmd implements raft.Raft.

func (*Raft) RequestVote

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

RequestVote implements gorums.RaftServer.

func (*Raft) Run

func (r *Raft) Run(server *grpc.Server, opts ...gorums.ManagerOption) error

Run starts a server running the Raft algorithm.

func (*Raft) State

func (r *Raft) State() State

State returns the current raft state.

func (*Raft) Stop

func (r *Raft) Stop()

Stop forcibly stops the Raft server.

type RaftQuorumSpec

type RaftQuorumSpec struct {
	N int
	Q int
}

RaftQuorumSpec holds information about the quorum size of the current configuration and allows us to invoke quorum calls.

func NewQuorumSpec

func NewQuorumSpec(peers int) *RaftQuorumSpec

NewQuorumSpec returns a RaftQuorumSpec for len(peers). You need to add 1 if you don't include yourself.

func (*RaftQuorumSpec) AppendEntriesQF

AppendEntriesQF gathers AppendEntriesResponses and calculates the log entries replicated, depending on the quorum configuration. TODO Implements gorums.QuorumSpec interface.

func (*RaftQuorumSpec) RequestVoteQF

func (qs *RaftQuorumSpec) RequestVoteQF(req *pb.RequestVoteRequest, replies []*pb.RequestVoteResponse) (*pb.RequestVoteResponse, bool)

RequestVoteQF gathers RequestVoteResponses and delivers a reply when a higher term is seen or a quorum of votes is received. TODO Implements gorums.QuorumSpec interface.

type State

type State int

State represents one of the Raft server states.

const (
	Inactive State = iota
	Follower
	Candidate
	Leader
)

Server states.

Directories

Path Synopsis
Package gorums is a generated protocol buffer package.
Package gorums is a generated protocol buffer package.
Package raftpb is a generated protocol buffer package.
Package raftpb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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