Documentation ¶
Index ¶
- Constants
- Variables
- func Bootstrap(config Config) error
- func Manifold(config ManifoldConfig) dependency.Manifold
- func NewLogStore(dir string) (*raftboltdb.BoltStore, error)
- func NewRaftConfig(config Config) (*raft.Config, error)
- func NewSnapshotStore(dir string, retain int, logger Logger) (raft.SnapshotStore, error)
- func NewWorker(config Config) (worker.Worker, error)
- func NewWorkerShim(config Config) (worker.Worker, error)
- type BootstrapFSM
- type Config
- type Logger
- type ManifoldConfig
- type SimpleFSM
- type SimpleSnapshot
- type Worker
Constants ¶
const ( // LoopTimeout is the max time we will wait until the raft object // is constructed and the main loop is started. This is to avoid // hard-to-debug problems where the transport hung and so this // worker wasn't really started even though it seemed like it // was. If it crashes instead the logging will give a path to the // problem. LoopTimeout = 1 * time.Minute )
Variables ¶
var ( // ErrWorkerStopped is returned by Worker.Raft if the // worker has been explicitly stopped. ErrWorkerStopped = errors.New("raft worker stopped") // ErrStartTimeout is returned by NewWorker if the worker loop // didn't start within LoopTimeout. ErrStartTimeout = errors.New("timed out waiting for worker loop") // ErrNoLeaderTimeout is returned by the worker loop if we've gone // too long without contact from the leader. It gives the worker a // chance to see any configuration changes the backstop worker // might have force-appended to the raft log. ErrNoLeaderTimeout = errors.New("timed out waiting for leader contact") )
Functions ¶
func Bootstrap ¶
Bootstrap bootstraps the raft cluster, using the given configuration.
This is only to be called once, at the beginning of the raft cluster's lifetime, by the bootstrap machine agent.
func Manifold ¶
func Manifold(config ManifoldConfig) dependency.Manifold
Manifold returns a dependency.Manifold that will run a raft worker.
func NewLogStore ¶
NewLogStore opens a boltDB logstore in the specified directory. If the directory doesn't already exist it'll be created.
func NewRaftConfig ¶
NewRaftConfig makes a raft config struct from the worker config struct passed in.
func NewSnapshotStore ¶
NewSnapshotStore opens a file-based snapshot store in the specified directory. If the directory doesn't exist it'll be created.
func NewWorkerShim ¶
NewWorkerShim is suitable for use in ManifoldConfig.NewWorker, and simply calls through to NewWorker.
Types ¶
type BootstrapFSM ¶
type BootstrapFSM struct{}
BootstrapFSM is a minimal implementation of raft.FSM for use during bootstrap. Its methods should never be invoked.
func (BootstrapFSM) Apply ¶
func (BootstrapFSM) Apply(log *raft.Log) interface{}
Apply is part of raft.FSM.
func (BootstrapFSM) Restore ¶
func (BootstrapFSM) Restore(io.ReadCloser) error
Restore is part of raft.FSM.
func (BootstrapFSM) Snapshot ¶
func (BootstrapFSM) Snapshot() (raft.FSMSnapshot, error)
Snapshot is part of raft.FSM.
type Config ¶
type Config struct { // FSM is the raft.FSM to use for this raft worker. This // must be non-nil for NewWorker, and nil for Bootstrap. FSM raft.FSM // Logger is the logger for this worker. Logger Logger // StorageDir is the directory in which to store raft // artifacts: logs, snapshots, etc. It is expected that // this directory is under the full control of the raft // worker. StorageDir string // LocalID is the raft.ServerID of this worker. LocalID raft.ServerID // Transport is the raft.Transport to use for communication // between raft servers. This must be non-nil for NewWorker, // and nil for Bootstrap. // // The raft worker expects the server address to exactly // match the server ID, which is the stringified agent tag. // The transport internally maps the server address to one // or more network addresses, i.e. by looking up the API // connection information in the state database. Transport raft.Transport // Clock is used for timeouts in the worker (although not inside // raft). Clock clock.Clock // NoLeaderTimeout, if non-zero, will override the default // timeout for leader contact before restarting. NoLeaderTimeout time.Duration // ElectionTimeout, if non-zero, will override the default // raft election timeout. ElectionTimeout time.Duration // HeartbeatTimeout, if non-zero, will override the default // raft heartbeat timeout. HeartbeatTimeout time.Duration // LeaderLeaseTimeout, if non-zero, will override the default // raft leader lease timeout. LeaderLeaseTimeout time.Duration // SnapshotRetention is the non-negative number of snapshots // to retain on disk. If zero, defaults to 2. SnapshotRetention int // PrometheusRegisterer is used to register the raft metrics. PrometheusRegisterer prometheus.Registerer }
Config is the configuration required for running a raft worker.
type Logger ¶
type Logger interface { Warningf(message string, args ...interface{}) Errorf(message string, args ...interface{}) Logf(level loggo.Level, message string, args ...interface{}) }
Logger represents the logging methods called.
type ManifoldConfig ¶
type ManifoldConfig struct { ClockName string AgentName string TransportName string FSM raft.FSM Logger Logger PrometheusRegisterer prometheus.Registerer NewWorker func(Config) (worker.Worker, error) }
ManifoldConfig holds the information necessary to run a raft worker in a dependency.Engine.
func (ManifoldConfig) Validate ¶
func (config ManifoldConfig) Validate() error
Validate validates the manifold configuration.
type SimpleFSM ¶
type SimpleFSM struct {
// contains filtered or unexported fields
}
SimpleFSM is an implementation of raft.FSM, which simply appends the log data to a slice.
type SimpleSnapshot ¶
type SimpleSnapshot struct {
// contains filtered or unexported fields
}
SimpleSnapshot is an implementation of raft.FSMSnapshot, returned by the SimpleFSM.Snapshot in this package.
func (*SimpleSnapshot) Persist ¶
func (snap *SimpleSnapshot) Persist(sink raft.SnapshotSink) error
Persist is part of the raft.FSMSnapshot interface.
func (*SimpleSnapshot) Release ¶
func (*SimpleSnapshot) Release()
Release is part of the raft.FSMSnapshot interface.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is a worker that manages a raft.Raft instance.
func (*Worker) LogStore ¶
LogStore returns the raft.LogStore managed by this worker, or an error if the worker has stopped.
func (*Worker) Raft ¶
Raft returns the raft.Raft managed by this worker, or an error if the worker has stopped.