Documentation ¶
Index ¶
- Constants
- Variables
- func FatalRaftError(err error) error
- func GetLeader() string
- func GetPeers() ([]string, error)
- func GetState() raft.RaftState
- func HttpGet(peer string, path string) ([]byte, error)
- func IsLeader() bool
- func IsPartOfQuorum() bool
- func IsPeer(peer string) (bool, error)
- func IsRaftEnabled() bool
- func Monitor()
- func PublishCommand(op string, value interface{}) (response interface{}, err error)
- func PublishYield(toPeer string) (response interface{}, err error)
- func PublishYieldHostnameHint(hostnameHint string) (response interface{}, err error)
- func QuorumSize() (int, error)
- func Setup(applier CommandApplier, thisHostname string) error
- func StepDown()
- type CommandApplier
- type RelSnapshotSink
- type RelSnapshotStore
- type RelationalStore
- func (relStore *RelationalStore) DeleteRange(min, max uint64) error
- func (relStore *RelationalStore) FirstIndex() (idx uint64, err error)
- func (relStore *RelationalStore) Get(key []byte) (val []byte, err error)
- func (relStore *RelationalStore) GetLog(index uint64, log *raft.Log) error
- func (relStore *RelationalStore) GetUint64(key []byte) (uint64, error)
- func (relStore *RelationalStore) LastIndex() (idx uint64, err error)
- func (relStore *RelationalStore) Set(key []byte, val []byte) error
- func (relStore *RelationalStore) SetUint64(key []byte, val uint64) error
- func (relStore *RelationalStore) StoreLog(log *raft.Log) error
- func (relStore *RelationalStore) StoreLogs(logs []*raft.Log) error
- type Store
Constants ¶
const ( YieldCommand = "yield" YieldHintCommand = "yield-hint" )
Variables ¶
var RaftNotRunning = fmt.Errorf("raft is not configured/running")
var ThisHostname string
Functions ¶
func FatalRaftError ¶
func IsPartOfQuorum ¶
func IsPartOfQuorum() bool
IsPartOfQuorum returns `true` when this node is part of the raft quorum, meaning its data and opinion are trustworthy. Comapre that to a node which has left (or has not yet joined) the quorum: it has stale data.
func IsRaftEnabled ¶
func IsRaftEnabled() bool
func Monitor ¶
func Monitor()
Monitor is a utility function to routinely observe leadership state. It doesn't actually do much; merely takes notes.
func PublishCommand ¶
PublishCommand will distribute a command across the group
func PublishYield ¶
func QuorumSize ¶
func Setup ¶
func Setup(applier CommandApplier, thisHostname string) error
Setup creates the entire raft shananga. Creates the store, associates with the throttler, contacts peer nodes, and subscribes to leader changes to export them.
Types ¶
type CommandApplier ¶
type RelSnapshotSink ¶
type RelSnapshotSink struct {
// contains filtered or unexported fields
}
RelSnapshotSink implements SnapshotSink with a file.
func (*RelSnapshotSink) Cancel ¶
func (s *RelSnapshotSink) Cancel() error
Cancel is used to indicate an unsuccessful end.
func (*RelSnapshotSink) Close ¶
func (s *RelSnapshotSink) Close() error
Close is used to indicate a successful end.
func (*RelSnapshotSink) ID ¶
func (s *RelSnapshotSink) ID() string
ID returns the ID of the snapshot, can be used with Open() after the snapshot is finalized.
type RelSnapshotStore ¶
type RelSnapshotStore struct {
// contains filtered or unexported fields
}
RelSnapshotStore implements the SnapshotStore interface and allows snapshots to be made on the local disk.
func NewRelSnapshotStore ¶
func NewRelSnapshotStore(retain int, logOutput io.Writer) (*RelSnapshotStore, error)
NewRelSnapshotStore creates a new RelSnapshotStore based on a base directory. The `retain` parameter controls how many snapshots are retained. Must be at least 1.
func NewRelSnapshotStoreWithLogger ¶
func NewRelSnapshotStoreWithLogger(retain int, logger *golog.Logger) (*RelSnapshotStore, error)
NewRelSnapshotStoreWithLogger creates a new RelSnapshotStore based on a base directory. The `retain` parameter controls how many snapshots are retained. Must be at least 1.
func (*RelSnapshotStore) Create ¶
func (f *RelSnapshotStore) Create(index, term uint64, peers []byte) (raft.SnapshotSink, error)
Create is used to start a new snapshot
func (*RelSnapshotStore) List ¶
func (f *RelSnapshotStore) List() ([]*raft.SnapshotMeta, error)
List returns available snapshots in the store.
func (*RelSnapshotStore) Open ¶
func (f *RelSnapshotStore) Open(id string) (*raft.SnapshotMeta, io.ReadCloser, error)
Open takes a snapshot ID and returns a ReadCloser for that snapshot.
func (*RelSnapshotStore) ReapSnapshots ¶
func (f *RelSnapshotStore) ReapSnapshots() error
ReapSnapshots reaps any snapshots beyond the retain count.
type RelationalStore ¶
type RelationalStore struct { }
RelationalStoreimplements: - hashicorp/raft.StableStore - hashicorp/log.LogStore
func NewRelationalStore ¶
func NewRelationalStore() *RelationalStore
func (*RelationalStore) DeleteRange ¶
func (relStore *RelationalStore) DeleteRange(min, max uint64) error
DeleteRange deletes a range of log entries. The range is inclusive.
func (*RelationalStore) FirstIndex ¶
func (relStore *RelationalStore) FirstIndex() (idx uint64, err error)
func (*RelationalStore) Get ¶
func (relStore *RelationalStore) Get(key []byte) (val []byte, err error)
Get returns the value for key, or an empty byte slice if key was not found.
func (*RelationalStore) GetLog ¶
func (relStore *RelationalStore) GetLog(index uint64, log *raft.Log) error
GetLog gets a log entry at a given index.
func (*RelationalStore) GetUint64 ¶
func (relStore *RelationalStore) GetUint64(key []byte) (uint64, error)
GetUint64 returns the uint64 value for key, or 0 if key was not found.
func (*RelationalStore) LastIndex ¶
func (relStore *RelationalStore) LastIndex() (idx uint64, err error)
LastIndex returns the last index written. 0 for no entries.
func (*RelationalStore) SetUint64 ¶
func (relStore *RelationalStore) SetUint64(key []byte, val uint64) error
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func NewStore ¶
func NewStore(raftDir string, raftBind string, applier CommandApplier) *Store
NewStore inits and returns a new store