lxd: github.com/lxc/lxd/lxd/cluster/raft Index | Files

package raft

import "github.com/lxc/lxd/lxd/cluster/raft"

Package raft contains the subset of hashicorp/raft needed to perform data migrations to dqlite 1.0.

Index

Package Files

bolt.go configuration.go doc.go file_snapshot.go log.go snapshot.go transport.go

Variables

var (

    // An error indicating a given key does not exist
    ErrKeyNotFound = errors.New("not found")

    ErrLogNotFound = errors.New("log not found")
)

type BoltStore Uses

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

BoltStore provides access to BoltDB for Raft to store and retrieve log entries. It also provides key/value storage, and can be used as a LogStore and StableStore.

func New Uses

func New(options Options) (*BoltStore, error)

New uses the supplied options to open the BoltDB and prepare it for use as a raft backend.

func NewBoltStore Uses

func NewBoltStore(path string) (*BoltStore, error)

NewBoltStore takes a file path and returns a connected Raft backend.

func (*BoltStore) Close Uses

func (b *BoltStore) Close() error

Close is used to gracefully close the DB connection.

func (*BoltStore) DeleteRange Uses

func (b *BoltStore) DeleteRange(min, max uint64) error

DeleteRange is used to delete logs within a given range inclusively.

func (*BoltStore) FirstIndex Uses

func (b *BoltStore) FirstIndex() (uint64, error)

FirstIndex returns the first known index from the Raft log.

func (*BoltStore) Get Uses

func (b *BoltStore) Get(k []byte) ([]byte, error)

Get is used to retrieve a value from the k/v store by key

func (*BoltStore) GetLog Uses

func (b *BoltStore) GetLog(idx uint64, log *Log) error

GetLog is used to retrieve a log from BoltDB at a given index.

func (*BoltStore) GetUint64 Uses

func (b *BoltStore) GetUint64(key []byte) (uint64, error)

GetUint64 is like Get, but handles uint64 values

func (*BoltStore) LastIndex Uses

func (b *BoltStore) LastIndex() (uint64, error)

LastIndex returns the last known index from the Raft log.

func (*BoltStore) Set Uses

func (b *BoltStore) Set(k, v []byte) error

Set is used to set a key/value set outside of the raft log

func (*BoltStore) SetUint64 Uses

func (b *BoltStore) SetUint64(key []byte, val uint64) error

SetUint64 is like Set, but handles uint64 values

func (*BoltStore) StoreLog Uses

func (b *BoltStore) StoreLog(log *Log) error

StoreLog is used to store a single raft log

func (*BoltStore) StoreLogs Uses

func (b *BoltStore) StoreLogs(logs []*Log) error

StoreLogs is used to store a set of raft logs

func (*BoltStore) Sync Uses

func (b *BoltStore) Sync() error

Sync performs an fsync on the database file handle. This is not necessary under normal operation unless NoSync is enabled, in which this forces the database file to sync against the disk.

type Configuration Uses

type Configuration struct {
    Servers []Server
}

Configuration tracks which servers are in the cluster, and whether they have votes. This should include the local server, if it's a member of the cluster. The servers are listed no particular order, but each should only appear once. These entries are appended to the log during membership changes.

type FileSnapshotSink Uses

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

FileSnapshotSink implements SnapshotSink with a file.

func (*FileSnapshotSink) Cancel Uses

func (s *FileSnapshotSink) Cancel() error

Cancel is used to indicate an unsuccessful end.

func (*FileSnapshotSink) Close Uses

func (s *FileSnapshotSink) Close() error

Close is used to indicate a successful end.

func (*FileSnapshotSink) ID Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (f *FileSnapshotStore) Create(version SnapshotVersion, index, term uint64,
    configuration Configuration, configurationIndex uint64, trans Transport) (SnapshotSink, error)

Create is used to start a new snapshot

func (*FileSnapshotStore) List Uses

func (f *FileSnapshotStore) List() ([]*SnapshotMeta, error)

List returns available snapshots in the store.

func (*FileSnapshotStore) Open Uses

func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error)

Open takes a snapshot ID and returns a ReadCloser for that snapshot.

func (*FileSnapshotStore) ReapSnapshots Uses

func (f *FileSnapshotStore) ReapSnapshots() error

ReapSnapshots reaps any snapshots beyond the retain count.

type Log Uses

type Log struct {
    // Index holds the index of the log entry.
    Index uint64

    // Term holds the election term of the log entry.
    Term uint64

    // Type holds the type of the log entry.
    Type LogType

    // Data holds the log entry's type-specific data.
    Data []byte
}

Log entries are replicated to all members of the Raft cluster and form the heart of the replicated state machine.

type LogStore Uses

