sqlite

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
var ErrNoDatabase = errors.New("store: database file does not exist")

ErrNoDatabase is returned by SecretKeyCounts when the database file does not exist.

Functions

func SecretHosts

func SecretHosts(ctx context.Context, path string) (map[string][]string, error)

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

func SecretKeyCounts(ctx context.Context, path string) (map[string]int64, error)

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

func StoredTargetSources(ctx context.Context, path string) ([]store.TargetSource, error)

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 AcquireLeaseParams

type AcquireLeaseParams struct {
	Name      string
	Holder    string
	ExpiresAt int64
}

type AddPendingReleaseParams

type AddPendingReleaseParams struct {
	WatchID     string
	TargetID    string
	Raw         string
	HeldAt      int64
	ReleaseJson string
}

type AddVersionParams

type AddVersionParams struct {
	TargetID    string
	Raw         string
	Normalized  string
	PublishedAt sql.NullInt64
	Prerelease  int64
	Yanked      int64
	FirstSeenAt int64
	RemovedAt   sql.NullInt64
}

type CountDeliveriesByStatusRow

type CountDeliveriesByStatusRow struct {
	Status string
	N      int64
}

type CountSecretsByKeyIDRow

type CountSecretsByKeyIDRow struct {
	KeyID string
	N     int64
}

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 CreateEventParams struct {
	ID          string
	WatchID     string
	Type        string
	PayloadJson string
	CreatedAt   int64
	RefEventID  sql.NullString
}

type CreateSecretParams

type CreateSecretParams struct {
	ID         string
	Name       string
	HostsJson  string
	KeyID      string
	Ciphertext []byte
	CreatedAt  int64
	UpdatedAt  int64
}

type CreateSinkParams

type CreateSinkParams struct {
	ID         string
	Kind       string
	ConfigJson []byte
	Name       sql.NullString
	ManagedBy  string
}

type CreateSubscriptionParams

type CreateSubscriptionParams struct {
	ID         string
	FilterJson string
	SinkID     string
	Template   string
	Name       sql.NullString
	ManagedBy  string
	PolicyJson string
}

type CreateTargetParams

type CreateTargetParams struct {
	ID              string
	Kind            string
	CoordinatesJson string
	FetchStateJson  string
	LastCheckedAt   sql.NullInt64
	NextCheckAt     int64
	ErrorCount      int64
	IntervalMs      sql.NullInt64
	SourceKind      sql.NullString
}

type CreateWatchParams

