raft

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: MIT Imports: 8 Imported by: 0

README

raft

Raft consensus

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendEntriesRequest

type AppendEntriesRequest struct {
	CurrentTerm uint64
	LeaderID    string
}

AppendEntriesRequest request

type AppendEntriesResponse

type AppendEntriesResponse struct {
	Term    uint64
	Success bool
}

AppendEntriesResponse response

type RPCServer

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

RPCServer provide a network interface for raft nodes

func (*RPCServer) AppendEntries

func (s *RPCServer) AppendEntries(appendRequest AppendEntriesRequest, response *AppendEntriesResponse) error

AppendEntries implements append entry RPC node

func (*RPCServer) RequestVote

func (s *RPCServer) RequestVote(voteRequest RequestVoteRequest, response *RequestVoteResponse) error

RequestVote request

type Raft

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

Raft node

func NewRaft

func NewRaft(listenAddress string, listenPort int, clusterNodes []string) *Raft

NewRaft creates a new Raft node

func (*Raft) GetLeader

func (r *Raft) GetLeader() string

GetLeader return leader address

func (*Raft) Shutdown

func (r *Raft) Shutdown()

Shutdown terminate a node

type RequestVoteRequest

type RequestVoteRequest struct {
	Term      uint64
	Candidate string
	Response  chan RequestVoteResponse
}

RequestVoteRequest requests a

type RequestVoteResponse

type RequestVoteResponse struct {
	Granted bool
}

RequestVoteResponse does

type State

type State uint32

State represent the current state of a raft node

const (
	// FOLLOWER state
	FOLLOWER State = iota
	// CANDIDATE state
	CANDIDATE
	// LEADER state
	LEADER
	// SHUTDOWN state
	SHUTDOWN
)

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

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