raftstorage

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package raftstorage implements a Raft-backed storage provider.

Index

Constants

View Source
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
)
View Source
const (
	Follower  = raft.Follower
	Candidate = raft.Candidate
	Leader    = raft.Leader
	Shutdown  = raft.Shutdown
)

Raft states.

View Source
const (
	Voter    = raft.Voter
	Nonvoter = raft.Nonvoter
)

Raft suffrage states.

Variables

View Source
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

func (r *Consensus) AddObserver(ctx context.Context, peer types.StoragePeer) error

AddObserver adds an observer to the consensus group.

func (*Consensus) AddVoter

func (r *Consensus) AddVoter(ctx context.Context, peer types.StoragePeer) error

AddVoter adds a voter to the consensus group.

func (*Consensus) DemoteVoter

func (r *Consensus) DemoteVoter(ctx context.Context, peer types.StoragePeer) error

DemoteVoter demotes a voter to an observer.

func (*Consensus) GetLeader

func (r *Consensus) GetLeader(ctx context.Context) (types.StoragePeer, error)

GetLeader returns the leader of the cluster.

func (*Consensus) GetPeer added in v0.11.5

func (r *Consensus) GetPeer(ctx context.Context, id string) (types.StoragePeer, error)

GetPeer returns the peer with the given ID.

func (*Consensus) GetPeers added in v0.7.2

func (r *Consensus) GetPeers(ctx context.Context) ([]types.StoragePeer, error)

GetPeers returns the peers of the cluster.

func (*Consensus) IsLeader

func (r *Consensus) IsLeader() bool

IsLeader returns true if the Raft node is the leader.

func (*Consensus) IsMember

func (r *Consensus) IsMember() bool

IsMember returns true if the Raft node is a member of the cluster.

func (*Consensus) RemovePeer

func (r *Consensus) RemovePeer(ctx context.Context, peer types.StoragePeer, wait bool) error

RemovePeer removes a peer from the consensus group.

func (*Consensus) StepDown added in v0.12.3

func (r *Consensus) StepDown(ctx context.Context) error

StepDown steps down from leadership.

type LeaderObservation

type LeaderObservation = raft.LeaderObservation

LeaderObservation is an alias for raft.LeaderObservation.

type MonotonicLogStore

type MonotonicLogStore struct {
	raft.LogStore
}

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.

func (*Options) RaftConfig

func (o *Options) RaftConfig(ctx context.Context, nodeID string) *raft.Config

RaftConfig builds a raft config.

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

func NewProvider(opts Options) *Provider

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

func (r *Provider) Bootstrap(ctx context.Context) error

Bootstrap bootstraps the raft storage provider.

func (*Provider) Close

func (r *Provider) Close() error

Close closes the mesh storage and shuts down the raft instance.

func (*Provider) Consensus

func (r *Provider) Consensus() storage.Consensus

Consensus returns the underlying Consensus instance.

func (*Provider) GetRaftConfiguration added in v0.7.1

func (r *Provider) GetRaftConfiguration() raft.Configuration

GetRaftConfiguration returns the current raft configuration.

func (*Provider) ListenPort

func (r *Provider) ListenPort() uint16

ListenPort returns the TCP port that the storage provider is listening on.

func (*Provider) MeshDB added in v0.9.0

func (r *Provider) MeshDB() storage.MeshDB

MeshDB returns the underlying MeshDB instance.

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

func (r *Provider) Start(ctx context.Context) error

Start starts the raft storage provider.

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) GetValue added in v0.7.1

func (rs *RaftStorage) GetValue(ctx context.Context, key []byte) ([]byte, error)

GetValue gets the value of 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) ListKeys added in v0.8.0

func (rs *RaftStorage) ListKeys(ctx context.Context, prefix []byte) ([][]byte, error)

ListKeys returns a list of keys.

func (*RaftStorage) PutValue

func (rs *RaftStorage) PutValue(ctx context.Context, key, value []byte, ttl time.Duration) error

Put sets the value of a key.

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.

Jump to

Keyboard shortcuts

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