orcraft

package
v3.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2017 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

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

Variables

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

Functions

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 HttpGet

func HttpGet(peer string, path string) ([]byte, error)

readResponse returns the body of an HTTP response

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 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 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.

func StepDown

func StepDown()

Types

type CommandApplier

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

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.

func (*RelSnapshotSink) Write

func (s *RelSnapshotSink) 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 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

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

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