type CreateWatchParams struct {
	ID           string
	TargetID     string
	PolicyJson   string
	LabelsJson   string
	BaselineDone int64
	Name         sql.NullString
	ManagedBy    string
	IntervalMs   sql.NullInt64
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type DeleteExpiredLeaseParams

type DeleteExpiredLeaseParams struct {
	Name      string
	ExpiresAt int64
}

type DeleteHeldDeliveriesOfEventParams

type DeleteHeldDeliveriesOfEventParams struct {
	EventID string
	Now     sql.NullInt64
}

type DeletePendingReleaseParams

type DeletePendingReleaseParams struct {
	WatchID  string
	TargetID string
	Raw      string
}

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 Event

type Event struct {
	Seq         int64
	ID          string
	WatchID     string
	Type        string
	PayloadJson string
	CreatedAt   int64
	RefEventID  sql.NullString
}

type EventPrune

type EventPrune struct {
	ID               int64
	HighestPrunedSeq int64
}

type FailHeldDeliveryParams

type FailHeldDeliveryParams struct {
	Reason sql.NullString
	ID     string
	Now    sql.NullInt64
}

type FailPendingDeliveriesParams

type FailPendingDeliveriesParams struct {
	LastError      sql.NullString
	SubscriptionID string
}

type FinishLeasedDeliveryParams

type FinishLeasedDeliveryParams struct {
	Status        string
	NextAttemptAt sql.NullInt64
	LastError     sql.NullString
	ID            string
	Attempt       int64
	LeaseName     string
	Holder        string
}

type GetLatestEventBySubjectParams

type GetLatestEventBySubjectParams struct {
	WatchID string
	Subject string
	Types   []string
}

type GetTargetByCoordinatesParams

type GetTargetByCoordinatesParams struct {
	Kind            string
	CoordinatesJson string
}

type Lease

type Lease struct {
	Name      string
	Holder    string
	ExpiresAt int64
}

type ListDeliveriesPageParams

type ListDeliveriesPageParams struct {
	StatusesJson        interface{}
	SubscriptionIdsJson string
	EventID             string
	BeforeSeq           int64
	BeforeID            string
	MaxRows             int64
}

type ListDeliveriesPageRow

type ListDeliveriesPageRow struct {
	Delivery Delivery
	EventSeq int64
}

type ListEventsAfterParams

type ListEventsAfterParams struct {
	Seq   int64
	Limit int64
}

type ListHeldDeliveriesParams

type ListHeldDeliveriesParams struct {
	SubscriptionID string
	HeldUntil      sql.NullInt64
}

type ListLeasableDueDeliveriesParams

type ListLeasableDueDeliveriesParams struct {
	Now     int64
	MaxRows int64
}

type ListLeasableDueTargetsParams

type ListLeasableDueTargetsParams struct {
	Now     int64
	MaxRows int64
}

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 ListPendingReleasesRow struct {
	WatchID     string
	TargetID    string
	Raw         string
	HeldAt      int64
	ReleaseJson string
	Yanked      int64
	RemovedAt   sql.NullInt64
}

type ListReplayCandidatesParams

type ListReplayCandidatesParams struct {
	StatusesJson   interface{}
	EventID        string
	SubscriptionID string
}

type ListReplayCandidatesRow

type ListReplayCandidatesRow struct {
	Delivery    Delivery
	EventSeq    int64
	PayloadJson string
}

type ListTargetDemandRow

type ListTargetDemandRow struct {
	Kind       string
	IntervalMs sql.NullInt64
	Targets    int64
}

type ListTargetSourcesRow

type ListTargetSourcesRow struct {
	Kind       string
	SourceKind sql.NullString
	Targets    int64
}

type PendingRelease

type PendingRelease struct {
	WatchID     string
	TargetID    string
	Raw         string
	HeldAt      int64
	ReleaseJson string
}

type PruneBatchEndParams

type PruneBatchEndParams struct {
	AfterSeq int64
	Before   int64
	Batch    int64
}

type PruneDeliveriesParams

type PruneDeliveriesParams struct {
	AfterSeq int64
	UpToSeq  int64
	Before   int64
}

type PruneEventsParams

type PruneEventsParams struct {
	AfterSeq int64
	UpToSeq  int64
	Before   int64
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AcquireLease

func (q *Queries) AcquireLease(ctx context.Context, arg AcquireLeaseParams) (int64, error)

func (*Queries) AddPendingRelease

func (q *Queries) AddPendingRelease(ctx context.Context, arg AddPendingReleaseParams) (int64, error)

func (*Queries) AddVersion

func (q *Queries) AddVersion(ctx context.Context, arg AddVersionParams) (int64, error)

func (*Queries) CountDeliveriesByStatus

func (q *Queries) CountDeliveriesByStatus(ctx context.Context) ([]CountDeliveriesByStatusRow, error)

func (*Queries) CountLeasableDueTargets

func (q *Queries) CountLeasableDueTargets(ctx context.Context, now int64) (int64, error)

func (*Queries) CountSecretsByKeyID

func (q *Queries) CountSecretsByKeyID(ctx context.Context) ([]CountSecretsByKeyIDRow, error)

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) DeleteExpiredLease

func (q *Queries) DeleteExpiredLease(ctx context.Context, arg DeleteExpiredLeaseParams) error

func (*Queries) DeleteExpiredTargetLeases

func (q *Queries) DeleteExpiredTargetLeases(ctx context.Context, expiresAt int64) (int64, error)

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 (q *Queries) DeletePendingRelease(ctx context.Context, arg DeletePendingReleaseParams) (int64, error)

func (*Queries) DeletePendingReleasesOfWatch

func (q *Queries) DeletePendingReleasesOfWatch(ctx context.Context, watchID string) (int64, error)

func (*Queries) DeleteSecret

func (q *Queries) DeleteSecret(ctx context.Context, id string) (int64, error)

func (*Queries) DeleteSink

func (q *Queries) DeleteSink(ctx context.Context, id string) (int64, error)

func (*Queries) DeleteSubscription

func (q *Queries) DeleteSubscription(ctx context.Context, id string) (int64, error)

func (*Queries) DeleteTargetIfUnused

func (q *Queries) DeleteTargetIfUnused(ctx context.Context, id string) (int64, error)

func (*Queries) DeleteTargetVersions

func (q *Queries) DeleteTargetVersions(ctx context.Context, targetID string) error

func (*Queries) DeleteWatch

func (q *Queries) DeleteWatch(ctx context.Context, id string) (int64, error)

func (*Queries) FailHeldDelivery

func (q *Queries) FailHeldDelivery(ctx context.Context, arg FailHeldDeliveryParams) (int64, error)

func (*Queries) FailPendingDeliveries

func (q *Queries) FailPendingDeliveries(ctx context.Context, arg FailPendingDeliveriesParams) (int64, error)

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) GetDelivery