type LogStore interface {
    // FirstIndex returns the first index written. 0 for no entries.
    FirstIndex() (uint64, error)

    // LastIndex returns the last index written. 0 for no entries.
    LastIndex() (uint64, error)

    // GetLog gets a log entry at a given index.
    GetLog(index uint64, log *Log) error

    // StoreLog stores a log entry.
    StoreLog(log *Log) error

    // StoreLogs stores multiple log entries.
    StoreLogs(logs []*Log) error

    // DeleteRange deletes a range of log entries. The range is inclusive.
    DeleteRange(min, max uint64) error
}

LogStore is used to provide an interface for storing and retrieving logs in a durable fashion.

type LogType Uses

type LogType uint8

LogType describes various types of log entries.

const (
    // LogCommand is applied to a user FSM.
    LogCommand LogType = iota

    // LogNoop is used to assert leadership.
    LogNoop

    // LogAddPeer is used to add a new peer. This should only be used with
    // older protocol versions designed to be compatible with unversioned
    // Raft servers. See comments in config.go for details.
    LogAddPeerDeprecated

    // LogRemovePeer is used to remove an existing peer. This should only be
    // used with older protocol versions designed to be compatible with
    // unversioned Raft servers. See comments in config.go for details.
    LogRemovePeerDeprecated

    // LogBarrier is used to ensure all preceding operations have been
    // applied to the FSM. It is similar to LogNoop, but instead of returning
    // once committed, it only returns once the FSM manager acks it. Otherwise
    // it is possible there are operations committed but not yet applied to
    // the FSM.
    LogBarrier

    // LogConfiguration establishes a membership change configuration. It is
    // created when a server is added, removed, promoted, etc. Only used
    // when protocol version 1 or greater is in use.
    LogConfiguration
)

type Options Uses

type Options struct {
    // Path is the file path to the BoltDB to use
    Path string

    // BoltOptions contains any specific BoltDB options you might
    // want to specify [e.g. open timeout]
    BoltOptions *bolt.Options

    // NoSync causes the database to skip fsync calls after each
    // write to the log. This is unsafe, so it should be used
    // with caution.
    NoSync bool
}

Options contains all the configuration used to open the BoltDB

type Server Uses

type Server struct {
    // ID is a unique string identifying this server for all time.
    ID  ServerID
    // Address is its network address that a transport can contact.
    Address ServerAddress
}

Server tracks the information about a single server in a configuration.

type ServerAddress Uses

type ServerAddress string

ServerAddress is a network address for a server that a transport can contact.

type ServerID Uses

type ServerID string

ServerID is a unique string identifying a server for all time.

type SnapshotMeta Uses

type SnapshotMeta struct {
    // Version is the version number of the snapshot metadata. This does not cover
    // the application's data in the snapshot, that should be versioned
    // separately.
    Version SnapshotVersion

    // ID is opaque to the store, and is used for opening.
    ID  string

    // Index and Term store when the snapshot was taken.
    Index uint64
    Term  uint64

    // Peers is deprecated and used to support version 0 snapshots, but will
    // be populated in version 1 snapshots as well to help with upgrades.
    Peers []byte

    // Configuration and ConfigurationIndex are present in version 1
    // snapshots and later.
    Configuration      Configuration
    ConfigurationIndex uint64

    // Size is the size of the snapshot in bytes.
    Size int64
}

SnapshotMeta is for metadata of a snapshot.

type SnapshotSink Uses

type SnapshotSink interface {
    io.WriteCloser
    ID() string
    Cancel() error
}

SnapshotSink is returned by StartSnapshot. The FSM will Write state to the sink and call Close on completion. On error, Cancel will be invoked.

type SnapshotStore Uses

type SnapshotStore interface {
    // Create is used to begin a snapshot at a given index and term, and with
    // the given committed configuration. The version parameter controls
    // which snapshot version to create.
    Create(version SnapshotVersion, index, term uint64, configuration Configuration,
        configurationIndex uint64, trans Transport) (SnapshotSink, error)

    // List is used to list the available snapshots in the store.
    // It should return then in descending order, with the highest index first.
    List() ([]*SnapshotMeta, error)

    // Open takes a snapshot ID and provides a ReadCloser. Once close is
    // called it is assumed the snapshot is no longer needed.
    Open(id string) (*SnapshotMeta, io.ReadCloser, error)
}

SnapshotStore interface is used to allow for flexible implementations of snapshot storage and retrieval. For example, a client could implement a shared state store such as S3, allowing new nodes to restore snapshots without streaming from the leader.

type SnapshotVersion Uses

type SnapshotVersion int
const (
    SnapshotVersionMin SnapshotVersion = 0
    SnapshotVersionMax                 = 1
)

type Transport Uses

type Transport interface {
    // EncodePeer is used to serialize a peer's address.
    EncodePeer(id ServerID, addr ServerAddress) []byte
}

Transport provides an interface for network transports to allow Raft to communicate with other nodes.

Package raft imports 19 packages (graph) and is imported by 2 packages. Updated 2019-07-01. Refresh now. Tools for package owners.