atepg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package atepg is an ate storage backend built on PostgreSQL.

Each table holds native SQL columns for fields SQL must operate on (primary keys, versions, pagination, update/delete preconditions) plus the complete protobuf message, binary-encoded, in a BYTEA column. TLS is configured entirely through the connection string passed to Connect (standard libpq sslmode/sslrootcert/sslcert/sslkey parameters)

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("PostgreSQL is unavailable")

ErrUnavailable reports that ateapi could not establish the initial PostgreSQL connection. Callers can retry this error before startup.

Functions

This section is empty.

Types

type Persistence

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

func Connect

func Connect(ctx context.Context, dsn, schema string) (*Persistence, error)

Connect opens a pgxpool against dsn, creates schema if necessary, and applies pending schema migrations. A dedicated watch pool isolates outbox polling and maintenance from writes.

func NewPersistence

func NewPersistence(ctx context.Context, pool *pgxpool.Pool) (*Persistence, error)

NewPersistence wraps an already-open pool, applying pending migrations. Callers that already hold a pool (e.g. tests using testcontainers) use this directly instead of Connect; outbox watch traffic shares the given pool.

func (*Persistence) AcquireLease

func (p *Persistence) AcquireLease(ctx context.Context, key string) (*store.Lease, error)

func (*Persistence) BindActorToWorker

func (p *Persistence) BindActorToWorker(ctx context.Context, workerName string, assignment *ateapipb.ActorAssignment, admit func(*ateapipb.Worker) error) error

func (*Persistence) Close

func (p *Persistence) Close()

Close stops the outbox maintenance loop and waits for it to exit, then closes the watch pool if Connect created one. It does not close the main pool, which the caller owns.

func (*Persistence) CreateActor

func (p *Persistence) CreateActor(ctx context.Context, actor *ateapipb.Actor) (*ateapipb.Actor, error)

func (*Persistence) CreateActorTemplate

func (p *Persistence) CreateActorTemplate(ctx context.Context, template *ateapipb.ActorTemplate) (*ateapipb.ActorTemplate, error)

func (*Persistence) CreateAtespace

func (p *Persistence) CreateAtespace(ctx context.Context, atespace *ateapipb.Atespace) (*ateapipb.Atespace, error)

func (*Persistence) CreateEgressPolicy

func (p *Persistence) CreateEgressPolicy(ctx context.Context, actorRef resources.ActorRef, policy *ateapipb.EgressPolicy) (*ateapipb.EgressPolicy, error)

func (*Persistence) CreateTag

func (p *Persistence) CreateTag(ctx context.Context, tag *ateapipb.Tag) (*ateapipb.Tag, error)

func (*Persistence) CreateWorker

func (p *Persistence) CreateWorker(ctx context.Context, worker *ateapipb.Worker) (*ateapipb.Worker, error)

func (*Persistence) DeleteActor

func (p *Persistence) DeleteActor(ctx context.Context, actorRef resources.ActorRef) (*ateapipb.Actor, error)

func (*Persistence) DeleteActorTemplate

func (p *Persistence) DeleteActorTemplate(ctx context.Context, templateRef resources.ActorTemplateRef) (*ateapipb.ActorTemplate, error)

func (*Persistence) DeleteAtespace

func (p *Persistence) DeleteAtespace(ctx context.Context, name string) (*ateapipb.Atespace, error)

func (*Persistence) DeleteEgressPolicy

func (p *Persistence) DeleteEgressPolicy(ctx context.Context, actorRef resources.ActorRef) (*ateapipb.EgressPolicy, error)

func (*Persistence) DeleteTag

func (p *Persistence) DeleteTag(ctx context.Context, tagRef resources.TagRef) (*ateapipb.Tag, error)

func (*Persistence) DeleteWorker

func (p *Persistence) DeleteWorker(ctx context.Context, name string, pre store.DeletePreconditions) (*ateapipb.Worker, error)

func (*Persistence) FindWorkerHostingActor

func (p *Persistence) FindWorkerHostingActor(ctx context.Context, actorUID string) (string, error)

func (*Persistence) GetActor

func (p *Persistence) GetActor(ctx context.Context, actorRef resources.ActorRef) (*ateapipb.Actor, error)

func (*Persistence) GetActorTemplate

