mirror of
https://github.com/stablyai/orca.git
synced 2026-10-07 16:02:29 +00:00
* fix(push): bound the delivery claim and stop keeping finished batches * fix(push): bound claim scans to the notification TTL and document the queue * test(push): boot waits out a table writer for the queue indexes; queue stays correct without them * fix(push): share the claim lock so a previous-revision claim cannot re-lease a delivery During a deploy overlap the previous revision's claim scans under an exclusive push-worker-claim lock and re-reads the row without checking lease_until, so it could overwrite a lease this revision had just committed and send twice. The new claim now takes the same key shared: new claimers never block each other, and the previous claim waits until their leases commit before it scans. Droppable one release after every worker runs this revision. * fix(push): install one queue index at boot, not three push_batches_leased_device indexed lease_until, so every lease, renew and finish UPDATE lost heap-only eligibility and rewrote every index. push_batches_pending_due was unused: on a synthetic 902k-row table the candidate scan plans onto the existing (state, due_at) and expiry indexes with or without it. The per-device pending index stays; the head check and the busy anti-join use it. Fewer boot-time builds also shorten the SHARE lock the first boot takes on the table. * test(push): pin the claim's TTL scan bound and the server's worker connection cap Removing either guard left the suite green. The claim test captures every row the candidate scan returns and plants one row that only the TTL term excludes; the server test drives the real worker through createPushServer and fails when the request-connection reservation is unwired (peak 4 instead of 2). * fix(push): renew delivery leases outside the background connection cap Renew shared the single background slot with claim retries and prune batches, so a heartbeat could wait long enough for a lease to lapse and the delivery to be re-leased mid-send. It is a keyed one-row UPDATE, so request traffic cannot starve it on the ungated pool. * docs(push): describe the shared claim lock for mixed-revision deploys
47 lines
1.9 KiB
TypeScript
47 lines
1.9 KiB
TypeScript
export const DURABLE_PUSH_SCHEMA = `
|
|
CREATE TABLE IF NOT EXISTS push_dismissed_events (
|
|
host_fingerprint TEXT NOT NULL,
|
|
notification_epoch TEXT NOT NULL,
|
|
notification_id TEXT NOT NULL,
|
|
notification_seq BIGINT NOT NULL,
|
|
created_at BIGINT NOT NULL,
|
|
PRIMARY KEY(host_fingerprint, notification_epoch, notification_id)
|
|
);
|
|
CREATE INDEX IF NOT EXISTS push_dismissed_retention ON push_dismissed_events(created_at);
|
|
CREATE TABLE IF NOT EXISTS push_events (
|
|
event_id TEXT PRIMARY KEY,
|
|
host_fingerprint TEXT NOT NULL,
|
|
kind TEXT NOT NULL,
|
|
fingerprint TEXT NOT NULL,
|
|
created_at BIGINT NOT NULL,
|
|
expires_at BIGINT NOT NULL
|
|
);
|
|
CREATE INDEX IF NOT EXISTS push_events_quota ON push_events(host_fingerprint, kind, created_at);
|
|
CREATE TABLE IF NOT EXISTS push_event_recipients (
|
|
event_id TEXT NOT NULL,
|
|
registration_id TEXT NOT NULL,
|
|
created_at BIGINT NOT NULL,
|
|
PRIMARY KEY(event_id, registration_id)
|
|
);
|
|
CREATE TABLE IF NOT EXISTS push_delivery_batches (
|
|
batch_id TEXT PRIMARY KEY,
|
|
host_fingerprint TEXT NOT NULL,
|
|
registration_id TEXT NOT NULL,
|
|
kind TEXT NOT NULL,
|
|
payload_json TEXT NOT NULL,
|
|
state TEXT NOT NULL,
|
|
due_at BIGINT NOT NULL,
|
|
expires_at BIGINT NOT NULL,
|
|
lease_token TEXT,
|
|
lease_until BIGINT NOT NULL,
|
|
attempts BIGINT NOT NULL,
|
|
created_at BIGINT NOT NULL
|
|
);
|
|
CREATE INDEX IF NOT EXISTS push_events_retention ON push_events(created_at);
|
|
CREATE INDEX IF NOT EXISTS push_recipients_retention ON push_event_recipients(created_at);
|
|
CREATE INDEX IF NOT EXISTS push_batches_expiry ON push_delivery_batches(expires_at);
|
|
CREATE INDEX IF NOT EXISTS push_batches_due ON push_delivery_batches(state, due_at);
|
|
CREATE INDEX IF NOT EXISTS push_batches_registration ON push_delivery_batches(registration_id, state);
|
|
CREATE INDEX IF NOT EXISTS push_batches_pending_device ON push_delivery_batches(registration_id, due_at, created_at, batch_id) WHERE state = 'pending';
|
|
`
|