func (q *Queries) GetDelivery(ctx context.Context, id string) (Delivery, error)

func (*Queries) GetEvent

func (q *Queries) GetEvent(ctx context.Context, id string) (Event, error)

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) GetSecret

func (q *Queries) GetSecret(ctx context.Context, id string) (Secret, error)

func (*Queries) GetSecretByName

func (q *Queries) GetSecretByName(ctx context.Context, name string) (Secret, error)

func (*Queries) GetSink

func (q *Queries) GetSink(ctx context.Context, id string) (Sink, error)

func (*Queries) GetSinkByName

func (q *Queries) GetSinkByName(ctx context.Context, name sql.NullString) (Sink, error)

func (*Queries) GetSubscription

func (q *Queries) GetSubscription(ctx context.Context, id string) (Subscription, error)

func (*Queries) GetSubscriptionByName

func (q *Queries) GetSubscriptionByName(ctx context.Context, name sql.NullString) (Subscription, error)

func (*Queries) GetTarget

func (q *Queries) GetTarget(ctx context.Context, id string) (Target, error)

func (*Queries) GetTargetByCoordinates

func (q *Queries) GetTargetByCoordinates(ctx context.Context, arg GetTargetByCoordinatesParams) (Target, error)

func (*Queries) GetWatch

func (q *Queries) GetWatch(ctx context.Context, id string) (Watch, error)

func (*Queries) GetWatchByName

func (q *Queries) GetWatchByName(ctx context.Context, name sql.NullString) (Watch, error)

func (*Queries) HasEventsAfter

func (q *Queries) HasEventsAfter(ctx context.Context, seq int64) (bool, error)

func (*Queries) HasLeasableDueDeliveries

func (q *Queries) HasLeasableDueDeliveries(ctx context.Context, now sql.NullInt64) (bool, error)

func (*Queries) HasLeasableDueTargets

func (q *Queries) HasLeasableDueTargets(ctx context.Context, now int64) (bool, error)

func (*Queries) HighestPrunedSeq

func (q *Queries) HighestPrunedSeq(ctx context.Context) (int64, error)

Kept current by the event_prune_seq trigger (00013).

func (*Queries) ListDeliveries

func (q *Queries) ListDeliveries(ctx context.Context, eventID string) ([]Delivery, error)

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 (q *Queries) ListEventsAfter(ctx context.Context, arg ListEventsAfterParams) ([]Event, error)

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 (q *Queries) ListNamedSinksPage(ctx context.Context, arg ListNamedSinksPageParams) ([]Sink, error)

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) ListSecrets

func (q *Queries) ListSecrets(ctx context.Context) ([]Secret, error)

func (*Queries) ListSinksManagedBy

func (q *Queries) ListSinksManagedBy(ctx context.Context, managedBy string) ([]Sink, error)

func (*Queries) ListSubscriptions

func (q *Queries) ListSubscriptions(ctx context.Context) ([]Subscription, error)

func (*Queries) ListSubscriptionsBySink

func (q *Queries) ListSubscriptionsBySink(ctx context.Context, sinkID string) ([]Subscription, error)

func (*Queries) ListSubscriptionsManagedBy

func (q *Queries) ListSubscriptionsManagedBy(ctx context.Context, managedBy string) ([]Subscription, error)

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 (q *Queries) ListVersions(ctx context.Context, targetID string) ([]Version, error)

func (*Queries) ListWatchesByTarget

func (q *Queries) ListWatchesByTarget(ctx context.Context, targetID string) ([]Watch, error)

func (*Queries) ListWatchesManagedBy

func (q *Queries) ListWatchesManagedBy(ctx context.Context, managedBy string) ([]Watch, error)

func (*Queries) MarkBaselineDone

func (q *Queries) MarkBaselineDone(ctx context.Context, id string) (int64, error)

func (*Queries) PruneBatchEnd

func (q *Queries) PruneBatchEnd(ctx context.Context, arg PruneBatchEndParams) ([]int64, error)

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 (q *Queries) PruneDeliveries(ctx context.Context, arg PruneDeliveriesParams) (int64, error)

