pg

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 11 Imported by: 0 modules, 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 pg is the PostgreSQL index of the store: repositories, packs, refs, workspaces and op heads.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("pg: not found")
	// ErrGone is a workspace that was deleted.
	ErrGone = errors.New("pg: workspace deleted")
	// ErrClaimLost is a write or claim whose epoch is not the stored one.
	ErrClaimLost = errors.New("pg: claim lost")
	// ErrWorkspaceConflict is a claim whose owner or repo differs from the stored one.
	ErrWorkspaceConflict = errors.New("pg: workspace owner or repo differs")
	// ErrWrongRepo is a grant whose repo is not the repo of the workspace.
	ErrWrongRepo = errors.New("pg: workspace is on another repo")
)

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) error

Migrate applies the embedded migrations that the database lacks, in name order. A lock serializes replicas that start together.

Types

type DB

type DB struct{ Pool *pgxpool.Pool }

func (*DB) AddPack

func (d *DB) AddPack(ctx context.Context, repo store.Repo, packID string, bytes int64) error

AddPack records a pack once. A repeat is a no-op.

func (*DB) Claim

func (d *DB) Claim(ctx context.Context, id string, epoch uint64, owner, repo string) (Workspace, error)

Claim raises the epoch of workspace id to epoch, or creates it. The stored epoch may be higher: the caller compares it with its own.

func (*DB) CreateRepo

func (d *DB) CreateRepo(ctx context.Context, r Repo, repoText, commit string) error

CreateRepo stores r and its ref main at commit in one transaction.

func (*DB) Delete

func (d *DB) Delete(ctx context.Context, id string) error

Delete marks a workspace deleted. It is idempotent, and a missing workspace is not an error.

func (*DB) DeleteRef

func (d *DB) DeleteRef(ctx context.Context, ws string, epoch uint64, repo, name string, expect int64) error

DeleteRef removes a ref when its stored generation is expect and the fence holds.

func (*DB) Flush

func (d *DB) Flush(ctx context.Context, ws string, epoch uint64, generation int64, prev, op, snapshot string) error

Flush is Report for the control plane: the repo comes from the workspace row, which never changes once set.

func (*DB) Live

func (d *DB) Live(ctx context.Context, id string, epoch uint64, repo string) error

Live checks that workspace id is on repo at epoch and not deleted.

func (*DB) OpHeads

func (d *DB) OpHeads(ctx context.Context, ws string) (OpHeads, error)

func (*DB) Packs

func (d *DB) Packs(ctx context.Context, repo store.Repo) ([]store.PackRef, error)

Packs lists the packs of a repo, oldest first.

func (*DB) Ping added in v0.5.0

func (d *DB) Ping(ctx context.Context) error

Ping checks that the database answers.

func (*DB) Ref

func (d *DB) Ref(ctx context.Context, repo, name string) (Ref, error)

func (*DB) Refs

func (d *DB) Refs(ctx context.Context, repo string) ([]Ref, error)

Refs lists the refs of a repo by name.

func (*DB) Repo

func (d *DB) Repo(ctx context.Context, path string) (Repo, error)

func (*DB) Report

func (d *DB) Report(ctx context.Context, ws string, epoch uint64, repo string, generation int64, prev, op, snapshot string) error

Report stores the op and snapshot of a workspace report or flush. generation 0 writes only while the stored op is prev. A lower generation than the stored one is dropped without an error; an equal one writes again. The UPDATE takes the row lock itself: a FOR SHARE guard here would deadlock two concurrent reports.

func (*DB) Repos

func (d *DB) Repos(ctx context.Context) ([]Repo, error)

Repos lists every repository, newest first.

func (*DB) SwapOpHeads

func (d *DB) SwapOpHeads(ctx context.Context, ws string, epoch uint64, repo string, expect int64, heads []string) (OpHeads, error)

SwapOpHeads replaces the head set when the stored generation is expect (0 for the first write) and the fence holds. A lost swap returns *OpHeadsConflict, or ErrClaimLost when the fence fails first.

func (*DB) SwapRef

func (d *DB) SwapRef(ctx context.Context, ws string, epoch uint64, repo, name string, expect int64, sha string) (Ref, error)

SwapRef moves a ref to sha when its stored generation is expect (0 creates the ref) and the fence holds. Every create and update takes a new generation from one sequence, so a deleted and recreated ref never repeats one. ErrClaimLost wins over *RefConflict.

type OpHeads added in v0.5.0

type OpHeads struct {
	Epoch      uint64
	Generation int64
	Heads      []string
}

OpHeads is the head set of the op log of a workspace.

type OpHeadsConflict

type OpHeadsConflict struct{ Current *OpHeads }

OpHeadsConflict is a lost op-heads compare-and-swap. Current is nil when no row exists.

func (*OpHeadsConflict) Error

func (*OpHeadsConflict) Error() string

type Ref added in v0.5.0

type Ref struct {
	Name       string
	Commit     string
	Generation int64
}

Ref is one ref of a repository.

type RefConflict

type RefConflict struct{ Current *Ref }

RefConflict is a lost ref compare-and-swap. Current is nil when the ref is absent.

func (*RefConflict) Error

func (*RefConflict) Error() string

type Repo

type Repo struct {
	Path, Name, Owner string
	CreatedAt         time.Time
}

type Workspace

type Workspace struct {
	Epoch    uint64
	Op       string
	Snapshot string
}

Jump to

Keyboard shortcuts

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