rowlock

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package rowlock owns the invariant PostgreSQL lock order for durable resource mutations. Every caller locks quota ledgers before Sandbox, then Workspace, then Snapshot when present, before acquiring operation-specific rows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveSubject added in v0.6.0

func ActiveSubject(
	ctx context.Context,
	tx pgx.Tx,
	tenantRef string,
	subjectRef string,
	now time.Time,
) error

ActiveSubject locks and validates the Subject after its quota ledger and before quota-bearing domain rows.

func QuotaScopes added in v0.6.0

func QuotaScopes(ctx context.Context, tx pgx.Tx, scopes []QuotaScope) error

QuotaScopes locks all tenant ledgers first, then all Subject ledgers, with each level sorted by logical identity before any domain row is locked.

func SandboxQuota added in v0.6.0

func SandboxQuota(ctx context.Context, tx pgx.Tx, sandboxID string) error

SandboxQuota locks the quota ledgers for a Sandbox before locking the Sandbox itself.

func SandboxQuotas added in v0.6.0

func SandboxQuotas(ctx context.Context, tx pgx.Tx, sandboxIDs []string) error

SandboxQuotas resolves Sandbox ownership without row locks, then locks every quota-ledger pair before a caller acquires any durable domain-row lock.

func TenantAndSubjectQuota added in v0.6.0

func TenantAndSubjectQuota(
	ctx context.Context,
	tx pgx.Tx,
	tenantRef string,
	subjectRef string,
) error

TenantAndSubjectQuota establishes the global PostgreSQL mutation lock order: tenant quota ledger, subject quota ledger, then domain rows such as Subject, ApplicationAuthority, Sandbox, Workspace, Snapshot, PortSession, or data-plane session. Trigger-backed quota accounting depends on every writer preserving this order before it locks or changes a quota-bearing domain row.

func TenantQuota added in v0.6.0

func TenantQuota(ctx context.Context, tx pgx.Tx, tenantRef string) error

TenantQuota locks the tenant-level quota ledger before any domain row.

Types

type QuotaScope added in v0.6.0

type QuotaScope struct {
	TenantRef  string
	SubjectRef string
}

QuotaScope identifies one tenant and Subject quota-ledger pair.

type SandboxWorkspace

type SandboxWorkspace struct {
	SandboxID         string
	TenantRef         string
	SubjectRef        string
	WorkspaceID       string
	ProfileRevisionID string
	SandboxState      string
	DesiredState      string
	Generation        int64
	Revision          int64
	CurrentInstanceID string
	ReconcileOwner    string
	Workspace         ports.HomeWorkspace
}

SandboxWorkspace is the durable authority protected by the first two locks.

func SandboxWorkspaceByID

func SandboxWorkspaceByID(
	ctx context.Context,
	tx pgx.Tx,
	sandboxID string,
) (SandboxWorkspace, error)

SandboxWorkspaceByID locks one internally identified Sandbox followed by its Workspace.

func SandboxWorkspaceForSubject

func SandboxWorkspaceForSubject(
	ctx context.Context,
	tx pgx.Tx,
	tenantRef string,
	subjectRef string,
	sandboxID string,
) (SandboxWorkspace, error)

SandboxWorkspaceForSubject locks one tenant-scoped Sandbox followed by its Workspace.

type Snapshot

type Snapshot struct {
	ID           string
	SandboxID    string
	WorkspaceID  string
	HomeRunnerID string
	State        string
}

Snapshot identifies the third row in the invariant lock order.

func SnapshotByID

func SnapshotByID(
	ctx context.Context,
	tx pgx.Tx,
	locked SandboxWorkspace,
	snapshotID string,
) (Snapshot, error)

SnapshotByID locks a Snapshot only after the caller holds its Sandbox and Workspace.

func SnapshotForSubject

func SnapshotForSubject(
	ctx context.Context,
	tx pgx.Tx,
	tenantRef string,
	subjectRef string,
	locked SandboxWorkspace,
	snapshotID string,
) (Snapshot, error)

SnapshotForSubject locks a Snapshot only after the caller holds its Sandbox and Workspace through SandboxWorkspaceForSubject or SandboxWorkspaceByID.

Jump to

Keyboard shortcuts

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