func (*Queries) PruneEvents

func (q *Queries) PruneEvents(ctx context.Context, arg PruneEventsParams) (int64, error)

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 (q *Queries) ReplayDelivery(ctx context.Context, arg ReplayDeliveryParams) (int64, error)

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 (q *Queries) RescheduleHeldDelivery(ctx context.Context, arg RescheduleHeldDeliveryParams) (int64, error)

func (*Queries) ResetWatchBaseline

func (q *Queries) ResetWatchBaseline(ctx context.Context, id string) (int64, error)

func (*Queries) SetTargetInterval

func (q *Queries) SetTargetInterval(ctx context.Context, arg SetTargetIntervalParams) (int64, error)

func (*Queries) StartDeliveryAttempt

func (q *Queries) StartDeliveryAttempt(ctx context.Context, id string) (Delivery, error)

Every lease of a delivery counts as an attempt, so an attempt cut short by a crash counts too.

func (*Queries) SubscriptionGeneration

func (q *Queries) SubscriptionGeneration(ctx context.Context) (int64, error)

func (*Queries) TargetExists

func (q *Queries) TargetExists(ctx context.Context, id string) (bool, error)

func (*Queries) UpdateSecret

func (q *Queries) UpdateSecret(ctx context.Context, arg UpdateSecretParams) (int64, error)

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 (q *Queries) UpdateSink(ctx context.Context, arg UpdateSinkParams) (int64, error)

func (*Queries) UpdateSubscription

func (q *Queries) UpdateSubscription(ctx context.Context, arg UpdateSubscriptionParams) (int64, error)

func (*Queries) UpdateTargetState

func (q *Queries) UpdateTargetState(ctx context.Context, arg UpdateTargetStateParams) (int64, error)

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 (q *Queries) UpdateVersionState(ctx context.Context, arg UpdateVersionStateParams) (int64, error)

func (*Queries) UpdateWatchConfig

func (q *Queries) UpdateWatchConfig(ctx context.Context, arg UpdateWatchConfigParams) (int64, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type ReleaseHeldDeliveryParams

type ReleaseHeldDeliveryParams struct {
	Now sql.NullInt64
	ID  string
}

type ReleaseLeaseParams

type ReleaseLeaseParams struct {
	Name   string
	Holder string
}

type ReplayDeliveryParams

type ReplayDeliveryParams struct {
	Now sql.NullInt64
	ID  string
}

type RescheduleHeldDeliveryParams

type RescheduleHeldDeliveryParams struct {
	Until sql.NullInt64
	ID    string
	Now   sql.NullInt64
}

type Secret

type Secret struct {
	ID         string
	Name       string
	HostsJson  string
	KeyID      string
	Ciphertext []byte
	Revision   int64
	CreatedAt  int64
	UpdatedAt  int64
}

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) Close

func (r *SecretReader) Close() error

Close closes the database.

func (*SecretReader) SecretByName

func (r *SecretReader) SecretByName(ctx context.Context, name string) (store.Secret, error)

SecretByName returns the secret with this name, or store.ErrNotFound.

type SetTargetIntervalParams

type SetTargetIntervalParams struct {
	IntervalMs  sql.NullInt64
	NextCheckAt int64
	ID          string
}

type Sink

type Sink struct {
	ID         string
	Kind       string
	ConfigJson []byte
	Name       sql.NullString
	ManagedBy  string
}

type Store

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

Store is the SQLite engine. It is safe for concurrent use.

func Open

func Open(ctx context.Context, path string, logger *slog.Logger) (*Store, error)

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 (*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

func (s *Store) AddPendingRelease(ctx context.Context, p store.PendingRelease) error

AddPendingRelease implements store.Tx in its own statement.

func (*Store) AddVersion

func (s *Store) AddVersion(ctx context.Context, v store.Version) (bool, error)

AddVersion implements store.Tx in its own statement.

func (*Store) AppendEvent

func (s *Store) AppendEvent(ctx context.Context, e store.Event, ds []store.Delivery) error

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) Close

func (s *Store) Close() error

Close closes the database.

func (*Store) CountDeliveriesByStatus

func (s *Store) CountDeliveriesByStatus(ctx context.Context) (map[string]int64, error)

CountDeliveriesByStatus implements store.Store.

func (*Store) CountDueTargets

func (s *Store) CountDueTargets(ctx context.Context, now time.Time) (int64, error)

