Documentation
¶
Overview ¶
Package state provides small persistent key/value storage that plugins can use to survive a restart. The motivating case is an input plugin's chainsync cursor: without it, a restart re-syncs from genesis or whatever intersect point is configured, instead of resuming from where it left off.
Values are opaque bytes; callers own their own encoding (JSON, CBOR, etc). Keys are chosen by the caller, so a single store can be shared by multiple plugins as long as they use distinct keys.
Index ¶
- Variables
- type QueueEntry
- type QueueStore
- type SqliteStore
- func (s *SqliteStore) Ack(queue string, id int64) error
- func (s *SqliteStore) Close() error
- func (s *SqliteStore) Enqueue(queue string, value []byte, limit int) (int64, error)
- func (s *SqliteStore) Get(key string) ([]byte, bool, error)
- func (s *SqliteStore) Peek(queue string) (QueueEntry, bool, error)
- func (s *SqliteStore) QueueLen(queue string) (int, error)
- func (s *SqliteStore) Set(key string, value []byte) error
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrQueueFull = errors.New("state: queue is full")
Functions ¶
This section is empty.
Types ¶
type QueueEntry ¶
QueueEntry is a persistently ordered item awaiting acknowledgement.
type QueueStore ¶
type QueueStore interface {
Enqueue(queue string, value []byte, limit int) (int64, error)
Peek(queue string) (QueueEntry, bool, error)
Ack(queue string, id int64) error
QueueLen(queue string) (int, error)
}
QueueStore supports bounded append, ordered replay, and explicit acknowledgement.
type SqliteStore ¶
type SqliteStore struct {
// contains filtered or unexported fields
}
SqliteStore is a Store backed by a SQLite database file.
func NewSqliteStore ¶
func NewSqliteStore(path string) (*SqliteStore, error)
NewSqliteStore opens (creating if necessary) a SQLite database at path and ensures its schema exists. Use ":memory:" for a store scoped to the process, which is useful in tests.
func (*SqliteStore) Ack ¶
func (s *SqliteStore) Ack(queue string, id int64) error
Ack removes one previously delivered entry.
func (*SqliteStore) Get ¶
func (s *SqliteStore) Get(key string) ([]byte, bool, error)
Get implements Store.
func (*SqliteStore) Peek ¶
func (s *SqliteStore) Peek(queue string) (QueueEntry, bool, error)
Peek returns the oldest pending entry in queue.
type Store ¶
type Store interface {
// Get returns the value stored for key. The second return value
// reports whether a value was found; false with a nil error means
// no value has ever been saved for key.
Get(key string) ([]byte, bool, error)
// Set persists value for key, overwriting any previously stored
// value.
Set(key string, value []byte) error
// Close releases any resources (file handles, database connections)
// held by the store. The store must not be used afterward.
Close() error
}
Store is a minimal persistent key/value store. Implementations must be safe for concurrent use.