arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.RateLimit.Schema

Description

Internal to the arbiter packages. Not covered by the PVP.

DDL and SQL fragments for the rate-limit feature. No database execution here.

Synopsis

Table names

arbiterRateLimitPoliciesTable :: SchemaName -> TextSource #

Qualified name of the app-global policies table.

arbiterRateLimitPoliciesTableName :: TextSource #

Bare name of the policies table, for catalog lookups by relname.

arbiterRateLimitsTable :: SchemaName -> TextSource #

Qualified name of the single bucket table.

arbiterRateLimitsTableName :: TextSource #

Bare name of the bucket table, for catalog lookups by relname.

SQL fragments

bucketSeedInsert :: Text -> Text -> Text -> Text -> TextSource #

The seed INSERT shared by the trigger functions and the claim's rl_seed CTE, parameterized over the source rows (aliased n) and key filter.

DDL

createRateLimitPoliciesTableSQL :: SchemaName -> TextSource #

DDL for the policies table. default_* is migration-owned. override_* is management-owned. The effective params are COALESCE(override, default).

createRateLimitsTableSQL :: SchemaName -> TextSource #

DDL for the bucket table, always created UNLOGGED.

alterRateLimitsDurabilitySQL :: SchemaName -> Durability -> TextSource #

Set the bucket table's WAL persistence. Rewrites the table under ACCESS EXCLUSIVE.

upsertRateLimitPolicyRowSQL :: SchemaName -> RateLimitPolicy -> TextSource #

Upsert a policy's default_* params. Any operator override_* is left untouched.

addRateLimitColumnsSQL :: SchemaName -> TableName -> TextSource #

Migration adding the rate-limit columns to a queue's job and DLQ tables. All nullable. throttled_until (job table only) marks a throttle-deferred job. A deferred grouped job holds its group's in-flight slot. A deferral spends no attempt.

addRateLimitCostColumnSQL :: SchemaName -> TableName -> TextSource #

Add the per-job token cost column to a queue's job and DLQ tables. Defaulted to a unit cost. Existing rows backfill to it. The DLQ stores it and a retried job retains its cost.

createThrottledIndexSQL :: SchemaName -> TableName -> TextSource #

Index backing the throttle wake and per-prefix count. The prefix leads and rate_limit_key trails.

createRateLimitBucketTriggerFunctionsSQL :: SchemaName -> TableName -> TextSource #

Per-queue trigger functions that seed a full token bucket row for each rate-limited job's key whose prefix has a policy. Tokens are spent at claim and refill over time. There is no delete function. Key creation or a dedup-replace key move seeds a row.

createRateLimitBucketTriggersSQL :: SchemaName -> TableName -> TextSource #

The statement-level AFTER INSERT and AFTER UPDATE triggers backing createRateLimitBucketTriggerFunctionsSQL. There is no delete trigger.