orcraft

package
v3.0.11+incompatible Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YieldCommand     = "yield"
	YieldHintCommand = "yield-hint"
)

Variables

View Source
var LeaderURI leaderURI
View Source
var RaftNotRunning = fmt.Errorf("raft is not configured/running")
View Source
var ThisHostname string

Functions

func AsyncSnapshot

func AsyncSnapshot() error

func FatalRaftError

func FatalRaftError(err error) error

func GetLeader

func GetLeader() string

GetLeader returns identity of raft leader

func GetPeers

func GetPeers() ([]string, error)

func GetState

func GetState() raft.RaftState

GetState returns current raft state

func HealthyMembers

func HealthyMembers() (advertised []string)

func HttpGetLeader

func HttpGetLeader(path string) (response []byte, err error)

func IsHealthy

func IsHealthy() bool

IsHealthy checks whether this node is healthy in the raft group

func IsLeader

func IsLeader() bool

IsLeader tells if this node is the current raft leader

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 IsPeer

func IsPeer(peer string) (bool, error)

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

func OnHealthReport(authenticationToken, raftBind, raftAdvertise string) (err error)

OnHealthReport acts on a raft-member reporting its health

func PublishCommand

func PublishCommand(op string, value interface{}) (response interface{}, err error)

PublishCommand will distribute a command across the group

func PublishYield

func PublishYield(toPeer string) (response interface{}, err error)

func PublishYieldHostnameHint

func PublishYieldHostnameHint(hostnameHint string) (response interface{}, err error)

func QuorumSize

func QuorumSize() (int, error)

func ReportToRaftLeader

func ReportToRaftLeader(authenticationToken string) (err error)

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.

func Snapshot

func Snapshot() error

func StepDown

func StepDown()

func Yield

func Yield() error

Types

type CommandApplier

type CommandApplier interface {
	ApplyCommand(op string, value []byte) interface{}
}

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.

func (*FileSnapshotSink) Write

func (s *FileSnapshotSink) Write(b []byte) (int, error)

Write is used to append to the state file. We write to the buffered IO object to reduce the amount of context switches.

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

func NewFileSnapshotStore(base string, retain int, logOutput io.Writer) (*FileSnapshotStore, error)

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, logger *log.Logger) (*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

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) Set

func (relStore *RelationalStore) Set(key []byte, val []byte) error

func (*RelationalStore) SetUint64

func (relStore *RelationalStore) SetUint64(key []byte, val uint64) error

func (*RelationalStore) StoreLog

func (relStore *RelationalStore) StoreLog(log *raft.Log) error

StoreLog stores a log entry.

func (*RelationalStore) StoreLogs

func (relStore *RelationalStore) StoreLogs(logs []*raft.Log) error

StoreLogs stores multiple log entries.

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) Join

func (store *Store) Join(addr string) error

Join joins a node, located at addr, to this store. The node must be ready to respond to Raft communications at that address.

func (*Store) Open

func (store *Store) Open(peerNodes []string) error

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.

Jump to

Keyboard shortcuts

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