arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.RateLimit.Schema

Description

Conversion of declared Policy values to upsertable rows, plus DDL for the policies table, bucket table, and job columns. No database execution here.

Synopsis

Policy rows

Source #data PolicyRow

A token-bucket policy as upsertable row fields.

Constructors

PolicyRow 

Instances

Instances details
Eq PolicyRow Source # 
Instance details

Defined in Arbiter.Core.RateLimit.Schema

Show PolicyRow Source # 
Instance details

Defined in Arbiter.Core.RateLimit.Schema

Source #toPolicyRow :: Policy -> PolicyRow

A policy in its stored form.

Table name helpers

Source #arbiterRateLimitPoliciesTable :: SchemaName -> Text

Qualified name of the app-global policies table.

Source #arbiterRateLimitPoliciesTableName :: Text

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

Source #arbiterRateLimitsTable :: SchemaName -> Text

Qualified name of the single bucket table. Its WAL durability is a table-level property reconciled by the migration.

Source #arbiterRateLimitsTableName :: Text

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

DDL

Source #createRateLimitPoliciesTableSQL :: SchemaName -> Text

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

Source #createRateLimitsTableSQL :: SchemaName -> Text

DDL for the bucket table, always created UNLOGGED.

Source #alterRateLimitsDurabilitySQL :: Durability -> SchemaName -> Text

Converge the bucket table's WAL persistence to a durability. Rewrites the table under ACCESS EXCLUSIVE. Callers issue it when the durability differs from the current state.

Source #upsertPolicyRowSQL :: SchemaName -> PolicyRow -> Text

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

Source #addRateLimitColumnsSQL :: SchemaName -> TableName -> Text

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 grouped head in-flight. Its group stays stalled and spends no attempt.

Source #addRateLimitCostColumnSQL :: SchemaName -> TableName -> Text

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.

Source #createThrottledIndexSQL :: SchemaName -> TableName -> Text

Index backing the throttle wake and per-prefix count, in its own migration. The prefix leads and rate_limit_key trails.

Source #createRateLimitBucketTriggerFunctionsSQL :: SchemaName -> TableName -> Text

Statement-level triggers that ensure a full token bucket row exists for every rate-limited job's key whose prefix has a policy. Tokens are spent at claim and refill over time. There is no delete trigger. Key creation or a dedup-replace key move seeds a row.

Source #createRateLimitBucketTriggersSQL :: SchemaName -> TableName -> Text

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

Source #bucketSeedInsert :: Text -> Text -> Text -> Text -> Text

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.