store

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("sandbox not found")

Functions

This section is empty.

Types

type ReserveHostPortResult added in v0.1.4

type ReserveHostPortResult struct {
	Reserved bool
	Existing *models.ExposedPort
}

ReserveHostPortResult is the three-state outcome of TryReserveHostPort. Exactly one of Reserved/Existing/(neither) is set:

  • Reserved: the row was inserted; the candidate host port is now ours.
  • Existing != nil: a row for (sandbox_id, port) already exists. The allocator MUST stop walking the pool — no other host_port will satisfy the (sandbox_id, port) primary key. Caller decides whether to reuse the existing exposure or surface an error.
  • both zero: the partial unique index on host_port rejected this candidate (some other sandbox owns it). Caller may retry.

type Store

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

func Open

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

func (*Store) Close

func (s *Store) Close() error

func (*Store) Create

func (s *Store) Create(ctx context.Context, sandbox *models.Sandbox) error

func (*Store) Delete

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

func (*Store) DeleteMounts

func (s *Store) DeleteMounts(ctx context.Context, sandboxID string) error

DeleteMounts removes mount config for a sandbox. The cascade on the sandboxes table handles this when a sandbox is destroyed; explicit deletes are useful for replacing mounts.

func (*Store) DeletePort

func (s *Store) DeletePort(ctx context.Context, sandboxID string, port int) error

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*models.Sandbox, error)

func (*Store) GetMounts

func (s *Store) GetMounts(ctx context.Context, sandboxID string) ([]byte, error)

GetMounts returns the encrypted mount blob, or ErrNotFound if no row exists.

func (*Store) HasActiveImageRef

func (s *Store) HasActiveImageRef(ctx context.Context, image string) (bool, error)

HasActiveImageRef reports whether any sandbox row references image with a status other than destroyed. Used by image GC: when this returns false the caller may safely remove the image from Docker. Single indexed query — constant cost regardless of how many destroyed rows have accumulated, so 10k destroyed historical rows do not slow the destroy hot path. Returns true on empty image as a conservative default (caller treats it as "still in use, do not delete").

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*models.Sandbox, error)

func (*Store) ListAllExposedPorts added in v0.1.4

func (s *Store) ListAllExposedPorts(ctx context.Context) ([]models.ExposedPort, error)

ListAllExposedPorts returns every row in exposed_ports across every sandbox. Used by reconcile to GC zombie caddy routes / layer4 servers without N+1 per-sandbox lookups.

func (*Store) PutMounts

func (s *Store) PutMounts(ctx context.Context, sandboxID string, sealed []byte) error

PutMounts stores an encrypted mount blob for a sandbox. The blob is opaque to the store layer; encryption / decryption happens in the service layer.

func (*Store) Touch

func (s *Store) Touch(ctx context.Context, id string, at time.Time) error

func (*Store) TryReserveHostPort added in v0.1.4

func (s *Store) TryReserveHostPort(ctx context.Context, sandboxID string, containerPort, hostPort int, protocol, publicURL string, now time.Time) (ReserveHostPortResult, error)

TryReserveHostPort attempts to claim hostPort for (sandboxID, containerPort) in a single INSERT OR IGNORE. The OR IGNORE swallows two distinct UNIQUE failures — the (sandbox_id, port) primary key AND the partial index on host_port — so on a no-op insert we follow up with a SELECT to disambiguate. Without that disambiguation, retrying expose for an already-exposed port looks identical to a host_port collision and walks the whole allocator pool before failing with "exhausted".

func (*Store) UpdateLifecycle

func (s *Store) UpdateLifecycle(ctx context.Context, id string, l models.Lifecycle) error

UpdateLifecycle replaces the four lifecycle timer fields on a sandbox row and bumps updated_at. Other fields are untouched. Returns ErrNotFound if no row matches id. The caller must validate the Lifecycle first; the store does not re-validate (it would couple two layers for no gain).

func (*Store) UpdateRuntime

func (s *Store) UpdateRuntime(ctx context.Context, id, containerID, containerIP, publicURL string) error

func (*Store) UpdateStatus

func (s *Store) UpdateStatus(ctx context.Context, id string, status models.SandboxStatus, lastError string) error

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, sandbox *models.Sandbox) error

func (*Store) UpsertPort

func (s *Store) UpsertPort(ctx context.Context, exposure models.ExposedPort) error

Jump to

Keyboard shortcuts

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