Documentation
¶
Overview ¶
Package postgres is the Postgres store engine (story #85, ADR 0028), through pgx/v5 behind database/sql. Store implements store.APIStore with the same semantics as the SQLite engine; queries are generated by sqlc from queries.sql and the migrations in store/migrations/postgres.
This file holds the schema side: the schema key that scopes every advisory lock to the current schema, and the goose migrations, run under a session advisory lock so that processes starting at once migrate one after the other.
Index ¶
- Constants
- Variables
- func Migrate(ctx context.Context, db *sql.DB, logger *slog.Logger) (int, error)
- func SchemaKey(ctx context.Context, db *sql.DB) (int32, error)
- type AckConsumerParams
- type AcquireLeaseParams
- type AddPendingReleaseParams
- type AddVersionParams
- type AdvisoryXactLockParams
- type ApiToken
- type Consumer
- type CountDeliveriesByStatusRow
- type CountSecretsByKeyIDRow
- type CreateAPITokenParams
- type CreateConsumerParams
- type CreateEventParams
- type CreateSecretParams
- type CreateSinkParams
- type CreateSubscriptionParams
- type CreateTargetParams
- type CreateWatchParams
- type DBTX
- type DeleteExpiredLeaseParams
- type DeleteHeldDeliveriesOfEventParams
- type DeletePendingReleaseParams
- type Delivery
- type Event
- type EventPrune
- type FailHeldDeliveryParams
- type FailPendingDeliveriesParams
- type FinishLeasedDeliveryParams
- type GetLatestEventBySubjectParams
- type GetTargetByCoordinatesParams
- type Lease
- type ListAPITokensPageParams
- type ListActiveAPITokensPageParams
- type ListConsumersPageParams
- type ListDeliveriesPageParams
- type ListDeliveriesPageRow
- type ListEventsAfterParams
- type ListHeldDeliveriesParams
- type ListLeasableDueDeliveriesParams
- type ListLeasableDueTargetsParams
- type ListNamedSinksPageParams
- type ListNamedSubscriptionsPageParams
- type ListNamedWatchesPageParams
- type ListPendingReleasesRow
- type ListReplayCandidatesParams
- type ListReplayCandidatesRow
- type ListTargetDemandRow
- type ListTargetSourcesRow
- type PendingRelease
- type PruneBatchEndParams
- type PruneDeliveriesParams
- type PruneEventsParams
- type Queries
- func (q *Queries) AckConsumer(ctx context.Context, arg AckConsumerParams) (Consumer, error)
- func (q *Queries) AcquireLease(ctx context.Context, arg AcquireLeaseParams) (int64, error)
- func (q *Queries) AddPendingRelease(ctx context.Context, arg AddPendingReleaseParams) (int64, error)
- func (q *Queries) AddVersion(ctx context.Context, arg AddVersionParams) (int64, error)
- func (q *Queries) AdvisoryXactLock(ctx context.Context, arg AdvisoryXactLockParams) error
- func (q *Queries) CountAPITokens(ctx context.Context) (int64, error)
- func (q *Queries) CountActiveAdminTokens(ctx context.Context, now int64) (int64, error)
- func (q *Queries) CountDeliveriesByStatus(ctx context.Context) ([]CountDeliveriesByStatusRow, error)
- func (q *Queries) CountLeasableDueTargets(ctx context.Context, now int64) (int64, error)
- func (q *Queries) CountSecretsByKeyID(ctx context.Context) ([]CountSecretsByKeyIDRow, error)
- func (q *Queries) CreateAPIToken(ctx context.Context, arg CreateAPITokenParams) error
- func (q *Queries) CreateConsumer(ctx context.Context, arg CreateConsumerParams) error
- func (q *Queries) CreateDeliveries(ctx context.Context, deliveriesJson json.RawMessage) error
- func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) error
- func (q *Queries) CreateSecret(ctx context.Context, arg CreateSecretParams) error
- func (q *Queries) CreateSink(ctx context.Context, arg CreateSinkParams) error
- func (q *Queries) CreateSubscription(ctx context.Context, arg CreateSubscriptionParams) error
- func (q *Queries) CreateTarget(ctx context.Context, arg CreateTargetParams) error
- func (q *Queries) CreateWatch(ctx context.Context, arg CreateWatchParams) error
- func (q *Queries) DeleteConsumer(ctx context.Context, id string) (int64, error)
- func (q *Queries) DeleteExpiredLease(ctx context.Context, arg DeleteExpiredLeaseParams) error
- func (q *Queries) DeleteExpiredTargetLeases(ctx context.Context, expiresAt int64) (int64, error)
- func (q *Queries) DeleteHeldDeliveriesOfEvent(ctx context.Context, arg DeleteHeldDeliveriesOfEventParams) (int64, error)
- func (q *Queries) DeletePendingRelease(ctx context.Context, arg DeletePendingReleaseParams) (int64, error)
- func (q *Queries) DeletePendingReleasesOfWatch(ctx context.Context, watchID string) (int64, error)
- func (q *Queries) DeleteSecret(ctx context.Context, id string) (int64, error)
- func (q *Queries) DeleteSink(ctx context.Context, id string) (int64, error)
- func (q *Queries) DeleteSubscription(ctx context.Context, id string) (int64, error)
- func (q *Queries) DeleteTargetIfUnused(ctx context.Context, id string) (int64, error)
- func (q *Queries) DeleteTargetVersions(ctx context.Context, targetID string) error
- func (q *Queries) DeleteWatch(ctx context.Context, id string) (int64, error)
- func (q *Queries) FailHeldDelivery(ctx context.Context, arg FailHeldDeliveryParams) (int64, error)
- func (q *Queries) FailPendingDeliveries(ctx context.Context, arg FailPendingDeliveriesParams) (int64, error)
- func (q *Queries) FinishLeasedDelivery(ctx context.Context, arg FinishLeasedDeliveryParams) (int64, error)
- func (q *Queries) GetAPIToken(ctx context.Context, id string) (ApiToken, error)
- func (q *Queries) GetConsumerByName(ctx context.Context, name string) (Consumer, error)
- func (q *Queries) GetDelivery(ctx context.Context, id string) (Delivery, error)
- func (q *Queries) GetEvent(ctx context.Context, id string) (Event, error)
- func (q *Queries) GetLatestEventBySubject(ctx context.Context, arg GetLatestEventBySubjectParams) (Event, error)
- func (q *Queries) GetSecret(ctx context.Context, id string) (Secret, error)
- func (q *Queries) GetSecretByName(ctx context.Context, name string) (Secret, error)
- func (q *Queries) GetSink(ctx context.Context, id string) (Sink, error)
- func (q *Queries) GetSinkByName(ctx context.Context, name sql.NullString) (Sink, error)
- func (q *Queries) GetSubscription(ctx context.Context, id string) (Subscription, error)
- func (q *Queries) GetSubscriptionByName(ctx context.Context, name sql.NullString) (Subscription, error)
- func (q *Queries) GetTarget(ctx context.Context, id string) (Target, error)
- func (q *Queries) GetTargetByCoordinates(ctx context.Context, arg GetTargetByCoordinatesParams) (Target, error)
- func (q *Queries) GetWatch(ctx context.Context, id string) (Watch, error)
- func (q *Queries) GetWatchByName(ctx context.Context, name sql.NullString) (Watch, error)
- func (q *Queries) HasEventsAfter(ctx context.Context, seq int64) (bool, error)
- func (q *Queries) HasLeasableDueDeliveries(ctx context.Context, now int64) (bool, error)
- func (q *Queries) HasLeasableDueTargets(ctx context.Context, now int64) (bool, error)
- func (q *Queries) HighestPrunedSeq(ctx context.Context) (int64, error)
- func (q *Queries) ListAPITokensPage(ctx context.Context, arg ListAPITokensPageParams) ([]ApiToken, error)
- func (q *Queries) ListActiveAPITokensPage(ctx context.Context, arg ListActiveAPITokensPageParams) ([]ApiToken, error)
- func (q *Queries) ListConsumersPage(ctx context.Context, arg ListConsumersPageParams) ([]Consumer, error)
- func (q *Queries) ListDeliveries(ctx context.Context, eventID string) ([]Delivery, error)
- func (q *Queries) ListDeliveriesPage(ctx context.Context, arg ListDeliveriesPageParams) ([]ListDeliveriesPageRow, error)
- func (q *Queries) ListEventsAfter(ctx context.Context, arg ListEventsAfterParams) ([]Event, error)
- func (q *Queries) ListHeldDeliveries(ctx context.Context, arg ListHeldDeliveriesParams) ([]Delivery, error)
- func (q *Queries) ListLeasableDueDeliveries(ctx context.Context, arg ListLeasableDueDeliveriesParams) ([]string, error)
- func (q *Queries) ListLeasableDueTargets(ctx context.Context, arg ListLeasableDueTargetsParams) ([]string, error)
- func (q *Queries) ListNamedSinksPage(ctx context.Context, arg ListNamedSinksPageParams) ([]Sink, error)
- func (q *Queries) ListNamedSubscriptionsPage(ctx context.Context, arg ListNamedSubscriptionsPageParams) ([]Subscription, error)
- func (q *Queries) ListNamedWatchesPage(ctx context.Context, arg ListNamedWatchesPageParams) ([]Watch, error)
- func (q *Queries) ListPendingReleases(ctx context.Context, targetID string) ([]ListPendingReleasesRow, error)
- func (q *Queries) ListReplayCandidates(ctx context.Context, arg ListReplayCandidatesParams) ([]ListReplayCandidatesRow, error)
- func (q *Queries) ListSecrets(ctx context.Context) ([]Secret, error)
- func (q *Queries) ListSinksManagedBy(ctx context.Context, managedBy string) ([]Sink, error)
- func (q *Queries) ListSubscriptions(ctx context.Context) ([]Subscription, error)
- func (q *Queries) ListSubscriptionsBySink(ctx context.Context, sinkID string) ([]Subscription, error)
- func (q *Queries) ListSubscriptionsManagedBy(ctx context.Context, managedBy string) ([]Subscription, error)
- func (q *Queries) ListTargetDemand(ctx context.Context) ([]ListTargetDemandRow, error)
- func (q *Queries) ListTargetSources(ctx context.Context) ([]ListTargetSourcesRow, error)
- func (q *Queries) ListVersions(ctx context.Context, targetID string) ([]Version, error)
- func (q *Queries) ListWatchesByTarget(ctx context.Context, targetID string) ([]Watch, error)
- func (q *Queries) ListWatchesManagedBy(ctx context.Context, managedBy string) ([]Watch, error)
- func (q *Queries) MarkBaselineDone(ctx context.Context, id string) (int64, error)
- func (q *Queries) MaxEventSeq(ctx context.Context) (int64, error)
- func (q *Queries) PruneBatchEnd(ctx context.Context, arg PruneBatchEndParams) ([]int64, error)
- func (q *Queries) PruneDeliveries(ctx context.Context, arg PruneDeliveriesParams) (int64, error)
- func (q *Queries) PruneEvents(ctx context.Context, arg PruneEventsParams) (int64, error)
- func (q *Queries) ReleaseHeldDelivery(ctx context.Context, arg ReleaseHeldDeliveryParams) (int64, error)
- func (q *Queries) ReleaseLease(ctx context.Context, arg ReleaseLeaseParams) error
- func (q *Queries) ReplayDelivery(ctx context.Context, arg ReplayDeliveryParams) (int64, error)
- func (q *Queries) RescheduleHeldDelivery(ctx context.Context, arg RescheduleHeldDeliveryParams) (int64, error)
- func (q *Queries) ResetWatchBaseline(ctx context.Context, id string) (int64, error)
- func (q *Queries) RevokeAPIToken(ctx context.Context, arg RevokeAPITokenParams) (int64, error)
- func (q *Queries) SetTargetInterval(ctx context.Context, arg SetTargetIntervalParams) (int64, error)
- func (q *Queries) StartDeliveryAttempt(ctx context.Context, arg StartDeliveryAttemptParams) (Delivery, error)
- func (q *Queries) SubscriptionGeneration(ctx context.Context) (int64, error)
- func (q *Queries) TargetExists(ctx context.Context, id string) (bool, error)
- func (q *Queries) TouchAPIToken(ctx context.Context, arg TouchAPITokenParams) error
- func (q *Queries) UpdateConsumerFilter(ctx context.Context, arg UpdateConsumerFilterParams) (int64, error)
- func (q *Queries) UpdateSecret(ctx context.Context, arg UpdateSecretParams) (int64, error)
- func (q *Queries) UpdateSink(ctx context.Context, arg UpdateSinkParams) (int64, error)
- func (q *Queries) UpdateSubscription(ctx context.Context, arg UpdateSubscriptionParams) (int64, error)
- func (q *Queries) UpdateTargetState(ctx context.Context, arg UpdateTargetStateParams) (int64, error)
- func (q *Queries) UpdateTargetStateLeased(ctx context.Context, arg UpdateTargetStateLeasedParams) (int64, error)
- func (q *Queries) UpdateVersionState(ctx context.Context, arg UpdateVersionStateParams) (int64, error)
- func (q *Queries) UpdateWatchConfig(ctx context.Context, arg UpdateWatchConfigParams) (int64, error)
- func (q *Queries) WithTx(tx *sql.Tx) *Queries
- type Reader
- func (r *Reader) Close() error
- func (r *Reader) CountSecretsByKeyID(ctx context.Context) (map[string]int64, error)
- func (r *Reader) Initialized(ctx context.Context) (bool, error)
- func (r *Reader) ListSecrets(ctx context.Context) ([]store.Secret, error)
- func (r *Reader) SecretByName(ctx context.Context, name string) (store.Secret, error)
- func (r *Reader) TargetSources(ctx context.Context) ([]store.TargetSource, error)
- type ReleaseHeldDeliveryParams
- type ReleaseLeaseParams
- type ReplayDeliveryParams
- type RescheduleHeldDeliveryParams
- type RevokeAPITokenParams
- type Secret
- type SetTargetIntervalParams
- type Sink
- type StartDeliveryAttemptParams
- type Store
- func (s *Store) APITokenByID(ctx context.Context, id string) (store.APIToken, error)
- func (s *Store) AcquireLease(ctx context.Context, name, holder string, now, until time.Time) (bool, error)
- func (s *Store) AddPendingRelease(ctx context.Context, p store.PendingRelease) error
- func (s *Store) AddVersion(ctx context.Context, v store.Version) (bool, error)
- func (s *Store) AppendEvent(ctx context.Context, e store.Event, ds []store.Delivery) error
- func (s *Store) CancelHeldDeliveries(ctx context.Context, eventID string, now time.Time) (int64, error)
- func (s *Store) Close() error
- func (s *Store) ConsumerByName(ctx context.Context, name string) (store.Consumer, error)
- func (s *Store) CountAPITokens(ctx context.Context) (int64, error)
- func (s *Store) CountActiveAdminTokens(ctx context.Context, now time.Time) (int64, error)
- func (s *Store) CountDeliveriesByStatus(ctx context.Context) (map[string]int64, error)
- func (s *Store) CountDueTargets(ctx context.Context, now time.Time) (int64, error)
- func (s *Store) CountSecretsByKeyID(ctx context.Context) (map[string]int64, error)
- func (s *Store) CreateAPIToken(ctx context.Context, t store.APIToken) error
- func (s *Store) CreateSink(ctx context.Context, k store.Sink) error
- func (s *Store) CreateSubscription(ctx context.Context, sub store.Subscription) error
- func (s *Store) CreateTarget(ctx context.Context, t store.Target) error
- func (s *Store) CreateWatch(ctx context.Context, w store.Watch) error
- func (s *Store) DeleteExpiredTargetLeases(ctx context.Context, now time.Time) (int64, error)
- func (s *Store) DeletePendingRelease(ctx context.Context, watchID, targetID, raw string) error
- func (s *Store) DeletePendingReleasesOfWatch(ctx context.Context, watchID string) (int64, error)
- func (s *Store) DeleteSink(ctx context.Context, id string) error
- func (s *Store) DeleteSubscription(ctx context.Context, id string) error
- func (s *Store) DeleteWatch(ctx context.Context, id string) error
- func (s *Store) FinishDelivery(ctx context.Context, f store.DeliveryFinish, holder string) (bool, error)
- func (s *Store) GetDelivery(ctx context.Context, id string) (store.Delivery, error)
- func (s *Store) GetEvent(ctx context.Context, id string) (store.Event, error)
- func (s *Store) GetLatestEventBySubject(ctx context.Context, watchID, subject string, types ...string) (store.Event, error)
- func (s *Store) GetSink(ctx context.Context, id string) (store.Sink, error)
- func (s *Store) GetSubscription(ctx context.Context, id string) (store.Subscription, error)
- func (s *Store) GetTarget(ctx context.Context, id string) (store.Target, error)
- func (s *Store) GetWatch(ctx context.Context, id string) (store.Watch, error)
- func (s *Store) HasDueDeliveries(ctx context.Context, now time.Time) (bool, error)
- func (s *Store) HasDueTargets(ctx context.Context, now time.Time) (bool, error)
- func (s *Store) HasEventsAfter(ctx context.Context, seq int64) (bool, error)
- func (s *Store) HighestPrunedSeq(ctx context.Context) (int64, error)
- func (s *Store) InAPITx(ctx context.Context, fn func(tx store.APITx) error) error
- func (s *Store) InConfigTx(ctx context.Context, fn func(tx store.ConfigTx) error) error
- func (s *Store) InSecretTx(ctx context.Context, fn func(tx store.SecretTx) error) error
- func (s *Store) InTx(ctx context.Context, fn func(tx store.Tx) error) error
- func (s *Store) LeaseDueDeliveries(ctx context.Context, holder string, now, until time.Time, limit int) ([]store.LeasedDelivery, error)
- func (s *Store) LeaseDueTargets(ctx context.Context, holder string, now, until time.Time, limit int) ([]store.Target, error)
- func (s *Store) ListAPITokens(ctx context.Context, afterID string, limit int, includeRevoked bool) ([]store.APIToken, error)
- func (s *Store) ListConsumers(ctx context.Context, afterName, afterID string, limit int) ([]store.Consumer, error)
- func (s *Store) ListDeliveries(ctx context.Context, eventID string) ([]store.Delivery, error)
- func (s *Store) ListDeliveryPage(ctx context.Context, q store.DeliveryQuery) ([]store.DeliveryRow, error)
- func (s *Store) ListEventsAfter(ctx context.Context, afterSeq int64, limit int) ([]store.Event, error)
- func (s *Store) ListNamedSinks(ctx context.Context, afterName, afterID string, limit int) ([]store.Sink, error)
- func (s *Store) ListNamedSubscriptions(ctx context.Context, afterName, afterID string, limit int) ([]store.Subscription, error)
- func (s *Store) ListNamedWatches(ctx context.Context, afterName, afterID string, limit int) ([]store.Watch, error)
- func (s *Store) ListPendingReleases(ctx context.Context, targetID string) ([]store.PendingRelease, error)
- func (s *Store) ListSecrets(ctx context.Context) ([]store.Secret, error)
- func (s *Store) ListSubscriptions(ctx context.Context) ([]store.Subscription, error)
- func (s *Store) ListVersions(ctx context.Context, targetID string) ([]store.Version, error)
- func (s *Store) ListWatches(ctx context.Context, targetID string) ([]store.Watch, error)
- func (s *Store) MarkBaselineDone(ctx context.Context, watchID string) error
- func (s *Store) MaxEventSeq(ctx context.Context) (int64, error)
- func (s *Store) PruneHistory(ctx context.Context, before time.Time, batch int) (store.PruneResult, error)
- func (s *Store) ReleaseLease(ctx context.Context, name, holder string) error
- func (s *Store) RevokeAPIToken(ctx context.Context, id string, at time.Time, by string) (bool, error)
- func (s *Store) SchemaVersion(ctx context.Context) (int64, error)
- func (s *Store) SecretByName(ctx context.Context, name string) (store.Secret, error)
- func (s *Store) SinkByName(ctx context.Context, name string) (store.Sink, error)
- func (s *Store) SubscriptionByName(ctx context.Context, name string) (store.Subscription, error)
- func (s *Store) SubscriptionGeneration(ctx context.Context) (int64, error)
- func (s *Store) SubscriptionsBySink(ctx context.Context, sinkID string) ([]store.Subscription, error)
- func (s *Store) TargetDemand(ctx context.Context) ([]store.TargetDemand, error)
- func (s *Store) TargetSources(ctx context.Context) ([]store.TargetSource, error)
- func (s *Store) TouchAPITokens(ctx context.Context, used map[string]time.Time) error
- func (s *Store) UpdateTarget(ctx context.Context, t store.Target) error
- func (s *Store) UpdateTargetLeased(ctx context.Context, t store.Target, leaseName, holder string, now time.Time) (bool, error)
- func (s *Store) UpdateVersion(ctx context.Context, v store.Version) error
- func (s *Store) WatchByName(ctx context.Context, name string) (store.Watch, error)
- type Subscription
- type SubscriptionGeneration
- type Target
- type TouchAPITokenParams
- type UpdateConsumerFilterParams
- type UpdateSecretParams
- type UpdateSinkParams
- type UpdateSubscriptionParams
- type UpdateTargetStateLeasedParams
- type UpdateTargetStateParams
- type UpdateVersionStateParams
- type UpdateWatchConfigParams
- type Version
- type Watch
Constants ¶
const DriverName = "pgx"
DriverName is the database/sql driver name of pgx/v5/stdlib.
Variables ¶
var ErrNoDatabase = errors.New("store: postgres: the database does not exist")
ErrNoDatabase says that the database named by the DSN does not exist on the server. Reader.Initialized tells whether Angelia ever created its tables in it.
var ErrNoSchema = errors.New("store: postgres: the search_path names no existing schema")
ErrNoSchema says that the connection's search_path names no existing schema, so current_schema() is NULL and there is nowhere to create the tables.
Functions ¶
func Migrate ¶
Migrate applies the pending Postgres migrations to the current schema and returns how many it applied. Running it on an up-to-date schema is a no-op. It holds a session advisory lock, scoped to the schema, while it runs, so processes that start at once on an empty schema both succeed and goose records each version once. A nil logger means slog.Default.
func SchemaKey ¶
SchemaKey returns the advisory-lock key of the connection's current schema, hashtext(current_schema()) (ADR 0028 §4). Two schemas, for example two Angelia instances in one database or two tests, get different keys, so their locks do not contend; a hash collision only adds waiting. It returns ErrNoSchema when current_schema() is NULL.
Types ¶
type AckConsumerParams ¶
type AcquireLeaseParams ¶
type AddPendingReleaseParams ¶
type AddVersionParams ¶
type AdvisoryXactLockParams ¶
type CountSecretsByKeyIDRow ¶
type CreateAPITokenParams ¶
type CreateConsumerParams ¶
type CreateEventParams ¶
type CreateSecretParams ¶
type CreateSinkParams ¶
type CreateTargetParams ¶
type CreateWatchParams ¶
type Delivery ¶
type Delivery struct {
ID string
EventID string
SubscriptionID string
Status string
Attempts int64
NextAttemptAt sql.NullInt64
LastError sql.NullString
HeldUntil sql.NullInt64
HoldStartedAt sql.NullInt64
HoldWatchCooldownMs sql.NullInt64
HoldPrerelease sql.NullBool
HoldWatchID sql.NullString
HoldRaw sql.NullString
HoldInput sql.NullString
Traceparent sql.NullString
ReplayBaseAttempts int64
}
type EventPrune ¶
type FailHeldDeliveryParams ¶
type FailPendingDeliveriesParams ¶
type FailPendingDeliveriesParams struct {
LastError sql.NullString
SubscriptionID string
}
type GetLatestEventBySubjectParams ¶
type GetLatestEventBySubjectParams struct {
WatchID string
Subject string
TypesJson json.RawMessage
}
type ListAPITokensPageParams ¶
type ListConsumersPageParams ¶
type ListDeliveriesPageRow ¶
type ListEventsAfterParams ¶
type ListPendingReleasesRow ¶
type ListReplayCandidatesParams ¶
type ListReplayCandidatesParams struct {
StatusesJson json.RawMessage
EventID string
SubscriptionID string
}
type ListReplayCandidatesRow ¶
type ListTargetDemandRow ¶
type ListTargetSourcesRow ¶
type ListTargetSourcesRow struct {
Kind string
SourceKind sql.NullString
Targets int64
}
type PendingRelease ¶
type PruneBatchEndParams ¶
type PruneDeliveriesParams ¶
type PruneEventsParams ¶
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func (*Queries) AckConsumer ¶
One statement, so concurrent acks never move the cursor back: the UPDATE re-reads the newest row version under READ COMMITTED.
func (*Queries) AcquireLease ¶
func (*Queries) AddPendingRelease ¶
func (*Queries) AddVersion ¶
func (*Queries) AdvisoryXactLock ¶
func (q *Queries) AdvisoryXactLock(ctx context.Context, arg AdvisoryXactLockParams) error
Postgres twin of sqlite/queries.sql (story #85, ADR 0028). The queries keep the SQLite names and semantics; the differences are Postgres syntax ($n, greatest, NULLS FIRST), booleans for the 0/1 flags, and lists passed as JSON text (json_array_elements_text) instead of sqlc.slice (ADR 0028 §5). Advisory locks (ADR 0028 §4): the first argument is the schema key, the second the kind (1 config, 2 event, 3 lease).
func (*Queries) CountAPITokens ¶
func (*Queries) CountActiveAdminTokens ¶
func (*Queries) CountDeliveriesByStatus ¶
func (q *Queries) CountDeliveriesByStatus(ctx context.Context) ([]CountDeliveriesByStatusRow, error)
func (*Queries) CountLeasableDueTargets ¶
func (*Queries) CountSecretsByKeyID ¶
func (q *Queries) CountSecretsByKeyID(ctx context.Context) ([]CountSecretsByKeyIDRow, error)
func (*Queries) CreateAPIToken ¶
func (q *Queries) CreateAPIToken(ctx context.Context, arg CreateAPITokenParams) error
API tokens (story #72, ADR 0030 T3). Every write is one statement and takes no config lock: the races (same active name, same id) end on the primary key and the partial unique index.
func (*Queries) CreateConsumer ¶
func (q *Queries) CreateConsumer(ctx context.Context, arg CreateConsumerParams) error
Named consumers (story #79-B).
func (*Queries) CreateDeliveries ¶
All deliveries of an event in one statement (ADR 0028 §1: the event lock is held for one round trip per event, whatever the number of subscriptions). deliveries_json is an array of objects keyed by column name.
func (*Queries) CreateEvent ¶
func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) error
func (*Queries) CreateSecret ¶
func (q *Queries) CreateSecret(ctx context.Context, arg CreateSecretParams) error
Stored secrets (story #75, ADR 0024 section 6).
func (*Queries) CreateSink ¶
func (q *Queries) CreateSink(ctx context.Context, arg CreateSinkParams) error
func (*Queries) CreateSubscription ¶
func (q *Queries) CreateSubscription(ctx context.Context, arg CreateSubscriptionParams) error
func (*Queries) CreateTarget ¶
func (q *Queries) CreateTarget(ctx context.Context, arg CreateTargetParams) error
func (*Queries) CreateWatch ¶
func (q *Queries) CreateWatch(ctx context.Context, arg CreateWatchParams) error
func (*Queries) DeleteConsumer ¶
func (*Queries) DeleteExpiredLease ¶
func (q *Queries) DeleteExpiredLease(ctx context.Context, arg DeleteExpiredLeaseParams) error
func (*Queries) DeleteExpiredTargetLeases ¶
func (*Queries) DeleteHeldDeliveriesOfEvent ¶
func (q *Queries) DeleteHeldDeliveriesOfEvent(ctx context.Context, arg DeleteHeldDeliveriesOfEventParams) (int64, error)
A yank cancels the deliveries of the original event that are still held (ADR 0014 section 4, ADR 0018).
func (*Queries) DeletePendingRelease ¶
func (*Queries) DeletePendingReleasesOfWatch ¶
func (*Queries) DeleteSecret ¶
func (*Queries) DeleteSink ¶
func (*Queries) DeleteSubscription ¶
func (*Queries) DeleteTargetIfUnused ¶
func (*Queries) DeleteTargetVersions ¶
func (*Queries) DeleteWatch ¶
func (*Queries) FailHeldDelivery ¶
func (*Queries) FailPendingDeliveries ¶
func (*Queries) FinishLeasedDelivery ¶
func (q *Queries) FinishLeasedDelivery(ctx context.Context, arg FinishLeasedDeliveryParams) (int64, error)
The end of an attempt, fenced by its lease: it applies only while holder still owns the lease row, expired or not, and the row is still at this attempt.
func (*Queries) GetAPIToken ¶
func (*Queries) GetConsumerByName ¶
func (*Queries) GetDelivery ¶
func (*Queries) GetLatestEventBySubject ¶
func (q *Queries) GetLatestEventBySubject(ctx context.Context, arg GetLatestEventBySubjectParams) (Event, error)
The expression, collation included, is the one of the event_watch_subject index (ADR 0018, ADR 0028 §7), so the lookup walks it.
func (*Queries) GetSecretByName ¶
func (*Queries) GetSinkByName ¶
func (*Queries) GetSubscription ¶
func (*Queries) GetSubscriptionByName ¶
func (q *Queries) GetSubscriptionByName(ctx context.Context, name sql.NullString) (Subscription, error)
func (*Queries) GetTargetByCoordinates ¶
func (*Queries) GetWatchByName ¶
func (*Queries) HasEventsAfter ¶
func (*Queries) HasLeasableDueDeliveries ¶
func (*Queries) HasLeasableDueTargets ¶
func (*Queries) HighestPrunedSeq ¶
Kept current by the event_prune_seq trigger.
func (*Queries) ListAPITokensPage ¶
func (*Queries) ListActiveAPITokensPage ¶
func (*Queries) ListConsumersPage ¶
func (*Queries) ListDeliveries ¶
func (*Queries) ListDeliveriesPage ¶
func (q *Queries) ListDeliveriesPage(ctx context.Context, arg ListDeliveriesPageParams) ([]ListDeliveriesPageRow, error)
Newest event first, then by delivery id. A subscription_ids_json of 'null' keeps every subscription.
func (*Queries) ListEventsAfter ¶
func (*Queries) ListHeldDeliveries ¶
func (q *Queries) ListHeldDeliveries(ctx context.Context, arg ListHeldDeliveriesParams) ([]Delivery, error)
A held delivery is pending and held_until is still ahead.
func (*Queries) ListLeasableDueDeliveries ¶
func (q *Queries) ListLeasableDueDeliveries(ctx context.Context, arg ListLeasableDueDeliveriesParams) ([]string, error)
Dispatcher (story #107, ADR 0017). The same three disjoint branches as on SQLite (story #232), each read in order from delivery_status_next_attempt_at_id, which is built NULLS FIRST.
func (*Queries) ListLeasableDueTargets ¶
func (q *Queries) ListLeasableDueTargets(ctx context.Context, arg ListLeasableDueTargetsParams) ([]string, error)
Due targets that no unexpired lease covers ('target:' || id, see store.TargetLeaseName), oldest due first. #86 adds FOR UPDATE SKIP LOCKED; until then the lease lock serializes lease transactions (ADR 0028 §3).
func (*Queries) ListNamedSinksPage ¶
func (*Queries) ListNamedSubscriptionsPage ¶
func (q *Queries) ListNamedSubscriptionsPage(ctx context.Context, arg ListNamedSubscriptionsPageParams) ([]Subscription, error)
func (*Queries) ListNamedWatchesPage ¶
func (q *Queries) ListNamedWatchesPage(ctx context.Context, arg ListNamedWatchesPageParams) ([]Watch, error)
REST API (story #71).
func (*Queries) ListPendingReleases ¶
func (q *Queries) ListPendingReleases(ctx context.Context, targetID string) ([]ListPendingReleasesRow, error)
Rows of watches that moved to another target are left out.
func (*Queries) ListReplayCandidates ¶
func (q *Queries) ListReplayCandidates(ctx context.Context, arg ListReplayCandidatesParams) ([]ListReplayCandidatesRow, error)
func (*Queries) ListSinksManagedBy ¶
func (*Queries) ListSubscriptions ¶
func (q *Queries) ListSubscriptions(ctx context.Context) ([]Subscription, error)
func (*Queries) ListSubscriptionsBySink ¶
func (*Queries) ListSubscriptionsManagedBy ¶
func (*Queries) ListTargetDemand ¶
func (q *Queries) ListTargetDemand(ctx context.Context) ([]ListTargetDemandRow, error)
func (*Queries) ListTargetSources ¶
func (q *Queries) ListTargetSources(ctx context.Context) ([]ListTargetSourcesRow, error)
func (*Queries) ListVersions ¶
func (*Queries) ListWatchesByTarget ¶
A check reads its watches FOR SHARE (ADR 0028 §2): a config transaction that updates or deletes one of them waits until the check commits. Config transactions must update a watch before deleting its held versions.
func (*Queries) ListWatchesManagedBy ¶
NULLS FIRST: SQLite sorts NULL names first, Postgres last by default.
func (*Queries) MarkBaselineDone ¶
func (*Queries) PruneBatchEnd ¶
There is no index on event.created_at, so this scans by seq from after_seq and stops at batch matches. That is fine for a periodic job, not for a hot path.
func (*Queries) PruneDeliveries ¶
func (*Queries) PruneEvents ¶
func (*Queries) ReleaseHeldDelivery ¶
func (q *Queries) ReleaseHeldDelivery(ctx context.Context, arg ReleaseHeldDeliveryParams) (int64, error)
The held queries only touch a delivery that is still held at now.
func (*Queries) ReleaseLease ¶
func (q *Queries) ReleaseLease(ctx context.Context, arg ReleaseLeaseParams) error
func (*Queries) ReplayDelivery ¶
func (*Queries) RescheduleHeldDelivery ¶
func (*Queries) ResetWatchBaseline ¶
func (*Queries) RevokeAPIToken ¶
func (*Queries) SetTargetInterval ¶
func (*Queries) StartDeliveryAttempt ¶
func (q *Queries) StartDeliveryAttempt(ctx context.Context, arg StartDeliveryAttemptParams) (Delivery, error)
Every lease of a delivery counts as an attempt, so an attempt cut short by a crash counts too. Unlike SQLite's, the update repeats the due predicate of ListLeasableDueDeliveries (ADR 0028 §3): writers that take no lease lock (FailPendingDeliveries, FailHeldDelivery, CancelHeldDeliveries) may have changed or deleted the row since it was selected; then no row comes back and the caller skips it. The holder's own new lease does not count.
func (*Queries) SubscriptionGeneration ¶
func (*Queries) TargetExists ¶
func (*Queries) TouchAPIToken ¶
func (q *Queries) TouchAPIToken(ctx context.Context, arg TouchAPITokenParams) error
last_used_at only moves forward; the UPDATE re-reads the newest row version under READ COMMITTED, so concurrent touches never move it back.
func (*Queries) UpdateConsumerFilter ¶
func (*Queries) UpdateSecret ¶
Fenced by the row's revision (ADR 0024 section 5). Under READ COMMITTED a concurrent update of the row makes Postgres re-check the WHERE on the newest version, so one of two writers at the same revision wins.
func (*Queries) UpdateSink ¶
func (*Queries) UpdateSubscription ¶
func (*Queries) UpdateTargetState ¶
func (*Queries) UpdateTargetStateLeased ¶
func (q *Queries) UpdateTargetStateLeased(ctx context.Context, arg UpdateTargetStateLeasedParams) (int64, error)
The target write of a check, fenced by its lease: it only applies while holder still owns an unexpired lease named lease_name.
func (*Queries) UpdateVersionState ¶
func (*Queries) UpdateWatchConfig ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads stored secrets and target sources over connections that are read-only (default_transaction_read_only). It never creates a schema, a table or a migration record, and never runs the migrations, so `angelia config check`, `secrets status` and the start-up checks leave a database as they found it, whatever the DSN. It implements store.SecretReader on the tables that exist: a database Angelia has not reached reads as empty. Close it after use.
func OpenReader ¶
OpenReader connects to the database named by dsn (same syntax and parameters as Open) for reading only. It returns ErrNoDatabase when the database does not exist; any other failure is an error that never holds the password.
func (*Reader) CountSecretsByKeyID ¶
CountSecretsByKeyID implements store.SecretReader.
func (*Reader) Initialized ¶
Initialized reports whether Angelia has created its tables here, which is what the instance-side commands need before they open the store.
func (*Reader) ListSecrets ¶
ListSecrets implements store.SecretReader.
func (*Reader) SecretByName ¶
SecretByName implements store.SecretReader; store.ErrNotFound without the secret table.
func (*Reader) TargetSources ¶
TargetSources lists the sources the stored targets use; none without the target table.
type ReleaseLeaseParams ¶
type ReplayDeliveryParams ¶
type RevokeAPITokenParams ¶
type SetTargetIntervalParams ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the Postgres engine. It is safe for concurrent use.
Transactions run at READ COMMITTED. Config, API and secret transactions (and the Store methods that write config rows) take the config lock as their first statement; lease transactions take the lease lock as theirs; a check transaction takes the event lock before each event insert, so event.seq is in commit order (ADR 0028 §1-§4).
func Open ¶
Open connects to the Postgres database named by dsn (a postgres:// URL or keyword/value pairs; the schema is the first existing one of its search_path) and migrates it to the latest schema version. The pool size is the DSN parameter pool_max_conns, which is removed before the DSN reaches the server (default: max(4, number of CPUs), like pgxpool). Neither the logs nor the errors ever hold the DSN. A nil logger means slog.Default.
func OpenExisting ¶
OpenExisting connects to the database named by dsn (same syntax and parameters as Open) for reading and writing, but never creates a schema and never migrates: the store-only opener of `angelia token create --local` (ADR 0030 T7). The caller checks Store.SchemaVersion before it writes. ErrNoDatabase when the database does not exist; any other failure is an error that never holds the password.
func (*Store) APITokenByID ¶
APITokenByID implements store.TokenReader.
func (*Store) AcquireLease ¶
func (s *Store) AcquireLease(ctx context.Context, name, holder string, now, until time.Time) (bool, error)
AcquireLease implements store.Store, under the lease lock.
func (*Store) AddPendingRelease ¶
AddPendingRelease implements store.Tx in its own statement.
func (*Store) AddVersion ¶
AddVersion implements store.Tx in its own statement.
func (*Store) AppendEvent ¶
AppendEvent implements store.Tx in its own transaction, under the event lock.
func (*Store) CancelHeldDeliveries ¶
func (s *Store) CancelHeldDeliveries(ctx context.Context, eventID string, now time.Time) (int64, error)
CancelHeldDeliveries implements store.Tx in its own statement.
func (*Store) ConsumerByName ¶
ConsumerByName implements store.APIReader.
func (*Store) CountAPITokens ¶
CountAPITokens implements store.TokenReader.
func (*Store) CountActiveAdminTokens ¶
CountActiveAdminTokens implements store.TokenReader.
func (*Store) CountDeliveriesByStatus ¶
CountDeliveriesByStatus implements store.Store.
func (*Store) CountDueTargets ¶
CountDueTargets implements store.Store.
func (*Store) CountSecretsByKeyID ¶
CountSecretsByKeyID implements store.SecretReader.
func (*Store) CreateAPIToken ¶
CreateAPIToken implements store.TokenStore.
func (*Store) CreateSink ¶
CreateSink implements store.Store.
func (*Store) CreateSubscription ¶
CreateSubscription implements store.Store.
func (*Store) CreateTarget ¶
CreateTarget implements store.Store.
func (*Store) CreateWatch ¶
CreateWatch implements store.Store.
func (*Store) DeleteExpiredTargetLeases ¶
DeleteExpiredTargetLeases implements store.Store, under the lease lock.
func (*Store) DeletePendingRelease ¶
DeletePendingRelease implements store.Tx in its own statement.
func (*Store) DeletePendingReleasesOfWatch ¶
DeletePendingReleasesOfWatch implements store.Tx in its own statement.
func (*Store) DeleteSink ¶
DeleteSink implements store.Store.
func (*Store) DeleteSubscription ¶
DeleteSubscription implements store.Store.
func (*Store) DeleteWatch ¶
DeleteWatch implements store.Store.
func (*Store) FinishDelivery ¶
func (s *Store) FinishDelivery(ctx context.Context, f store.DeliveryFinish, holder string) (bool, error)
FinishDelivery implements store.Store, under the lease lock.
func (*Store) GetDelivery ¶
GetDelivery implements store.APIReader.
func (*Store) GetEvent ¶
GetEvent implements store.APIReader.
func (*Store) GetLatestEventBySubject ¶
func (s *Store) GetLatestEventBySubject(ctx context.Context, watchID, subject string, types ...string) (store.Event, error)
GetLatestEventBySubject implements store.Tx outside a transaction.
func (*Store) GetSink ¶
GetSink implements store.APIReader.
func (*Store) GetSubscription ¶
GetSubscription implements store.APIReader.
func (*Store) GetTarget ¶
GetTarget implements store.Store.
func (*Store) GetWatch ¶
GetWatch implements store.Store.
func (*Store) HasDueDeliveries ¶
HasDueDeliveries implements store.Store with a read only.
func (*Store) HasDueTargets ¶
HasDueTargets implements store.Store with a read only.
func (*Store) HasEventsAfter ¶
HasEventsAfter implements store.APIReader.
func (*Store) HighestPrunedSeq ¶
HighestPrunedSeq implements store.Store.
func (*Store) InAPITx ¶
InAPITx implements store.APIStore, under the config lock.
func (*Store) InConfigTx ¶
InConfigTx implements store.Store. The transaction takes the config lock first, so config, API and secret writes serialize as on SQLite (ADR 0028 §2).
func (*Store) InSecretTx ¶
InSecretTx implements store.SecretStore. The transaction takes the config lock first, so no other config, API or secret write interleaves with a rotation batch (ADR 0028 §2); UpdateSecret keeps its revision fence too.
func (*Store) InTx ¶
InTx implements store.Store. A check transaction takes no lock at BEGIN: AppendEvent takes the event lock before each insert.
func (*Store) LeaseDueDeliveries ¶
func (s *Store) LeaseDueDeliveries(ctx context.Context, holder string, now, until time.Time, limit int) ([]store.LeasedDelivery, error)
LeaseDueDeliveries implements store.Store under the lease lock (ADR 0028 §3). Writers that take no lease lock (FailPendingDeliveries, FailHeldDelivery, CancelHeldDeliveries) can change or delete a selected row before it is set in flight: StartDeliveryAttempt re-checks the due predicate, and a row that no longer matches is skipped and its new lease dropped, instead of being revived or failing the batch.
func (*Store) LeaseDueTargets ¶
func (s *Store) LeaseDueTargets(ctx context.Context, holder string, now, until time.Time, limit int) ([]store.Target, error)
LeaseDueTargets implements store.Store. It runs under the lease lock, so lease transactions of every process exclude each other (ADR 0028 §3). Each target is read back after its lease is written: one deleted since the select (DeleteTargetIfUnused takes no lease lock) is skipped and its new lease dropped.
func (*Store) ListAPITokens ¶
func (s *Store) ListAPITokens(ctx context.Context, afterID string, limit int, includeRevoked bool) ([]store.APIToken, error)
ListAPITokens implements store.TokenReader.
func (*Store) ListConsumers ¶
func (s *Store) ListConsumers(ctx context.Context, afterName, afterID string, limit int) ([]store.Consumer, error)
ListConsumers implements store.APIReader.
func (*Store) ListDeliveries ¶
ListDeliveries implements store.Store.
func (*Store) ListDeliveryPage ¶
func (s *Store) ListDeliveryPage(ctx context.Context, q store.DeliveryQuery) ([]store.DeliveryRow, error)
ListDeliveryPage implements store.APIReader.
func (*Store) ListEventsAfter ¶
func (s *Store) ListEventsAfter(ctx context.Context, afterSeq int64, limit int) ([]store.Event, error)
ListEventsAfter implements store.Store: one statement, so one snapshot. Event inserts hold the event lock until they commit, so the events it sees above the cursor are a prefix of what will ever commit there (ADR 0028 §1).
func (*Store) ListNamedSinks ¶
func (s *Store) ListNamedSinks(ctx context.Context, afterName, afterID string, limit int) ([]store.Sink, error)
ListNamedSinks implements store.APIReader.
func (*Store) ListNamedSubscriptions ¶
func (s *Store) ListNamedSubscriptions(ctx context.Context, afterName, afterID string, limit int) ([]store.Subscription, error)
ListNamedSubscriptions implements store.APIReader.
func (*Store) ListNamedWatches ¶
func (s *Store) ListNamedWatches(ctx context.Context, afterName, afterID string, limit int) ([]store.Watch, error)
ListNamedWatches implements store.APIReader.
func (*Store) ListPendingReleases ¶
func (s *Store) ListPendingReleases(ctx context.Context, targetID string) ([]store.PendingRelease, error)
ListPendingReleases implements store.Tx outside a transaction.
func (*Store) ListSecrets ¶
ListSecrets implements store.SecretReader.
func (*Store) ListSubscriptions ¶
ListSubscriptions implements store.Tx outside a transaction.
func (*Store) ListVersions ¶
ListVersions implements store.Tx outside a transaction.
func (*Store) ListWatches ¶
ListWatches implements store.Tx outside a transaction (its share locks end with the statement).
func (*Store) MarkBaselineDone ¶
MarkBaselineDone implements store.Tx in its own statement.
func (*Store) MaxEventSeq ¶
MaxEventSeq implements store.APIReader.
func (*Store) PruneHistory ¶
func (s *Store) PruneHistory(ctx context.Context, before time.Time, batch int) (store.PruneResult, error)
PruneHistory implements store.Store like the SQLite engine: batches of events in seq order, each one transaction that deletes the terminal deliveries of its events, then the events left without deliveries. It takes no advisory lock; the event_prune_seq trigger updates one row, so two prunes queue on it (ADR 0028 §2).
func (*Store) ReleaseLease ¶
ReleaseLease implements store.Store, under the lease lock.
func (*Store) RevokeAPIToken ¶
func (s *Store) RevokeAPIToken(ctx context.Context, id string, at time.Time, by string) (bool, error)
RevokeAPIToken implements store.TokenStore.
func (*Store) SchemaVersion ¶
SchemaVersion returns the highest applied migration version of the current schema, 0 when it holds no migration record (Angelia never migrated it).
func (*Store) SecretByName ¶
SecretByName implements store.SecretReader.
func (*Store) SinkByName ¶
SinkByName implements store.APIReader.
func (*Store) SubscriptionByName ¶
SubscriptionByName implements store.APIReader.
func (*Store) SubscriptionGeneration ¶
SubscriptionGeneration implements store.Tx outside a transaction.
func (*Store) SubscriptionsBySink ¶
func (s *Store) SubscriptionsBySink(ctx context.Context, sinkID string) ([]store.Subscription, error)
SubscriptionsBySink implements store.APIReader.
func (*Store) TargetDemand ¶
TargetDemand groups the stored targets by source name and check interval, for the per-host request demand estimate of the scheduler (story #220).
func (*Store) TargetSources ¶
TargetSources lists the distinct sources the stored targets use, with how many targets each has, for `config check` and the start-up check of the configured source names (story #205). Like the SQLite engine's method of the same name, it is not part of store.Store.
func (*Store) TouchAPITokens ¶
TouchAPITokens implements store.TokenStore: one UPDATE per id, in id order.
func (*Store) UpdateTarget ¶
UpdateTarget implements store.Tx in its own statement.
func (*Store) UpdateTargetLeased ¶
func (s *Store) UpdateTargetLeased(ctx context.Context, t store.Target, leaseName, holder string, now time.Time) (bool, error)
UpdateTargetLeased implements store.Store, under the lease lock.
func (*Store) UpdateVersion ¶
UpdateVersion implements store.Tx in its own statement.
func (*Store) WatchByName ¶
WatchByName implements store.APIReader.