juju: github.com/juju/juju/worker/raft Index | Files | Directories

package raft

import "github.com/juju/juju/worker/raft"

Index

Package Files

manifold.go metrics.go reporter.go shim.go simplefsm.go synclogstore.go worker.go

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

func Bootstrap Uses

func Bootstrap(config Config) error

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 Uses

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency.Manifold that will run a raft worker.

func NewLogStore Uses

func NewLogStore(dir string) (*raftboltdb.BoltStore, error)

NewLogStore opens a boltDB logstore in the specified directory. If the directory doesn't already exist it'll be created.

func NewRaftConfig Uses

func NewRaftConfig(config Config) (*raft.Config, error)

NewRaftConfig makes a raft config struct from the worker config struct passed in.

func NewSnapshotStore Uses

func NewSnapshotStore(
    dir string,
    retain int,
    logger Logger,
) (raft.SnapshotStore, error)

NewSnapshotStore opens a file-based snapshot store in the specified directory. If the directory doesn't exist it'll be created.

func NewWorker Uses

func NewWorker(config Config) (worker.Worker, error)

NewWorker returns a new raft worker, with the given configuration.

func NewWorkerShim Uses

func NewWorkerShim(config Config) (worker.Worker, error)

NewWorkerShim is suitable for use in ManifoldConfig.NewWorker, and simply calls through to NewWorker.

type BootstrapFSM Uses

type BootstrapFSM struct{}

BootstrapFSM is a minimal implementation of raft.FSM for use during bootstrap. Its methods should never be invoked.

func (BootstrapFSM) Apply Uses

func (BootstrapFSM) Apply(log *raft.Log) interface{}

Apply is part of raft.FSM.

func (BootstrapFSM) Restore Uses

func (BootstrapFSM) Restore(io.ReadCloser) error

Restore is part of raft.FSM.

func (BootstrapFSM) Snapshot Uses

func (BootstrapFSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot is part of raft.FSM.

type Config Uses

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.

func (Config) Validate Uses

func (config Config) Validate() error

Validate validates the raft worker configuration.

type Logger Uses

type Logger interface {
    Warningf(message string, args ...interface{})
    Errorf(message string, args ...interface{})
    Tracef(message string, args ...interface{})
    Logf(level loggo.Level, message string, args ...interface{})
}

Logger represents the logging methods called.

type ManifoldConfig Uses

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 Uses

func (config ManifoldConfig) Validate() error

Validate validates the manifold configuration.

type SimpleFSM Uses

type SimpleFSM struct {
    // contains filtered or unexported fields
}

SimpleFSM is an implementation of raft.FSM, which simply appends the log data to a slice.

func (*SimpleFSM) Apply Uses

func (fsm *SimpleFSM) Apply(log *raft.Log) interface{}

Apply is part of the raft.FSM interface.

func (*SimpleFSM) Logs Uses

func (fsm *SimpleFSM) Logs() [][]byte

Logs returns the accumulated log data.

func (*SimpleFSM) Restore Uses

func (fsm *SimpleFSM) Restore(rc io.ReadCloser) error

Restore is part of the raft.FSM interface.

func (*SimpleFSM) Snapshot Uses

func (fsm *SimpleFSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot is part of the raft.FSM interface.

type SimpleSnapshot Uses

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 Uses

func (snap *SimpleSnapshot) Persist(sink raft.SnapshotSink) error

Persist is part of the raft.FSMSnapshot interface.

func (*SimpleSnapshot) Release Uses

func (*SimpleSnapshot) Release()

Release is part of the raft.FSMSnapshot interface.

type Worker Uses

type Worker struct {
    // contains filtered or unexported fields
}

Worker is a worker that manages a raft.Raft instance.

func (*Worker) Kill Uses

func (w *Worker) Kill()

Kill is part of the worker.Worker interface.

func (*Worker) LogStore Uses

func (w *Worker) LogStore() (raft.LogStore, error)

LogStore returns the raft.LogStore managed by this worker, or an error if the worker has stopped.

func (*Worker) Raft Uses

func (w *Worker) Raft() (*raft.Raft, error)

Raft returns the raft.Raft managed by this worker, or an error if the worker has stopped.

func (*Worker) Report Uses

func (w *Worker) Report() map[string]interface{}

Report is part of the dependency.Reporter interface.

func (*Worker) Wait Uses

func (w *Worker) Wait() error

Wait is part of the worker.Worker interface.

Directories

PathSynopsis
raftbackstop
raftclusterer
raftflag
raftforwarder
rafttest
rafttransport
raftutil

Package raft imports 21 packages (graph) and is imported by 9 packages. Updated 2019-09-10. Refresh now. Tools for package owners.