registry

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SourceSeeding SourceState = "seeding"
	SourceReady   SourceState = "ready"
	SourceFailed  SourceState = "failed"

	BranchCreating   BranchState = "creating"
	BranchReady      BranchState = "ready"
	BranchFailed     BranchState = "failed"
	BranchResetting  BranchState = "resetting"
	BranchDestroying BranchState = "destroying"
	BranchDestroyed  BranchState = "destroyed"
)
View Source
const (
	SeedViaBasebackup = "basebackup" // pg_basebackup (needs REPLICATION privilege)
	SeedViaDump       = "dump"       // pg_dump into a fresh initdb'd cluster (managed Postgres)
)

Seeding methods: how a source's data dir is built from the live Postgres.

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrUnsupportedPGVersion = errors.New("unsupported pg_version")

ErrUnsupportedPGVersion rejects sources whose pg_version is outside the supported matrix. Majors 14-18 only: branch startup relies on recovery_init_sync_method=syncfs, which PG 13 and older do not have.

Functions

This section is empty.

Types

type Branch

type Branch struct {
	ID, Name, SourceID, ContainerID, RWVolume string
	SourceVolume                              string // source volume the branch was created from
	ExpiresAt                                 string // RFC3339, "" = never
	Host                                      string // address the instance listens on (127.0.0.1 for docker, pod IP for k8s)
	BaseLayerID                               string // top of the layer chain the branch bases on; "" = the source volume directly
	ParentBranchName                          string // display-only: branch this one was created from ("" = created from the source)
	Password                                  string // rotated per-branch password; "" = credentials inherited from the source
	Port                                      int
	State                                     BranchState
	CreatedAt                                 string
}

type BranchState

type BranchState string

type Layer

type Layer struct {
	ID, SourceID, Volume, ParentLayerID string
}

Layer is a frozen branch rw volume: an immutable overlay layer between the source volume and the branches cloned from that branch. Layers chain via ParentLayerID ("" = the layer sits directly on the source volume).

type MaskScript

type MaskScript struct {
	Name string
	SQL  string
}

MaskScript is one masking statement: SQL the engine runs (via in-container psql) on every new/reset branch of the owning source, in stored order.

type Registry

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

func Open

func Open(path string) (*Registry, error)

func (*Registry) BumpSourceGeneration

func (r *Registry) BumpSourceGeneration(id, newVolume string) error

BumpSourceGeneration advances a source to its next generation volume after a successful refresh seed.

func (*Registry) Close

func (r *Registry) Close() error

func (*Registry) CommitFreeze

func (r *Registry) CommitFreeze(parentID, childID, layerVolume, newParentRW, containerID, host string, port int, reason string) (*Layer, error)

CommitFreeze atomically records a completed freeze, once the parent is running on its fresh rw volume and the child instance is up:

  • the parent's old rw volume becomes a new immutable layer (chained onto the parent's previous base layer, if any),
  • the parent row swaps to the fresh rw volume + new container/host/port and transitions resetting -> ready,
  • the child branch bases on the new layer.

The parent must be mid-freeze (resetting); all of it commits or none does.

func (*Registry) CountBranchesReferencingLayer

func (r *Registry) CountBranchesReferencingLayer(layerID string) (int, error)

CountBranchesReferencingLayer computes a layer's refcount: the number of live branches whose layer chain contains it (directly or via descendants). Refcounts are derived, never stored.

func (*Registry) CountLiveBranchesByRWVolume

func (r *Registry) CountLiveBranchesByRWVolume(volume string) (int, error)

CountLiveBranchesByRWVolume counts live branches whose writable layer is the given volume/dataset. Used as a GC guard: a volume that is some live branch's rw layer must never be removed as an orphaned source layer (zfs children record their parent's clone dataset as their SourceVolume).

func (*Registry) CountLiveBranchesBySource

func (r *Registry) CountLiveBranchesBySource(sourceID string) (int, error)

func (*Registry) CountLiveBranchesByVolume

func (r *Registry) CountLiveBranchesByVolume(volume string) (int, error)

func (*Registry) CreateBranch

func (r *Registry) CreateBranch(b *Branch) error

func (*Registry) CreateLayer

func (r *Registry) CreateLayer(l *Layer) error

CreateLayer records a frozen layer (assigns its ID).

func (*Registry) CreateSource

func (r *Registry) CreateSource(s *Source) error

func (*Registry) DeleteLayer

func (r *Registry) DeleteLayer(id string) error

DeleteLayer removes a layer row. Fails (FK) while a child layer still chains onto it — callers GC topmost-first.

func (*Registry) DeleteSource

func (r *Registry) DeleteSource(id string) error

DeleteSource removes a source row and its (destroyed) branch history rows. Callers must ensure no live branches reference the source first.

func (*Registry) GetBranchByName

func (r *Registry) GetBranchByName(name string) (*Branch, error)

func (*Registry) GetLayer

func (r *Registry) GetLayer(id string) (*Layer, error)

func (*Registry) GetMaskScripts

func (r *Registry) GetMaskScripts(sourceID string) ([]MaskScript, error)

GetMaskScripts returns a source's masking scripts in application order.

func (*Registry) GetSourceByID

func (r *Registry) GetSourceByID(id string) (*Source, error)

func (*Registry) GetSourceByName

func (r *Registry) GetSourceByName(name string) (*Source, error)

func (*Registry) LayerChain

func (r *Registry) LayerChain(branchID string) ([]Layer, error)

LayerChain resolves a branch's layer chain, topmost (newest) layer first. Empty for branches based directly on the source volume. The full overlay stack is: chain[0], chain[1], …, source volume.

func (*Registry) ListExpiredBranches

func (r *Registry) ListExpiredBranches(now string) ([]*Branch, error)

ListExpiredBranches returns ready/failed branches whose expiry (RFC3339 UTC, lexicographically comparable) has passed. now must be RFC3339 UTC.

func (*Registry) ListLayersBySource

func (r *Registry) ListLayersBySource(sourceID string) ([]*Layer, error)

ListLayersBySource returns every layer frozen under the given source.

func (*Registry) ListLiveBranches

func (r *Registry) ListLiveBranches() ([]*Branch, error)

func (*Registry) ListSources

func (r *Registry) ListSources() ([]*Source, error)

func (*Registry) MarkBranchReady

func (r *Registry) MarkBranchReady(id, containerID, host string, port int) error

func (*Registry) SetBranchPassword added in v0.3.0

func (r *Registry) SetBranchPassword(id, password string) error

SetBranchPassword stores a branch's rotated per-branch password ("" = credentials inherited from the source). Called by the engine after the in-branch ALTER ROLE succeeded, before the branch is marked ready.

func (*Registry) SetMaskScripts

func (r *Registry) SetMaskScripts(sourceID string, scripts []MaskScript) error

SetMaskScripts replaces a source's masking scripts with the given ordered list (empty/nil clears them).

func (*Registry) SetSourceState

func (r *Registry) SetSourceState(id string, to SourceState, reason string) error

func (*Registry) TransitionBranch

func (r *Registry) TransitionBranch(id string, to BranchState, reason string) error

type Source

type Source struct {
	ID, Name, PGVersion, Volume         string
	ConnHost, ConnUser, ConnDB, Network string
	SeedVia                             string   // SeedViaBasebackup (default) or SeedViaDump
	DumpSchemas                         []string // dump mode only: schemas to dump (empty = whole database)
	ConnPort                            int
	Generation                          int
	State                               SourceState
	CreatedAt                           string
}

type SourceState

type SourceState string

Jump to

Keyboard shortcuts

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