Documentation
¶
Overview ¶
Package postgres is the Postgres adapter for the ports a stateless deployment needs (docs/adr/0008): store.ManifestStore, store.OperationalStore, store.BundleStore and store.DocStore, over one database through pgx, a pure-Go driver, so the binary stays CGO_ENABLED=0. There is no store.StateStore: every row is live.
Schema migrations are embedded and applied on Open, under an advisory lock, so replicas starting together apply each one once.
Index ¶
- func Open(ctx context.Context, url string) (*pgxpool.Pool, error)
- type BundleStore
- type DocStore
- func (d *DocStore) Append(ctx context.Context, docID string, data []byte) (int64, error)
- func (d *DocStore) Compact(ctx context.Context, docID string, snapshot []byte, upTo int64) error
- func (d *DocStore) Create(ctx context.Context, kind, id, docID string, snapshot []byte) (string, bool, error)
- func (d *DocStore) DocumentFor(ctx context.Context, kind, id string) (string, error)
- func (d *DocStore) Load(ctx context.Context, docID string) ([]byte, []store.Chunk, error)
- func (d *DocStore) ManifestFor(ctx context.Context, docID string) (string, string, error)
- func (d *DocStore) Since(ctx context.Context, docID string, after int64) ([]store.Chunk, error)
- type ManifestStore
- func (m *ManifestStore) Counts(ctx context.Context) (map[string]int, error)
- func (m *ManifestStore) Exclude(ctx context.Context, kind, id, name, reason, operator string) error
- func (m *ManifestStore) GetCurrent(ctx context.Context, kind, id string) (store.Version, bool, error)
- func (m *ManifestStore) GetVersion(ctx context.Context, kind, id string, number int) (store.Version, bool, error)
- func (m *ManifestStore) GetWorking(ctx context.Context, kind, id string) ([]byte, bool, error)
- func (m *ManifestStore) IndexReferences(ctx context.Context, fromKind, fromID string, refs []store.Ref) error
- func (m *ManifestStore) ListAllVersions(ctx context.Context, limit int, cursor string) ([]store.Version, string, error)
- func (m *ManifestStore) ListExcluded(ctx context.Context) ([]store.Exclusion, error)
- func (m *ManifestStore) ListIDs(ctx context.Context, kind string) ([]string, error)
- func (m *ManifestStore) ListReferencedBy(ctx context.Context, fromKind, fromID string) ([]store.Ref, error)
- func (m *ManifestStore) ListReferencing(ctx context.Context, toKind, toID string) ([]store.Summary, error)
- func (m *ManifestStore) ListSummaries(ctx context.Context, kind, query string, refs []store.RefFilter) ([]store.Summary, error)
- func (m *ManifestStore) ListVersions(ctx context.Context, kind, id string) ([]store.Version, error)
- func (m *ManifestStore) PutVersion(ctx context.Context, v store.Version) error
- func (m *ManifestStore) PutWorking(ctx context.Context, kind, id string, yamlBytes []byte) error
- func (m *ManifestStore) Recover(ctx context.Context, kind, id, reason, operator string) error
- func (m *ManifestStore) WithinTransaction(ctx context.Context, ...) error
- type OperationalStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BundleStore ¶
type BundleStore struct {
// contains filtered or unexported fields
}
BundleStore keeps handoff bundles as rows of bytes. A bundle is a few rendered documents, small enough that a database is a fine home; an object store is the adapter to write when that stops being true.
func NewBundleStore ¶
func NewBundleStore(pool *pgxpool.Pool) *BundleStore
NewBundleStore returns a BundleStore over a pool Open returned.
func (*BundleStore) File ¶
File returns one file of a stored bundle, by the location PutBundle returned and the file's name.
func (*BundleStore) PutBundle ¶
func (b *BundleStore) PutBundle(ctx context.Context, projectID string, version int, files map[string][]byte) (store.Bundle, error)
PutBundle stores files under "handoff/<project>/v<n>", the location the other adapters use, replacing whatever was there, in one transaction.
type DocStore ¶
type DocStore struct {
// contains filtered or unexported fields
}
DocStore is the Postgres adapter for store.DocStore: one row per document holding its snapshot, and one row per chunk appended since.
func NewDocStore ¶
NewDocStore returns a DocStore over a pool Open returned.
func (*DocStore) Append ¶
Append takes the next sequence number under the document row's lock and stores the chunk in the same transaction, so concurrent appenders on any replica get distinct, rising numbers, and a number is never handed out for a chunk that was not stored.
func (*DocStore) Compact ¶
Compact replaces the snapshot and drops the chunks it includes, under the document row's lock. Chunks after upTo are untouched, whoever appends them meanwhile. A compaction older than the one already stored changes nothing: its snapshot lacks chunks that are gone.
func (*DocStore) Create ¶
func (d *DocStore) Create(ctx context.Context, kind, id, docID string, snapshot []byte) (string, bool, error)
Create inserts the document unless the manifest has one. When two replicas race, the unique key on the manifest makes the second insert wait for the first and then do nothing; the second then reads the winner's id, which its own read can see once the first has committed.
func (*DocStore) DocumentFor ¶
DocumentFor returns the id of a manifest's document.
func (*DocStore) Load ¶
Load reads the snapshot and the chunks in one repeatable-read transaction, so a compaction committing in between cannot leave it with a snapshot that lacks chunks it no longer sees.
func (*DocStore) ManifestFor ¶
ManifestFor returns the manifest a document belongs to.
type ManifestStore ¶
type ManifestStore struct {
// contains filtered or unexported fields
}
ManifestStore is the Postgres adapter for store.ManifestStore. Construct it with NewManifestStore.
func NewManifestStore ¶
func NewManifestStore(pool *pgxpool.Pool) *ManifestStore
NewManifestStore returns a ManifestStore over a pool Open returned.
func (*ManifestStore) Exclude ¶
func (m *ManifestStore) Exclude(ctx context.Context, kind, id, name, reason, operator string) error
Exclude records that a manifest is excluded. There is no state manifest to remove it from; the record is what an interface reads.
func (*ManifestStore) GetCurrent ¶
func (m *ManifestStore) GetCurrent(ctx context.Context, kind, id string) (store.Version, bool, error)
GetCurrent returns the working copy when there is one, as version 0, and the highest version otherwise: the same answer the SQLite adapter gives.
func (*ManifestStore) GetVersion ¶
func (m *ManifestStore) GetVersion(ctx context.Context, kind, id string, number int) (store.Version, bool, error)
GetVersion returns one version, if it exists.
func (*ManifestStore) GetWorking ¶
GetWorking returns a manifest's working copy, if it has one.
func (*ManifestStore) IndexReferences ¶
func (m *ManifestStore) IndexReferences(ctx context.Context, fromKind, fromID string, refs []store.Ref) error
IndexReferences replaces a manifest's recorded outgoing references.
func (*ManifestStore) ListAllVersions ¶
func (m *ManifestStore) ListAllVersions(ctx context.Context, limit int, cursor string) ([]store.Version, string, error)
ListAllVersions pages through every version, newest first. The cursor is the last row's sort key, "on,kind,id,number", the format the other adapters use.
func (*ManifestStore) ListExcluded ¶
ListExcluded returns every exclusion, newest first.
func (*ManifestStore) ListIDs ¶
ListIDs returns the id of every manifest of a kind, versioned or only saved as a working copy.
func (*ManifestStore) ListReferencedBy ¶
func (m *ManifestStore) ListReferencedBy(ctx context.Context, fromKind, fromID string) ([]store.Ref, error)
ListReferencedBy returns a manifest's recorded outgoing references.
func (*ManifestStore) ListReferencing ¶
func (m *ManifestStore) ListReferencing(ctx context.Context, toKind, toID string) ([]store.Summary, error)
ListReferencing returns the current summary of every manifest that references toKind/toID.
func (*ManifestStore) ListSummaries ¶
func (m *ManifestStore) ListSummaries(ctx context.Context, kind, query string, refs []store.RefFilter) ([]store.Summary, error)
ListSummaries returns the current content of every manifest of a kind that matches the query and every reference filter.
func (*ManifestStore) ListVersions ¶
ListVersions returns every version of a manifest, oldest first.
func (*ManifestStore) PutVersion ¶
PutVersion inserts v only when its number is one more than the highest recorded, in one statement. Two writers racing for the same number both pass that test, and the primary key refuses the second.
func (*ManifestStore) PutWorking ¶
PutWorking replaces a manifest's working copy.
func (*ManifestStore) Recover ¶
func (m *ManifestStore) Recover(ctx context.Context, kind, id, reason, operator string) error
Recover removes an exclusion record.
func (*ManifestStore) WithinTransaction ¶
func (m *ManifestStore) WithinTransaction(ctx context.Context, fn func(ctx context.Context, tx store.ManifestStore) error) error
WithinTransaction runs fn against a ManifestStore inside one transaction, committed when fn returns nil.
type OperationalStore ¶
type OperationalStore struct {
// contains filtered or unexported fields
}
OperationalStore is the Postgres adapter for store.OperationalStore.
func NewOperationalStore ¶
func NewOperationalStore(pool *pgxpool.Pool) *OperationalStore
NewOperationalStore returns an OperationalStore over a pool Open returned.
func (*OperationalStore) ListProjectStateHistory ¶
func (o *OperationalStore) ListProjectStateHistory(ctx context.Context, projectID string) ([]store.ProjectStateEntry, error)
ListProjectStateHistory returns a project's history, oldest first; rows written at the same instant keep the order they were written in.
func (*OperationalStore) PutProjectStateTransition ¶
func (o *OperationalStore) PutProjectStateTransition(ctx context.Context, e store.ProjectStateEntry) error
PutProjectStateTransition appends one row to a project's history.