Documentation
¶
Index ¶
- type AcquireMessagesByTopicParams
- type ClaimMaintenanceLeasesParams
- type ConsumerSession
- type CountLiveConsumerSessionsRow
- type DBTX
- type DeleteExpiredMessagesParams
- type DeleteMessagesByIdsParams
- type GetMaintenanceCandidateTopicsParams
- type GetMaintenanceCandidateTopicsRow
- type GetTopicForUpdateRow
- type GetTopicsWithExpirationRow
- type InsertMaintenanceLeaseIfAbsentParams
- type InsertMaintenanceLeasesParams
- type InsertMessageParams
- type InsertTopicIfAbsentParams
- type MaintenanceLease
- type Message
- type Queries
- func (q *Queries) AcquireMessagesByTopic(ctx context.Context, db DBTX, arg AcquireMessagesByTopicParams) ([]*Message, error)
- func (q *Queries) BumpTopicActivityIfStale(ctx context.Context, db DBTX, topic string) error
- func (q *Queries) ClaimMaintenanceLeases(ctx context.Context, db DBTX, arg ClaimMaintenanceLeasesParams) ([]string, error)
- func (q *Queries) CountLiveConsumerSessions(ctx context.Context, db DBTX) (*CountLiveConsumerSessionsRow, error)
- func (q *Queries) DeleteExpiredConsumerSessions(ctx context.Context, db DBTX, cutoff pgtype.Timestamptz) error
- func (q *Queries) DeleteExpiredMessages(ctx context.Context, db DBTX, arg DeleteExpiredMessagesParams) error
- func (q *Queries) DeleteMessagesByIds(ctx context.Context, db DBTX, arg DeleteMessagesByIdsParams) error
- func (q *Queries) GetMaintenanceCandidateTopics(ctx context.Context, db DBTX, arg GetMaintenanceCandidateTopicsParams) ([]*GetMaintenanceCandidateTopicsRow, error)
- func (q *Queries) GetOldestMessageInsertedAt(ctx context.Context, db DBTX, topic string) (pgtype.Timestamptz, error)
- func (q *Queries) GetTopicForUpdate(ctx context.Context, db DBTX, topic string) (*GetTopicForUpdateRow, error)
- func (q *Queries) GetTopicsWithExpiration(ctx context.Context, db DBTX) ([]*GetTopicsWithExpirationRow, error)
- func (q *Queries) GetTopicsWithMessages(ctx context.Context, db DBTX) ([]string, error)
- func (q *Queries) InsertMaintenanceLeaseIfAbsent(ctx context.Context, db DBTX, arg InsertMaintenanceLeaseIfAbsentParams) error
- func (q *Queries) InsertMaintenanceLeases(ctx context.Context, db DBTX, arg InsertMaintenanceLeasesParams) ([]string, error)
- func (q *Queries) InsertMessage(ctx context.Context, db DBTX, arg []InsertMessageParams) (int64, error)
- func (q *Queries) InsertTopicIfAbsent(ctx context.Context, db DBTX, arg InsertTopicIfAbsentParams) error
- func (q *Queries) ReleaseMaintenanceLease(ctx context.Context, db DBTX, arg ReleaseMaintenanceLeaseParams) error
- func (q *Queries) RenewTopicExclusiveConsumer(ctx context.Context, db DBTX, arg RenewTopicExclusiveConsumerParams) error
- func (q *Queries) SelectMaintenanceLeaseForUpdate(ctx context.Context, db DBTX, arg SelectMaintenanceLeaseForUpdateParams) (*SelectMaintenanceLeaseForUpdateRow, error)
- func (q *Queries) SetTopicExclusiveConsumer(ctx context.Context, db DBTX, arg SetTopicExclusiveConsumerParams) error
- func (q *Queries) UpdateMaintenanceLease(ctx context.Context, db DBTX, arg UpdateMaintenanceLeaseParams) error
- func (q *Queries) UpsertConsumerSession(ctx context.Context, db DBTX, arg UpsertConsumerSessionParams) error
- type ReleaseMaintenanceLeaseParams
- type RenewTopicExclusiveConsumerParams
- type SelectMaintenanceLeaseForUpdateParams
- type SelectMaintenanceLeaseForUpdateRow
- type SetTopicExclusiveConsumerParams
- type Topic
- type UpdateMaintenanceLeaseParams
- type UpsertConsumerSessionParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClaimMaintenanceLeasesParams ¶ added in v0.3.0
type ClaimMaintenanceLeasesParams struct {
HolderID uuid.UUID `json:"holder_id"`
Topics []string `json:"topics"`
StaleCutoff pgtype.Timestamptz `json:"stale_cutoff"`
}
type ConsumerSession ¶ added in v0.3.0
type ConsumerSession struct {
ConsumerID uuid.UUID `json:"consumer_id"`
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
MaintainsDefaultExpiration bool `json:"maintains_default_expiration"`
}
type CountLiveConsumerSessionsRow ¶ added in v0.3.0
type DBTX ¶
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}
type DeleteExpiredMessagesParams ¶ added in v0.2.0
type DeleteExpiredMessagesParams struct {
Topic string `json:"topic"`
Cutoff pgtype.Timestamptz `json:"cutoff"`
}
type GetMaintenanceCandidateTopicsParams ¶ added in v0.3.0
type GetMaintenanceCandidateTopicsParams struct {
HolderID uuid.UUID `json:"holder_id"`
StaleCutoff pgtype.Timestamptz `json:"stale_cutoff"`
DefaultExpirationNanos pgtype.Int8 `json:"default_expiration_nanos"`
IncludeTopics []string `json:"include_topics"`
SlackSeconds float64 `json:"slack_seconds"`
}
type GetMaintenanceCandidateTopicsRow ¶ added in v0.3.0
type GetTopicForUpdateRow ¶ added in v0.2.0
type GetTopicForUpdateRow struct {
ExclusiveConsumerID *uuid.UUID `json:"exclusive_consumer_id"`
ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
}
type GetTopicsWithExpirationRow ¶ added in v0.3.0
type InsertMaintenanceLeaseIfAbsentParams ¶ added in v0.2.0
type InsertMaintenanceLeasesParams ¶ added in v0.3.0
type InsertMessageParams ¶
type InsertTopicIfAbsentParams ¶ added in v0.2.0
type MaintenanceLease ¶ added in v0.2.0
type MaintenanceLease struct {
Topic string `json:"topic"`
HolderID uuid.UUID `json:"holder_id"`
AcquiredAt pgtype.Timestamptz `json:"acquired_at"`
}
type Message ¶
type Message struct {
ID int64 `json:"id"`
InsertedAt pgtype.Timestamptz `json:"inserted_at"`
Topic string `json:"topic"`
Payload []byte `json:"payload"`
}
type Queries ¶
type Queries struct {
}
func (*Queries) AcquireMessagesByTopic ¶
func (*Queries) BumpTopicActivityIfStale ¶ added in v0.3.0
Flush-path counterpart of the insert trigger's activity bump. The trigger bumps with FOR UPDATE SKIP LOCKED, and ProcessMessages holds the topic row lock for its whole transaction — so on a continuously-processed topic the trigger can be starved out of every bump. The flush transaction already holds that lock, so it compensates by bumping here after processing messages, gated to the same 30-second granularity as the trigger.
func (*Queries) ClaimMaintenanceLeases ¶ added in v0.3.0
func (q *Queries) ClaimMaintenanceLeases(ctx context.Context, db DBTX, arg ClaimMaintenanceLeasesParams) ([]string, error)
Takeover path for lease rows whose holder is gone: its session lapsed, or (pre-session holder) its acquired_at went stale. SKIP LOCKED lets racing claimants skip contested rows instead of queueing; the loser claims other topics on its next scan. consumer_sessions (the small side, kept small by the retention sweep) is narrowed once into a MATERIALIZED CTE so the planner hashes it instead of choosing its own join shape against maintenance_leases.
func (*Queries) CountLiveConsumerSessions ¶ added in v0.3.0
func (q *Queries) CountLiveConsumerSessions(ctx context.Context, db DBTX) (*CountLiveConsumerSessionsRow, error)
Two fair-share denominators: every live instance can maintain topics with an explicit TTL, but only instances configured with a default expiration can even see default-TTL topics as candidates — dividing those by the total would leave most of a default-TTL backlog to the floor-of-1 trickle.
func (*Queries) DeleteExpiredConsumerSessions ¶ added in v0.3.0
func (q *Queries) DeleteExpiredConsumerSessions(ctx context.Context, db DBTX, cutoff pgtype.Timestamptz) error
GC for session rows left behind by dead instances (one per process lifetime, since instance ids are per-NewOutbox). Bounding the table keeps CountLiveConsumerSessions and the lease-liveness joins on a small seq scan. Deleting a row is equivalent to it being expired, so the cutoff buffer is caution, not correctness; a live instance wrongly swept just re-inserts itself on its next heartbeat.
func (*Queries) DeleteExpiredMessages ¶ added in v0.2.0
func (*Queries) DeleteMessagesByIds ¶
func (*Queries) GetMaintenanceCandidateTopics ¶ added in v0.3.0
func (q *Queries) GetMaintenanceCandidateTopics(ctx context.Context, db DBTX, arg GetMaintenanceCandidateTopicsParams) ([]*GetMaintenanceCandidateTopicsRow, error)
Topics that may still hold unexpired messages (last insert newer than TTL + slack; NULL activity is treated as active, belt-and-braces for rows that predate the column), plus any topics force-included by the catch-up sweep, together with their maintenance-lease state. Lease liveness defers to the holder's consumer session, falling back to the staleness cutoff for pre-session holders (see SelectMaintenanceLeaseForUpdate). The plan is pinned to a deliberate shape: one seq scan of topics (the activity predicate is unindexable by design), maintenance_leases joined on its primary key, and consumer_sessions — the small side, kept small by the retention sweep — narrowed once into a MATERIALIZED CTE and hashed.
func (*Queries) GetOldestMessageInsertedAt ¶ added in v0.2.0
func (*Queries) GetTopicForUpdate ¶ added in v0.2.0
func (q *Queries) GetTopicForUpdate(ctx context.Context, db DBTX, topic string) (*GetTopicForUpdateRow, error)
A NULL exclusive_consumer_expires_at on the topics row means "defer to the holder's consumer session for liveness"; a non-NULL value is a per-topic override (release, grace-period expiry, or a lease written by a pre-session version of pgoutbox) and wins the COALESCE. FOR UPDATE OF t locks only the topics row, not the joined session row shared by every topic the holder owns.
func (*Queries) GetTopicsWithExpiration ¶ added in v0.2.0
func (*Queries) GetTopicsWithMessages ¶ added in v0.3.0
Loose index scan emulated over the (topic, id) PK: O(distinct topics) index probes the planner cannot degrade to a seq scan of messages. Used by the catch-up sweep to find topics holding messages regardless of activity.
func (*Queries) InsertMaintenanceLeaseIfAbsent ¶ added in v0.2.0
func (*Queries) InsertMaintenanceLeases ¶ added in v0.3.0
func (q *Queries) InsertMaintenanceLeases(ctx context.Context, db DBTX, arg InsertMaintenanceLeasesParams) ([]string, error)
Claim path for topics that have no lease row yet. RETURNING reports the subset this instance actually won; a concurrent instance may have inserted a row first, in which case the conflict arm drops that topic silently.
func (*Queries) InsertMessage ¶
func (*Queries) InsertTopicIfAbsent ¶ added in v0.2.0
func (*Queries) ReleaseMaintenanceLease ¶ added in v0.3.0
func (q *Queries) ReleaseMaintenanceLease(ctx context.Context, db DBTX, arg ReleaseMaintenanceLeaseParams) error
Dormancy release: dormant topics carry no lease row at all. Guarded by holder so a lease that was concurrently taken over is never deleted.
func (*Queries) RenewTopicExclusiveConsumer ¶ added in v0.2.0
func (*Queries) SelectMaintenanceLeaseForUpdate ¶ added in v0.2.0
func (q *Queries) SelectMaintenanceLeaseForUpdate(ctx context.Context, db DBTX, arg SelectMaintenanceLeaseForUpdateParams) (*SelectMaintenanceLeaseForUpdateRow, error)
Lease liveness defers to the holder's consumer session; a holder with no session row (written by a pre-session version of pgoutbox) is judged by acquired_at against the caller-computed staleness cutoff, exactly the rule that version applies to itself. FOR UPDATE OF l leaves the session row unlocked, since every other lease held by the same instance reads it too.
func (*Queries) SetTopicExclusiveConsumer ¶ added in v0.2.0
func (*Queries) UpdateMaintenanceLease ¶ added in v0.2.0
func (*Queries) UpsertConsumerSession ¶ added in v0.3.0
type ReleaseMaintenanceLeaseParams ¶ added in v0.3.0
type RenewTopicExclusiveConsumerParams ¶ added in v0.2.0
type RenewTopicExclusiveConsumerParams struct {
Topic string `json:"topic"`
ExclusiveConsumerID *uuid.UUID `json:"exclusive_consumer_id"`
ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
}
type SelectMaintenanceLeaseForUpdateParams ¶ added in v0.3.0
type SelectMaintenanceLeaseForUpdateParams struct {
StaleCutoff pgtype.Timestamptz `json:"stale_cutoff"`
Topic string `json:"topic"`
}
type SelectMaintenanceLeaseForUpdateRow ¶ added in v0.2.0
type SetTopicExclusiveConsumerParams ¶ added in v0.2.0
type SetTopicExclusiveConsumerParams struct {
Topic string `json:"topic"`
ExclusiveConsumerID *uuid.UUID `json:"exclusive_consumer_id"`
ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
}
type Topic ¶ added in v0.2.0
type Topic struct {
Topic string `json:"topic"`
ExpirationNanos pgtype.Int8 `json:"expiration_nanos"`
ExclusiveConsumerID *uuid.UUID `json:"exclusive_consumer_id"`
ExclusiveConsumerExpiresAt pgtype.Timestamptz `json:"exclusive_consumer_expires_at"`
LastInsertedAt pgtype.Timestamptz `json:"last_inserted_at"`
}
type UpdateMaintenanceLeaseParams ¶ added in v0.2.0
type UpsertConsumerSessionParams ¶ added in v0.3.0
type UpsertConsumerSessionParams struct {
ConsumerID uuid.UUID `json:"consumer_id"`
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
MaintainsDefaultExpiration bool `json:"maintains_default_expiration"`
}