Documentation ¶
Index ¶
- Constants
- Variables
- func AddPeer(addr string) (response interface{}, err error)
- func AsyncSnapshot() error
- func FatalRaftError(err error) error
- func GetLeader() string
- func GetPeers() ([]string, error)
- func GetRaftAdvertise() string
- func GetRaftBind() string
- func GetRaftHttpTransport() (*http.Transport, error)
- func GetState() raft.RaftState
- func HealthyMembers() (advertised []string)
- func HttpGetLeader(path string) (response []byte, err error)
- func IsHealthy() bool
- func IsLeader() bool
- func IsPartOfQuorum() bool
- func IsPeer(peer string) (bool, error)
- func IsRaftEnabled() bool
- func Monitor()
- func OnHealthReport(authenticationToken, raftBind, raftAdvertise string) (err error)
- 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 RemovePeer(addr string) (response interface{}, err error)
- func ReportToRaftLeader(authenticationToken string) (err error)
- func Setup(applier CommandApplier, snapshotCreatorApplier SnapshotCreatorApplier, ...) error
- func Snapshot() error
- func StepDown()
- func Yield() error
- type CommandApplier
- type FileSnapshotSink
- type FileSnapshotStore
- func (f *FileSnapshotStore) Create(index, term uint64, peers []byte) (raft.SnapshotSink, error)
- func (f *FileSnapshotStore) List() ([]*raft.SnapshotMeta, error)
- func (f *FileSnapshotStore) Open(id string) (*raft.SnapshotMeta, io.ReadCloser, error)
- func (f *FileSnapshotStore) ReapSnapshots(currentSnapshotMeta *fileSnapshotMeta) error
- type RelationalStore
- func (relStore *RelationalStore) DeleteAll() error
- 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 SnapshotCreatorApplier
- type Store
Constants ¶
const ( YieldCommand = "yield" YieldHintCommand = "yield-hint" )
Variables ¶
var LeaderURI leaderURI
var RaftNotRunning error = fmt.Errorf("raft is not configured/running")
var ThisHostname string
Functions ¶
func AsyncSnapshot ¶
func AsyncSnapshot() error
func FatalRaftError ¶
func GetRaftAdvertise ¶
func GetRaftAdvertise() string
func GetRaftBind ¶
func GetRaftBind() string
func GetRaftHttpTransport ¶
func HealthyMembers ¶
func HealthyMembers() (advertised []string)
func HttpGetLeader ¶
func IsHealthy ¶
func IsHealthy() bool
IsHealthy checks whether this node is healthy in the raft group
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 OnHealthReport ¶
OnHealthReport acts on a raft-member reporting its health
func PublishCommand ¶
PublishCommand will distribute a command across the group
func PublishYield ¶
func QuorumSize ¶
func RemovePeer ¶
func ReportToRaftLeader ¶
ReportToRaftLeader tells the leader this raft node is raft-healthy
func Setup ¶
func Setup(applier CommandApplier, snapshotCreatorApplier SnapshotCreatorApplier, 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 FileSnapshotSink ¶
type FileSnapshotSink struct {
// contains filtered or unexported fields
}
FileSnapshotSink implements SnapshotSink with a file.
func (*FileSnapshotSink) Cancel ¶
func (s *FileSnapshotSink) Cancel() error
Cancel is used to indicate an unsuccessful end.
func (*FileSnapshotSink) Close ¶
func (s *FileSnapshotSink) Close() error
Close is used to indicate a successful end.
func (*FileSnapshotSink) ID ¶
func (s *FileSnapshotSink) ID() string
ID returns the ID of the snapshot, can be used with Open() after the snapshot is finalized.
type FileSnapshotStore ¶
type FileSnapshotStore struct {
// contains filtered or unexported fields
}
FileSnapshotStore implements the SnapshotStore interface and allows snapshots to be made on the local disk.
func NewFileSnapshotStore ¶
NewFileSnapshotStore creates a new FileSnapshotStore based on a base directory. The `retain` parameter controls how many snapshots are retained. Must be at least 1.
func NewFileSnapshotStoreWithLogger ¶
func NewFileSnapshotStoreWithLogger(base string, retain int) (*FileSnapshotStore, error)
NewFileSnapshotStoreWithLogger creates a new FileSnapshotStore based on a base directory. The `retain` parameter controls how many snapshots are retained. Must be at least 1.
func (*FileSnapshotStore) Create ¶
func (f *FileSnapshotStore) Create(index, term uint64, peers []byte) (raft.SnapshotSink, error)
Create is used to start a new snapshot
func (*FileSnapshotStore) List ¶
func (f *FileSnapshotStore) List() ([]*raft.SnapshotMeta, error)
List returns available snapshots in the store.
func (*FileSnapshotStore) Open ¶
func (f *FileSnapshotStore) Open(id string) (*raft.SnapshotMeta, io.ReadCloser, error)
Open takes a snapshot ID and returns a ReadCloser for that snapshot.
func (*FileSnapshotStore) ReapSnapshots ¶
func (f *FileSnapshotStore) ReapSnapshots(currentSnapshotMeta *fileSnapshotMeta) error
ReapSnapshots reaps any snapshots beyond the retain count.
type RelationalStore ¶
type RelationalStore struct {
// contains filtered or unexported fields
}
RelationalStoreimplements: - hashicorp/raft.StableStore - hashicorp/log.LogStore
func NewRelationalStore ¶
func NewRelationalStore(dataDir string) *RelationalStore
func (*RelationalStore) DeleteAll ¶
func (relStore *RelationalStore) DeleteAll() error
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 SnapshotCreatorApplier ¶
type SnapshotCreatorApplier interface { GetData() (data []byte, err error) Restore(rc io.ReadCloser) error }
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func NewStore ¶
func NewStore(raftDir string, raftBind string, raftAdvertise string, applier CommandApplier, snapshotCreatorApplier SnapshotCreatorApplier) *Store
NewStore inits and returns a new store
func (*Store) AddPeer ¶
AddPeer adds a node, located at addr, to this store. The node must be ready to respond to Raft communications at that address.
func (*Store) Open ¶
Open opens the store. If enableSingle is set, and there are no existing peers, then this node becomes the first node, and therefore leader, of the cluster.
func (*Store) RemovePeer ¶
RemovePeer removes a node from this raft setup