consensus

package
Version: v0.0.0-...-fc1e718 Latest Latest
Warning

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

Go to latest
Published: May 10, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package consensus implements the core of the Ios consensus algorithm. Package consensus is pure and does not perform any of its own IO operations such as writing to disk or sending packets. It is uses msgs.Io for this purpose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(peerNet *msgs.PeerNet, clientNet *msgs.ClientNet, config Config, app *app.StateMachine, fail *msgs.FailureNotifier, storage msgs.Storage)

Init runs a fresh instance of the consensus algorithm. The caller is requried to process Io requests using msgs.Io It will not return until the application is terminated.

func Recover

func Recover(peerNet *msgs.PeerNet, clientNet *msgs.ClientNet, config Config, view int, log *Log, app *app.StateMachine, snapshotIndex int, fail *msgs.FailureNotifier, storage msgs.Storage)

Recover restores an instance of the consensus algorithm. The caller is requried to process Io requests using msgs.Io It will not return until the application is terminated.

Types

type Config

type Config struct {
	All         ConfigAll
	Master      ConfigMaster
	Coordinator ConfigCoordinator
	Participant ConfigParticipant
	Interfacer  ConfigInterfacer
}

Config describes the static configuration of the consensus algorithm

type ConfigAll

type ConfigAll struct {
	ID         int       // id of node
	N          int       // size of cluster (nodes numbered 0 to N-1)
	WindowSize int       // how many requests can the master have inflight at once
	Quorum     QuorumSys // which quorum system to use
}

type ConfigCoordinator

type ConfigCoordinator struct {
	ExplicitCommit bool // if enabled, Ios coordinators will send commit messages to all after replication
	ThriftyQuorum  bool // if enabled, Ios coordinations will send writes to only a quorum (instead of broadcast)
}

type ConfigInterfacer

type ConfigInterfacer struct {
	ParticipantHandle bool // if enabled, non-master nodes can handle to client requests
	ParticipantRead   bool // if enabled, non-master nodes can serve reads. To enable, ParticipantHandle must also be enabled
}

type ConfigMaster

type ConfigMaster struct {
	BatchInterval       int  // how often to batch process request in ms, 0 means no batching
	MaxBatch            int  // maximum requests in a batch, unused if BatchInterval=0
	DelegateReplication int  // how many replication coordinators to delegate to when master
	IndexExclusivity    bool // if enabled, Ios will assign each index to at most one request
}

type ConfigParticipant

type ConfigParticipant struct {
	SnapshotInterval     int  // how often to record state machine snapshots, 0 means snapshotting is disabled
	ImplicitWindowCommit bool // if enabled, then commit pending out-of-window requests
	LogLength            int  // max log size
}

type Log

type Log struct {
	LogEntries    []msgs.Entry // contents of log, indexed from 0 to maxLength - 1
	LastIndex     int          // greatest absolute index in log with entry, -1 means that the log has no entries
	AbsoluteIndex int          // absolute index of first index in log
	// contains filtered or unexported fields
}

Log holds the replication log used of Ios. Only indexes between AbsoluteIndex and (AbsoluteIndex + maxLength -1) are accessible Do not access LogEntries direct, always use AddEntry and AddEntries functions

func NewLog

func NewLog(maxLength int) *Log

func RestoreLog

func RestoreLog(maxLength int, startIndex int) *Log

func (*Log) AddEntries

func (l *Log) AddEntries(startIndex int, endIndex int, entries []msgs.Entry)

func (*Log) AddEntry

func (l *Log) AddEntry(index int, entry msgs.Entry)

func (*Log) GetEntries

func (l *Log) GetEntries(startIndex int, endIndex int) []msgs.Entry

func (*Log) GetEntriesFrom

func (l *Log) GetEntriesFrom(startIndex int) []msgs.Entry

func (*Log) GetEntry

func (l *Log) GetEntry(index int) msgs.Entry

func (*Log) ImplicitCommit

func (l *Log) ImplicitCommit(windowSize int, commitIndex int)

ImplicitCommit will marked any uncommitted entries after commitIndex as committed if they are out-of-window and of the same view

type QuorumSys

type QuorumSys struct {
	Name            string
	RecoverySize    int
	ReplicationSize int
}

QuorumSys offers basic suport for various of quorum systems currently only "counting systems" are supported

func NewQuorum

func NewQuorum(configName string, n int) (QuorumSys, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL