sitestore

package
v1.167.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 12 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 sitestore is the PostgreSQL store of sites, releases and domains (#2518).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCleanupRunning is a publish refused because a sweep held the site's
	// stored files for longer than a publish waits.
	ErrCleanupRunning = errors.New("the release sweep is removing this site's unused stored files; publish again in a few minutes")
	// ErrHoldExpired is a publish whose hold on the site's stored files ran
	// out before its release was recorded: a sweep may have run since, so the
	// release is not recorded.
	ErrHoldExpired = errors.New("the publish took longer than its hold on the site's stored files allows, so it was not recorded; publish again")
)

Functions

func NewJobID added in v1.156.0

func NewJobID() string

NewJobID is a job's id.

func NewReleaseID

func NewReleaseID() string

NewReleaseID is a release's id.

func NewSiteID

func NewSiteID() string

NewSiteID is a site's id.

func WithHold added in v1.159.0

func WithHold(ctx context.Context, h *Hold) context.Context

WithHold carries a publish's upload hold on its context: storing a file renews it (HoldOf(ctx).Renew), and RecordRelease checks it is still held in the transaction that records the release.

Types

type Hold added in v1.159.0

type Hold struct {
	// contains filtered or unexported fields
}

Hold is one hold on a site's stored objects. A nil Hold holds nothing, and its methods do nothing, which is what a store without holds hands back.

func HoldOf added in v1.159.0

func HoldOf(ctx context.Context) *Hold

HoldOf is the hold a context carries, nil for none.

func (*Hold) Release added in v1.159.0

func (h *Hold) Release(ctx context.Context)

Release ends a hold. It is best effort: a hold left behind expires.

func (*Hold) Renew added in v1.159.0

func (h *Hold) Renew(ctx context.Context) error

Renew extends a live hold once its last renewal is old enough, and is ErrHoldExpired when the hold has run out: the work it covered must stop, since the other kind may have been taken since. Safe from many goroutines.

type PruneResult added in v1.159.0

type PruneResult struct {
	// Skipped is true when a publish or copy job was running or a publish
	// held the site's stored files, so the site was left for the next sweep.
	Skipped bool
	// Releases is the numbers of the releases pruned.
	Releases []int
	// Rewritten is how many kept releases were rewritten so that none still
	// reads its files through a pruned one.
	Rewritten int
	// Objects is each object no kept release names: one per digest for a file
	// stored by digest, one per path for a file stored under a release's own
	// prefix.
	Objects []site.File
	// Bytes is what the objects and their compressed forms hold.
	Bytes int64
}

PruneResult is what a sweep of one site did, or in report mode would do.

type SiteRef added in v1.159.0

type SiteRef struct {
	ID   string
	Name string
}

SiteRef names a site for a sweep.

type Store

type Store struct {

	// KeepDefault is the deployment's release limit in force (#2602); nil is
	// siteconfig.DefaultKeepReleases.
	KeepDefault func() int
	// contains filtered or unexported fields
}

Store is the PostgreSQL store.

func New

func New(db *sql.DB) *Store

New builds the store over db.

func (*Store) ActiveJobs added in v1.156.0

func (s *Store) ActiveJobs(ctx context.Context, siteID string) ([]site.Job, error)

ActiveJobs lists a site's running jobs, newest first.

func (*Store) AddDomain

func (s *Store) AddDomain(ctx context.Context, d *site.Domain) error

AddDomain records a hostname, which routes at once.

func (*Store) ApplicationHosts

func (s *Store) ApplicationHosts(ctx context.Context, applicationID, pagesDomain string) ([]string, error)

ApplicationHosts lists the hostnames of the site environments an application holds as parts: each added domain, and the site's own address under pagesDomain where the part is its default environment.

func (*Store) Create

func (s *Store) Create(ctx context.Context, st *site.Site) error

Create writes a site and the environments it names.

func (*Store) CreateJob added in v1.156.0

func (s *Store) CreateJob(ctx context.Context, j *site.Job) error

CreateJob records a job as running.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes a site, its releases, environments and domains.

