Documentation
¶
Overview ¶
Package sqlite implements store.Store on SQLite through the pure-Go modernc.org/sqlite driver (no CGO). Queries are generated by sqlc from queries.sql and the migrations in store/migrations/sqlite.
Concurrency settings, applied to every pooled connection:
- at most maxConns (8) open connections, kept idle without expiry: more connections only add writers queueing on SQLite's single write lock, and beyond the busy timeout they fail with SQLITE_BUSY; the pool queues them in Go instead;
- journal_mode=WAL: readers do not block the writer;
- busy_timeout=BusyTimeout (5 s): a writer waits up to 5 s for the write lock;
- _txlock=immediate: transactions take the write lock at BEGIN, so the busy timeout applies and two readers never deadlock upgrading to write;
- foreign_keys=ON and synchronous=NORMAL (durable with WAL).
Index ¶
- Constants
- Variables
- func SchemaVersionOf(ctx context.Context, path string) (int64, error)
- func SecretHosts(ctx context.Context, path string) (map[string][]string, error)
- func SecretKeyCounts(ctx context.Context, path string) (map[string]int64, error)
- func StoredTargetSources(ctx context.Context, path string) ([]store.TargetSource, error)
- type AckConsumerParams
- type AcquireLeaseParams
- type AddPendingReleaseParams
- type AddVersionParams
- type ApiToken
- type Consumer
- type CountDeliveriesByStatusRow
- type CountSecretsByKeyIDRow
- type CreateAPITokenParams
- type CreateConsumerParams
- type CreateDeliveryParams
- 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) 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) CreateDelivery(ctx context.Context, arg CreateDeliveryParams) 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 sql.NullInt64) (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) ([]Target, 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, id string) (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 ReleaseHeldDeliveryParams
- type ReleaseLeaseParams
- type ReplayDeliveryParams
- type RescheduleHeldDeliveryParams
- type RevokeAPITokenParams
- type Secret
- type SecretReader
- type SetTargetIntervalParams
- type Sink
- 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 BusyTimeout = 5 * time.Second
BusyTimeout is how long a writer waits for SQLite's write lock before failing with SQLITE_BUSY. Callers that bound a store write with their own timeout keep it above this value, so a busy database delays the write instead of cancelling it.
Variables ¶
var ErrNoDatabase = errors.New("store: database file does not exist")
ErrNoDatabase is returned by SecretKeyCounts when the database file does not exist.
Functions ¶
func SchemaVersionOf ¶ added in v0.2.0
SchemaVersionOf reads the schema version of the database file at path through a read-only connection with no pragmas, so the file is left byte-for-byte as it was, even an empty one: see Store.SchemaVersion. ErrNoDatabase when the file does not exist.
func SecretHosts ¶
SecretHosts reads the name and hosts of every stored secret from the database file at path, read-only like SecretKeyCounts and without touching a ciphertext. `angelia config check` uses it to check the secrets a configuration names. A database the secret migration has not reached has none. ErrNoDatabase when the file does not exist.
func SecretKeyCounts ¶
SecretKeyCounts opens the database file at path read-only, without creating it or applying migrations, and counts the stored secrets per key id. `angelia config check` uses it so that a check has no side effect. A database the secret migration has not reached has no secret: the result is empty. ErrNoDatabase when the file does not exist.
func StoredTargetSources ¶
StoredTargetSources reads the sources the stored targets use from the database file at path, read-only and without applying migrations, like SecretHosts. A database that has no targets yet, or that migration 00017 has not reached (every target then has the kind of its name), is read as far as it goes. ErrNoDatabase when the file does not exist.
Types ¶
type AckConsumerParams ¶ added in v0.2.0
type AcquireLeaseParams ¶
type AddPendingReleaseParams ¶
type AddVersionParams ¶
type CountSecretsByKeyIDRow ¶
type CreateAPITokenParams ¶ added in v0.2.0
type CreateConsumerParams ¶ added in v0.2.0
type CreateDeliveryParams ¶
type CreateDeliveryParams 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.NullInt64
HoldWatchID sql.NullString
HoldRaw sql.NullString
HoldInput sql.NullString
Traceparent sql.NullString
}
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.NullInt64
HoldWatchID sql.NullString
HoldRaw sql.NullString
HoldInput sql.NullString
Traceparent sql.NullString
ReplayBaseAttempts int64
}
type EventPrune ¶
type FailHeldDeliveryParams ¶
type FailHeldDeliveryParams struct {
Reason sql.NullString
ID string
Now sql.NullInt64
}
type FailPendingDeliveriesParams ¶
type FailPendingDeliveriesParams struct {
LastError sql.NullString
SubscriptionID string
}
type ListAPITokensPageParams ¶ added in v0.2.0
type ListActiveAPITokensPageParams ¶ added in v0.2.0
type ListConsumersPageParams ¶ added in v0.2.0
type ListDeliveriesPageRow ¶
type ListEventsAfterParams ¶
type ListNamedSinksPageParams ¶
type ListNamedSinksPageParams struct {
AfterName sql.NullString
AfterID string
MaxRows int64
}
type ListNamedSubscriptionsPageParams ¶
type ListNamedSubscriptionsPageParams struct {
AfterName sql.NullString
AfterID string
MaxRows int64
}
type ListNamedWatchesPageParams ¶
type ListNamedWatchesPageParams struct {
AfterName sql.NullString
AfterID string
MaxRows int64
}
type ListPendingReleasesRow ¶
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 ¶ added in v0.2.0
One statement, so concurrent acks never move the cursor back. A lower or equal seq changes nothing, acked_at included. An ack never changes updated_at, the time of the last filter change (spec schema Consumer).
func (*Queries) AcquireLease ¶
func (*Queries) AddPendingRelease ¶
func (*Queries) AddVersion ¶
func (*Queries) CountAPITokens ¶ added in v0.2.0
func (*Queries) CountActiveAdminTokens ¶ added in v0.2.0
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 ¶ added in v0.2.0
func (q *Queries) CreateAPIToken(ctx context.Context, arg CreateAPITokenParams) error
API tokens (story #72, ADR 0030 T3). Every write is one statement: the races (same active name, same id) end on the primary key and the partial unique index, never on a lock.
func (*Queries) CreateConsumer ¶ added in v0.2.0
func (q *Queries) CreateConsumer(ctx context.Context, arg CreateConsumerParams) error
Named consumers (story #79-B).
func (*Queries) CreateDelivery ¶
func (q *Queries) CreateDelivery(ctx context.Context, arg CreateDeliveryParams) error
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 ¶ added in v0.2.0
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. Leasing replaces the row and counts a new attempt, so a holder whose delivery was taken over (by another holder or by itself, after its lease expired) writes nothing.
func (*Queries) GetAPIToken ¶ added in v0.2.0
func (*Queries) GetConsumerByName ¶ added in v0.2.0
func (*Queries) GetDelivery ¶
func (*Queries) GetLatestEventBySubject ¶
func (q *Queries) GetLatestEventBySubject(ctx context.Context, arg GetLatestEventBySubjectParams) (Event, error)
The expression is the one of the event_watch_subject index (00009).
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 (00013).
func (*Queries) ListAPITokensPage ¶ added in v0.2.0
func (*Queries) ListActiveAPITokensPage ¶ added in v0.2.0
func (*Queries) ListConsumersPage ¶ added in v0.2.0
func (*Queries) ListDeliveries ¶
func (*Queries) ListDeliveriesPage ¶
func (q *Queries) ListDeliveriesPage(ctx context.Context, arg ListDeliveriesPageParams) ([]ListDeliveriesPageRow, error)
Newest event first, then by delivery id. all_subscriptions true ignores subscription_ids.
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). A delivery is due when it is pending and its next_attempt_at has passed (NULL counts as due), or when it is in flight under no unexpired lease: its holder crashed or stalled, so it is sent again (at-least-once). Oldest due first: ORDER BY next_attempt_at, id, NULLs first. Postgres will use FOR UPDATE SKIP LOCKED here instead.
The three kinds of due row are three disjoint branches, each read in order from delivery_status_next_attempt_at_id and cut at max_rows; the outer ORDER BY merges at most 3 * max_rows rows. The rows it returns are the ones a single ORDER BY over the OR of the branches would return, in the same order, but a lease no longer sorts the whole due backlog (story #232). The in_flight branch walks every in-flight row, skipping those under a live lease, so its cost grows with the number of deliveries in flight (bounded by the dispatcher workers of all instances), not with the backlog: about 0.27 ms with 16 in flight, 1.5 ms with 1,000 and 8.4 ms with 5,000 at 20k pending.
func (*Queries) ListLeasableDueTargets ¶
func (q *Queries) ListLeasableDueTargets(ctx context.Context, arg ListLeasableDueTargetsParams) ([]Target, error)
Due targets that no unexpired lease covers ('target:' || id, see store.TargetLeaseName), oldest due first. Postgres will use FOR UPDATE SKIP LOCKED here instead.
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). Additive: reads by name and by page, and replay. Rows without a name cannot be addressed through the API and are left out of its lists.
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 ¶
func (*Queries) ListWatchesManagedBy ¶
func (*Queries) MarkBaselineDone ¶
func (*Queries) MaxEventSeq ¶ added in v0.2.0
The highest seq ever committed: the log's newest event or, when pruning removed it, the highest pruned seq.
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 ¶
A replay keeps attempts and last_error, and starts a new retry budget from the current attempts (spec docs/api.md decision 28).
func (*Queries) RescheduleHeldDelivery ¶
func (*Queries) ResetWatchBaseline ¶
func (*Queries) RevokeAPIToken ¶ added in v0.2.0
func (*Queries) SetTargetInterval ¶
func (*Queries) StartDeliveryAttempt ¶
Every lease of a delivery counts as an attempt, so an attempt cut short by a crash counts too.
func (*Queries) SubscriptionGeneration ¶
func (*Queries) TargetExists ¶
func (*Queries) TouchAPIToken ¶ added in v0.2.0
func (q *Queries) TouchAPIToken(ctx context.Context, arg TouchAPITokenParams) error
last_used_at only moves forward. SQLite's max() of a NULL is NULL, hence the coalesce.
func (*Queries) UpdateConsumerFilter ¶ added in v0.2.0
func (*Queries) UpdateSecret ¶
An update fenced by the row's revision (ADR 0024 section 5): it writes only while the row is still at the revision the caller read, and increments it.
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 ReleaseLeaseParams ¶
type ReplayDeliveryParams ¶
type RevokeAPITokenParams ¶ added in v0.2.0
type SecretReader ¶
type SecretReader struct {
// contains filtered or unexported fields
}
SecretReader reads stored secrets from a database opened read-only, for `angelia config check` (ADR 0026 decided questions 4 and 7). It implements secrets.Lookup. Close it after use.
func OpenSecretReader ¶
func OpenSecretReader(ctx context.Context, path string) (*SecretReader, error)
OpenSecretReader opens the database file at path read-only, without creating it or applying migrations. ErrNoDatabase when the file does not exist; a database without the secret table reads as empty.
func (*SecretReader) SecretByName ¶
SecretByName returns the secret with this name, or store.ErrNotFound.
type SetTargetIntervalParams ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the SQLite engine. It is safe for concurrent use.
func Open ¶
Open opens (creating if needed) the database file at path and migrates it to the latest schema version. A nil logger means slog.Default.
func OpenExisting ¶ added in v0.2.0
OpenExisting opens the database file at path for reading and writing, like Open, but never creates the file and never migrates it: the store-only opener of `angelia token create --local` (ADR 0030 T7). The caller checks SchemaVersionOf first, since this open sets the pragmas of Open (WAL), which write to the file. ErrNoDatabase when the file does not exist.
func (*Store) APITokenByID ¶ added in v0.2.0
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.
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.
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 ¶ added in v0.2.0
ConsumerByName implements store.APIReader.
func (*Store) CountAPITokens ¶ added in v0.2.0
CountAPITokens implements store.TokenReader.
func (*Store) CountActiveAdminTokens ¶ added in v0.2.0
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 ¶ added in v0.2.0
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.
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.
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.
func (*Store) HasDueTargets ¶
HasDueTargets implements store.Store. It is a plain read, so an idle scheduler poll does not take SQLite's write lock.
func (*Store) HasEventsAfter ¶
HasEventsAfter implements store.APIReader.
func (*Store) HighestPrunedSeq ¶
HighestPrunedSeq implements store.Store. The event_prune_seq trigger (migration 00013) records it on every event delete, in the deleting transaction.
func (*Store) InAPITx ¶
InAPITx implements store.APIStore.
func (*Store) InConfigTx ¶
InConfigTx implements store.Store.
func (*Store) InSecretTx ¶
InSecretTx implements store.SecretStore. The transaction takes SQLite's write lock at BEGIN (_txlock=immediate), so no other writer interleaves.
func (*Store) InTx ¶
InTx implements store.Store.
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. Like LeaseDueTargets it runs in one immediate transaction, so SQLite's write lock serializes callers.
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. The select and the lease writes run in one immediate transaction, which holds SQLite's single write lock, so two callers never lease the same target.
func (*Store) ListAPITokens ¶ added in v0.2.0
func (s *Store) ListAPITokens(ctx context.Context, afterID string, limit int, includeRevoked bool) ([]store.APIToken, error)
ListAPITokens implements store.TokenReader.
func (*Store) ListConsumers ¶ added in v0.2.0
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.
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.
func (*Store) MarkBaselineDone ¶
MarkBaselineDone implements store.Tx in its own statement.
func (*Store) MaxEventSeq ¶ added in v0.2.0
MaxEventSeq implements store.APIReader: the larger of the newest event in the log and the highest pruned seq (event_prune, migration 00013).
func (*Store) PruneHistory ¶
func (s *Store) PruneHistory(ctx context.Context, before time.Time, batch int) (store.PruneResult, error)
PruneHistory implements store.Store. It walks the event log in seq order, batch events at a time (see [pruneBatchSize] for the bounds). Each batch is one transaction that deletes the terminal deliveries of its events, then the events that have no deliveries left. Events and deliveries that are still pending or in flight are kept, so the write lock is held only for one batch.
Age is the event's created_at. The delivery table has no timestamp of when a delivery reached its terminal state (next_attempt_at is the next schedule, not that moment), so a delivered or dead delivery is pruned together with its event, even if it finished more recently than the cutoff. For example, a delivery that died yesterday on an event older than the cutoff is deleted in this run. Keeping a longer dead-letter window needs a delivery timestamp, which is a migration and not part of this function.
func (*Store) ReleaseLease ¶
ReleaseLease implements store.Store.
func (*Store) RevokeAPIToken ¶ added in v0.2.0
func (s *Store) RevokeAPIToken(ctx context.Context, id string, at time.Time, by string) (bool, error)
RevokeAPIToken implements store.TokenStore.
func (*Store) SchemaVersion ¶ added in v0.2.0
SchemaVersion returns the highest applied migration version, 0 when the database 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).
func (*Store) TouchAPITokens ¶ added in v0.2.0
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. The lease check and the update are one statement; the existence check that tells a lost lease from a missing target runs in the same transaction.
func (*Store) UpdateVersion ¶
UpdateVersion implements store.Tx in its own statement.
func (*Store) WatchByName ¶
WatchByName implements store.APIReader.