Concepts
Spaces, shapes, programs, time and request ids. The reference lists every key and statement; API-008 is the full specification.
Shapes
| Shape | Columns | Holds |
|---|---|---|
| Queue | id, key, state, priority, due_at, attempts, version, lease_owner, timestamps and a JSON body, then the declared fields | Work items: sends, workflow instance heads, effects, external events deduplicated by key |
| Table | id, version, created_at, updated_at, expires_at with expire_after_write, then the declared fields; the key fields get a unique index | Keyed state, idempotency records, admission chunks, suppression flags, counters |
| Sequenced table | A table without key, whose id comes from a counter row in the same transaction | Timelines and transition history |
Field types are text, int, float,
bool, timestamp, json and
text_set. Every declared field may be null.
index: true creates an index on a field, a GIN index for a
text_set. A table field may declare a merge rule:
add_only for a set, non_decreasing for a number
or time. An update that breaks it rejects the program unless it sets
override_merge: true.
Schema changes only add: queues and tables with any indexes, unindexed
fields on existing objects, and reads or read versions. They can also
raise request_retention and a queue's retention.
A field added to a live object can't be indexed, because building the
index would block the object's writes.
Queue items
An item is pending, leased, complete
or failed. due_at is when it next needs
attention: when a pending item becomes claimable, or when a lease
expires. A claim leases due items in (due_at, priority, id)
order, so priority breaks ties among items due at the same instant.
- Each claim charges an attempt and returns a random lease token.
settleandrenewaddress an item by id and token. A wrong token or a lapsed lease reportsstaleand leaves the item alone.- A lapsed lease makes the item claimable again if it has attempts left; otherwise it counts as
failed.max_attempts: unlimitedturns the bound off. releasegives the claim's attempt back, so a timer that charges nothing is areleasesettle withafter.- Every change gives the item a new
versionfrom a sequence per space, so a key's versions never repeat, even after a delete and a reinsert.
Every selection uses an index
A where in select, update,
delete and assert needs an access term: an
eq, in or contains between an
indexed column and a value. Ranges narrow an access term but aren't
one. Selecting by ids or keys needs no
where, and an aggregate whose columns one btree index holds
reads that index. Every statement has a limit, and every transaction
runs under a 5 s statement timeout.
Time is the database's clock
Every statement reads the time from fireweed.now(), the
transaction's start time. Tests set the session setting
fireweed.now to fix an instant. Time-driven changes are
conditions on stored times: a pending item is claimable once
due_at <= now, and every statement that reads
state sees the effective state. sweep writes
effective states back and deletes finished items past retention,
expired table rows and old request records. Results don't depend on
when it runs.
One program, one transaction
Statements run in order, and each sees the effects of those before it.
A statement can reject the program: key_conflict,
stale_lease, limit_exceeded,
expect_unmet or merge_violation. Then every
statement rolls back and the response names the statement and reason.
Programs run at READ COMMITTED; guards lock the rows they
count.
A program that writes carries a request_id and the
issued_at time the caller created it, both resent unchanged
on every retry. A replay returns the recorded response, rejections
included. A request issued before now - request_retention
fails with request_expired and has no effect, so a request
whose record may be gone is refused, never run twice.
Durability
On PostgreSQL, durable (the default) is a normal commit to
a server assumed fully replicated. fire_and_forget commits
with synchronous_commit = off. The response reports the
level.