Documentation ¶
Overview ¶
Package raft implements a Consensus component for IPFS Cluster which uses Raft (go-libp2p-raft).
Index ¶
- Constants
- Variables
- type Consensus
- func (cc *Consensus) Leader() (peer.ID, error)
- func (cc *Consensus) LogAddPeer(addr ma.Multiaddr) error
- func (cc *Consensus) LogPin(c api.Pin) error
- func (cc *Consensus) LogRmPeer(pid peer.ID) error
- func (cc *Consensus) LogUnpin(c api.Pin) error
- func (cc *Consensus) Ready() <-chan struct{}
- func (cc *Consensus) Rollback(state state.State) error
- func (cc *Consensus) SetClient(c *rpc.Client)
- func (cc *Consensus) Shutdown() error
- func (cc *Consensus) State() (state.State, error)
- func (cc *Consensus) WaitForSync() error
- type LogOp
- type LogOpType
- type Raft
Constants ¶
const ( LogOpPin = iota + 1 LogOpUnpin LogOpAddPeer LogOpRmPeer )
Type of consensus operation
Variables ¶
var CommitRetries = 2
CommitRetries specifies how many times we retry a failed commit until we give up
var DefaultRaftConfig = hashiraft.DefaultConfig()
DefaultRaftConfig allows to tweak Raft configuration used by Cluster from from the outside.
var LeaderTimeout = 15 * time.Second
LeaderTimeout specifies how long to wait before failing an operation because there is no leader
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 ¶
Leader returns the peerID of the Leader of the cluster. It returns an error when there is no leader.
func (*Consensus) LogAddPeer ¶
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 ¶
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 ¶
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) 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 ¶
Rollback replaces the current agreed-upon state with the state provided. Only the consensus leader can perform this operation.
func (*Consensus) Shutdown ¶
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 ¶
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 ¶
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.
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 (*Raft) Leader ¶
Leader returns Raft's leader. It may be an empty string if there is no leader or it is unknown.
func (*Raft) RemovePeer ¶
RemovePeer removes a peer from Raft
func (*Raft) WaitForLeader ¶
WaitForLeader holds until Raft says we have a leader. Returns an error if we don't.