state

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
var ErrQueueFull = errors.New("state: queue is full")

Functions

This section is empty.

Types

type QueueEntry

type QueueEntry struct {
	ID        int64
	CreatedAt time.Time
	Value     []byte
}

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) Close

func (s *SqliteStore) Close() error

Close implements Store.

func (*SqliteStore) Enqueue

func (s *SqliteStore) Enqueue(queue string, value []byte, limit int) (int64, error)

Enqueue appends value if queue has fewer than limit pending entries.

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.

func (*SqliteStore) QueueLen

func (s *SqliteStore) QueueLen(queue string) (int, error)

QueueLen returns the number of unacknowledged entries in queue.

func (*SqliteStore) Set

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

Set implements Store.

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.

Jump to

Keyboard shortcuts

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