storage

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerStorage

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

BadgerStorage implements BadgerDB-based persistent storage

func NewBadgerStorage

func NewBadgerStorage(config BadgerStorageConfig, logger forge.Logger) (*BadgerStorage, error)

NewBadgerStorage creates a new BadgerDB storage

func (*BadgerStorage) Backup

func (bs *BadgerStorage) Backup(writer interface{}) error

Backup creates a backup of the database

func (*BadgerStorage) Compact

func (bs *BadgerStorage) Compact() error

Compact triggers manual compaction

func (*BadgerStorage) Delete

func (bs *BadgerStorage) Delete(key []byte) error

Delete deletes a key

func (*BadgerStorage) Exists

func (bs *BadgerStorage) Exists(key []byte) (bool, error)

Exists checks if a key exists

func (*BadgerStorage) Get

func (bs *BadgerStorage) Get(key []byte) ([]byte, error)

Get retrieves a value by key

func (*BadgerStorage) GetRange

func (bs *BadgerStorage) GetRange(start, end []byte) ([]internal.KeyValue, error)

GetRange retrieves a range of key-value pairs

func (*BadgerStorage) Iterate

func (bs *BadgerStorage) Iterate(prefix []byte, fn func(key, value []byte) error) error

Iterate iterates over all key-value pairs with a given prefix

func (*BadgerStorage) ListKeys

func (bs *BadgerStorage) ListKeys(prefix []byte) ([][]byte, error)

ListKeys lists all keys with a given prefix

func (*BadgerStorage) RunGC

func (bs *BadgerStorage) RunGC(discardRatio float64) error

RunGC runs garbage collection

func (*BadgerStorage) Set

func (bs *BadgerStorage) Set(key, value []byte) error

Set stores a key-value pair

func (*BadgerStorage) Size

func (bs *BadgerStorage) Size() (int64, error)

Size returns the approximate size of the database in bytes

func (*BadgerStorage) Start

func (bs *BadgerStorage) Start(ctx context.Context) error

Start starts the storage backend

func (*BadgerStorage) Stop

func (bs *BadgerStorage) Stop(ctx context.Context) error

Stop stops the storage backend

func (*BadgerStorage) WriteBatch

func (bs *BadgerStorage) WriteBatch(ops []internal.BatchOp) error

WriteBatch writes a batch of operations atomically

type BadgerStorageConfig

type BadgerStorageConfig struct {
	Path               string
	SyncWrites         bool
	ValueLogFileSize   int64
	NumVersionsToKeep  int
	NumCompactors      int
	MemTableSize       int64
	BaseTableSize      int64
	BloomFalsePositive float64
	BlockSize          int
	BlockCacheSize     int64
	IndexCacheSize     int64
	NumLevelZeroTables int
	NumLevelZeroStalls int
	ValueThreshold     int
	NumMemtables       int
	DetectConflicts    bool
	CompactL0OnClose   bool
}

BadgerStorageConfig contains BadgerDB storage configuration

type BoltDBStorage

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

BoltDBStorage implements BoltDB-based persistent storage

func NewBoltDBStorage

func NewBoltDBStorage(config BoltDBStorageConfig, logger forge.Logger) (*BoltDBStorage, error)

NewBoltDBStorage creates a new BoltDB storage

func (*BoltDBStorage) Backup

func (bs *BoltDBStorage) Backup(path string) error

Backup creates a backup of the database

func (*BoltDBStorage) Compact

func (bs *BoltDBStorage) Compact() error

Compact triggers manual compaction (BoltDB compacts automatically)

func (*BoltDBStorage) Delete

func (bs *BoltDBStorage) Delete(key []byte) error

Delete deletes a key

func (*BoltDBStorage) Exists

func (bs *BoltDBStorage) Exists(key []byte) (bool, error)

Exists checks if a key exists

func (*BoltDBStorage) Get

func (bs *BoltDBStorage) Get(key []byte) ([]byte, error)

Get retrieves a value by key

func (*BoltDBStorage) GetRange

func (bs *BoltDBStorage) GetRange(start, end []byte) ([]internal.KeyValue, error)

GetRange retrieves a range of key-value pairs

func (*BoltDBStorage) Iterate

func (bs *BoltDBStorage) Iterate(prefix []byte, fn func(key, value []byte) error) error

Iterate iterates over all key-value pairs with a given prefix

func (*BoltDBStorage) ListKeys

func (bs *BoltDBStorage) ListKeys(prefix []byte) ([][]byte, error)

ListKeys lists all keys with a given prefix

func (*BoltDBStorage) Set

func (bs *BoltDBStorage) Set(key, value []byte) error

Set stores a key-value pair

func (*BoltDBStorage) Size

func (bs *BoltDBStorage) Size() (int64, error)

Size returns the size of the database in bytes

func (*BoltDBStorage) Start

func (bs *BoltDBStorage) Start(ctx context.Context) error

Start starts the storage backend

func (*BoltDBStorage) Stats

func (bs *BoltDBStorage) Stats() map[string]interface{}

Stats returns database statistics

func (*BoltDBStorage) Stop

