Documentation
¶
Overview ¶
Package pg is the PostgreSQL index of the store: repositories, packs, refs, workspaces and op heads.
Index ¶
- Variables
- func Migrate(ctx context.Context, pool *pgxpool.Pool) error
- type DB
- func (d *DB) AddPack(ctx context.Context, repo store.Repo, packID string, bytes int64) error
- func (d *DB) Claim(ctx context.Context, id string, epoch uint64, owner, repo string) (Workspace, error)
- func (d *DB) CreateRepo(ctx context.Context, r Repo, repoText, commit string) error
- func (d *DB) Delete(ctx context.Context, id string) error
- func (d *DB) DeleteRef(ctx context.Context, ws string, epoch uint64, repo, name string, expect int64) error
- func (d *DB) Flush(ctx context.Context, ws string, epoch uint64, generation int64, ...) error
- func (d *DB) Live(ctx context.Context, id string, epoch uint64, repo string) error
- func (d *DB) OpHeads(ctx context.Context, ws string) (OpHeads, error)
- func (d *DB) Packs(ctx context.Context, repo store.Repo) ([]store.PackRef, error)
- func (d *DB) Ping(ctx context.Context) error
- func (d *DB) Ref(ctx context.Context, repo, name string) (Ref, error)
- func (d *DB) Refs(ctx context.Context, repo string) ([]Ref, error)
- func (d *DB) Repo(ctx context.Context, path string) (Repo, error)
- func (d *DB) Report(ctx context.Context, ws string, epoch uint64, repo string, generation int64, ...) error
- func (d *DB) Repos(ctx context.Context) ([]Repo, error)
- func (d *DB) SwapOpHeads(ctx context.Context, ws string, epoch uint64, repo string, expect int64, ...) (OpHeads, error)
- func (d *DB) SwapRef(ctx context.Context, ws string, epoch uint64, repo, name string, expect int64, ...) (Ref, error)
- type OpHeads
- type OpHeadsConflict
- type Ref
- type RefConflict
- type Repo
- type Workspace
Constants ¶
This section is empty.
Variables ¶
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 ¶
Types ¶
type DB ¶
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 ¶
CreateRepo stores r and its ref main at commit in one transaction.
func (*DB) Delete ¶
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) 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) 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 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 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