raft

package
v1.14.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MPL-2.0 Imports: 65 Imported by: 15

Documentation

Index

Constants

View Source
const (
	// EnvVaultRaftNodeID is used to fetch the Raft node ID from the environment.
	EnvVaultRaftNodeID = "VAULT_RAFT_NODE_ID"

	// EnvVaultRaftPath is used to fetch the path where Raft data is stored from the environment.
	EnvVaultRaftPath = "VAULT_RAFT_PATH"

	// EnvVaultRaftNonVoter is used to override the non_voter config option, telling Vault to join as a non-voter (i.e. read replica).
	EnvVaultRaftNonVoter = "VAULT_RAFT_RETRY_JOIN_AS_NON_VOTER"
)
View Source
const (
	CleanupDeadServersUnset    CleanupDeadServersValue = 0
	CleanupDeadServersTrue     CleanupDeadServersValue = 1
	CleanupDeadServersFalse    CleanupDeadServersValue = 2
	AutopilotUpgradeVersionTag string                  = "upgrade_version"
	AutopilotRedundancyZoneTag string                  = "redundancy_zone"
)

Variables

View Source
var File_physical_raft_types_proto protoreflect.FileDescriptor
View Source
var (
	GetInTxnDisabledError = errors.New("get operations inside transactions are disabled in raft backend")
)

Functions

func EnsurePath

func EnsurePath(path string, dir bool) error

EnsurePath is used to make sure a path exists

func NewRaftBackend

func NewRaftBackend(conf map[string]string, logger log.Logger) (physical.Backend, error)

NewRaftBackend constructs a RaftBackend using the given directory

func NewRaftLayer

func NewRaftLayer(logger log.Logger, raftTLSKeyring *TLSKeyring, clusterListener cluster.ClusterHook) (*raftLayer, error)

NewRaftLayer creates a new raftLayer object. It parses the TLS information from the network config.

Types

type AutopilotConfig added in v1.7.0

type AutopilotConfig struct {
	// CleanupDeadServers controls whether to remove dead servers from the Raft
	// peer list periodically or when a new server joins.
	CleanupDeadServers bool `mapstructure:"cleanup_dead_servers"`

	// CleanupDeadServersValue is used to shadow the CleanupDeadServers field in
	// storage. Having it as an int helps in knowing if the value was set explicitly
	// using the API or not.
	CleanupDeadServersValue CleanupDeadServersValue `mapstructure:"cleanup_dead_servers_value"`

	// LastContactThreshold is the limit on the amount of time a server can go
	// without leader contact before being considered unhealthy.
	LastContactThreshold time.Duration `mapstructure:"-"`

	// DeadServerLastContactThreshold is the limit on the amount of time a server
	// can go without leader contact before being considered failed. This takes
	// effect only when CleanupDeadServers is set.
	DeadServerLastContactThreshold time.Duration `mapstructure:"-"`

	// MaxTrailingLogs is the amount of entries in the Raft Log that a server can
	// be behind before being considered unhealthy.
	MaxTrailingLogs uint64 `mapstructure:"max_trailing_logs"`

	// MinQuorum sets the minimum number of servers allowed in a cluster before
	// autopilot can prune dead servers.
	MinQuorum uint `mapstructure:"min_quorum"`

	// ServerStabilizationTime is the minimum amount of time a server must be in a
	// stable, healthy state before it can be added to the cluster. Only applicable
	// with Raft protocol version 3 or higher.
	ServerStabilizationTime time.Duration `mapstructure:"-"`

	// (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration
	// strategy of waiting until enough newer-versioned servers have been added to the
	// cluster before promoting them to voters.
	DisableUpgradeMigration bool `mapstructure:"disable_upgrade_migration"`

	// (Enterprise-only) RedundancyZoneTag is the node tag to use for separating
	// servers into zones for redundancy. If left blank, this feature will be disabled.
	RedundancyZoneTag string `mapstructure:"redundancy_zone_tag"`

	// (Enterprise-only) UpgradeVersionTag is the node tag to use for version info when
	// performing upgrade migrations. If left blank, the Consul version will be used.
	UpgradeVersionTag string `mapstructure:"upgrade_version_tag"`
}

AutopilotConfig is used for querying/setting the Autopilot configuration.

func (*AutopilotConfig) Clone added in v1.7.0

func (ac *AutopilotConfig) Clone() *AutopilotConfig

Clone returns a duplicate instance of AutopilotConfig with the exact same values.

func (*AutopilotConfig) MarshalJSON added in v1.7.0

func (ac *AutopilotConfig) MarshalJSON() ([]byte, error)

MarshalJSON makes the autopilot config fields JSON compatible

func (*AutopilotConfig) Merge added in v1.7.0

func (to *AutopilotConfig) Merge(from *AutopilotConfig)

Merge combines the supplied config with the receiver. Supplied ones take priority.

func (*AutopilotConfig) UnmarshalJSON added in v1.7.0

