storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT, MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int

Level is the durability level of the storage

const (
	Low Level = iota
	Medium
	High
)

type MemoryStore

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

MemoryStore is an in-memory implementation of the LogStore interface. It can optionally persist the logs to disk.

func NewStore

func NewStore(path string, durability Level, logger *slog.Logger) (*MemoryStore, error)

NewStore creates a new MemoryStore

func (*MemoryStore) Close

func (s *MemoryStore) Close() error

Close closes the store

func (*MemoryStore) DeleteRange

func (s *MemoryStore) DeleteRange(min, max uint64) (err error)

func (*MemoryStore) FirstIndex

func (s *MemoryStore) FirstIndex() (uint64, error)

FirstIndex returns the first index written. 0 for no entries.

func (*MemoryStore) Get

func (s *MemoryStore) Get(key []byte) ([]byte, error)

Get is used to get a value for a given key

func (*MemoryStore) GetLog

func (s *MemoryStore) GetLog(index uint64) (*log.LogEntry, error)

GetLog gets a log entry at a given index.

func (*MemoryStore) GetUint64

func (s *MemoryStore) GetUint64(key []byte) (uint64, error)

GetUint64 is used to get a value for a given key

func (*MemoryStore) LastIndex

func (s *MemoryStore) LastIndex() (uint64, error)

LastIndex returns the last index written. 0 for no entries.

func (*MemoryStore) Set

func (s *MemoryStore) Set(key, val []byte) error

Set is used to set a key value pair

func (*MemoryStore) SetUint64

func (s *MemoryStore) SetUint64(key []byte, val uint64) error

SetUint64 is used to set a key value pair

func (*MemoryStore) Shrink

func (s *MemoryStore) Shrink() error

Shrink is used to shrink the storage it is used to shrink the storage when the size of the file is greater than minShrinkSize The storage is shrunk by creating a new file and copying only the logs that are in memory to the new file. The new file is then renamed to the old file.

func (*MemoryStore) StoreLogs

func (s *MemoryStore) StoreLogs(logs []*log.LogEntry) error

StoreLogs is used to store a set of raft logs

type Store

type Store 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.LogEntry, error)

	// StoreLogs stores multiple log entries. By default the logs stored may not be contiguous with previous logs (i.e. may have a gap in Index since the last log written). If an implementation can't tolerate this it may optionally implement `MonotonicLogStore` to indicate that this is not allowed. This changes Raft's behaviour after restoring a user snapshot to remove all previous logs instead of relying on a "gap" to signal the discontinuity between logs before the snapshot and logs after.
	StoreLogs(logs []*log.LogEntry) error

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

	// Set is used to set a key value pair
	Set(key []byte, val []byte) error

	// Get returns the value for key, or an error.
	Get(key []byte) ([]byte, error)

	// SetUint64 is used to set a key value pair
	SetUint64(key []byte, val uint64) error

	// GetUint64 returns the value for key, or an error.
	GetUint64(key []byte) (uint64, error)
}

Store is an interface that is used to store the logs

Jump to

Keyboard shortcuts

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