func (*Store) Deployments

func (s *Store) Deployments(ctx context.Context, siteID, environment string, limit int) ([]site.Deployment, error)

Deployments lists an environment's moves, newest first; limit 0 is the default bound.

func (*Store) Domain

func (s *Store) Domain(ctx context.Context, hostname string) (*site.Domain, error)

Domain reads one hostname's mapping.

func (*Store) Domains

func (s *Store) Domains(ctx context.Context) ([]site.Domain, error)

Domains lists every mapping.

func (*Store) ExpireHandoffs

func (s *Store) ExpireHandoffs(ctx context.Context, now time.Time) error

ExpireHandoffs removes the used codes past their expiry.

func (*Store) Files

func (s *Store) Files(ctx context.Context, releaseID string) ([]site.File, error)

Files is what a release serves, in path order.

func (*Store) FinishJob added in v1.156.0

func (s *Store) FinishJob(ctx context.Context, id string, r site.JobResult) error

FinishJob records how a job ended.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*site.Site, error)

Get reads a site by id.

func (*Store) GetByName

func (s *Store) GetByName(ctx context.Context, name string) (*site.Site, error)

GetByName reads a site by name.

func (*Store) GrantLevel added in v1.156.0

func (s *Store) GrantLevel(ctx context.Context, siteID, email string) (string, error)

GrantLevel is the level of the grant to a person's email, "" for none.

func (*Store) GrantedSiteIDs added in v1.166.1

func (s *Store) GrantedSiteIDs(ctx context.Context, email, persona string) ([]string, error)

GrantedSiteIDs is the sites with a grant to the email or the persona, the candidates for the environments shared with a person (#2718); which of a site's environments a grant opens is SiteAccess's to say.

func (*Store) Grants added in v1.156.0

func (s *Store) Grants(ctx context.Context, siteID string) ([]site.Grant, error)

Grants lists who has been given access to a site.

func (*Store) HoldSweep added in v1.159.0

func (s *Store) HoldSweep(ctx context.Context, siteID string) (*Hold, error)

HoldSweep holds a site's stored objects for a sweep about to decide what to delete, or is nil when the site is busy: a publish holds its files, or a publish or copy job is running.

func (*Store) HoldUpload added in v1.159.0

func (s *Store) HoldUpload(ctx context.Context, siteID string) (*Hold, error)

HoldUpload holds a site's stored objects for a publish about to store files, waiting while a sweep holds them and refusing with ErrCleanupRunning past the wait.

func (*Store) Hosts added in v1.156.0

func (s *Store) Hosts(ctx context.Context) ([]string, error)

Hosts lists every hostname that routes.

func (*Store) Job added in v1.156.0

func (s *Store) Job(ctx context.Context, id string) (*site.Job, error)

Job reads a job by id.

func (*Store) KeptBy added in v1.159.0

func (s *Store) KeptBy(ctx context.Context, siteID string) (map[int][]string, error)

KeptBy is, for each release number the site keeps, what keeps it: the environments whose window holds it, each application release pinning it ("application <name>"), and a pending approval request ("approval"). A release with no entry is pruned at the next sweep, or was pruned.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]site.Site, error)

List reads every site with its environments.

func (*Store) Media added in v1.159.0

func (s *Store) Media(ctx context.Context, siteID string) ([]site.Mount, error)