CountDueTargets implements store.Store.

func (*Store) CountSecretsByKeyID

func (s *Store) CountSecretsByKeyID(ctx context.Context) (map[string]int64, error)

CountSecretsByKeyID implements store.SecretReader.

func (*Store) CreateSink

func (s *Store) CreateSink(ctx context.Context, k store.Sink) error

CreateSink implements store.Store.

func (*Store) CreateSubscription

func (s *Store) CreateSubscription(ctx context.Context, sub store.Subscription) error

CreateSubscription implements store.Store.

func (*Store) CreateTarget

func (s *Store) CreateTarget(ctx context.Context, t store.Target) error

CreateTarget implements store.Store.

func (*Store) CreateWatch

func (s *Store) CreateWatch(ctx context.Context, w store.Watch) error

CreateWatch implements store.Store.

func (*Store) DeleteExpiredTargetLeases

func (s *Store) DeleteExpiredTargetLeases(ctx context.Context, now time.Time) (int64, error)

DeleteExpiredTargetLeases implements store.Store.

func (*Store) DeletePendingRelease

func (s *Store) DeletePendingRelease(ctx context.Context, watchID, targetID, raw string) error

DeletePendingRelease implements store.Tx in its own statement.

func (*Store) DeletePendingReleasesOfWatch

func (s *Store) DeletePendingReleasesOfWatch(ctx context.Context, watchID string) (int64, error)

DeletePendingReleasesOfWatch implements store.Tx in its own statement.

func (*Store) DeleteSink

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

DeleteSink implements store.Store.

func (*Store) DeleteSubscription

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

DeleteSubscription implements store.Store.

func (*Store) DeleteWatch

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

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

func (s *Store) GetDelivery(ctx context.Context, id string) (store.Delivery, error)

GetDelivery implements store.APIReader.

func (*Store) GetEvent

func (s *Store) GetEvent(ctx context.Context, id string) (store.Event, error)

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

func (s *Store) GetSink(ctx context.Context, id string) (store.Sink, error)

GetSink implements store.APIReader.

func (*Store) GetSubscription

func (s *Store) GetSubscription(ctx context.Context, id string) (store.Subscription, error)

GetSubscription implements store.APIReader.

func (*Store) GetTarget

func (s *Store) GetTarget(ctx context.Context, id string) (store.Target, error)

GetTarget implements store.Store.

func (*Store) GetWatch

func (s *Store) GetWatch(ctx context.Context, id string) (store.Watch, error)

GetWatch implements store.Store.

func (*Store) HasDueDeliveries

func (s *Store) HasDueDeliveries(ctx context.Context, now time.Time) (bool, error)

HasDueDeliveries implements store.Store.

func (*Store) HasDueTargets

func (s *Store) HasDueTargets(ctx context.Context, now time.Time) (bool, error)

HasDueTargets implements store.Store. It is a plain read, so an idle scheduler poll does not take SQLite's write lock.

func (*Store) HasEventsAfter

func (s *Store) HasEventsAfter(ctx context.Context, seq int64) (bool, error)

HasEventsAfter implements store.APIReader.

func (*Store) HighestPrunedSeq

func (s *Store) HighestPrunedSeq(ctx context.Context) (int64, error)

HighestPrunedSeq implements store.Store. The event_prune_seq trigger (migration 00013) records it on every event delete, in the deleting transaction.

func (*Store) InAPITx

func (s *Store) InAPITx(ctx context.Context, fn func(tx store.APITx) error) error

InAPITx implements store.APIStore.

func (*Store) InConfigTx

func (s *Store) InConfigTx(ctx context.Context, fn func(tx store.ConfigTx) error) error

InConfigTx implements store.Store.

func (*Store) InSecretTx

func (s *Store) InSecretTx(ctx context.Context, fn func(tx store.SecretTx) error) error

InSecretTx implements store.SecretStore. The transaction takes SQLite's write lock at BEGIN (_txlock=immediate), so no other writer interleaves.

func (*Store) InTx

func (s *Store) InTx(ctx context.Context, fn func(tx store.Tx) error) error

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) ListDeliveries

func (s *Store) ListDeliveries(ctx context.Context, eventID string) ([]store.Delivery, error)

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

func (s *Store) ListSecrets(ctx context.Context) ([]store.Secret, error)

ListSecrets implements store.SecretReader.

func (*Store) ListSubscriptions

func (s *Store) ListSubscriptions(ctx context.Context) ([]store.Subscription, error)

