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 ¶
- Variables
- type BoltStore
- func (b *BoltStore) Close() error
- func (b *BoltStore) Delete(key []byte) error
- func (b *BoltStore) Flush() error
- func (b *BoltStore) Get(key []byte) ([]byte, error)
- func (b *BoltStore) Put(key, value []byte) error
- func (b *BoltStore) Range(from, to []byte) Iterator
- func (b *BoltStore) Restore(snapshot []byte) error
- func (b *BoltStore) Snapshot() ([]byte, error)
- type Iterator
- type MemoryStore
- func (m *MemoryStore) Close() error
- func (m *MemoryStore) Delete(key []byte) error
- func (m *MemoryStore) Flush() error
- func (m *MemoryStore) Get(key []byte) ([]byte, error)
- func (m *MemoryStore) Put(key, value []byte) error
- func (m *MemoryStore) Range(from, to []byte) Iterator
- func (m *MemoryStore) Restore(data []byte) error
- func (m *MemoryStore) Snapshot() ([]byte, error)
- type StateStore
Constants ¶
This section is empty.
Variables ¶
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 ¶
NewBoltStore creates a new BoltDB-backed state store at the given path.
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) 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.