Documentation ¶
Overview ¶
Package raftstorage implements a Raft-backed storage provider.
Index ¶
- Constants
- Variables
- type Consensus
- func (r *Consensus) AddObserver(ctx context.Context, peer *v1.StoragePeer) error
- func (r *Consensus) AddVoter(ctx context.Context, peer *v1.StoragePeer) error
- func (r *Consensus) DemoteVoter(ctx context.Context, peer *v1.StoragePeer) error
- func (r *Consensus) GetLeader(ctx context.Context) (*v1.StoragePeer, error)
- func (r *Consensus) GetPeer(ctx context.Context, id string) (*v1.StoragePeer, error)
- func (r *Consensus) GetPeers(ctx context.Context) ([]*v1.StoragePeer, error)
- func (r *Consensus) IsLeader() bool
- func (r *Consensus) IsMember() bool
- func (r *Consensus) RemovePeer(ctx context.Context, peer *v1.StoragePeer, wait bool) error
- type LeaderObservation
- type MonotonicLogStore
- type Observation
- type ObservationCallback
- type Options
- type PeerObservation
- type Provider
- func (r *Provider) ApplyRaftLog(ctx context.Context, log *v1.RaftLogEntry) (*v1.RaftApplyResponse, error)
- func (r *Provider) Bootstrap(ctx context.Context) error
- func (r *Provider) Close() error
- func (r *Provider) Consensus() storage.Consensus
- func (r *Provider) GetRaftConfiguration() raft.Configuration
- func (r *Provider) ListenPort() uint16
- func (r *Provider) MeshDB() storage.MeshDB
- func (r *Provider) MeshStorage() storage.MeshStorage
- func (r *Provider) OnObservation(cb ObservationCallback)
- func (r *Provider) Start(ctx context.Context) error
- func (r *Provider) Status() *v1.StorageStatus
- type RaftStorage
- func (rs *RaftStorage) Close() error
- func (rs *RaftStorage) Delete(ctx context.Context, key []byte) error
- func (rs *RaftStorage) GetValue(ctx context.Context, key []byte) ([]byte, error)
- func (rs *RaftStorage) IterPrefix(ctx context.Context, prefix []byte, fn storage.PrefixIterator) error
- func (rs *RaftStorage) ListKeys(ctx context.Context, prefix []byte) ([][]byte, error)
- func (rs *RaftStorage) PutValue(ctx context.Context, key, value []byte, ttl time.Duration) error
- func (rs *RaftStorage) Subscribe(ctx context.Context, prefix []byte, fn storage.KVSubscribeFunc) (context.CancelFunc, error)
- type SnapshotMeta
Constants ¶
const ( // DefaultListenPort is the default raft listen port DefaultListenPort = 9000 // DefaultListenAddress is the default raft listen address DefaultListenAddress = "[::]:9000" // DefaultBarrierThreshold is the threshold for sending a barrier after // a write operation. DefaultBarrierThreshold = 10 )
const ( Follower = raft.Follower Candidate = raft.Candidate Leader = raft.Leader Shutdown = raft.Shutdown )
Raft states.
const ( Voter = raft.Voter Nonvoter = raft.Nonvoter )
Raft suffrage states.
Variables ¶
var DefaultDataDir = func() string { if runtime.GOOS == "windows" { return "C:\\ProgramData\\webmesh\\store" } return "/var/lib/webmesh/store" }()
DefaultDataDir is the default data directory.
Functions ¶
This section is empty.
Types ¶
type Consensus ¶
type Consensus struct {
*Provider
}
RaftConsensus is the Raft consensus implementation.
func (*Consensus) AddObserver ¶
AddObserver adds an observer to the consensus group.
func (*Consensus) DemoteVoter ¶
DemoteVoter demotes a voter to an observer.
func (*Consensus) RemovePeer ¶
RemovePeer removes a peer from the consensus group.
type LeaderObservation ¶
type LeaderObservation = raft.LeaderObservation
LeaderObservation is an alias for raft.LeaderObservation.
type MonotonicLogStore ¶
MonotonicLogStore is a LogStore that is monotonic.
func (*MonotonicLogStore) IsMonotonic ¶
func (m *MonotonicLogStore) IsMonotonic() bool
IsMonotonic returns true if the log store is monotonic.
type Observation ¶
type Observation = raft.Observation
Observation is an alias for raft.Observation.
type ObservationCallback ¶
type ObservationCallback func(ctx context.Context, obs Observation)
ObservationCallback is a callback that can be registered for when an observation is received.
type Options ¶
type Options struct { // NodeID is the node ID. NodeID types.NodeID // Transport is the Raft transport to use for communicating with // other Raft nodes. Transport transport.RaftTransport // DataDir is the directory to store data in. DataDir string // ClearDataDir is if the data directory should be cleared on startup. ClearDataDir bool // InMemory is if the store should be in memory. This should only be used for testing and ephemeral nodes. InMemory bool // ConnectionPoolCount is the number of connections to pool. If 0, no connection pooling is used. ConnectionPoolCount int // ConnectionTimeout is the timeout for connections. ConnectionTimeout time.Duration // HeartbeatTimeout is the timeout for heartbeats. HeartbeatTimeout time.Duration // ElectionTimeout is the timeout for elections. ElectionTimeout time.Duration // ApplyTimeout is the timeout for applying. ApplyTimeout time.Duration // CommitTimeout is the timeout for committing. CommitTimeout time.Duration // MaxAppendEntries is the maximum number of append entries. MaxAppendEntries int // LeaderLeaseTimeout is the timeout for leader leases. LeaderLeaseTimeout time.Duration // SnapshotInterval is the interval to take snapshots. SnapshotInterval time.Duration // SnapshotThreshold is the threshold to take snapshots. SnapshotThreshold uint64 // SnapshotRetention is the number of snapshots to retain. SnapshotRetention uint64 // ObserverChanBuffer is the buffer size for the observer channel. ObserverChanBuffer int // BarrierThreshold is the threshold for sending a barrier after a write operation. BarrierThreshold int32 // LogLevel is the log level for the raft backend. LogLevel string // LogFormat is the log format for the raft backend. LogFormat string }
Options are the raft options.
func NewOptions ¶
func NewOptions(nodeID types.NodeID, transport transport.RaftTransport) Options
NewOptions returns new raft options with sensible defaults.
type PeerObservation ¶
type PeerObservation = raft.PeerObservation
PeerObservation is an alias for raft.PeerObservation.
type Provider ¶
type Provider struct { Options // contains filtered or unexported fields }
RaftStorage is a storage provider that uses Raft for consensus. BadgerDB is used for the underlying storage.
func NewProvider ¶
NewProvider returns a new RaftStorageProvider.
func (*Provider) ApplyRaftLog ¶ added in v0.7.1
func (r *Provider) ApplyRaftLog(ctx context.Context, log *v1.RaftLogEntry) (*v1.RaftApplyResponse, error)
ApplyRaftLog applies a raft log entry.
func (*Provider) GetRaftConfiguration ¶ added in v0.7.1
func (r *Provider) GetRaftConfiguration() raft.Configuration
GetRaftConfiguration returns the current raft configuration.
func (*Provider) ListenPort ¶
ListenPort returns the TCP port that the storage provider is listening on.
func (*Provider) MeshStorage ¶
func (r *Provider) MeshStorage() storage.MeshStorage
MeshStorage returns the underlying MeshStorage instance.
func (*Provider) OnObservation ¶
func (r *Provider) OnObservation(cb ObservationCallback)
OnObservation registers a callback for when an observation is received.
func (*Provider) Status ¶
func (r *Provider) Status() *v1.StorageStatus
Status returns the status of the storage provider.
type RaftStorage ¶
type RaftStorage struct {
// contains filtered or unexported fields
}
RaftStorage wraps the storage.Storage interface to force write operations through the Raft log.
func (*RaftStorage) Close ¶ added in v0.7.1
func (rs *RaftStorage) Close() error
Close closes the storage.
func (*RaftStorage) Delete ¶
func (rs *RaftStorage) Delete(ctx context.Context, key []byte) error
Delete removes a key.
func (*RaftStorage) IterPrefix ¶ added in v0.7.1
func (rs *RaftStorage) IterPrefix(ctx context.Context, prefix []byte, fn storage.PrefixIterator) error
IterPrefix iterates over all keys with a given prefix.
func (*RaftStorage) Subscribe ¶ added in v0.7.1
func (rs *RaftStorage) Subscribe(ctx context.Context, prefix []byte, fn storage.KVSubscribeFunc) (context.CancelFunc, error)
Subscribe subscribes to changes to a prefix.
type SnapshotMeta ¶
type SnapshotMeta = raft.SnapshotMeta
SnapshotMeta is an alias for raft.SnapshotMeta.
Directories ¶
Path | Synopsis |
---|---|
Package fsm implements the Raft FSM.
|
Package fsm implements the Raft FSM. |
Package raftlogs provides facilities for applying raft logs to a database.
|
Package raftlogs provides facilities for applying raft logs to a database. |
Package snapshots provides an interface for managing raft snapshots.
|
Package snapshots provides an interface for managing raft snapshots. |