logdb

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSnapshot = errors.New("no snapshot")
	ErrNoSavedLog = errors.New("no saved log")
	ErrNotFound   = errors.New("not found")
)

Functions

func IsEmptyRaftReady

func IsEmptyRaftReady(rd raft.Ready) bool

Types

type KVLogDB

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

KVLogDB is a LogDB implementation built on top of a Key-Value store.

func NewKVLogDB

func NewKVLogDB(ms storage.KVMetadataStore, logger *zap.Logger) *KVLogDB

func (*KVLogDB) Close

func (l *KVLogDB) Close() error

func (*KVLogDB) GetAllSnapshots

func (l *KVLogDB) GetAllSnapshots(shardID uint64) ([]raftpb.Snapshot, error)

func (*KVLogDB) GetSnapshot

func (l *KVLogDB) GetSnapshot(shardID uint64) (raftpb.Snapshot, error)

func (*KVLogDB) IterateEntries

func (l *KVLogDB) IterateEntries(ents []raftpb.Entry,
	size uint64, shardID uint64, replicaID uint64, low uint64,
	high uint64, maxSize uint64) ([]raftpb.Entry, uint64, error)

func (*KVLogDB) Name

func (l *KVLogDB) Name() string

func (*KVLogDB) NewWorkerContext

func (l *KVLogDB) NewWorkerContext() *WorkerContext

func (*KVLogDB) ReadRaftState

func (l *KVLogDB) ReadRaftState(shardID uint64,
	replicaID uint64, snapshotIndex uint64) (RaftState, error)

func (*KVLogDB) RemoveEntriesTo

func (l *KVLogDB) RemoveEntriesTo(shardID uint64, replicaID uint64, index uint64) error

TODO: check whether index below is larger than the max index RemoveEntriesTo deletes all raft log entries between [0, index].

func (*KVLogDB) RemoveReplicaData

func (l *KVLogDB) RemoveReplicaData(shardID uint64) error

func (*KVLogDB) RemoveSnapshot

func (l *KVLogDB) RemoveSnapshot(shardID uint64, index uint64) error

func (*KVLogDB) SaveRaftState

func (l *KVLogDB) SaveRaftState(shardID uint64,
	replicaID uint64, rd raft.Ready, ctx *WorkerContext) error

type LogDB

type LogDB interface {
	// Name returns the type name of the ILogDB instance.
	Name() string
	// Close closes the ILogDB instance.
	Close() error
	// NewWorkerContext creates a new worker context which used by `SaveRaftState`.
	NewWorkerContext() *WorkerContext
	// SaveRaftState atomically saves the Raft states, log entries and snapshots
	// metadata found in the pb.Update list to the log DB. shardID is a 1-based
	// ID of the worker invoking the SaveRaftState method, as each worker
	// accesses the log DB from its own thread, SaveRaftState will never be
	// concurrently called with the same shardID.
	SaveRaftState(shardID uint64,
		replicaID uint64, rd raft.Ready, ctx *WorkerContext) error
	// IterateEntries returns the continuous Raft log entries of the specified
	// Raft node between the index value range of [low, high) up to a max size
	// limit of maxSize bytes. It returns the located log entries, their total
	// size in bytes and the occurred error.
	IterateEntries(ents []raftpb.Entry,
		size uint64, shardID uint64, replicaID uint64, low uint64,
		high uint64, maxSize uint64) ([]raftpb.Entry, uint64, error)
	// ReadRaftState returns the persistented raft state found in Log DB.
	ReadRaftState(shardID uint64, replicaID uint64, snapshotIndex uint64) (RaftState, error)
	// RemoveEntriesTo removes entries with indexes between (0, index].
	RemoveEntriesTo(shardID uint64, replicaID uint64, index uint64) error
	// GetSnapshot returns the most recent snapshot metadata for the specified
	// replica.
	GetSnapshot(shardID uint64) (raftpb.Snapshot, error)
	// GetAllSnapshots returns all snapshots known to the LogDB.
	GetAllSnapshots(shardID uint64) ([]raftpb.Snapshot, error)
	// RemoveSnapshot removes the specified snapshot.
	RemoveSnapshot(shardID uint64, index uint64) error
	// RemoveReplicaData removes all LogDB data that belongs to the specified
	// replica.
	RemoveReplicaData(shardID uint64) error
}

LogDB is the interface to be implemented for concrete LogDB types used for saving raft logs and states.

type RaftState

type RaftState struct {
	// State is the Raft state persistent to the disk
	State raftpb.HardState
	// FirstIndex is the index of the first entry to iterate
	FirstIndex uint64
	// EntryCount is the number of entries to iterate
	EntryCount uint64
}

RaftState is the persistent Raft state found in the LogDB.

type WorkerContext

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

WorkerContext is the per worker context owned and used by each raft worker. It contains write batch and buffers that can be reused across iterations.

func (*WorkerContext) Close

func (w *WorkerContext) Close()

func (*WorkerContext) Reset

func (w *WorkerContext) Reset()

Reset resets the worker context so it can be reused.

Jump to

Keyboard shortcuts

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