state

package
v0.0.0-...-2c2f5ba Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package state provides the StateStore interface and implementations for managing processor state. It includes an in-memory store and a BoltDB-backed persistent store suitable for production use.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("state: key not found")

ErrNotFound is returned when a key is not present in the store.

Functions

This section is empty.

Types

type BoltStore

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

BoltStore is a persistent StateStore backed by BoltDB.

func NewBoltStore

func NewBoltStore(dir string) (*BoltStore, error)

NewBoltStore creates a new BoltDB-backed state store at the given path.

func (*BoltStore) Close

func (b *BoltStore) Close() error

Close closes the database.

func (*BoltStore) Delete

func (b *BoltStore) Delete(key []byte) error

Delete removes a key from the store.

func (*BoltStore) Flush

func (b *BoltStore) Flush() error

Flush syncs the database to disk.

func (*BoltStore) Get

func (b *BoltStore) Get(key []byte) ([]byte, error)

Get retrieves the value for the given key.

func (*BoltStore) Put

func (b *BoltStore) Put(key, value []byte) error

Put stores a key-value pair.

func (*BoltStore) Range

func (b *BoltStore) Range(from, to []byte) Iterator

Range returns an iterator over keys in [from, to).

func (*BoltStore) Restore

func (b *BoltStore) Restore(snapshot []byte) error

Restore rebuilds the store from a snapshot.

func (*BoltStore) Snapshot

func (b *BoltStore) Snapshot() ([]byte, error)

Snapshot serializes the entire store for checkpointing.

type Iterator

type Iterator interface {
	// Next advances the iterator. Returns false when exhausted.
	Next() bool
	// Key returns the current key.
	Key() []byte
	// Value returns the current value.
	Value() []byte
	// Close releases resources held by the iterator.
	Close() error
}

Iterator allows scanning over a range of key-value pairs.

type MemoryStore

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

MemoryStore is a thread-safe in-memory StateStore backed by a sorted map.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates a new in-memory state store.

func (*MemoryStore) Close

func (m *MemoryStore) Close() error

Close clears the store data.

func (*MemoryStore) Delete

func (m *MemoryStore) Delete(key []byte) error

Delete removes a key from the store.

func (*MemoryStore) Flush

func (m *MemoryStore) Flush() error

Flush is a no-op for in-memory store.

func (*MemoryStore) Get

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

Get retrieves the value for the given key.

func (*MemoryStore) Put

func (m *MemoryStore) Put(key, value []byte) error

Put stores a key-value pair.

func (*MemoryStore) Range

func (m *MemoryStore) Range(from, to []byte) Iterator

Range returns an iterator over keys in the range [from, to). Pass nil for from or to for an unbounded range.

func (*MemoryStore) Restore

func (m *MemoryStore) Restore(data []byte) error

Restore rebuilds the store from a gob-encoded snapshot.

func (*MemoryStore) Snapshot

func (m *MemoryStore) Snapshot() ([]byte, error)

Snapshot serializes the entire store using gob encoding.

type StateStore

type StateStore interface {
	// Get retrieves the value for a key. Returns ErrNotFound if absent.
	Get(key []byte) ([]byte, error)
	// Put stores a key-value pair.
	Put(key, value []byte) error
	// Delete removes a key. No error if the key does not exist.
	Delete(key []byte) error
	// Range returns an iterator over keys in [from, to). Pass nil for unbounded.
	Range(from, to []byte) Iterator
	// Flush persists any buffered writes.
	Flush() error
	// Snapshot returns a serialized snapshot of the entire store for checkpointing.
	Snapshot() ([]byte, error)
	// Restore rebuilds the store from a snapshot.
	Restore(data []byte) error
	// Close releases all resources.
	Close() error
}

StateStore is the interface for key-value state storage used by processors.

Jump to

Keyboard shortcuts

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