libraft

package
v0.0.0-...-22f7c09 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const AP_ALREADY_IN_CONFIGURATION = AddProvisionalError("ALREADY_IN_CONFIGURATION")
View Source
const AP_ALREADY_PROVISIONAL = AddProvisionalError("ALREADY_PROVISIONAL")
View Source
const AP_NOT_LEADER = AddProvisionalError("NOT_LEADER")
View Source
const AP_SUCCESS = AddProvisionalError("SUCCESS")
View Source
const AR_ALREADY_COMPLETE = AddRemoveServerError("ALREADY_IN_CONFIGURATION")
View Source
const AR_CONCURRENT_CHANGE = AddRemoveServerError("CONCURRENT_CHANGE")
View Source
const AR_NEW_LEADER = AddRemoveServerError("NEW_LEADER")
View Source
const AR_NOT_CAUGHT_UP = AddRemoveServerError("NOT_CAUGHT_UP")
View Source
const AR_NOT_LEADER = AddRemoveServerError("NOT_LEADER")
View Source
const AR_NOT_PROVISIONAL = AddRemoveServerError("NOT_PROVISIONAL")
View Source
const AR_OK = AddRemoveServerError("OK")

Variables

This section is empty.

Functions

This section is empty.

Types

type AddProvisionalError

type AddProvisionalError string

type AddRemoveServerError

type AddRemoveServerError string

type ApplyMsg

type ApplyMsg struct {
	CommandValid bool
	Command      interface{}
	CommandTerm  int
	CommandIndex int

	// For 2D:
	SnapshotValid bool
	Snapshot      []byte
	SnapshotTerm  int
	SnapshotIndex int

	RaftUpdateValid bool // Indicates that the leader has changed
	IsLeader        bool

	ConfigValid   bool // Indicates server configuration has changed
	Configuration map[string]bool
}

type Persister

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

Persister provides support for Raft and an application using Raft to save persistent state.

func MakePersister

func MakePersister() *Persister

func (*Persister) Copy

func (ps *Persister) Copy() *Persister

func (*Persister) RaftStateSize

func (ps *Persister) RaftStateSize() int

func (*Persister) ReadRaftState

func (ps *Persister) ReadRaftState() []byte

func (*Persister) ReadSnapshot

func (ps *Persister) ReadSnapshot() []byte

func (*Persister) SaveRaftState

func (ps *Persister) SaveRaftState(state []byte)

func (*Persister) SaveStateAndSnapshot

func (ps *Persister) SaveStateAndSnapshot(state []byte, snapshot []byte)

Save both Raft state and K/V snapshot as a single atomic action, to help avoid them getting out of sync.

func (*Persister) SnapshotSize

func (ps *Persister) SnapshotSize() int

type Raft

type Raft interface {
	// Start initiates consensus on the supplied command.
	// If this server isn't the leader, return false. Otherwise, start
	// the agreement and return immediately.
	//
	// The first return value is the index that the command will appear at
	// if it's ever committed. The second return value is the current
	// term. The third return value is true if this server believes it is
	// the leader.
	Start(command interface{}) (int, int, bool)

	// Kill kills all long-running goroutines and releases any memory
	// used by the Raft instance. After calling Kill no other methods
	// may be called.
	Kill()

	// Snapshot should be called after the service using Raft has created
	// a snapshot of its data up to and including index. Raft may then
	// discard a prefix of its log.
	Snapshot(index int, snapshot []byte)

	// CondInstallSnapshot returns true if the service should install a snapshot
	// that was given to it on the applyCh. If false is returned, the service should
	// discard the snapshot.
	CondInstallSnapshot(lastIncludedTerm int, lastIncludedIndex int, snapshot []byte) bool

	// GetApplyCh returns a channel that Raft sends updates on. The same channel
	// is always returned.
	GetApplyCh() <-chan ApplyMsg

	// GetState returns currentTerm and whether this server
	// believes it is the leader.
	// Useful for testing.
	GetState() (int, bool)

	// GetProvisionalConfiguration returns whether or not the server thinks it's the leader
	// and a set of servers with provisional status
	GetProvisionalConfiguration() (bool, map[string]bool)

	// GetCurrentConfiguration returns whether or not the server thinks it's the leader
	// and a set of servers with voting status
	GetCurrentConfiguration() (bool, map[string]bool)

	AddProvisional(peer string) (int, AddProvisionalError)

	RemoveServer(peer string) (<-chan bool, AddRemoveServerError)

	AddServer(peer string) (<-chan bool, AddRemoveServerError)
}

Raft can manage a shared log.

Jump to

Keyboard shortcuts

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