func (bs *BoltDBStorage) Stop(ctx context.Context) error

Stop stops the storage backend

func (*BoltDBStorage) WriteBatch

func (bs *BoltDBStorage) WriteBatch(ops []internal.BatchOp) error

WriteBatch writes a batch of operations atomically

type BoltDBStorageConfig

type BoltDBStorageConfig struct {
	Path       string
	BucketName string
	Timeout    time.Duration
	NoSync     bool
	NoGrowSync bool
	ReadOnly   bool
	MmapFlags  int
}

BoltDBStorageConfig contains BoltDB storage configuration

type MemoryStorage

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

MemoryStorage implements an in-memory storage backend

func NewMemoryStorage

func NewMemoryStorage(config MemoryStorageConfig, logger forge.Logger) *MemoryStorage

NewMemoryStorage creates a new memory storage

func (*MemoryStorage) Batch

func (s *MemoryStorage) Batch(ops []internal.BatchOp) error

Batch executes a batch of operations

func (*MemoryStorage) Clear

func (s *MemoryStorage) Clear() error

Clear removes all stored data

func (*MemoryStorage) Close

func (s *MemoryStorage) Close() error

Close closes the storage backend

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete(key []byte) error

Delete deletes a key

func (*MemoryStorage) Exists

func (s *MemoryStorage) Exists(key []byte) (bool, error)

Exists checks if a key exists

func (*MemoryStorage) Get

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

Get retrieves a value by key

func (*MemoryStorage) GetRange

func (s *MemoryStorage) GetRange(start, end []byte) ([]internal.KeyValue, error)

GetRange retrieves a range of key-value pairs

func (*MemoryStorage) Iterate

func (s *MemoryStorage) Iterate(prefix []byte, fn func(key, value []byte) error) error

Iterate iterates over all key-value pairs

func (*MemoryStorage) ListKeys

func (s *MemoryStorage) ListKeys(prefix []byte) ([][]byte, error)

ListKeys lists all keys with a given prefix

func (*MemoryStorage) Set

func (s *MemoryStorage) Set(key, value []byte) error

Set stores a key-value pair

func (*MemoryStorage) Size

func (s *MemoryStorage) Size() int

Size returns the number of stored keys

func (*MemoryStorage) Start

func (s *MemoryStorage) Start(ctx context.Context) error

Start starts the storage backend

func (*MemoryStorage) Stop

func (s *MemoryStorage) Stop(ctx context.Context) error

Stop stops the storage backend

func (*MemoryStorage) WriteBatch

func (s *MemoryStorage) WriteBatch(ops []internal.BatchOp) error

WriteBatch writes a batch of operations atomically

type MemoryStorageConfig

type MemoryStorageConfig struct {
	InitialCapacity int
}

MemoryStorageConfig contains configuration for memory storage

type WAL

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

WAL implements Write-Ahead Logging for consensus operations

func NewWAL

func NewWAL(nodeID string, config WALConfig, logger forge.Logger) (*WAL, error)

NewWAL creates a new WAL

func (*WAL) Close

func (w *WAL) Close() error

Close closes the WAL

func (*WAL) GetStatistics

func (w *WAL) GetStatistics() WALStatistics

GetStatistics returns WAL statistics

func (*WAL) Read

func (w *WAL) Read(ctx context.Context, startIndex uint64) ([]*WALEntry, error)

Read reads entries from the WAL

func (*WAL) Sync

func (w *WAL) Sync() error

Sync syncs the WAL to disk

func (*WAL) Truncate

func (w *WAL) Truncate(ctx context.Context, index uint64) error

Truncate truncates the WAL up to the given index

func (*WAL) Write

func (w *WAL) Write(ctx context.Context, entry *WALEntry) error

Write writes an entry to the WAL

type WALConfig

type WALConfig struct {
	Dir               string
	MaxFileSize       int64
	SyncInterval      time.Duration
	EnableCompression bool
	EnableChecksum    bool
}

WALConfig contains WAL configuration

type WALEntry

type WALEntry struct {
	Type      WALEntryType
	Index     uint64
	Term      uint64
	Data      []byte
	Timestamp time.Time
	Checksum  uint32
}

WALEntry represents a WAL entry

type WALEntryType

type WALEntryType uint8

WALEntryType represents the type of WAL entry

const (
	// WALEntryTypeLog log entry
	WALEntryTypeLog WALEntryType = 1
	// WALEntryTypeMeta metadata entry
	WALEntryTypeMeta WALEntryType = 2
	// WALEntryTypeSnapshot snapshot entry
	WALEntryTypeSnapshot WALEntryType = 3
	// WALEntryTypeCheckpoint checkpoint entry
	WALEntryTypeCheckpoint WALEntryType = 4
)

type WALStatistics

type WALStatistics struct {
	TotalWrites   int64
	TotalReads    int64
	BytesWritten  int64
	BytesRead     int64
	SyncCount     int64
	RotationCount int64
	LastSync      time.Time
	LastRotation  time.Time
}

WALStatistics contains WAL statistics

Jump to

Keyboard shortcuts

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