Documentation
¶
Overview ¶
Package refstore persists reference records in a SQLite database: name bytes → CBOR record bytes, stored verbatim. It is a dumb KV layer; record validation belongs to the daemon and the reference package.
The database is <dir>/refs.sqlite in WAL mode, so any number of processes may hold a store open at once: readers work from a snapshot and never block, and writers — in this process or another — queue behind one another (SQLite runs one write transaction at a time; a second writer waits up to busyTimeout). The file format is shared with other implementations; see architecture/references.md. Queries are generated by sqlc from queries.sql, and the schema is built by the numbered files in migrations/.
Index ¶
- Variables
- type Record
- type Store
- func (s *Store) All() ([]Record, error)
- func (s *Store) Close() error
- func (s *Store) CompareAndDelete(name string, old key.Key) error
- func (s *Store) CompareAndSwap(name string, old key.Key, record []byte) error
- func (s *Store) Create(name string, record []byte) error
- func (s *Store) Delete(name string) error
- func (s *Store) Get(name string) ([]byte, error)
- func (s *Store) Put(name string, record []byte) error
- func (s *Store) PutBatch(records []Record) (err error)
- func (s *Store) Wipe() error
Constants ¶
This section is empty.
Variables ¶
var ErrConflict = errors.New("refstore: reference is not at the expected key")
ErrConflict is returned by the optimistic writes when the reference is not in the state the caller expected: for Create it exists, for the compare forms it points at another key. Nothing was changed; the caller re-reads and decides.
var ErrNotFound = errors.New("refstore: reference not found")
ErrNotFound is returned by Get, Delete and the compare forms for an absent name.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite-backed name→record map. It is safe for concurrent use, by goroutines and by processes. Readers (Get, All) never block; writes are serialized in-process by writeMu, so they queue on the mutex rather than polling SQLite's file lock, and across processes by SQLite itself.
func Open ¶
Open opens (creating if missing) the refs database in dir. sync selects the write durability, matching the daemon's --sync flag. A Pebble store left in dir by an earlier release is imported first; see migrate.go.
func (*Store) CompareAndDelete ¶ added in v0.0.10
CompareAndDelete removes name only if it currently points at old, with CompareAndSwap's errors.
func (*Store) CompareAndSwap ¶ added in v0.0.10
CompareAndSwap stores record under name only if the reference currently points at old — the move from one key to the next that must not overwrite somebody else's move. It returns ErrNotFound if the reference does not exist and ErrConflict if it points elsewhere. The expectation is the key, not the record bytes: a rewrite that kept the key does not invalidate it. record is stored verbatim, as by Put.
func (*Store) Create ¶ added in v0.0.10
Create stores record under name only if no such reference exists, and returns ErrConflict if one does.
func (*Store) Delete ¶
Delete removes name, or returns ErrNotFound if absent. The check is the statement's own row count, so concurrent Deletes of the same name — from any process — report ErrNotFound to all but one caller.