refstore

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: GPL-3.0, LGPL-3.0 Imports: 22 Imported by: 7

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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 Record

type Record struct {
	Name string
	Data []byte
}

Record is one (name, record-bytes) pair from All.

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

func Open(dir string, sync bool) (*Store, error)

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

func (s *Store) All() ([]Record, error)

All returns every record in lexicographic name order, from one snapshot.

func (*Store) Close

func (s *Store) Close() error

Close closes the database.

func (*Store) CompareAndDelete added in v0.0.10

func (s *Store) CompareAndDelete(name string, old key.Key) error

CompareAndDelete removes name only if it currently points at old, with CompareAndSwap's errors.

func (*Store) CompareAndSwap added in v0.0.10

func (s *Store) CompareAndSwap(name string, old key.Key, record []byte) error

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

func (s *Store) Create(name string, record []byte) error

Create stores record under name only if no such reference exists, and returns ErrConflict if one does.

func (*Store) Delete

func (s *Store) Delete(name string) error

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.

func (*Store) Get

func (s *Store) Get(name string) ([]byte, error)

Get returns the record stored under name, or ErrNotFound.

func (*Store) Put

func (s *Store) Put(name string, record []byte) error

Put stores record under name, overwriting unconditionally.

func (*Store) PutBatch added in v0.0.5

func (s *Store) PutBatch(records []Record) (err error)

PutBatch publishes records atomically, using the configured write durability. When names repeat, the last record wins. An empty batch changes nothing.

func (*Store) Wipe

func (s *Store) Wipe() error

Wipe deletes every record (the store-wipe operation).

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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