func (ac *AutopilotConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the autopilot config JSON blob

type AutopilotServer added in v1.7.0

type AutopilotServer struct {
	ID             string            `json:"id" mapstructure:"id"`
	Name           string            `json:"name" mapstructure:"name"`
	Address        string            `json:"address" mapstructure:"address"`
	NodeStatus     string            `json:"node_status" mapstructure:"node_status"`
	LastContact    *ReadableDuration `json:"last_contact" mapstructure:"last_contact"`
	LastTerm       uint64            `json:"last_term" mapstructure:"last_term"`
	LastIndex      uint64            `json:"last_index" mapstructure:"last_index"`
	Healthy        bool              `json:"healthy" mapstructure:"healthy"`
	StableSince    time.Time         `json:"stable_since" mapstructure:"stable_since"`
	Status         string            `json:"status" mapstructure:"status"`
	Version        string            `json:"version" mapstructure:"version"`
	RedundancyZone string            `json:"redundancy_zone,omitempty" mapstructure:"redundancy_zone,omitempty"`
	UpgradeVersion string            `json:"upgrade_version,omitempty" mapstructure:"upgrade_version,omitempty"`
	ReadReplica    bool              `json:"read_replica,omitempty" mapstructure:"read_replica,omitempty"`
	NodeType       string            `json:"node_type,omitempty" mapstructure:"node_type,omitempty"`
}

AutopilotServer represents the health information of individual server node retrieved from autopilot.

type AutopilotState added in v1.7.0

type AutopilotState struct {
	Healthy                    bool                        `json:"healthy" mapstructure:"healthy"`
	FailureTolerance           int                         `json:"failure_tolerance" mapstructure:"failure_tolerance"`
	Servers                    map[string]*AutopilotServer `json:"servers" mapstructure:"servers"`
	Leader                     string                      `json:"leader" mapstructure:"leader"`
	Voters                     []string                    `json:"voters" mapstructure:"voters"`
	NonVoters                  []string                    `json:"non_voters,omitempty" mapstructure:"non_voters,omitempty"`
	RedundancyZones            map[string]AutopilotZone    `json:"redundancy_zones,omitempty" mapstructure:"redundancy_zones,omitempty"`
	Upgrade                    *AutopilotUpgrade           `json:"upgrade_info,omitempty" mapstructure:"upgrade_info,omitempty"`
	OptimisticFailureTolerance int                         `json:"optimistic_failure_tolerance,omitempty" mapstructure:"optimistic_failure_tolerance,omitempty"`
}

AutopilotState represents the health information retrieved from autopilot.

type AutopilotUpgrade added in v1.11.0

type AutopilotUpgrade struct {
	Status                    string                                  `json:"status" mapstructure:"status"`
	TargetVersion             string                                  `json:"target_version,omitempty" mapstructure:"target_version,omitempty"`
	TargetVersionVoters       []string                                `json:"target_version_voters,omitempty" mapstructure:"target_version_voters,omitempty"`
	TargetVersionNonVoters    []string                                `json:"target_version_non_voters,omitempty" mapstructure:"target_version_non_voters,omitempty"`
	TargetVersionReadReplicas []string                                `json:"target_version_read_replicas,omitempty" mapstructure:"target_version_read_replicas,omitempty"`
	OtherVersionVoters        []string                                `json:"other_version_voters,omitempty" mapstructure:"other_version_voters,omitempty"`
	OtherVersionNonVoters     []string                                `json:"other_version_non_voters,omitempty" mapstructure:"other_version_non_voters,omitempty"`
	OtherVersionReadReplicas  []string                                `json:"other_version_read_replicas,omitempty" mapstructure:"other_version_read_replicas,omitempty"`
	RedundancyZones           map[string]AutopilotZoneUpgradeVersions `json:"redundancy_zones,omitempty" mapstructure:"redundancy_zones,omitempty"`
}

type AutopilotZone added in v1.11.0

type AutopilotZone struct {
	Servers          []string `json:"servers,omitempty" mapstructure:"servers,omitempty"`
	Voters           []string `json:"voters,omitempty" mapstructure:"voters,omitempty"`
	FailureTolerance int      `json:"failure_tolerance,omitempty" mapstructure:"failure_tolerance,omitempty"`
}

type AutopilotZoneUpgradeVersions added in v1.11.0

type AutopilotZoneUpgradeVersions struct {
	TargetVersionVoters    []string `json:"target_version_voters,omitempty" mapstructure:"target_version_voters,omitempty"`
	TargetVersionNonVoters []string `json:"target_version_non_voters,omitempty" mapstructure:"target_version_non_voters,omitempty"`
	OtherVersionVoters     []string `json:"other_version_voters,omitempty" mapstructure:"other_version_voters,omitempty"`
	OtherVersionNonVoters  []string `json:"other_version_non_voters,omitempty" mapstructure:"other_version_non_voters,omitempty"`
}

type BoltSnapshotSink

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

BoltSnapshotSink implements SnapshotSink optionally choosing to write to a file.

func (*BoltSnapshotSink) Cancel

func (s *BoltSnapshotSink) Cancel() error

Cancel is used to indicate an unsuccessful end.

func (*BoltSnapshotSink) Close

func (s *BoltSnapshotSink) Close() error

Close is used to indicate a successful end.

func (*BoltSnapshotSink) ID

func (s *BoltSnapshotSink) ID() string

ID returns the ID of the snapshot, can be used with Open() after the snapshot is finalized.

func (*BoltSnapshotSink) Write

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

Write is used to append to the bolt file. The first call to write ensures we have the file created.

type BoltSnapshotStore

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

BoltSnapshotStore implements the SnapshotStore interface and allows snapshots to be stored in BoltDB files on local disk. Since we always have an up to date FSM we use a special snapshot ID to indicate that the snapshot can be pulled from the BoltDB file that is currently backing the FSM. This allows us to provide just-in-time snapshots without doing incremental data dumps.

When a snapshot is being installed on the node we will Create and Write data to it. This will cause the snapshot store to create a new BoltDB file and write the snapshot data to it. Then, we can simply rename the snapshot to the FSM's filename. This allows us to atomically install the snapshot and reduces the amount of disk i/o. Older snapshots are reaped on startup and before each subsequent snapshot write. This ensures we only have one snapshot on disk at a time.

func NewBoltSnapshotStore

func NewBoltSnapshotStore(base string, logger log.Logger, fsm *FSM) (*BoltSnapshotStore, error)

NewBoltSnapshotStore creates a new BoltSnapshotStore based on a base directory.

func (*BoltSnapshotStore) Create

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

Create is used to start a new snapshot

func (*BoltSnapshotStore) List

func (f *BoltSnapshotStore) List() ([]*raft.SnapshotMeta, error)

List returns available snapshots in the store. It only returns bolt snapshots. No snapshot will be returned if there are no indexes in the FSM.

func (*BoltSnapshotStore) Open

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

func (*BoltSnapshotStore) ReapSnapshots

func (f *BoltSnapshotStore) ReapSnapshots() error

ReapSnapshots reaps all snapshots.

type CleanupDeadServersValue added in v1.7.0

type CleanupDeadServersValue int

func (CleanupDeadServersValue) Value added in v1.7.0

func (c CleanupDeadServersValue) Value() bool

type ConfigurationValue

type ConfigurationValue struct {
	Index   uint64    `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
	Servers []*Server `protobuf:"bytes,2,rep,name=servers,proto3" json:"servers,omitempty"`
	// contains filtered or unexported fields
}

func (*ConfigurationValue) Descriptor deprecated

func (*ConfigurationValue) Descriptor() ([]byte, []int)

Deprecated: Use ConfigurationValue.ProtoReflect.Descriptor instead.

func (*ConfigurationValue) GetIndex

func (x *ConfigurationValue) GetIndex() uint64

func (*ConfigurationValue) GetServers

func (x *ConfigurationValue) GetServers() []*Server

func (*ConfigurationValue) ProtoMessage

func (*ConfigurationValue) ProtoMessage()

func (*ConfigurationValue) ProtoReflect added in v1.5.0

func (x *ConfigurationValue) ProtoReflect() protoreflect.Message

func (*ConfigurationValue) Reset

func (x *ConfigurationValue) Reset()

func (*ConfigurationValue) String

func (x *ConfigurationValue) String() string

type Delegate added in v1.7.0

type Delegate struct {
	*RaftBackend
	// contains filtered or unexported fields
}

Delegate is an implementation of autopilot.ApplicationIntegration interface. This is used by the autopilot library to retrieve information and to have application specific tasks performed.

func NewDelegate added in v1.13.3

func NewDelegate(b *RaftBackend) *Delegate

func (*Delegate) AutopilotConfig added in v1.7.0

func (d *Delegate) AutopilotConfig() *autopilot.Config

AutopilotConfig is called by the autopilot library to know the desired autopilot configuration.

func (*Delegate) FetchServerStats added in v1.7.0

func (d *Delegate) FetchServerStats(ctx context.Context, servers map[raft.ServerID]*autopilot.Server) map[raft.ServerID]*autopilot.ServerStats

FetchServerStats is called by the autopilot library to retrieve information about all the nodes in the raft cluster.

func (*Delegate) KnownServers added in v1.7.0

func (d *Delegate) KnownServers() map[raft.ServerID]*autopilot.Server

KnownServers is called by the autopilot library to know the status of each node in the raft cluster. If the application thinks that certain nodes left, it is here that we let the autopilot library know of the same.

func (*Delegate) NotifyState added in v1.7.0

func (d *Delegate) NotifyState(state *autopilot.State)

NotifyState is called by the autopilot library whenever there is a state change. We update a few metrics when this happens.

func (*Delegate) RemoveFailedServer added in v1.7.0

func (d *Delegate) RemoveFailedServer(server *autopilot.Server)

RemoveFailedServer is called by the autopilot library when it desires a node to be removed from the raft configuration. This function removes the node from the raft cluster and stops tracking its information in follower states. This function needs to return quickly. Hence removal is performed in a goroutine.

type EchoRequestUpdate added in v1.11.0

type EchoRequestUpdate struct {
	NodeID          string
	AppliedIndex    uint64
	Term            uint64
	DesiredSuffrage string
	UpgradeVersion  string
	SDKVersion      string
	RedundancyZone  string
}

EchoRequestUpdate is here to avoid 1) the list of arguments to Update() getting huge 2) an import cycle on the vault package

type FSM

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

FSM is Vault's primary state storage. It writes updates to a bolt db file that lives on local disk. FSM implements raft.FSM and physical.Backend interfaces.

func NewFSM

func NewFSM(path string, localID string, logger log.Logger) (*FSM, error)

NewFSM constructs a FSM using the given directory

func (*FSM) Apply

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

Apply will apply a log value to the FSM. This is called from the raft library.

func (*FSM) ApplyBatch added in v1.3.0

func (f *FSM) ApplyBatch(logs []*raft.Log) []interface{}

ApplyBatch will apply a set of logs to the FSM. This is called from the raft library.

func (*FSM) Close added in v1.5.0

func (f *FSM) Close() error

func (*FSM) Delete

func (f *FSM) Delete(ctx context.Context, path string) error

Delete deletes the given key from the bolt file.

func (*FSM) DeletePrefix

func (f *FSM) DeletePrefix(ctx context.Context, prefix string) error

Delete deletes the given key from the bolt file.

func (*FSM) DesiredSuffrage added in v1.7.0

func (f *FSM) DesiredSuffrage() string

func (*FSM) Get

func (f *FSM) Get(ctx context.Context, path string) (*physical.Entry, error)

Get retrieves the value at the given path from the bolt file.

func (*FSM) LatestState

func (f *FSM) LatestState() (*IndexValue, *ConfigurationValue)

LatestState returns the latest index and configuration values we have seen on this FSM.

func (*FSM) List

func (f *FSM) List(ctx context.Context, prefix string) ([]string, error)

List retrieves the set of keys with the given prefix from the bolt file.

func (*FSM) Put

func (f *FSM) Put(ctx context.Context, entry *physical.Entry) error

Put writes the given entry to the bolt file.

func (*FSM) Restore

func (f *FSM) Restore(r io.ReadCloser) error

Restore installs a new snapshot from the provided reader. It does an atomic rename of the snapshot file into the database filepath. While a restore is happening the FSM is locked and no writes or reads can be performed.

func (*FSM) SetNoopRestore

func (f *FSM) SetNoopRestore(enabled bool)

SetNoopRestore is used to disable restore operations on raft startup. Because we are using persistent storage in our FSM we do not need to issue a restore on startup.

func (*FSM) Snapshot

func (f *FSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot implements the FSM interface. It returns a noop snapshot object.

func (*FSM) Stats added in v1.10.10

func (f *FSM) Stats() bolt.Stats

func (*FSM) Transaction

func (f *FSM) Transaction(ctx context.Context, txns []*physical.TxnEntry) error

Transaction writes all the operations in the provided transaction to the bolt file.

type FSMApplyResponse

type FSMApplyResponse struct {
	Success    bool
	EntrySlice []*FSMEntry
}

FSMApplyResponse is returned from an FSM apply. It indicates if the apply was successful or not. EntryMap contains the keys/values from the Get operations.

type FSMChunkStorage

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

func (*FSMChunkStorage) FinalizeOp

func (f *FSMChunkStorage) FinalizeOp(opNum uint64) ([]*raftchunking.ChunkInfo, error)

func (*FSMChunkStorage) GetChunks

func (f *FSMChunkStorage) GetChunks() (raftchunking.ChunkMap, error)

func (*FSMChunkStorage) RestoreChunks

func (f *FSMChunkStorage) RestoreChunks(chunks raftchunking.ChunkMap) error

func (*FSMChunkStorage) StoreChunk

func (f *FSMChunkStorage) StoreChunk(chunk *raftchunking.ChunkInfo) (bool, error)

type FSMEntry added in v1.12.0

type FSMEntry struct {
	Key   string
	Value []byte
}

func (*FSMEntry) String added in v1.12.0

func (f *FSMEntry) String() string

type FollowerState added in v1.7.0

type FollowerState struct {
	AppliedIndex    uint64
	LastHeartbeat   time.Time
	LastTerm        uint64
	IsDead          *atomic.Bool
	DesiredSuffrage string
	Version         string
	UpgradeVersion  string
	RedundancyZone  string
}

FollowerState represents the information about peer that the leader tracks.

type FollowerStates added in v1.7.0

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

FollowerStates holds information about all the followers in the raft cluster tracked by the leader.

func NewFollowerStates added in v1.7.0

func NewFollowerStates() *FollowerStates

NewFollowerStates creates a new FollowerStates object

func (*FollowerStates) Clear added in v1.7.0

func (s *FollowerStates) Clear()

Clear wipes all the information regarding peers in the follower states.

func (*FollowerStates) Delete added in v1.7.0

func (s *FollowerStates) Delete(nodeID string)

Delete the entry of a peer represented by the nodeID from follower states.

func (*FollowerStates) MinIndex added in v1.7.0

func (s *FollowerStates) MinIndex() uint64

MinIndex returns the minimum raft index applied in the raft cluster.

func (*FollowerStates) Update added in v1.7.0

func (s *FollowerStates) Update(req *EchoRequestUpdate)

Update the peer information in the follower states. Note that this function runs on the active node.

type IndexValue

type IndexValue struct {
	Term  uint64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
	Index uint64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"`
	// contains filtered or unexported fields
}

func (*IndexValue) Descriptor deprecated

func (*IndexValue) Descriptor() ([]byte, []int)

Deprecated: Use IndexValue.ProtoReflect.Descriptor instead.

func (*IndexValue) GetIndex

func (x *IndexValue) GetIndex() uint64

func (*IndexValue) GetTerm

func (x *IndexValue) GetTerm() uint64

func (*IndexValue) ProtoMessage

func (*IndexValue) ProtoMessage()

func (*IndexValue) ProtoReflect added in v1.5.0

func (x *IndexValue) ProtoReflect() protoreflect.Message

func (*IndexValue) Reset

func (x *IndexValue) Reset()

func (*IndexValue) String

func (x *IndexValue) String() string

type LeaderJoinInfo added in v1.4.0

type LeaderJoinInfo struct {
	// AutoJoin defines any cloud auto-join metadata. If supplied, Vault will
	// attempt to automatically discover peers in addition to what can be provided
	// via 'leader_api_addr'.
	AutoJoin string `json:"auto_join"`

	// AutoJoinScheme defines the optional URI protocol scheme for addresses
	// discovered via auto-join.
	AutoJoinScheme string `json:"auto_join_scheme"`

	// AutoJoinPort defines the optional port used for addressed discovered via
	// auto-join.
	AutoJoinPort uint `json:"auto_join_port"`

	// LeaderAPIAddr is the address of the leader node to connect to
	LeaderAPIAddr string `json:"leader_api_addr"`

	// LeaderCACert is the CA cert of the leader node
	LeaderCACert string `json:"leader_ca_cert"`

	// LeaderClientCert is the client certificate for the follower node to
	// establish client authentication during TLS
	LeaderClientCert string `json:"leader_client_cert"`

	// LeaderClientKey is the client key for the follower node to establish
	// client authentication during TLS.
	LeaderClientKey string `json:"leader_client_key"`

	// LeaderCACertFile is the path on disk to the the CA cert file of the
	// leader node. This should only be provided via Vault's configuration file.
	LeaderCACertFile string `json:"leader_ca_cert_file"`

	// LeaderClientCertFile is the path on disk to the client certificate file
	// for the follower node to establish client authentication during TLS. This
	// should only be provided via Vault's configuration file.
	LeaderClientCertFile string `json:"leader_client_cert_file"`

	// LeaderClientKeyFile is the path on disk to the client key file for the
	// follower node to establish client authentication during TLS. This should
	// only be provided via Vault's configuration file.
	LeaderClientKeyFile string `json:"leader_client_key_file"`

	// LeaderTLSServerName is the optional ServerName to expect in the leader's
	// certificate, instead of the host/IP we're actually connecting to.
	LeaderTLSServerName string `json:"leader_tls_servername"`

	// Retry indicates if the join process should automatically be retried
	Retry bool `json:"-"`

	// TLSConfig for the API client to use when communicating with the leader node
	TLSConfig *tls.Config `json:"-"`
}

LeaderJoinInfo contains information required by a node to join itself as a follower to an existing raft cluster

type LocalNodeConfigValue added in v1.7.0

type LocalNodeConfigValue struct {
	DesiredSuffrage string `protobuf:"bytes,1,opt,name=desired_suffrage,json=desiredSuffrage,proto3" json:"desired_suffrage,omitempty"`
	// contains filtered or unexported fields
}

func (*LocalNodeConfigValue) Descriptor deprecated added in v1.7.0

func (*LocalNodeConfigValue) Descriptor() ([]byte, []int)

Deprecated: Use LocalNodeConfigValue.ProtoReflect.Descriptor instead.

func (*LocalNodeConfigValue) GetDesiredSuffrage added in v1.7.0

func (x *LocalNodeConfigValue) GetDesiredSuffrage() string

func (*LocalNodeConfigValue) ProtoMessage added in v1.7.0

func (*LocalNodeConfigValue) ProtoMessage()

func (*LocalNodeConfigValue) ProtoReflect added in v1.7.0

func (x *LocalNodeConfigValue) ProtoReflect() protoreflect.Message

func (*LocalNodeConfigValue) Reset added in v1.7.0

func (x *LocalNodeConfigValue) Reset()

func (*LocalNodeConfigValue) String added in v1.7.0

func (x *LocalNodeConfigValue) String() string

type LogData

type LogData struct {
	Operations []*LogOperation `protobuf:"bytes,1,rep,name=operations,proto3" json:"operations,omitempty"`
	// contains filtered or unexported fields
}

func (*LogData) Descriptor deprecated

func (*LogData) Descriptor() ([]byte, []int)

Deprecated: Use LogData.ProtoReflect.Descriptor instead.

func (*LogData) GetOperations

func (x *LogData) GetOperations() []*LogOperation

func (*LogData) ProtoMessage

func (*LogData) ProtoMessage()

func (*LogData) ProtoReflect added in v1.5.0

func (x *LogData) ProtoReflect() protoreflect.Message

func (*LogData) Reset

func (x *LogData) Reset()

func (*LogData) String

func (x *LogData) String() string

type LogOperation

type LogOperation struct {

	// OpType is the Operation type
	OpType uint32 `protobuf:"varint,1,opt,name=op_type,json=opType,proto3" json:"op_type,omitempty"`
	// Flags is an opaque value, currently unused. Reserved.
	Flags uint64 `protobuf:"varint,2,opt,name=flags,proto3" json:"flags,omitempty"`
	// Key that is being affected
	Key string `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"`
	// Value is optional, corresponds to the key
	Value []byte `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*LogOperation) Descriptor deprecated

func (*LogOperation) Descriptor() ([]byte, []int)

Deprecated: Use LogOperation.ProtoReflect.Descriptor instead.

func (*LogOperation) GetFlags

func (x *LogOperation) GetFlags() uint64

func (*LogOperation) GetKey

func (x *LogOperation) GetKey() string

func (*LogOperation) GetOpType

func (x *LogOperation) GetOpType() uint32

func (*LogOperation) GetValue

func (x *LogOperation) GetValue() []byte

func (*LogOperation) ProtoMessage

func (*LogOperation) ProtoMessage()

func (*LogOperation) ProtoReflect added in v1.5.0

func (x *LogOperation) ProtoReflect() protoreflect.Message

func (*LogOperation) Reset

func (x *LogOperation) Reset()

func (*LogOperation) String

func (x *LogOperation) String() string

type Peer

type Peer struct {
	ID       string `json:"id"`
	Address  string `json:"address"`
	Suffrage int    `json:"suffrage"`
}

Peer defines the ID and Address for a given member of the raft cluster.

type RaftBackend

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

RaftBackend implements the backend interfaces and uses the raft protocol to persist writes to the FSM.

func GetRaft added in v1.13.0

func GetRaft(t testing.TB, bootstrap bool, noStoreState bool) (*RaftBackend, string)

func (*RaftBackend) AddNonVotingPeer added in v1.3.0

func (b *RaftBackend) AddNonVotingPeer(ctx context.Context, peerID, clusterAddr string) error

AddNonVotingPeer adds a new server to the raft cluster

func (*RaftBackend) AddPeer

func (b *RaftBackend) AddPeer(ctx context.Context, peerID, clusterAddr string) error

AddPeer adds a new server to the raft cluster

func (*RaftBackend) AppliedIndex

func (b *RaftBackend) AppliedIndex() uint64

AppliedIndex returns the latest index applied to the FSM

func (*RaftBackend) AutopilotConfig added in v1.7.0

func (b *RaftBackend) AutopilotConfig() *AutopilotConfig

AutopilotConfig returns the autopilot configuration in the backend.

func (*RaftBackend) AutopilotDisabled added in v1.7.0

func (b *RaftBackend) AutopilotDisabled() bool

func (*RaftBackend) Bootstrap

func (b *RaftBackend) Bootstrap(peers []Peer) error

Bootstrap prepares the given peers to be part of the raft cluster

func (*RaftBackend) Close added in v1.5.0

func (b *RaftBackend) Close() error

Close is used to gracefully close all file resources. N.B. This method should only be called if you are sure the RaftBackend will never be used again.

func (*RaftBackend) CollectMetrics added in v1.8.0

func (b *RaftBackend) CollectMetrics(sink *metricsutil.ClusterMetricSink)

func (*RaftBackend) CommittedIndex added in v1.4.2

func (b *RaftBackend) CommittedIndex() uint64

CommittedIndex returns the latest index committed to stable storage

func (*RaftBackend) Delete

func (b *RaftBackend) Delete(ctx context.Context, path string) error

Delete inserts an entry in the log to delete the given path

func (*RaftBackend) DesiredSuffrage added in v1.7.0

func (b *RaftBackend) DesiredSuffrage() string

func (*RaftBackend) DisableAutopilot added in v1.7.0

func (b *RaftBackend) DisableAutopilot()

func (*RaftBackend) DisableUpgradeMigration added in v1.11.0

func (b *RaftBackend) DisableUpgradeMigration() (bool, bool)

DisableUpgradeMigration returns the state of the DisableUpgradeMigration config flag and whether it was set or not

func (*RaftBackend) EffectiveVersion added in v1.11.0

func (b *RaftBackend) EffectiveVersion() string

func (*RaftBackend) FailGetInTxn added in v1.13.0

func (b *RaftBackend) FailGetInTxn(fail bool)

func (*RaftBackend) Get

func (b *RaftBackend) Get(ctx context.Context, path string) (*physical.Entry, error)

Get returns the value corresponding to the given path from the fsm

func (*RaftBackend) GetAutopilotServerState added in v1.7.0

func (b *RaftBackend) GetAutopilotServerState(ctx context.Context) (*AutopilotState, error)

GetAutopilotServerState retrieves raft cluster state from autopilot to return over the API.

func (*RaftBackend) GetConfiguration

func (b *RaftBackend) GetConfiguration(ctx context.Context) (*RaftConfigurationResponse, error)

func (*RaftBackend) GetConfigurationOffline added in v1.8.0

func (b *RaftBackend) GetConfigurationOffline() (*RaftConfigurationResponse, error)

GetConfigurationOffline is used to read the stale, last known raft configuration to this node. It accesses the last state written into the FSM. When a server is online use GetConfiguration instead.

func (*RaftBackend) HAEnabled

func (b *RaftBackend) HAEnabled() bool

HAEnabled is the implementation of the HABackend interface

func (*RaftBackend) HasState added in v1.5.0

func (b *RaftBackend) HasState() (bool, error)

func (*RaftBackend) Initialized

func (b *RaftBackend) Initialized() bool

Initialized tells if raft is running or not

func (*RaftBackend) JoinConfig added in v1.4.0

func (b *RaftBackend) JoinConfig() ([]*LeaderJoinInfo, error)

JoinConfig returns a list of information about possible leader nodes that this node can join as a follower

func (*RaftBackend) List

func (b *RaftBackend) List(ctx context.Context, prefix string) ([]string, error)

List enumerates all the items under the prefix from the fsm

func (*RaftBackend) LockWith

func (b *RaftBackend) LockWith(key, value string) (physical.Lock, error)

HAEnabled is the implementation of the HABackend interface

func (*RaftBackend) NodeID

func (b *RaftBackend) NodeID() string

NodeID returns the identifier of the node

func (*RaftBackend) NonVoter added in v1.12.2

func (b *RaftBackend) NonVoter() bool

func (*RaftBackend) Peers

func (b *RaftBackend) Peers(ctx context.Context) ([]Peer, error)

Peers returns all the servers present in the raft cluster

func (*RaftBackend) Put

func (b *RaftBackend) Put(ctx context.Context, entry *physical.Entry) error

Put inserts an entry in the log for the put operation. It will return an error if the resulting entry encoding exceeds the configured max_entry_size or if the call to applyLog fails.

func (*RaftBackend) RedundancyZone added in v1.11.0

func (b *RaftBackend) RedundancyZone() string

func (*RaftBackend) RemovePeer

func (b *RaftBackend) RemovePeer(ctx context.Context, peerID string) error

RemovePeer removes the given peer ID from the raft cluster. If the node is ourselves we will give up leadership.

func (*RaftBackend) RestoreSnapshot

func (b *RaftBackend) RestoreSnapshot(ctx context.Context, metadata raft.SnapshotMeta, snap io.Reader) error

RestoreSnapshot applies the provided snapshot metadata and snapshot data to raft.

func (*RaftBackend) SetAutopilotConfig added in v1.7.0

func (b *RaftBackend) SetAutopilotConfig(config *AutopilotConfig)

SetAutopilotConfig updates the autopilot configuration in the backend.

func (*RaftBackend) SetDesiredSuffrage added in v1.7.0

func (b *RaftBackend) SetDesiredSuffrage(nonVoter bool) error

SetDesiredSuffrage sets a field in the fsm indicating the suffrage intent for this node.

func (*RaftBackend) SetEffectiveSDKVersion added in v1.12.0

func (b *RaftBackend) SetEffectiveSDKVersion(sdkVersion string)

func (*RaftBackend) SetFSMApplyCallback added in v1.7.0

func (r *RaftBackend) SetFSMApplyCallback(f func())

func (*RaftBackend) SetFSMDelay added in v1.5.4

func (r *RaftBackend) SetFSMDelay(delay time.Duration)

SetFSMDelay adds a delay to the FSM apply. This is used in tests to simulate a slow apply.

func (*RaftBackend) SetFollowerStates added in v1.7.0

func (b *RaftBackend) SetFollowerStates(states *FollowerStates)

SetFollowerStates sets the followerStates field in the backend to track peers in the raft cluster.

func (*RaftBackend) SetRestoreCallback

func (b *RaftBackend) SetRestoreCallback(restoreCb restoreCallback)

SetRestoreCallback sets the callback to be used when a restoreCallbackOp is processed through the FSM.

func (*RaftBackend) SetServerAddressProvider

func (b *RaftBackend) SetServerAddressProvider(provider raft.ServerAddressProvider)

SetServerAddressProvider sets a the address provider for determining the raft node addresses. This is currently only used in tests.

func (*RaftBackend) SetTLSKeyring

func (b *RaftBackend) SetTLSKeyring(keyring *TLSKeyring) error

SetTLSKeyring is used to install a new keyring. If the active key has changed it will also close any network connections or streams forcing a reconnect with the new key.

func (*RaftBackend) SetupAutopilot added in v1.7.0

func (b *RaftBackend) SetupAutopilot(ctx context.Context, storageConfig *AutopilotConfig, followerStates *FollowerStates, disable bool)

SetupAutopilot gathers information required to configure autopilot and starts it. If autopilot is disabled, this function does nothing.

func (*RaftBackend) SetupCluster

func (b *RaftBackend) SetupCluster(ctx context.Context, opts SetupOpts) error

SetupCluster starts the raft cluster and enables the networking needed for the raft nodes to communicate.

func (*RaftBackend) Snapshot

func (b *RaftBackend) Snapshot(out io.Writer, access seal.Access) error

Snapshot takes a raft snapshot, packages it into a archive file and writes it to the provided writer. Seal access is used to encrypt the SHASUM file so we can validate the snapshot was taken using the same root keys or not.

func (*RaftBackend) SnapshotHTTP added in v1.6.0

func (b *RaftBackend) SnapshotHTTP(out *logical.HTTPResponseWriter, access seal.Access) error

SnapshotHTTP is a wrapper for Snapshot that sends the snapshot as an HTTP response.

func (*RaftBackend) StartRecoveryCluster added in v1.3.0

func (b *RaftBackend) StartRecoveryCluster(ctx context.Context, peer Peer) error

func (*RaftBackend) StopAutopilot added in v1.7.0

func (b *RaftBackend) StopAutopilot()

StopAutopilot stops a running autopilot instance. This should only be called on the active node.

func (*RaftBackend) TeardownCluster

func (b *RaftBackend) TeardownCluster(clusterListener cluster.ClusterHook) error

TeardownCluster shuts down the raft cluster

func (*RaftBackend) Term added in v1.7.0

func (b *RaftBackend) Term() uint64

Term returns the raft term of this node.

func (*RaftBackend) Transaction

func (b *RaftBackend) Transaction(ctx context.Context, txns []*physical.TxnEntry) error

Transaction applies all the given operations into a single log and applies it.

func (*RaftBackend) WriteSnapshotToTemp

func (b *RaftBackend) WriteSnapshotToTemp(in io.ReadCloser, access seal.Access) (*os.File, func(), raft.SnapshotMeta, error)

WriteSnapshotToTemp reads a snapshot archive off the provided reader, extracts the data and writes the snapshot to a temporary file. The seal access is used to decrypt the SHASUM file in the archive to ensure this snapshot has the same root key as the running instance. If the provided access is nil then it will skip that validation.

type RaftConfigurationResponse

type RaftConfigurationResponse struct {
	// Servers has the list of servers in the Raft configuration.
	Servers []*RaftServer `json:"servers"`

	// Index has the Raft index of this configuration.
	Index uint64 `json:"index"`
}

RaftConfigurationResponse is returned when querying for the current Raft configuration.

type RaftLock

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

RaftLock implements the physical Lock interface and enables HA for this backend. The Lock uses the raftNotifyCh for receiving leadership edge triggers. Vault's active duty matches raft's leadership.

func (*RaftLock) Lock

func (l *RaftLock) Lock(stopCh <-chan struct{}) (<-chan struct{}, error)

Lock blocks until we become leader or are shutdown. It returns a channel that is closed when we detect a loss of leadership.

func (*RaftLock) Unlock

func (l *RaftLock) Unlock() error

Unlock gives up leadership.

func (*RaftLock) Value

func (l *RaftLock) Value() (bool, string, error)

Value reads the value of the lock. This informs us who is currently leader.

type RaftServer

type RaftServer struct {
	// NodeID is the name of the server
	NodeID string `json:"node_id"`

	// Address is the IP:port of the server, used for Raft communications
	Address string `json:"address"`

	// Leader is true if this server is the current cluster leader
	Leader bool `json:"leader"`

	// Protocol version is the raft protocol version used by the server
	ProtocolVersion string `json:"protocol_version"`

	// Voter is true if this server has a vote in the cluster. This might
	// be false if the server is staging and still coming online.
	Voter bool `json:"voter"`
}

RaftServer has information about a server in the Raft configuration

type ReadCloser added in v1.5.0

type ReadCloser interface {
	Reader
	io.Closer
}

func NewDelimitedReader added in v1.5.0

func NewDelimitedReader(r io.Reader, maxSize int) ReadCloser

type ReadableDuration added in v1.7.0

type ReadableDuration time.Duration

ReadableDuration is a duration type that is serialized to JSON in human readable format.

func NewReadableDuration added in v1.7.0

func NewReadableDuration(dur time.Duration) *ReadableDuration

func (*ReadableDuration) Duration added in v1.7.0

func (d *ReadableDuration) Duration() time.Duration

func (*ReadableDuration) MarshalJSON added in v1.7.0

func (d *ReadableDuration) MarshalJSON() ([]byte, error)

func (*ReadableDuration) String added in v1.7.0

func (d *ReadableDuration) String() string

func (*ReadableDuration) UnmarshalJSON added in v1.7.0

func (d *ReadableDuration) UnmarshalJSON(raw []byte) (err error)

type Reader added in v1.5.0

type Reader interface {
	ReadMsg(msg proto.Message) error
}

type Server

type Server struct {
	Suffrage int32  `protobuf:"varint,1,opt,name=suffrage,proto3" json:"suffrage,omitempty"`
	Id       string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	Address  string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`
	// contains filtered or unexported fields
}

func (*Server) Descriptor deprecated

func (*Server) Descriptor() ([]byte, []int)

Deprecated: Use Server.ProtoReflect.Descriptor instead.

func (*Server) GetAddress

func (x *Server) GetAddress() string

func (*Server) GetId

func (x *Server) GetId() string

func (*Server) GetSuffrage

func (x *Server) GetSuffrage() int32

func (*Server) ProtoMessage

func (*Server) ProtoMessage()

func (*Server) ProtoReflect added in v1.5.0

func (x *Server) ProtoReflect() protoreflect.Message

func (*Server) Reset

func (x *Server) Reset()

func (*Server) String

func (x *Server) String() string

type SetupOpts

type SetupOpts struct {
	// TLSKeyring is the keyring to use for the cluster traffic.
	TLSKeyring *TLSKeyring

	// ClusterListener is the cluster hook used to register the raft handler and
	// client with core's cluster listeners.
	ClusterListener cluster.ClusterHook

	// StartAsLeader is used to specify this node should start as leader and
	// bypass the leader election. This should be used with caution.
	StartAsLeader bool

	// RecoveryModeConfig is the configuration for the raft cluster in recovery
	// mode.
	RecoveryModeConfig *raft.Configuration
}

SetupOpts are used to pass options to the raft setup function.

type TLSKey

type TLSKey struct {
	// ID is a unique identifier for this Key
	ID string `json:"id"`

	// KeyType defines the algorighm used to generate the private keys
	KeyType string `json:"key_type"`

	// AppliedIndex is the earliest known raft index that safely contains this
	// key.
	AppliedIndex uint64 `json:"applied_index"`

	// CertBytes is the marshaled certificate.
	CertBytes []byte `json:"cluster_cert"`

	// KeyParams is the marshaled private key.
	KeyParams *certutil.ClusterKeyParams `json:"cluster_key_params"`

	// CreatedTime is the time this key was generated. This value is useful in
	// determining when the next rotation should be.
	CreatedTime time.Time `json:"created_time"`
	// contains filtered or unexported fields
}

TLSKey is a single TLS keypair in the Keyring

func GenerateTLSKey

func GenerateTLSKey(reader io.Reader) (*TLSKey, error)

type TLSKeyring

type TLSKeyring struct {
	// Keys is the set of available key pairs
	Keys []*TLSKey `json:"keys"`

	// AppliedIndex is the earliest known raft index that safely contains the
	// latest key in the keyring.
	AppliedIndex uint64 `json:"applied_index"`

	// Term is an incrementing identifier value used to quickly determine if two
	// states of the keyring are different.
	Term uint64 `json:"term"`

	// ActiveKeyID is the key ID to track the active key in the keyring. Only
	// the active key is used for dialing.
	ActiveKeyID string `json:"active_key_id"`
}

TLSKeyring is the set of keys that raft uses for network communication. Only one key is used to dial at a time but both keys will be used to accept connections.

func (*TLSKeyring) GetActive

func (k *TLSKeyring) GetActive() *TLSKey

GetActive returns the active key.

type WriteCloser added in v1.5.0

type WriteCloser interface {
	Writer
	io.Closer
}

func NewDelimitedWriter added in v1.5.0

func NewDelimitedWriter(w io.Writer) WriteCloser

type Writer added in v1.5.0

type Writer interface {
	WriteMsg(proto.Message) error
}

Jump to

Keyboard shortcuts

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