PgQue icon indicating copy to clipboard operation
PgQue copied to clipboard

fix(partition-keys): prevent incomplete slot setup from losing history

Open NikolayS opened this issue 4 months ago • 1 comments

Severity

Medium-high — silent message-history loss for a partitioned consumer.

Problem

subscribe_slot(queue, consumer, slot, n) creates only one engine subscription per call. If a producer sends/ticks events before all 0..n-1 slots are registered, a late slot subscription starts at the current tick and permanently skips earlier events in its hash class.

The status view makes this especially dangerous: a missing slot is synthesized with last_tick = NULL but pending_events = 0, which looks caught up rather than incomplete.

Reproduction

  1. Create a queue and subscribe only slot 0 with n=2.
  2. Send/tick an event whose key hashes to slot 1.
  3. Observe slot 1 in partition_slot_status: last_tick=NULL, pending_events=0.
  4. Subscribe and claim slot 1.
  5. receive_partitioned returns zero rows; the historical event is unreachable by that partitioned consumer.

Affected implementation:

  • subscribe_slot in devel/sql/pgque-api/partition_keys.sql
  • pgque.partition_slot_status in the same file

Expected resolution

Make incomplete setup impossible or unmistakable. Preferred direction: an atomic whole-consumer registration API that creates all N slot subscriptions in one transaction and is the public setup path. At minimum, expose an explicit subscribed state, return unknown lag rather than zero for missing subscriptions, and hard-document that registration must finish atomically before producing.

Add regressions for partial setup, late registration, status semantics, and preservation of all slot histories. This needs an explicit API decision before final 0.3.0.

NikolayS avatar Jul 10 '26 09:07 NikolayS

Shipped in v0.3.0-rc.2 (merged to main via #395 at f4c7457): https://github.com/NikolayS/PgQue/releases/tag/v0.3.0-rc.2

NikolayS avatar Nov 21 '26 16:11 NikolayS