Documentation
¶
Overview ¶
Package sitestore is the PostgreSQL store of sites, releases and domains (#2518).
Index ¶
- Variables
- func NewJobID() string
- func NewReleaseID() string
- func NewSiteID() string
- func WithHold(ctx context.Context, h *Hold) context.Context
- type Hold
- type PruneResult
- type SiteRef
- type Store
- func (s *Store) ActiveJobs(ctx context.Context, siteID string) ([]site.Job, error)
- func (s *Store) AddDomain(ctx context.Context, d *site.Domain) error
- func (s *Store) ApplicationHosts(ctx context.Context, applicationID, pagesDomain string) ([]string, error)
- func (s *Store) Create(ctx context.Context, st *site.Site) error
- func (s *Store) CreateJob(ctx context.Context, j *site.Job) error
- func (s *Store) Delete(ctx context.Context, id string) error
- func (s *Store) Deployments(ctx context.Context, siteID, environment string, limit int) ([]site.Deployment, error)
- func (s *Store) Domain(ctx context.Context, hostname string) (*site.Domain, error)
- func (s *Store) Domains(ctx context.Context) ([]site.Domain, error)
- func (s *Store) ExpireHandoffs(ctx context.Context, now time.Time) error
- func (s *Store) Files(ctx context.Context, releaseID string) ([]site.File, error)
- func (s *Store) FinishJob(ctx context.Context, id string, r site.JobResult) error
- func (s *Store) Get(ctx context.Context, id string) (*site.Site, error)
- func (s *Store) GetByName(ctx context.Context, name string) (*site.Site, error)
- func (s *Store) GrantLevel(ctx context.Context, siteID, email string) (string, error)
- func (s *Store) GrantedSiteIDs(ctx context.Context, email, persona string) ([]string, error)
- func (s *Store) Grants(ctx context.Context, siteID string) ([]site.Grant, error)
- func (s *Store) HoldSweep(ctx context.Context, siteID string) (*Hold, error)
- func (s *Store) HoldUpload(ctx context.Context, siteID string) (*Hold, error)
- func (s *Store) Hosts(ctx context.Context) ([]string, error)
- func (s *Store) Job(ctx context.Context, id string) (*site.Job, error)
- func (s *Store) KeptBy(ctx context.Context, siteID string) (map[int][]string, error)
- func (s *Store) List(ctx context.Context) ([]site.Site, error)
- func (s *Store) Media(ctx context.Context, siteID string) ([]site.Mount, error)
- func (s *Store) Point(ctx context.Context, p site.Pointer) error
- func (s *Store) Prune(ctx context.Context, siteID string, apply bool) (*PruneResult, error)
- func (s *Store) RecordRelease(ctx context.Context, r *site.Release, move *site.Pointer) error
- func (s *Store) RecordSweep(ctx context.Context, w *Sweep) error
- func (s *Store) Release(ctx context.Context, siteID string, number int) (*site.Release, error)
- func (s *Store) ReleaseByID(ctx context.Context, id string) (*site.Release, error)
- func (s *Store) Releases(ctx context.Context, siteID string) ([]site.Release, error)
- func (s *Store) RemoveDomain(ctx context.Context, hostname string) error
- func (s *Store) RemoveEnvironment(ctx context.Context, siteID, name string) error
- func (s *Store) RemoveGrant(ctx context.Context, siteID, email, persona string) error
- func (s *Store) RenameEnvironment(ctx context.Context, siteID, from, to, actor string) error
- func (s *Store) ReportJob(ctx context.Context, id string, p site.JobProgress) (bool, error)
- func (s *Store) RouteEnv(ctx context.Context, siteName, env string) (*site.Route, error)
- func (s *Store) RouteHost(ctx context.Context, hostname string) (*site.Route, error)
- func (s *Store) RouteOwn(ctx context.Context, siteName string) (*site.Route, error)
- func (s *Store) SetDomainPublic(ctx context.Context, hostname string, public bool) error
- func (s *Store) SetDomainRole(ctx context.Context, hostname string, primary bool, mode string) error
- func (s *Store) SetEnvironment(ctx context.Context, siteID, name string, set site.EnvironmentSettings, ...) error
- func (s *Store) SetGrant(ctx context.Context, siteID string, g *site.Grant) error
- func (s *Store) SetMainEnvironment(ctx context.Context, siteID, env string) error
- func (s *Store) SetMedia(ctx context.Context, siteID string, mounts []site.Mount, actor string) error
- func (s *Store) SetStatus(ctx context.Context, siteID, env string, st site.EnvironmentStatus, ...) error
- func (s *Store) SiteAccess(ctx context.Context, siteID, env, email, persona string) (*site.Access, error)
- func (s *Store) SiteDomains(ctx context.Context, siteID string) ([]site.Domain, error)
- func (s *Store) SiteRefs(ctx context.Context) ([]SiteRef, error)
- func (s *Store) StopJob(ctx context.Context, id string) error
- func (s *Store) StoredFiles(ctx context.Context, siteID string) ([]site.File, error)
- func (s *Store) Sweeps(ctx context.Context, limit int) ([]Sweep, error)
- func (s *Store) Tree(ctx context.Context, releaseID, tree string) ([]site.File, error)
- func (s *Store) Update(ctx context.Context, st *site.Site) error
- func (s *Store) UseHandoff(ctx context.Context, codeHash string, expires time.Time) (bool, error)
- type Sweep
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 (*Hold) Release ¶ added in v1.159.0
Release ends a hold. It is best effort: a hold left behind expires.
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 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 (*Store) ActiveJobs ¶ added in v1.156.0
ActiveJobs lists a site's running jobs, newest first.
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) 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) ExpireHandoffs ¶
ExpireHandoffs removes the used codes past their expiry.
func (*Store) GrantLevel ¶ added in v1.156.0
GrantLevel is the level of the grant to a person's email, "" for none.
func (*Store) GrantedSiteIDs ¶ added in v1.166.1
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) HoldSweep ¶ added in v1.159.0
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
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) KeptBy ¶ added in v1.159.0
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) Media ¶ added in v1.159.0
Media is the resource folders a site serves at URL prefixes (#2591), by prefix.
func (*Store) Point ¶
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
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 ¶
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
RecordSweep stores a sweep's counts and drops the oldest past keptSweeps.
func (*Store) ReleaseByID ¶
ReleaseByID reads a release by its id.
func (*Store) RemoveDomain ¶
RemoveDomain deletes a mapping.
func (*Store) RemoveEnvironment ¶ added in v1.162.0
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
RemoveGrant takes access away from an email, or from a persona with email "".
func (*Store) RenameEnvironment ¶ added in v1.162.0
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
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
RouteEnv is what <site>--<env> serves, always private (#2619).
func (*Store) RouteOwn ¶ added in v1.156.0
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
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
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
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
SiteDomains lists the hostnames added to one site.
func (*Store) StopJob ¶ added in v1.156.0
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
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) Tree ¶ added in v1.157.0
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.
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.