Media is the resource folders a site serves at URL prefixes (#2591), by prefix.

func (*Store) Point

func (s *Store) Point(ctx context.Context, p site.Pointer) error

Point moves an environment's pointer and records the deployment, in one transaction under a compare-and-set on the release the move was decided against.

func (*Store) Prune added in v1.159.0

func (s *Store) Prune(ctx context.Context, siteID string, apply bool) (*PruneResult, error)

Prune sweeps one site: with apply it prunes, and without it only reports what pruning would do, deciding both the same way.

func (*Store) RecordRelease

func (s *Store) RecordRelease(ctx context.Context, r *site.Release, move *site.Pointer) error

RecordRelease writes a release and its files, numbering it next under the site's row lock so two publishes get two numbers. A move points the environment at the release in the same transaction.

func (*Store) RecordSweep added in v1.159.0

func (s *Store) RecordSweep(ctx context.Context, w *Sweep) error

RecordSweep stores a sweep's counts and drops the oldest past keptSweeps.

func (*Store) Release

func (s *Store) Release(ctx context.Context, siteID string, number int) (*site.Release, error)

Release reads a release by its number.

func (*Store) ReleaseByID

func (s *Store) ReleaseByID(ctx context.Context, id string) (*site.Release, error)

ReleaseByID reads a release by its id.

func (*Store) Releases

func (s *Store) Releases(ctx context.Context, siteID string) ([]site.Release, error)

Releases lists a site's releases, newest first.

func (*Store) RemoveDomain

func (s *Store) RemoveDomain(ctx context.Context, hostname string) error

RemoveDomain deletes a mapping.

func (*Store) RemoveEnvironment added in v1.162.0

func (s *Store) RemoveEnvironment(ctx context.Context, siteID, name string) error

RemoveEnvironment removes an environment between dev and prod (#2630) in one transaction under the site's row lock, refusing one that still has a domain, holds the main address, is a part of an application, or has a job running. It withdraws pending approvals that target it, drops it from each grant's environment list and deletes a grant that named only it (an empty list means every private environment, so emptying one would widen the grant), marks its history removed, deletes its tile so the tile's object is reclaimed (#2751), and numbers the remaining environments again.

func (*Store) RemoveGrant added in v1.156.0

func (s *Store) RemoveGrant(ctx context.Context, siteID, email, persona string) error

RemoveGrant takes access away from an email, or from a persona with email "".

func (*Store) RenameEnvironment added in v1.162.0

func (s *Store) RenameEnvironment(ctx context.Context, siteID, from, to, actor string) error

RenameEnvironment renames an environment between dev and prod (#2630), moving every reference to its name in one transaction under the site's row lock: the environment, its domains, its live history, its jobs, the main address, each grant's environment list, the application parts and pins written "<site>/<env>", the target of pending approvals, and its tile, which still shows what it serves (#2751; a tile row already under the new name, left by an earlier removal, is deleted first). The rename is recorded in the environment's history.

func (*Store) ReportJob added in v1.156.0

func (s *Store) ReportJob(ctx context.Context, id string, p site.JobProgress) (bool, error)

ReportJob records progress, which is the job's heartbeat, and reads in the same statement whether it was asked to stop.

func (*Store) RouteEnv added in v1.158.0

func (s *Store) RouteEnv(ctx context.Context, siteName, env string) (*site.Route, error)

RouteEnv is what <site>--<env> serves, always private (#2619).

func (*Store) RouteHost

func (s *Store) RouteHost(ctx context.Context, hostname string) (*site.Route, error)

RouteHost is what an added hostname serves.

func (*Store) RouteOwn added in v1.156.0

func (s *Store) RouteOwn(ctx context.Context, siteName string) (*site.Route, error)

RouteOwn is what a site's main address serves: the environment it is given to, ErrNoDomain when it is given to none. An address on the pages domain is always private (#2619).

func (*Store) SetDomainPublic added in v1.159.0

func (s *Store) SetDomainPublic(ctx context.Context, hostname string, public bool) error

SetDomainPublic makes a site's domain public or private, stamping when its access changed (#2619). An application's domain has no such setting.

func (*Store) SetDomainRole added in v1.163.0

func (s *Store) SetDomainRole(ctx context.Context, hostname string, primary bool, mode string) error

SetDomainRole makes a site's domain its environment's primary or not, and sets whether it serves or redirects (#2687), in one transaction: a new primary takes the mark from the environment's previous one.

func (*Store) SetEnvironment

func (s *Store) SetEnvironment(ctx context.Context, siteID, name string, set site.EnvironmentSettings, actor string) error

SetEnvironment creates an environment or changes its settings. A nil setting keeps what the environment has, or false on a new one. A nil Keep keeps the limit, or the deployment's default on a new environment, and KeepDefault returns to it. A new environment, or one given a Place, is put in the site's order under the site's row lock, so two changes to one site's order cannot interleave (#2617).

func (*Store) SetGrant added in v1.156.0

func (s *Store) SetGrant(ctx context.Context, siteID string, g *site.Grant) error

SetGrant adds a person or persona or changes their grant, and fills in g.CreatedAt from the row it wrote.

func (*Store) SetMainEnvironment added in v1.158.0

func (s *Store) SetMainEnvironment(ctx context.Context, siteID, env string) error

SetMainEnvironment gives the main address to an environment of the site, or to none with env "".

func (*Store) SetMedia added in v1.159.0

func (s *Store) SetMedia(ctx context.Context, siteID string, mounts []site.Mount, actor string) error

SetMedia makes a site's mounts exactly these, in one transaction: a mount kept at its prefix keeps who added it and when.

func (*Store) SetStatus added in v1.162.0

func (s *Store) SetStatus(ctx context.Context, siteID, env string, st site.EnvironmentStatus, actor string) error

SetStatus changes what an environment answers (#2631, #2632) and records the change in its history, in one transaction. The release pointer is not touched.

func (*Store) SiteAccess added in v1.156.0

func (s *Store) SiteAccess(ctx context.Context, siteID, env, email, persona string) (*site.Access, error)

SiteAccess reads, in one statement, what decides whether a person may open one environment of a site: the owner, the environment's own internal view, and whether a grant to their email or to their persona opens it. It is read on every request and held nowhere, so removing a person, or a change to a persona, takes effect on their next request on every replica.

func (*Store) SiteDomains added in v1.156.0

func (s *Store) SiteDomains(ctx context.Context, siteID string) ([]site.Domain, error)

SiteDomains lists the hostnames added to one site.

func (*Store) SiteRefs added in v1.159.0

func (s *Store) SiteRefs(ctx context.Context) ([]SiteRef, error)

SiteRefs lists every site, by name.

func (*Store) StopJob added in v1.156.0

func (s *Store) StopJob(ctx context.Context, id string) error

StopJob asks a running job to stop; the replica running it reads this at its next report.

func (*Store) StoredFiles added in v1.157.0

func (s *Store) StoredFiles(ctx context.Context, siteID string) ([]site.File, error)

StoredFiles lists what a site holds in object storage, each object once: a digest shared by a thousand releases is one object, and a file stored under a release of its own is one object per path.

func (*Store) Sweeps added in v1.159.0

func (s *Store) Sweeps(ctx context.Context, limit int) ([]Sweep, error)

Sweeps lists the most recent sweeps, newest first.

func (*Store) Tree added in v1.157.0

func (s *Store) Tree(ctx context.Context, releaseID, tree string) ([]site.File, error)

Tree is one tree of a release in path order: for each path, the row of the nearest release in its chain, unless that row removes the path.

func (*Store) Update

func (s *Store) Update(ctx context.Context, st *site.Site) error

Update writes the description and the owner.

func (*Store) UseHandoff

func (s *Store) UseHandoff(ctx context.Context, codeHash string, expires time.Time) (bool, error)

UseHandoff records a handoff code's hash, reporting false when it was used before.

type Sweep added in v1.159.0

type Sweep struct {
	Mode        string    `json:"mode" example:"delete"`
	RunBy       string    `json:"run_by,omitempty"`
	Scope       string    `json:"scope,omitempty"`
	Sites       int       `json:"sites_swept"`
	Releases    int       `json:"releases"`
	Rewritten   int       `json:"rewritten"`
	Files       int       `json:"files"`
	Bytes       int64     `json:"bytes"`
	Orphans     int       `json:"orphans"`
	OrphanBytes int64     `json:"orphan_bytes"`
	Skipped     int       `json:"skipped"`
	Refused     int       `json:"refused"`
	Failed      int       `json:"failed"`
	StartedAt   time.Time `json:"started_at"`
	FinishedAt  time.Time `json:"finished_at"`
}

Sweep is one recorded sweep: counts only, never a path or a key.

Jump to

Keyboard shortcuts

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