func (p *Persistence) GetActorTemplate(ctx context.Context, templateRef resources.ActorTemplateRef) (*ateapipb.ActorTemplate, error)

func (*Persistence) GetAtespace

func (p *Persistence) GetAtespace(ctx context.Context, name string) (*ateapipb.Atespace, error)

func (*Persistence) GetEgressPolicy

func (p *Persistence) GetEgressPolicy(ctx context.Context, actorRef resources.ActorRef) (*ateapipb.EgressPolicy, error)

func (*Persistence) GetTag

func (p *Persistence) GetTag(ctx context.Context, tagRef resources.TagRef) (*ateapipb.Tag, error)

func (*Persistence) GetWorker

func (p *Persistence) GetWorker(ctx context.Context, name string) (*ateapipb.Worker, error)

func (*Persistence) GetWorkerAssignment

func (p *Persistence) GetWorkerAssignment(ctx context.Context, workerName, actorUID string) (*ateapipb.ActorAssignment, error)

func (*Persistence) ListActorTemplates

func (p *Persistence) ListActorTemplates(ctx context.Context, atespace string, opts store.ListOptions) (store.ListResponse[*ateapipb.ActorTemplate], error)

func (*Persistence) ListActors

func (p *Persistence) ListActors(ctx context.Context, atespace string, opts store.ListOptions) (store.ListResponse[*ateapipb.Actor], error)

func (*Persistence) ListAtespaces

func (*Persistence) ListTags

func (p *Persistence) ListTags(ctx context.Context, atespace string, opts store.ListOptions) (store.ListResponse[*ateapipb.Tag], error)

func (*Persistence) ListWorkerAssignments

func (p *Persistence) ListWorkerAssignments(ctx context.Context, workerName string, opts store.ListOptions) (store.ListResponse[*ateapipb.ActorAssignment], error)

func (*Persistence) ListWorkers

func (*Persistence) ReleaseActorFromWorker

func (p *Persistence) ReleaseActorFromWorker(ctx context.Context, workerName string, actorUID string) (*ateapipb.Worker, error)

func (*Persistence) UpdateActor

func (p *Persistence) UpdateActor(ctx context.Context, actorRef resources.ActorRef, precondition store.Precondition, mutate func(*ateapipb.Actor) error) (*ateapipb.Actor, error)

func (*Persistence) UpdateActorTemplate

func (p *Persistence) UpdateActorTemplate(ctx context.Context, templateRef resources.ActorTemplateRef, precondition store.Precondition, mutate func(*ateapipb.ActorTemplate) error) (*ateapipb.ActorTemplate, error)

func (*Persistence) UpdateEgressPolicy

func (p *Persistence) UpdateEgressPolicy(ctx context.Context, actorRef resources.ActorRef, precondition store.Precondition, mutate func(*ateapipb.EgressPolicy) error) (*ateapipb.EgressPolicy, error)

func (*Persistence) UpdateTag

func (p *Persistence) UpdateTag(ctx context.Context, tagRef resources.TagRef, precondition store.Precondition, mutate func(*ateapipb.Tag) error) (*ateapipb.Tag, error)

func (*Persistence) UpdateWorker

func (p *Persistence) UpdateWorker(ctx context.Context, name string, precondition store.Precondition, mutate func(*ateapipb.Worker) error) (*ateapipb.Worker, error)

UpdateWorker runs mutate against the worker read FOR UPDATE inside the write transaction, so a concurrent writer blocks on the row lock rather than interleaving. That is what makes an occupancy test inside mutate a compare-and-set. The predicate cannot be pushed into SQL: the row stores an opaque marshaled proto, so assignment is not addressable in a WHERE clause.

func (*Persistence) WatchWorkers

func (p *Persistence) WatchWorkers(ctx context.Context) (*store.WorkerWatch, error)

WatchWorkers subscribes by polling the worker_outbox table using an xid cursor. It fences reads behind pg_snapshot_xmin (the oldest in-flight transaction) to guarantee gap-free delivery. Note that a long-running transaction anywhere in the database will stall delivery.

Events are delivered in xid order, so consumers must reconcile worker versions. If the watcher detects missed events—either by lagging behind retention drops or if a database restart truncates the UNLOGGED partitions—it closes the channel to force the consumer to resync from the primary tables.

Jump to

Keyboard shortcuts

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