Skip to main content

Module store

Module store 

Source
Expand description

The PostgreSQL EventStore.

Ordering is the whole job. global_sequence is assigned inside the append transaction, under the gwk_internal.writer row lock, and that lock is held until commit — so the order values are handed out IS the order transactions commit in. Unique and strictly increasing, deliberately not gapless: a rolled-back append gives its number back, a crashed one may not, and no reader is allowed to care.

This is why the column is not BIGSERIAL. A sequence allocates at INSERT time while transactions commit in another order, so a reader paging an allocation-ordered column can see N+1 committed before N exists and then never see N at all. That hole cannot be patched by reading more carefully; it has to be closed at allocation.

Writes are admitted through a bounded permit set and then serialize on that same row lock. The bound is what turns a flood into a refusal instead of an unbounded queue of connections waiting on one row.

Structs§

PgEventStore
The PostgreSQL event store.

Constants§

EVENT_CHANNEL
The wake-up channel. Carries the new watermark, but only as a hint: a consumer that never receives a single notification still recovers the whole suffix from its durable cursor, which is what makes this channel droppable.
MAX_INFLIGHT_APPENDS
How many appends may be in flight before the store refuses.

Functions§

connect_pool
Open a pool whose sessions are pinned to UTC.
validate_batch
What a batch must be before it reaches the database.