ListSubscriptions implements store.Tx outside a transaction.

func (*Store) ListVersions

func (s *Store) ListVersions(ctx context.Context, targetID string) ([]store.Version, error)

ListVersions implements store.Tx outside a transaction.

func (*Store) ListWatches

func (s *Store) ListWatches(ctx context.Context, targetID string) ([]store.Watch, error)

ListWatches implements store.Tx outside a transaction.

func (*Store) MarkBaselineDone

func (s *Store) MarkBaselineDone(ctx context.Context, watchID string) error

MarkBaselineDone implements store.Tx in its own statement.

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

func (s *Store) ReleaseLease(ctx context.Context, name, holder string) error

ReleaseLease implements store.Store.

func (*Store) SecretByName

func (s *Store) SecretByName(ctx context.Context, name string) (store.Secret, error)

SecretByName implements store.SecretReader.

func (*Store) SinkByName

func (s *Store) SinkByName(ctx context.Context, name string) (store.Sink, error)

SinkByName implements store.APIReader.

func (*Store) SubscriptionByName

func (s *Store) SubscriptionByName(ctx context.Context, name string) (store.Subscription, error)

SubscriptionByName implements store.APIReader.

func (*Store) SubscriptionGeneration

func (s *Store) SubscriptionGeneration(ctx context.Context) (int64, error)

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

func (s *Store) TargetDemand(ctx context.Context) ([]store.TargetDemand, error)

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

func (s *Store) TargetSources(ctx context.Context) ([]store.TargetSource, error)

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) UpdateTarget

func (s *Store) UpdateTarget(ctx context.Context, t store.Target) error

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

func (s *Store) UpdateVersion(ctx context.Context, v store.Version) error

UpdateVersion implements store.Tx in its own statement.

func (*Store) WatchByName

func (s *Store) WatchByName(ctx context.Context, name string) (store.Watch, error)

WatchByName implements store.APIReader.

type Subscription

type Subscription struct {
	ID         string
	FilterJson string
	SinkID     string
	Template   string
	Name       sql.NullString
	ManagedBy  string
	PolicyJson string
}

type SubscriptionGeneration

type SubscriptionGeneration struct {
	ID         int64
	Generation int64
}

type Target

type Target struct {
	ID              string
	Kind            string
	CoordinatesJson string
	FetchStateJson  string
	LastCheckedAt   sql.NullInt64
	NextCheckAt     int64
	ErrorCount      int64
	IntervalMs      sql.NullInt64
	SourceKind      sql.NullString
}

type UpdateSecretParams

type UpdateSecretParams struct {
	HostsJson  string
	KeyID      string
	Ciphertext []byte
	UpdatedAt  int64
	ID         string
	Revision   int64
}

type UpdateSinkParams

type UpdateSinkParams struct {
	Kind       string
	ConfigJson []byte
	ID         string
}

type UpdateSubscriptionParams

type UpdateSubscriptionParams struct {
	FilterJson string
	SinkID     string
	Template   string
	PolicyJson string
	ID         string
}

type UpdateTargetStateLeasedParams

type UpdateTargetStateLeasedParams struct {
	FetchStateJson string
	LastCheckedAt  sql.NullInt64
	NextCheckAt    int64
	ErrorCount     int64
	ID             string
	LeaseName      string
	Holder         string
	Now            int64
}

type UpdateTargetStateParams

type UpdateTargetStateParams struct {
	FetchStateJson string
	LastCheckedAt  sql.NullInt64
	NextCheckAt    int64
	ErrorCount     int64
	ID             string
}

type UpdateVersionStateParams

type UpdateVersionStateParams struct {
	Yanked    int64
	RemovedAt sql.NullInt64
	TargetID  string
	Raw       string
}

type UpdateWatchConfigParams

type UpdateWatchConfigParams struct {
	TargetID   string
	PolicyJson string
	LabelsJson string
	IntervalMs sql.NullInt64
	ID         string
}

type Version

type Version struct {
	TargetID    string
	Raw         string
	Normalized  string
	PublishedAt sql.NullInt64
	Prerelease  int64
	Yanked      int64
	FirstSeenAt int64
	RemovedAt   sql.NullInt64
}

type Watch

type Watch struct {
	ID           string
	TargetID     string
	PolicyJson   string
	LabelsJson   string
	BaselineDone int64
	Name         sql.NullString
	ManagedBy    string
	IntervalMs   sql.NullInt64
}

Jump to

Keyboard shortcuts

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