raft

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2017 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package raft implements a Consensus component for IPFS Cluster which uses Raft (go-libp2p-raft).

Index

Constants

View Source
const (
	LogOpPin = iota + 1
	LogOpUnpin
	LogOpAddPeer
	LogOpRmPeer
)

Type of consensus operation

Variables

View Source
var CommitRetries = 2

CommitRetries specifies how many times we retry a failed commit until we give up

View Source
var DefaultRaftConfig = hashiraft.DefaultConfig()

DefaultRaftConfig allows to tweak Raft configuration used by Cluster from from the outside.

View Source
var LeaderTimeout = 15 * time.Second

LeaderTimeout specifies how long to wait before failing an operation because there is no leader

View Source
var RaftMaxSnapshots = 5

RaftMaxSnapshots indicates how many snapshots to keep in the consensus data folder.

Functions

This section is empty.

Types

type Consensus

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

Consensus handles the work of keeping a shared-state between the peers of an IPFS Cluster, as well as modifying that state and applying any updates in a thread-safe manner.

func NewConsensus

func NewConsensus(clusterPeers []peer.ID, host host.Host, dataFolder string, state state.State) (*Consensus, error)

NewConsensus builds a new ClusterConsensus component. The state is used to initialize the Consensus system, so any information in it is discarded.

func (*Consensus) Leader

func (cc *Consensus) Leader() (peer.ID, error)

Leader returns the peerID of the Leader of the cluster. It returns an error when there is no leader.

func (*Consensus) LogAddPeer

func (cc *Consensus) LogAddPeer(addr ma.Multiaddr) error

LogAddPeer submits a new peer to the shared state of the cluster. It will forward the operation to the leader if this is not it.

func (*Consensus) LogPin

func (cc *Consensus) LogPin(c api.Pin) error

LogPin submits a Cid to the shared state of the cluster. It will forward the operation to the leader if this is not it.

func (*Consensus) LogRmPeer

func (cc *Consensus) LogRmPeer(pid peer.ID) error

LogRmPeer removes a peer from the shared state of the cluster. It will forward the operation to the leader if this is not it.

func (*Consensus) LogUnpin

func (cc *Consensus) LogUnpin(c api.Pin) error

LogUnpin removes a Cid from the shared state of the cluster.

func (*Consensus) Ready

func (cc *Consensus) Ready() <-chan struct{}

Ready returns a channel which is signaled when the Consensus algorithm has finished bootstrapping and is ready to use

func (*Consensus) Rollback

func (cc *Consensus) Rollback(state state.State) error

Rollback replaces the current agreed-upon state with the state provided. Only the consensus leader can perform this operation.

func (*Consensus) SetClient

func (cc *Consensus) SetClient(c *rpc.Client)

SetClient makes the component ready to perform RPC requets

func (*Consensus) Shutdown

func (cc *Consensus) Shutdown() error

Shutdown stops the component so it will not process any more updates. The underlying consensus is permanently shutdown, along with the libp2p transport.

func (*Consensus) State

func (cc *Consensus) State() (state.State, error)

State retrieves the current consensus State. It may error if no State has been agreed upon or the state is not consistent. The returned State is the last agreed-upon State known by this node.

func (*Consensus) WaitForSync

func (cc *Consensus) WaitForSync() error

WaitForSync waits for a leader and for the state to be up to date, then returns.

type LogOp

type LogOp struct {
	Cid  api.PinSerial
	Peer api.MultiaddrSerial
	Type LogOpType
	// contains filtered or unexported fields
}

LogOp represents an operation for the OpLogConsensus system. It implements the consensus.Op interface and it is used by the Consensus component.

func (*LogOp) ApplyTo

func (op *LogOp) ApplyTo(cstate consensus.State) (consensus.State, error)

ApplyTo applies the operation to the State

type LogOpType

type LogOpType int

LogOpType expresses the type of a consensus Operation

type Raft

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

Raft performs all Raft-specific operations which are needed by Cluster but are not fulfilled by the consensus interface. It should contain most of the Raft-related stuff so it can be easily replaced in the future, if need be.

func NewRaft

func NewRaft(peers []peer.ID, host host.Host, dataFolder string, fsm hashiraft.FSM) (*Raft, error)

NewRaft launches a go-libp2p-raft consensus peer.

func (*Raft) AddPeer

func (r *Raft) AddPeer(peer string) error

AddPeer adds a peer to Raft

func (*Raft) Leader

func (r *Raft) Leader() string

Leader returns Raft's leader. It may be an empty string if there is no leader or it is unknown.

func (*Raft) RemovePeer

func (r *Raft) RemovePeer(peer string) error

RemovePeer removes a peer from Raft

func (*Raft) Shutdown

func (r *Raft) Shutdown() error

Shutdown shutdown Raft and closes the BoltDB.

func (*Raft) Snapshot

func (r *Raft) Snapshot() error

Snapshot tells Raft to take a snapshot.

func (*Raft) WaitForLeader

func (r *Raft) WaitForLeader(ctx context.Context) error

WaitForLeader holds until Raft says we have a leader. Returns an error if we don't.

func (*Raft) WaitForUpdates

func (r *Raft) WaitForUpdates(ctx context.Context) error

WaitForUpdates holds until Raft has synced to the last index in the log

Jump to

Keyboard shortcuts

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