bunqueue 2.8.60 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -76
- package/dist/application/background/dlq.js +2 -0
- package/dist/application/contextFactory.js +5 -0
- package/dist/application/dlqManager.d.ts +10 -0
- package/dist/application/dlqManager.js +47 -9
- package/dist/application/dlqRetry.js +59 -38
- package/dist/application/eventsManager.d.ts +1 -1
- package/dist/application/eventsManager.js +30 -26
- package/dist/application/operations/jobManagement.d.ts +4 -0
- package/dist/application/operations/jobMoveOperations.js +9 -4
- package/dist/application/postgres-queue-manager/batchSnapshot.d.ts +16 -0
- package/dist/application/postgres-queue-manager/batchSnapshot.js +17 -0
- package/dist/application/postgres-queue-manager/cloud.d.ts +30 -0
- package/dist/application/postgres-queue-manager/cloud.js +55 -0
- package/dist/application/postgres-queue-manager/config.d.ts +5 -0
- package/dist/application/postgres-queue-manager/config.js +1 -0
- package/dist/application/postgres-queue-manager/control.d.ts +26 -0
- package/dist/application/postgres-queue-manager/control.js +186 -0
- package/dist/application/postgres-queue-manager/deferredWrites.d.ts +13 -0
- package/dist/application/postgres-queue-manager/deferredWrites.js +60 -0
- package/dist/application/postgres-queue-manager/delivery.d.ts +19 -0
- package/dist/application/postgres-queue-manager/delivery.js +80 -0
- package/dist/application/postgres-queue-manager/lease.d.ts +13 -0
- package/dist/application/postgres-queue-manager/lease.js +88 -0
- package/dist/application/postgres-queue-manager/lifetimeMetrics.d.ts +32 -0
- package/dist/application/postgres-queue-manager/lifetimeMetrics.js +53 -0
- package/dist/application/postgres-queue-manager/maintenance.d.ts +14 -0
- package/dist/application/postgres-queue-manager/maintenance.js +100 -0
- package/dist/application/postgres-queue-manager/operationGate.d.ts +26 -0
- package/dist/application/postgres-queue-manager/operationGate.js +96 -0
- package/dist/application/postgres-queue-manager/operations.d.ts +25 -0
- package/dist/application/postgres-queue-manager/operations.js +194 -0
- package/dist/application/postgres-queue-manager/projectionRefreshes.d.ts +43 -0
- package/dist/application/postgres-queue-manager/projectionRefreshes.js +170 -0
- package/dist/application/postgres-queue-manager/queries.d.ts +142 -0
- package/dist/application/postgres-queue-manager/queries.js +231 -0
- package/dist/application/postgres-queue-manager/relationships.d.ts +10 -0
- package/dist/application/postgres-queue-manager/relationships.js +45 -0
- package/dist/application/postgres-queue-manager/services.d.ts +31 -0
- package/dist/application/postgres-queue-manager/services.js +149 -0
- package/dist/application/postgres-queue-manager/snapshot.d.ts +51 -0
- package/dist/application/postgres-queue-manager/snapshot.js +236 -0
- package/dist/application/postgres-queue-manager/snapshotViews.d.ts +15 -0
- package/dist/application/postgres-queue-manager/snapshotViews.js +100 -0
- package/dist/application/postgres-queue-manager/startupEventBuffer.d.ts +12 -0
- package/dist/application/postgres-queue-manager/startupEventBuffer.js +36 -0
- package/dist/application/postgres-queue-manager/state.d.ts +47 -0
- package/dist/application/postgres-queue-manager/state.js +273 -0
- package/dist/application/postgres-queue-manager/terminalDelivery.d.ts +20 -0
- package/dist/application/postgres-queue-manager/terminalDelivery.js +100 -0
- package/dist/application/postgresQueueManager.d.ts +2 -0
- package/dist/application/postgresQueueManager.js +1 -0
- package/dist/application/queue-manager/flow-failures.js +4 -0
- package/dist/application/queue-manager/limits.d.ts +2 -0
- package/dist/application/queue-manager/limits.js +4 -0
- package/dist/application/queue-manager/observability.js +15 -3
- package/dist/application/queue-manager/queries.d.ts +7 -0
- package/dist/application/queue-manager/queries.js +9 -0
- package/dist/application/queue-manager/services.d.ts +1 -1
- package/dist/application/queue-manager/services.js +4 -2
- package/dist/application/queue-manager/state.js +16 -1
- package/dist/cli/commands/server.js +1 -1
- package/dist/client/forwarder.d.ts +6 -4
- package/dist/client/forwarder.js +5 -3
- package/dist/client/queue/dlq.d.ts +2 -0
- package/dist/client/queue/dlq.js +14 -0
- package/dist/client/queue/dlqOps.d.ts +2 -0
- package/dist/client/queue/dlqOps.js +4 -0
- package/dist/client/queue/helpers.js +2 -0
- package/dist/client/queue/runtime/configuration.d.ts +4 -0
- package/dist/client/queue/runtime/configuration.js +8 -0
- package/dist/client/worker/runtime/execution.js +3 -8
- package/dist/client/worker/runtime/polling.d.ts +1 -0
- package/dist/client/worker/runtime/polling.js +9 -0
- package/dist/config/resolve.d.ts +14 -0
- package/dist/config/resolve.js +50 -5
- package/dist/config/types.d.ts +18 -0
- package/dist/domain/queue/dlqShard.d.ts +2 -0
- package/dist/domain/queue/dlqShard.js +16 -0
- package/dist/domain/queue/shard/dlq.d.ts +1 -0
- package/dist/domain/queue/shard/dlq.js +3 -0
- package/dist/domain/types/commands/dlq.d.ts +5 -0
- package/dist/domain/types/commands/union.d.ts +1 -1
- package/dist/domain/types/cron.d.ts +5 -0
- package/dist/domain/types/cron.js +14 -3
- package/dist/domain/types/dlq.d.ts +1 -1
- package/dist/domain/types/dlq.js +1 -2
- package/dist/domain/types/jobs/model.d.ts +1 -1
- package/dist/infrastructure/cloud/commandHandler.js +5 -3
- package/dist/infrastructure/cloud/commands/integrations.js +11 -11
- package/dist/infrastructure/cloud/commands/jobs.js +48 -40
- package/dist/infrastructure/cloud/commands/queues.js +61 -75
- package/dist/infrastructure/cloud/queueAdapter/local.d.ts +41 -0
- package/dist/infrastructure/cloud/queueAdapter/local.js +187 -0
- package/dist/infrastructure/cloud/queueAdapter/postgres.d.ts +42 -0
- package/dist/infrastructure/cloud/queueAdapter/postgres.js +188 -0
- package/dist/infrastructure/cloud/queueAdapter/registry.d.ts +4 -0
- package/dist/infrastructure/cloud/queueAdapter/registry.js +15 -0
- package/dist/infrastructure/cloud/queueAdapter/types.d.ts +87 -0
- package/dist/infrastructure/cloud/queueAdapter/types.js +1 -0
- package/dist/infrastructure/cloud/snapshot/analytics.d.ts +2 -0
- package/dist/infrastructure/cloud/snapshot/analytics.js +7 -0
- package/dist/infrastructure/cloud/snapshot/collector.d.ts +4 -0
- package/dist/infrastructure/cloud/snapshot/collector.js +39 -1
- package/dist/infrastructure/cloud/snapshot/config.d.ts +3 -0
- package/dist/infrastructure/cloud/snapshot/config.js +43 -0
- package/dist/infrastructure/cloud/snapshot/jobs.d.ts +3 -0
- package/dist/infrastructure/cloud/snapshot/jobs.js +32 -1
- package/dist/infrastructure/cloud/snapshotCollector.js +20 -35
- package/dist/infrastructure/cloud/snapshotHelpers.d.ts +3 -3
- package/dist/infrastructure/cloud/snapshotHelpers.js +3 -3
- package/dist/infrastructure/cloud/statsRefresh.js +2 -1
- package/dist/infrastructure/cloud/types/command.d.ts +2 -2
- package/dist/infrastructure/persistence/postgres/admission.d.ts +18 -0
- package/dist/infrastructure/persistence/postgres/admission.js +193 -0
- package/dist/infrastructure/persistence/postgres/admissionParent.d.ts +5 -0
- package/dist/infrastructure/persistence/postgres/admissionParent.js +35 -0
- package/dist/infrastructure/persistence/postgres/admissionResult.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/admissionResult.js +1 -0
- package/dist/infrastructure/persistence/postgres/admissionStore.d.ts +12 -0
- package/dist/infrastructure/persistence/postgres/admissionStore.js +101 -0
- package/dist/infrastructure/persistence/postgres/advisoryLocks.d.ts +2 -0
- package/dist/infrastructure/persistence/postgres/advisoryLocks.js +13 -0
- package/dist/infrastructure/persistence/postgres/batchAdmission.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/batchAdmission.js +110 -0
- package/dist/infrastructure/persistence/postgres/batchCompletion.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/batchCompletion.js +174 -0
- package/dist/infrastructure/persistence/postgres/batchEvents.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/batchEvents.js +72 -0
- package/dist/infrastructure/persistence/postgres/brokerSessions.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/brokerSessions.js +94 -0
- package/dist/infrastructure/persistence/postgres/claimBatch.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/claimBatch.js +56 -0
- package/dist/infrastructure/persistence/postgres/claimSelection.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/claimSelection.js +198 -0
- package/dist/infrastructure/persistence/postgres/claims.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/claims.js +137 -0
- package/dist/infrastructure/persistence/postgres/cloudReadModel.d.ts +26 -0
- package/dist/infrastructure/persistence/postgres/cloudReadModel.js +123 -0
- package/dist/infrastructure/persistence/postgres/codec.d.ts +30 -0
- package/dist/infrastructure/persistence/postgres/codec.js +82 -0
- package/dist/infrastructure/persistence/postgres/completionEvents.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/completionEvents.js +21 -0
- package/dist/infrastructure/persistence/postgres/completionLifecycle.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/completionLifecycle.js +145 -0
- package/dist/infrastructure/persistence/postgres/completionOutcome.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/completionOutcome.js +112 -0
- package/dist/infrastructure/persistence/postgres/completionQueries.d.ts +10 -0
- package/dist/infrastructure/persistence/postgres/completionQueries.js +87 -0
- package/dist/infrastructure/persistence/postgres/connection.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/connection.js +15 -0
- package/dist/infrastructure/persistence/postgres/context.d.ts +28 -0
- package/dist/infrastructure/persistence/postgres/context.js +74 -0
- package/dist/infrastructure/persistence/postgres/control.d.ts +23 -0
- package/dist/infrastructure/persistence/postgres/control.js +105 -0
- package/dist/infrastructure/persistence/postgres/crons.d.ts +18 -0
- package/dist/infrastructure/persistence/postgres/crons.js +205 -0
- package/dist/infrastructure/persistence/postgres/deduplication.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/deduplication.js +47 -0
- package/dist/infrastructure/persistence/postgres/dependencyDestruction.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/dependencyDestruction.js +74 -0
- package/dist/infrastructure/persistence/postgres/dependencyPromotion.d.ts +29 -0
- package/dist/infrastructure/persistence/postgres/dependencyPromotion.js +212 -0
- package/dist/infrastructure/persistence/postgres/destructiveMutations.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/destructiveMutations.js +111 -0
- package/dist/infrastructure/persistence/postgres/dlqLifecycle.d.ts +13 -0
- package/dist/infrastructure/persistence/postgres/dlqLifecycle.js +184 -0
- package/dist/infrastructure/persistence/postgres/dlqMaintenance.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/dlqMaintenance.js +36 -0
- package/dist/infrastructure/persistence/postgres/dlqRetryPlan.d.ts +21 -0
- package/dist/infrastructure/persistence/postgres/dlqRetryPlan.js +92 -0
- package/dist/infrastructure/persistence/postgres/eventCommitGc.d.ts +27 -0
- package/dist/infrastructure/persistence/postgres/eventCommitGc.js +62 -0
- package/dist/infrastructure/persistence/postgres/eventJournal.d.ts +18 -0
- package/dist/infrastructure/persistence/postgres/eventJournal.js +76 -0
- package/dist/infrastructure/persistence/postgres/eventJournalSchema.d.ts +5 -0
- package/dist/infrastructure/persistence/postgres/eventJournalSchema.js +253 -0
- package/dist/infrastructure/persistence/postgres/eventPruneWatermarks.d.ts +24 -0
- package/dist/infrastructure/persistence/postgres/eventPruneWatermarks.js +111 -0
- package/dist/infrastructure/persistence/postgres/eventRetention.d.ts +18 -0
- package/dist/infrastructure/persistence/postgres/eventRetention.js +76 -0
- package/dist/infrastructure/persistence/postgres/events.d.ts +45 -0
- package/dist/infrastructure/persistence/postgres/events.js +249 -0
- package/dist/infrastructure/persistence/postgres/expiry.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/expiry.js +74 -0
- package/dist/infrastructure/persistence/postgres/flowFailures.d.ts +17 -0
- package/dist/infrastructure/persistence/postgres/flowFailures.js +199 -0
- package/dist/infrastructure/persistence/postgres/jobData.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/jobData.js +32 -0
- package/dist/infrastructure/persistence/postgres/leaseRelease.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/leaseRelease.js +120 -0
- package/dist/infrastructure/persistence/postgres/leaseRenewal.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/leaseRenewal.js +35 -0
- package/dist/infrastructure/persistence/postgres/lifetimeMetrics.d.ts +15 -0
- package/dist/infrastructure/persistence/postgres/lifetimeMetrics.js +46 -0
- package/dist/infrastructure/persistence/postgres/lifetimeMetricsFinalizer.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/lifetimeMetricsFinalizer.js +13 -0
- package/dist/infrastructure/persistence/postgres/logs.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/logs.js +70 -0
- package/dist/infrastructure/persistence/postgres/maintenance.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/maintenance.js +138 -0
- package/dist/infrastructure/persistence/postgres/maintenanceFlights.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/maintenanceFlights.js +66 -0
- package/dist/infrastructure/persistence/postgres/metricWrites.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/metricWrites.js +94 -0
- package/dist/infrastructure/persistence/postgres/mutations.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/mutations.js +171 -0
- package/dist/infrastructure/persistence/postgres/outcomes.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/outcomes.js +194 -0
- package/dist/infrastructure/persistence/postgres/policies.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/policies.js +18 -0
- package/dist/infrastructure/persistence/postgres/postCommitMaintenance.d.ts +17 -0
- package/dist/infrastructure/persistence/postgres/postCommitMaintenance.js +117 -0
- package/dist/infrastructure/persistence/postgres/promotion.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/promotion.js +43 -0
- package/dist/infrastructure/persistence/postgres/queries.d.ts +22 -0
- package/dist/infrastructure/persistence/postgres/queries.js +152 -0
- package/dist/infrastructure/persistence/postgres/queueDestruction.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/queueDestruction.js +154 -0
- package/dist/infrastructure/persistence/postgres/queueLifecycle.d.ts +10 -0
- package/dist/infrastructure/persistence/postgres/queueLifecycle.js +60 -0
- package/dist/infrastructure/persistence/postgres/rateLimit.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/rateLimit.js +10 -0
- package/dist/infrastructure/persistence/postgres/readModels.d.ts +32 -0
- package/dist/infrastructure/persistence/postgres/readModels.js +72 -0
- package/dist/infrastructure/persistence/postgres/recovery.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/recovery.js +178 -0
- package/dist/infrastructure/persistence/postgres/relationships.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/relationships.js +201 -0
- package/dist/infrastructure/persistence/postgres/removeUnprocessedChildren.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/removeUnprocessedChildren.js +241 -0
- package/dist/infrastructure/persistence/postgres/repeatMutations.d.ts +5 -0
- package/dist/infrastructure/persistence/postgres/repeatMutations.js +37 -0
- package/dist/infrastructure/persistence/postgres/runtime.d.ts +46 -0
- package/dist/infrastructure/persistence/postgres/runtime.js +236 -0
- package/dist/infrastructure/persistence/postgres/runtimeConfig.d.ts +21 -0
- package/dist/infrastructure/persistence/postgres/runtimeConfig.js +39 -0
- package/dist/infrastructure/persistence/postgres/schema.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/schema.js +257 -0
- package/dist/infrastructure/persistence/postgres/schemaInitialization.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/schemaInitialization.js +221 -0
- package/dist/infrastructure/persistence/postgres/serialAdmission.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/serialAdmission.js +96 -0
- package/dist/infrastructure/persistence/postgres/snapshotBudget.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/snapshotBudget.js +83 -0
- package/dist/infrastructure/persistence/postgres/storageHealth.d.ts +10 -0
- package/dist/infrastructure/persistence/postgres/storageHealth.js +29 -0
- package/dist/infrastructure/persistence/postgres/store.d.ts +90 -0
- package/dist/infrastructure/persistence/postgres/store.js +136 -0
- package/dist/infrastructure/persistence/postgres/telemetry.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/telemetry.js +88 -0
- package/dist/infrastructure/persistence/postgres/terminal.d.ts +8 -0
- package/dist/infrastructure/persistence/postgres/terminal.js +137 -0
- package/dist/infrastructure/persistence/postgres/transactionRetry.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/transactionRetry.js +42 -0
- package/dist/infrastructure/persistence/postgres/types.d.ts +175 -0
- package/dist/infrastructure/persistence/postgres/types.js +1 -0
- package/dist/infrastructure/persistence/postgres/workers.d.ts +15 -0
- package/dist/infrastructure/persistence/postgres/workers.js +126 -0
- package/dist/infrastructure/persistence/postgres.d.ts +2 -0
- package/dist/infrastructure/persistence/postgres.js +1 -0
- package/dist/infrastructure/persistence/sqlite/jobs.js +2 -0
- package/dist/infrastructure/scheduler/cron/persisted.d.ts +5 -0
- package/dist/infrastructure/scheduler/cron/persisted.js +27 -0
- package/dist/infrastructure/scheduler/cron/runtime.js +5 -10
- package/dist/infrastructure/scheduler/cron/validation.d.ts +3 -0
- package/dist/infrastructure/scheduler/cron/validation.js +11 -0
- package/dist/infrastructure/scheduler/cronParser.d.ts +1 -1
- package/dist/infrastructure/scheduler/cronParser.js +144 -11
- package/dist/infrastructure/server/bootstrap.d.ts +2 -3
- package/dist/infrastructure/server/bootstrap.js +33 -59
- package/dist/infrastructure/server/errors.d.ts +4 -0
- package/dist/infrastructure/server/errors.js +54 -0
- package/dist/infrastructure/server/handler-routes/control.d.ts +5 -5
- package/dist/infrastructure/server/handler-routes/control.js +3 -1
- package/dist/infrastructure/server/handler-routes/monitoring.d.ts +2 -2
- package/dist/infrastructure/server/handler.js +9 -11
- package/dist/infrastructure/server/handlers/advanced/dependencies.js +7 -6
- package/dist/infrastructure/server/handlers/advanced/jobs.js +19 -6
- package/dist/infrastructure/server/handlers/advanced/queue.d.ts +9 -9
- package/dist/infrastructure/server/handlers/advanced/queue.js +91 -27
- package/dist/infrastructure/server/handlers/core.js +32 -31
- package/dist/infrastructure/server/handlers/cron.d.ts +4 -4
- package/dist/infrastructure/server/handlers/cron.js +60 -59
- package/dist/infrastructure/server/handlers/dashboard.d.ts +1 -1
- package/dist/infrastructure/server/handlers/dashboard.js +21 -8
- package/dist/infrastructure/server/handlers/dlq.d.ts +6 -3
- package/dist/infrastructure/server/handlers/dlq.js +35 -9
- package/dist/infrastructure/server/handlers/flow.js +2 -1
- package/dist/infrastructure/server/handlers/management.d.ts +5 -5
- package/dist/infrastructure/server/handlers/management.js +36 -9
- package/dist/infrastructure/server/handlers/monitoring/health.d.ts +5 -5
- package/dist/infrastructure/server/handlers/monitoring/health.js +45 -16
- package/dist/infrastructure/server/handlers/monitoring/operations.d.ts +1 -1
- package/dist/infrastructure/server/handlers/monitoring/operations.js +8 -1
- package/dist/infrastructure/server/handlers/monitoring/workers.d.ts +3 -3
- package/dist/infrastructure/server/handlers/monitoring/workers.js +31 -7
- package/dist/infrastructure/server/handlers/pushBatchValidation.d.ts +3 -1
- package/dist/infrastructure/server/handlers/pushBatchValidation.js +52 -7
- package/dist/infrastructure/server/handlers/query.d.ts +1 -1
- package/dist/infrastructure/server/handlers/query.js +5 -4
- package/dist/infrastructure/server/http.js +2 -2
- package/dist/infrastructure/server/httpDashboardEndpoints.d.ts +1 -1
- package/dist/infrastructure/server/httpDashboardEndpoints.js +19 -6
- package/dist/infrastructure/server/httpEndpoints.js +18 -7
- package/dist/infrastructure/server/httpRouteQueues.js +11 -1
- package/dist/infrastructure/server/shutdownCoordinator.d.ts +24 -0
- package/dist/infrastructure/server/shutdownCoordinator.js +106 -0
- package/dist/infrastructure/server/sseHandler.js +8 -3
- package/dist/infrastructure/server/storageAdapter.d.ts +29 -0
- package/dist/infrastructure/server/storageAdapter.js +61 -0
- package/dist/infrastructure/server/storageManager.d.ts +12 -0
- package/dist/infrastructure/server/storageManager.js +102 -0
- package/dist/infrastructure/server/tcp.js +2 -3
- package/dist/infrastructure/server/ws/snapshots.d.ts +1 -1
- package/dist/infrastructure/server/ws/snapshots.js +19 -4
- package/dist/infrastructure/server/wsHandler.js +10 -5
- package/dist/main.js +1 -1
- package/dist/mcp/backend/embedded/services.js +2 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +2 -2
- package/dist/shared/storageHealth.d.ts +9 -0
- package/dist/shared/storageHealth.js +12 -0
- package/package.json +74 -65
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const POSTGRES_REGISTER_EVENT_ROWS_BODY = "BEGIN\n INSERT INTO bunqueue_event_commits (namespace, transaction_id)\n SELECT DISTINCT namespace, transaction_id FROM new_event_rows\n ORDER BY namespace, transaction_id\n ON CONFLICT DO NOTHING;\n RETURN NULL;\nEND;";
|
|
2
|
+
export declare const POSTGRES_REGISTER_WATERMARK_ROWS_BODY = "BEGIN\n INSERT INTO bunqueue_event_commits (namespace, transaction_id)\n SELECT DISTINCT namespace, transaction_id FROM new_watermark_rows\n ORDER BY namespace, transaction_id\n ON CONFLICT DO NOTHING;\n RETURN NULL;\nEND;";
|
|
3
|
+
export declare const POSTGRES_ASSIGN_EVENT_COMMIT_BODY = "DECLARE\n assigned_commit_seq BIGINT;\nBEGIN\n PERFORM pg_advisory_xact_lock(hashtextextended(\n 'bunqueue:event-commit:' || length(NEW.namespace)::text || ':' || NEW.namespace,\n 0\n ));\n assigned_commit_seq := nextval('bunqueue_event_commit_seq');\n\n UPDATE bunqueue_event_commits\n SET commit_seq = assigned_commit_seq\n WHERE namespace = NEW.namespace\n AND transaction_id = NEW.transaction_id\n AND commit_seq IS NULL;\n UPDATE bunqueue_event_prune_watermarks\n SET commit_seq = assigned_commit_seq,\n pruned_commit_seq = CASE\n WHEN prunes_current_transaction THEN GREATEST(\n COALESCE(pruned_commit_seq, 0), assigned_commit_seq\n )\n ELSE pruned_commit_seq\n END,\n prunes_current_transaction = FALSE\n WHERE namespace = NEW.namespace\n AND transaction_id = NEW.transaction_id\n AND commit_seq IS NULL;\n RETURN NULL;\nEND;";
|
|
4
|
+
/** Commit-time journal sequencer installed by the PostgreSQL schema migration. */
|
|
5
|
+
export declare const POSTGRES_EVENT_JOURNAL_SCHEMA = "\nCREATE SEQUENCE IF NOT EXISTS bunqueue_event_commit_seq AS BIGINT CACHE 1;\nALTER SEQUENCE bunqueue_event_commit_seq\n AS BIGINT INCREMENT BY 1 NO MINVALUE NO MAXVALUE NO CYCLE CACHE 1;\n\nCREATE TABLE IF NOT EXISTS bunqueue_event_commits (\n namespace TEXT NOT NULL,\n transaction_id BIGINT NOT NULL,\n commit_seq BIGINT,\n PRIMARY KEY (namespace, transaction_id)\n);\n\nALTER TABLE bunqueue_event_commits\n ADD COLUMN IF NOT EXISTS namespace TEXT;\nALTER TABLE bunqueue_event_commits\n ADD COLUMN IF NOT EXISTS transaction_id BIGINT;\nALTER TABLE bunqueue_event_commits\n ADD COLUMN IF NOT EXISTS commit_seq BIGINT;\nALTER TABLE bunqueue_event_commits\n ALTER COLUMN namespace TYPE TEXT USING namespace::text,\n ALTER COLUMN transaction_id TYPE BIGINT USING transaction_id::bigint,\n ALTER COLUMN commit_seq TYPE BIGINT USING commit_seq::bigint;\n\nALTER TABLE bunqueue_events\n ADD COLUMN IF NOT EXISTS transaction_id BIGINT;\nALTER TABLE bunqueue_events\n ALTER COLUMN transaction_id DROP DEFAULT;\nALTER TABLE bunqueue_events\n ALTER COLUMN transaction_id TYPE BIGINT USING transaction_id::bigint;\nALTER TABLE bunqueue_events\n ALTER COLUMN transaction_id SET DEFAULT (pg_current_xact_id()::text::bigint);\n\nALTER TABLE bunqueue_event_prune_watermarks\n ADD COLUMN IF NOT EXISTS transaction_id BIGINT;\nALTER TABLE bunqueue_event_prune_watermarks\n ADD COLUMN IF NOT EXISTS commit_seq BIGINT;\nALTER TABLE bunqueue_event_prune_watermarks\n ADD COLUMN IF NOT EXISTS pruned_commit_seq BIGINT;\nALTER TABLE bunqueue_event_prune_watermarks\n ADD COLUMN IF NOT EXISTS prunes_current_transaction BOOLEAN NOT NULL DEFAULT FALSE;\nALTER TABLE bunqueue_event_prune_watermarks\n ALTER COLUMN transaction_id DROP DEFAULT,\n ALTER COLUMN pruned_commit_seq DROP DEFAULT,\n ALTER COLUMN prunes_current_transaction DROP DEFAULT;\nALTER TABLE bunqueue_event_prune_watermarks\n ALTER COLUMN transaction_id TYPE BIGINT USING transaction_id::bigint,\n ALTER COLUMN commit_seq TYPE BIGINT USING commit_seq::bigint,\n ALTER COLUMN pruned_commit_seq TYPE BIGINT USING pruned_commit_seq::bigint,\n ALTER COLUMN prunes_current_transaction TYPE BOOLEAN\n USING prunes_current_transaction::boolean;\nALTER TABLE bunqueue_event_prune_watermarks\n ALTER COLUMN transaction_id SET DEFAULT (pg_current_xact_id()::text::bigint);\nALTER TABLE bunqueue_event_prune_watermarks\n ALTER COLUMN pruned_commit_seq SET DEFAULT 0,\n ALTER COLUMN prunes_current_transaction SET DEFAULT FALSE;\n\nUPDATE bunqueue_events\nSET transaction_id = -id\nWHERE transaction_id IS NULL;\nUPDATE bunqueue_event_prune_watermarks\nSET transaction_id = COALESCE(transaction_id, -source_event_id),\n commit_seq = COALESCE(commit_seq, source_event_id),\n pruned_commit_seq = COALESCE(pruned_commit_seq, commit_seq, source_event_id)\nWHERE transaction_id IS NULL OR commit_seq IS NULL OR pruned_commit_seq IS NULL;\n\nALTER TABLE bunqueue_events\n ALTER COLUMN transaction_id SET NOT NULL;\nALTER TABLE bunqueue_event_commits\n ALTER COLUMN namespace SET NOT NULL,\n ALTER COLUMN transaction_id SET NOT NULL;\nALTER TABLE bunqueue_event_prune_watermarks\n ALTER COLUMN transaction_id SET NOT NULL,\n ALTER COLUMN pruned_commit_seq SET NOT NULL,\n ALTER COLUMN prunes_current_transaction SET NOT NULL;\n\nDO $migration$\nBEGIN\n IF EXISTS (\n SELECT 1 FROM pg_attribute\n WHERE attrelid = to_regclass('bunqueue_events')\n AND attname = 'commit_seq' AND NOT attisdropped\n ) THEN\n EXECUTE $sql$\n INSERT INTO bunqueue_event_commits (namespace, transaction_id, commit_seq)\n SELECT namespace, transaction_id, MAX(commit_seq)\n FROM bunqueue_events\n WHERE commit_seq IS NOT NULL\n GROUP BY namespace, transaction_id\n ON CONFLICT (namespace, transaction_id) DO UPDATE SET\n commit_seq = GREATEST(\n COALESCE(bunqueue_event_commits.commit_seq, 0),\n excluded.commit_seq\n )\n $sql$;\n ELSE\n INSERT INTO bunqueue_event_commits (namespace, transaction_id, commit_seq)\n SELECT namespace, transaction_id, MAX(id)\n FROM bunqueue_events\n GROUP BY namespace, transaction_id\n ON CONFLICT (namespace, transaction_id) DO NOTHING;\n END IF;\nEND;\n$migration$;\n\nINSERT INTO bunqueue_event_commits (namespace, transaction_id, commit_seq)\nSELECT namespace, transaction_id, MAX(commit_seq)\nFROM bunqueue_event_prune_watermarks\nWHERE commit_seq IS NOT NULL\nGROUP BY namespace, transaction_id\nON CONFLICT (namespace, transaction_id) DO UPDATE SET\n commit_seq = GREATEST(\n COALESCE(bunqueue_event_commits.commit_seq, 0),\n excluded.commit_seq\n );\n\nDO $block$\nDECLARE\n journal_floor BIGINT := 0;\n legacy_head_floor BIGINT := 0;\n sequence_floor BIGINT := 0;\nBEGIN\n SELECT COALESCE(MAX(commit_seq), 0) INTO journal_floor\n FROM bunqueue_event_commits;\n SELECT last_value INTO sequence_floor FROM bunqueue_event_commit_seq;\n IF to_regclass('bunqueue_event_commit_heads') IS NOT NULL THEN\n EXECUTE 'SELECT COALESCE(MAX(commit_seq), 0) FROM bunqueue_event_commit_heads'\n INTO legacy_head_floor;\n END IF;\n PERFORM setval(\n 'bunqueue_event_commit_seq',\n GREATEST(journal_floor, legacy_head_floor, sequence_floor, 1),\n TRUE\n );\nEND;\n$block$;\n\nDROP TABLE IF EXISTS bunqueue_event_commit_heads;\n\nDROP TRIGGER IF EXISTS bunqueue_events_register_commit ON bunqueue_events;\nDROP TRIGGER IF EXISTS bunqueue_watermarks_insert_register_commit\n ON bunqueue_event_prune_watermarks;\nDROP TRIGGER IF EXISTS bunqueue_watermarks_update_register_commit\n ON bunqueue_event_prune_watermarks;\nDROP TABLE IF EXISTS bunqueue_event_commit_assignments CASCADE;\nDROP INDEX IF EXISTS bunqueue_events_commit_idx;\nDROP INDEX IF EXISTS bunqueue_events_pending_commit_idx;\nALTER TABLE bunqueue_events DROP COLUMN IF EXISTS commit_seq;\n\nDROP INDEX IF EXISTS bunqueue_events_transaction_idx;\nDROP INDEX IF EXISTS bunqueue_event_commits_replay_idx;\nDROP INDEX IF EXISTS bunqueue_event_prune_watermarks_commit_idx;\nDROP INDEX IF EXISTS bunqueue_event_prune_watermarks_pending_commit_idx;\nDROP INDEX IF EXISTS bunqueue_event_prune_watermarks_transaction_idx;\n\nCREATE INDEX bunqueue_events_transaction_idx\n ON bunqueue_events(namespace, transaction_id, id);\nCREATE INDEX bunqueue_event_commits_replay_idx\n ON bunqueue_event_commits(namespace, commit_seq, transaction_id)\n WHERE commit_seq IS NOT NULL;\nCREATE INDEX bunqueue_event_prune_watermarks_commit_idx\n ON bunqueue_event_prune_watermarks(namespace, queue, commit_seq DESC)\n WHERE commit_seq IS NOT NULL;\nCREATE INDEX bunqueue_event_prune_watermarks_pending_commit_idx\n ON bunqueue_event_prune_watermarks(namespace, transaction_id)\n WHERE commit_seq IS NULL;\nCREATE INDEX bunqueue_event_prune_watermarks_transaction_idx\n ON bunqueue_event_prune_watermarks(namespace, transaction_id);\n\nCREATE OR REPLACE FUNCTION bunqueue_register_event_rows()\nRETURNS TRIGGER LANGUAGE plpgsql AS $function$\nBEGIN\n INSERT INTO bunqueue_event_commits (namespace, transaction_id)\n SELECT DISTINCT namespace, transaction_id FROM new_event_rows\n ORDER BY namespace, transaction_id\n ON CONFLICT DO NOTHING;\n RETURN NULL;\nEND;\n$function$;\n\nCREATE OR REPLACE FUNCTION bunqueue_register_watermark_rows()\nRETURNS TRIGGER LANGUAGE plpgsql AS $function$\nBEGIN\n INSERT INTO bunqueue_event_commits (namespace, transaction_id)\n SELECT DISTINCT namespace, transaction_id FROM new_watermark_rows\n ORDER BY namespace, transaction_id\n ON CONFLICT DO NOTHING;\n RETURN NULL;\nEND;\n$function$;\n\nCREATE OR REPLACE FUNCTION bunqueue_assign_event_commit()\nRETURNS TRIGGER LANGUAGE plpgsql AS $function$\nDECLARE\n assigned_commit_seq BIGINT;\nBEGIN\n PERFORM pg_advisory_xact_lock(hashtextextended(\n 'bunqueue:event-commit:' || length(NEW.namespace)::text || ':' || NEW.namespace,\n 0\n ));\n assigned_commit_seq := nextval('bunqueue_event_commit_seq');\n\n UPDATE bunqueue_event_commits\n SET commit_seq = assigned_commit_seq\n WHERE namespace = NEW.namespace\n AND transaction_id = NEW.transaction_id\n AND commit_seq IS NULL;\n UPDATE bunqueue_event_prune_watermarks\n SET commit_seq = assigned_commit_seq,\n pruned_commit_seq = CASE\n WHEN prunes_current_transaction THEN GREATEST(\n COALESCE(pruned_commit_seq, 0), assigned_commit_seq\n )\n ELSE pruned_commit_seq\n END,\n prunes_current_transaction = FALSE\n WHERE namespace = NEW.namespace\n AND transaction_id = NEW.transaction_id\n AND commit_seq IS NULL;\n RETURN NULL;\nEND;\n$function$;\n\nDROP TRIGGER IF EXISTS bunqueue_events_register_commit ON bunqueue_events;\nCREATE TRIGGER bunqueue_events_register_commit\nAFTER INSERT ON bunqueue_events\nREFERENCING NEW TABLE AS new_event_rows\nFOR EACH STATEMENT EXECUTE FUNCTION bunqueue_register_event_rows();\n\nDROP TRIGGER IF EXISTS bunqueue_watermarks_insert_register_commit\n ON bunqueue_event_prune_watermarks;\nCREATE TRIGGER bunqueue_watermarks_insert_register_commit\nAFTER INSERT ON bunqueue_event_prune_watermarks\nREFERENCING NEW TABLE AS new_watermark_rows\nFOR EACH STATEMENT EXECUTE FUNCTION bunqueue_register_watermark_rows();\n\nDROP TRIGGER IF EXISTS bunqueue_watermarks_update_register_commit\n ON bunqueue_event_prune_watermarks;\nCREATE TRIGGER bunqueue_watermarks_update_register_commit\nAFTER UPDATE ON bunqueue_event_prune_watermarks\nREFERENCING NEW TABLE AS new_watermark_rows\nFOR EACH STATEMENT EXECUTE FUNCTION bunqueue_register_watermark_rows();\n\nDROP TRIGGER IF EXISTS bunqueue_assign_event_commit\n ON bunqueue_event_commits;\nCREATE CONSTRAINT TRIGGER bunqueue_assign_event_commit\nAFTER INSERT ON bunqueue_event_commits\nDEFERRABLE INITIALLY DEFERRED\nFOR EACH ROW EXECUTE FUNCTION bunqueue_assign_event_commit();\n";
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
export const POSTGRES_REGISTER_EVENT_ROWS_BODY = `BEGIN
|
|
2
|
+
INSERT INTO bunqueue_event_commits (namespace, transaction_id)
|
|
3
|
+
SELECT DISTINCT namespace, transaction_id FROM new_event_rows
|
|
4
|
+
ORDER BY namespace, transaction_id
|
|
5
|
+
ON CONFLICT DO NOTHING;
|
|
6
|
+
RETURN NULL;
|
|
7
|
+
END;`;
|
|
8
|
+
export const POSTGRES_REGISTER_WATERMARK_ROWS_BODY = `BEGIN
|
|
9
|
+
INSERT INTO bunqueue_event_commits (namespace, transaction_id)
|
|
10
|
+
SELECT DISTINCT namespace, transaction_id FROM new_watermark_rows
|
|
11
|
+
ORDER BY namespace, transaction_id
|
|
12
|
+
ON CONFLICT DO NOTHING;
|
|
13
|
+
RETURN NULL;
|
|
14
|
+
END;`;
|
|
15
|
+
export const POSTGRES_ASSIGN_EVENT_COMMIT_BODY = `DECLARE
|
|
16
|
+
assigned_commit_seq BIGINT;
|
|
17
|
+
BEGIN
|
|
18
|
+
PERFORM pg_advisory_xact_lock(hashtextextended(
|
|
19
|
+
'bunqueue:event-commit:' || length(NEW.namespace)::text || ':' || NEW.namespace,
|
|
20
|
+
0
|
|
21
|
+
));
|
|
22
|
+
assigned_commit_seq := nextval('bunqueue_event_commit_seq');
|
|
23
|
+
|
|
24
|
+
UPDATE bunqueue_event_commits
|
|
25
|
+
SET commit_seq = assigned_commit_seq
|
|
26
|
+
WHERE namespace = NEW.namespace
|
|
27
|
+
AND transaction_id = NEW.transaction_id
|
|
28
|
+
AND commit_seq IS NULL;
|
|
29
|
+
UPDATE bunqueue_event_prune_watermarks
|
|
30
|
+
SET commit_seq = assigned_commit_seq,
|
|
31
|
+
pruned_commit_seq = CASE
|
|
32
|
+
WHEN prunes_current_transaction THEN GREATEST(
|
|
33
|
+
COALESCE(pruned_commit_seq, 0), assigned_commit_seq
|
|
34
|
+
)
|
|
35
|
+
ELSE pruned_commit_seq
|
|
36
|
+
END,
|
|
37
|
+
prunes_current_transaction = FALSE
|
|
38
|
+
WHERE namespace = NEW.namespace
|
|
39
|
+
AND transaction_id = NEW.transaction_id
|
|
40
|
+
AND commit_seq IS NULL;
|
|
41
|
+
RETURN NULL;
|
|
42
|
+
END;`;
|
|
43
|
+
/** Commit-time journal sequencer installed by the PostgreSQL schema migration. */
|
|
44
|
+
export const POSTGRES_EVENT_JOURNAL_SCHEMA = `
|
|
45
|
+
CREATE SEQUENCE IF NOT EXISTS bunqueue_event_commit_seq AS BIGINT CACHE 1;
|
|
46
|
+
ALTER SEQUENCE bunqueue_event_commit_seq
|
|
47
|
+
AS BIGINT INCREMENT BY 1 NO MINVALUE NO MAXVALUE NO CYCLE CACHE 1;
|
|
48
|
+
|
|
49
|
+
CREATE TABLE IF NOT EXISTS bunqueue_event_commits (
|
|
50
|
+
namespace TEXT NOT NULL,
|
|
51
|
+
transaction_id BIGINT NOT NULL,
|
|
52
|
+
commit_seq BIGINT,
|
|
53
|
+
PRIMARY KEY (namespace, transaction_id)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
ALTER TABLE bunqueue_event_commits
|
|
57
|
+
ADD COLUMN IF NOT EXISTS namespace TEXT;
|
|
58
|
+
ALTER TABLE bunqueue_event_commits
|
|
59
|
+
ADD COLUMN IF NOT EXISTS transaction_id BIGINT;
|
|
60
|
+
ALTER TABLE bunqueue_event_commits
|
|
61
|
+
ADD COLUMN IF NOT EXISTS commit_seq BIGINT;
|
|
62
|
+
ALTER TABLE bunqueue_event_commits
|
|
63
|
+
ALTER COLUMN namespace TYPE TEXT USING namespace::text,
|
|
64
|
+
ALTER COLUMN transaction_id TYPE BIGINT USING transaction_id::bigint,
|
|
65
|
+
ALTER COLUMN commit_seq TYPE BIGINT USING commit_seq::bigint;
|
|
66
|
+
|
|
67
|
+
ALTER TABLE bunqueue_events
|
|
68
|
+
ADD COLUMN IF NOT EXISTS transaction_id BIGINT;
|
|
69
|
+
ALTER TABLE bunqueue_events
|
|
70
|
+
ALTER COLUMN transaction_id DROP DEFAULT;
|
|
71
|
+
ALTER TABLE bunqueue_events
|
|
72
|
+
ALTER COLUMN transaction_id TYPE BIGINT USING transaction_id::bigint;
|
|
73
|
+
ALTER TABLE bunqueue_events
|
|
74
|
+
ALTER COLUMN transaction_id SET DEFAULT (pg_current_xact_id()::text::bigint);
|
|
75
|
+
|
|
76
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
77
|
+
ADD COLUMN IF NOT EXISTS transaction_id BIGINT;
|
|
78
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
79
|
+
ADD COLUMN IF NOT EXISTS commit_seq BIGINT;
|
|
80
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
81
|
+
ADD COLUMN IF NOT EXISTS pruned_commit_seq BIGINT;
|
|
82
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
83
|
+
ADD COLUMN IF NOT EXISTS prunes_current_transaction BOOLEAN NOT NULL DEFAULT FALSE;
|
|
84
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
85
|
+
ALTER COLUMN transaction_id DROP DEFAULT,
|
|
86
|
+
ALTER COLUMN pruned_commit_seq DROP DEFAULT,
|
|
87
|
+
ALTER COLUMN prunes_current_transaction DROP DEFAULT;
|
|
88
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
89
|
+
ALTER COLUMN transaction_id TYPE BIGINT USING transaction_id::bigint,
|
|
90
|
+
ALTER COLUMN commit_seq TYPE BIGINT USING commit_seq::bigint,
|
|
91
|
+
ALTER COLUMN pruned_commit_seq TYPE BIGINT USING pruned_commit_seq::bigint,
|
|
92
|
+
ALTER COLUMN prunes_current_transaction TYPE BOOLEAN
|
|
93
|
+
USING prunes_current_transaction::boolean;
|
|
94
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
95
|
+
ALTER COLUMN transaction_id SET DEFAULT (pg_current_xact_id()::text::bigint);
|
|
96
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
97
|
+
ALTER COLUMN pruned_commit_seq SET DEFAULT 0,
|
|
98
|
+
ALTER COLUMN prunes_current_transaction SET DEFAULT FALSE;
|
|
99
|
+
|
|
100
|
+
UPDATE bunqueue_events
|
|
101
|
+
SET transaction_id = -id
|
|
102
|
+
WHERE transaction_id IS NULL;
|
|
103
|
+
UPDATE bunqueue_event_prune_watermarks
|
|
104
|
+
SET transaction_id = COALESCE(transaction_id, -source_event_id),
|
|
105
|
+
commit_seq = COALESCE(commit_seq, source_event_id),
|
|
106
|
+
pruned_commit_seq = COALESCE(pruned_commit_seq, commit_seq, source_event_id)
|
|
107
|
+
WHERE transaction_id IS NULL OR commit_seq IS NULL OR pruned_commit_seq IS NULL;
|
|
108
|
+
|
|
109
|
+
ALTER TABLE bunqueue_events
|
|
110
|
+
ALTER COLUMN transaction_id SET NOT NULL;
|
|
111
|
+
ALTER TABLE bunqueue_event_commits
|
|
112
|
+
ALTER COLUMN namespace SET NOT NULL,
|
|
113
|
+
ALTER COLUMN transaction_id SET NOT NULL;
|
|
114
|
+
ALTER TABLE bunqueue_event_prune_watermarks
|
|
115
|
+
ALTER COLUMN transaction_id SET NOT NULL,
|
|
116
|
+
ALTER COLUMN pruned_commit_seq SET NOT NULL,
|
|
117
|
+
ALTER COLUMN prunes_current_transaction SET NOT NULL;
|
|
118
|
+
|
|
119
|
+
DO $migration$
|
|
120
|
+
BEGIN
|
|
121
|
+
IF EXISTS (
|
|
122
|
+
SELECT 1 FROM pg_attribute
|
|
123
|
+
WHERE attrelid = to_regclass('bunqueue_events')
|
|
124
|
+
AND attname = 'commit_seq' AND NOT attisdropped
|
|
125
|
+
) THEN
|
|
126
|
+
EXECUTE $sql$
|
|
127
|
+
INSERT INTO bunqueue_event_commits (namespace, transaction_id, commit_seq)
|
|
128
|
+
SELECT namespace, transaction_id, MAX(commit_seq)
|
|
129
|
+
FROM bunqueue_events
|
|
130
|
+
WHERE commit_seq IS NOT NULL
|
|
131
|
+
GROUP BY namespace, transaction_id
|
|
132
|
+
ON CONFLICT (namespace, transaction_id) DO UPDATE SET
|
|
133
|
+
commit_seq = GREATEST(
|
|
134
|
+
COALESCE(bunqueue_event_commits.commit_seq, 0),
|
|
135
|
+
excluded.commit_seq
|
|
136
|
+
)
|
|
137
|
+
$sql$;
|
|
138
|
+
ELSE
|
|
139
|
+
INSERT INTO bunqueue_event_commits (namespace, transaction_id, commit_seq)
|
|
140
|
+
SELECT namespace, transaction_id, MAX(id)
|
|
141
|
+
FROM bunqueue_events
|
|
142
|
+
GROUP BY namespace, transaction_id
|
|
143
|
+
ON CONFLICT (namespace, transaction_id) DO NOTHING;
|
|
144
|
+
END IF;
|
|
145
|
+
END;
|
|
146
|
+
$migration$;
|
|
147
|
+
|
|
148
|
+
INSERT INTO bunqueue_event_commits (namespace, transaction_id, commit_seq)
|
|
149
|
+
SELECT namespace, transaction_id, MAX(commit_seq)
|
|
150
|
+
FROM bunqueue_event_prune_watermarks
|
|
151
|
+
WHERE commit_seq IS NOT NULL
|
|
152
|
+
GROUP BY namespace, transaction_id
|
|
153
|
+
ON CONFLICT (namespace, transaction_id) DO UPDATE SET
|
|
154
|
+
commit_seq = GREATEST(
|
|
155
|
+
COALESCE(bunqueue_event_commits.commit_seq, 0),
|
|
156
|
+
excluded.commit_seq
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
DO $block$
|
|
160
|
+
DECLARE
|
|
161
|
+
journal_floor BIGINT := 0;
|
|
162
|
+
legacy_head_floor BIGINT := 0;
|
|
163
|
+
sequence_floor BIGINT := 0;
|
|
164
|
+
BEGIN
|
|
165
|
+
SELECT COALESCE(MAX(commit_seq), 0) INTO journal_floor
|
|
166
|
+
FROM bunqueue_event_commits;
|
|
167
|
+
SELECT last_value INTO sequence_floor FROM bunqueue_event_commit_seq;
|
|
168
|
+
IF to_regclass('bunqueue_event_commit_heads') IS NOT NULL THEN
|
|
169
|
+
EXECUTE 'SELECT COALESCE(MAX(commit_seq), 0) FROM bunqueue_event_commit_heads'
|
|
170
|
+
INTO legacy_head_floor;
|
|
171
|
+
END IF;
|
|
172
|
+
PERFORM setval(
|
|
173
|
+
'bunqueue_event_commit_seq',
|
|
174
|
+
GREATEST(journal_floor, legacy_head_floor, sequence_floor, 1),
|
|
175
|
+
TRUE
|
|
176
|
+
);
|
|
177
|
+
END;
|
|
178
|
+
$block$;
|
|
179
|
+
|
|
180
|
+
DROP TABLE IF EXISTS bunqueue_event_commit_heads;
|
|
181
|
+
|
|
182
|
+
DROP TRIGGER IF EXISTS bunqueue_events_register_commit ON bunqueue_events;
|
|
183
|
+
DROP TRIGGER IF EXISTS bunqueue_watermarks_insert_register_commit
|
|
184
|
+
ON bunqueue_event_prune_watermarks;
|
|
185
|
+
DROP TRIGGER IF EXISTS bunqueue_watermarks_update_register_commit
|
|
186
|
+
ON bunqueue_event_prune_watermarks;
|
|
187
|
+
DROP TABLE IF EXISTS bunqueue_event_commit_assignments CASCADE;
|
|
188
|
+
DROP INDEX IF EXISTS bunqueue_events_commit_idx;
|
|
189
|
+
DROP INDEX IF EXISTS bunqueue_events_pending_commit_idx;
|
|
190
|
+
ALTER TABLE bunqueue_events DROP COLUMN IF EXISTS commit_seq;
|
|
191
|
+
|
|
192
|
+
DROP INDEX IF EXISTS bunqueue_events_transaction_idx;
|
|
193
|
+
DROP INDEX IF EXISTS bunqueue_event_commits_replay_idx;
|
|
194
|
+
DROP INDEX IF EXISTS bunqueue_event_prune_watermarks_commit_idx;
|
|
195
|
+
DROP INDEX IF EXISTS bunqueue_event_prune_watermarks_pending_commit_idx;
|
|
196
|
+
DROP INDEX IF EXISTS bunqueue_event_prune_watermarks_transaction_idx;
|
|
197
|
+
|
|
198
|
+
CREATE INDEX bunqueue_events_transaction_idx
|
|
199
|
+
ON bunqueue_events(namespace, transaction_id, id);
|
|
200
|
+
CREATE INDEX bunqueue_event_commits_replay_idx
|
|
201
|
+
ON bunqueue_event_commits(namespace, commit_seq, transaction_id)
|
|
202
|
+
WHERE commit_seq IS NOT NULL;
|
|
203
|
+
CREATE INDEX bunqueue_event_prune_watermarks_commit_idx
|
|
204
|
+
ON bunqueue_event_prune_watermarks(namespace, queue, commit_seq DESC)
|
|
205
|
+
WHERE commit_seq IS NOT NULL;
|
|
206
|
+
CREATE INDEX bunqueue_event_prune_watermarks_pending_commit_idx
|
|
207
|
+
ON bunqueue_event_prune_watermarks(namespace, transaction_id)
|
|
208
|
+
WHERE commit_seq IS NULL;
|
|
209
|
+
CREATE INDEX bunqueue_event_prune_watermarks_transaction_idx
|
|
210
|
+
ON bunqueue_event_prune_watermarks(namespace, transaction_id);
|
|
211
|
+
|
|
212
|
+
CREATE OR REPLACE FUNCTION bunqueue_register_event_rows()
|
|
213
|
+
RETURNS TRIGGER LANGUAGE plpgsql AS $function$
|
|
214
|
+
${POSTGRES_REGISTER_EVENT_ROWS_BODY}
|
|
215
|
+
$function$;
|
|
216
|
+
|
|
217
|
+
CREATE OR REPLACE FUNCTION bunqueue_register_watermark_rows()
|
|
218
|
+
RETURNS TRIGGER LANGUAGE plpgsql AS $function$
|
|
219
|
+
${POSTGRES_REGISTER_WATERMARK_ROWS_BODY}
|
|
220
|
+
$function$;
|
|
221
|
+
|
|
222
|
+
CREATE OR REPLACE FUNCTION bunqueue_assign_event_commit()
|
|
223
|
+
RETURNS TRIGGER LANGUAGE plpgsql AS $function$
|
|
224
|
+
${POSTGRES_ASSIGN_EVENT_COMMIT_BODY}
|
|
225
|
+
$function$;
|
|
226
|
+
|
|
227
|
+
DROP TRIGGER IF EXISTS bunqueue_events_register_commit ON bunqueue_events;
|
|
228
|
+
CREATE TRIGGER bunqueue_events_register_commit
|
|
229
|
+
AFTER INSERT ON bunqueue_events
|
|
230
|
+
REFERENCING NEW TABLE AS new_event_rows
|
|
231
|
+
FOR EACH STATEMENT EXECUTE FUNCTION bunqueue_register_event_rows();
|
|
232
|
+
|
|
233
|
+
DROP TRIGGER IF EXISTS bunqueue_watermarks_insert_register_commit
|
|
234
|
+
ON bunqueue_event_prune_watermarks;
|
|
235
|
+
CREATE TRIGGER bunqueue_watermarks_insert_register_commit
|
|
236
|
+
AFTER INSERT ON bunqueue_event_prune_watermarks
|
|
237
|
+
REFERENCING NEW TABLE AS new_watermark_rows
|
|
238
|
+
FOR EACH STATEMENT EXECUTE FUNCTION bunqueue_register_watermark_rows();
|
|
239
|
+
|
|
240
|
+
DROP TRIGGER IF EXISTS bunqueue_watermarks_update_register_commit
|
|
241
|
+
ON bunqueue_event_prune_watermarks;
|
|
242
|
+
CREATE TRIGGER bunqueue_watermarks_update_register_commit
|
|
243
|
+
AFTER UPDATE ON bunqueue_event_prune_watermarks
|
|
244
|
+
REFERENCING NEW TABLE AS new_watermark_rows
|
|
245
|
+
FOR EACH STATEMENT EXECUTE FUNCTION bunqueue_register_watermark_rows();
|
|
246
|
+
|
|
247
|
+
DROP TRIGGER IF EXISTS bunqueue_assign_event_commit
|
|
248
|
+
ON bunqueue_event_commits;
|
|
249
|
+
CREATE CONSTRAINT TRIGGER bunqueue_assign_event_commit
|
|
250
|
+
AFTER INSERT ON bunqueue_event_commits
|
|
251
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
252
|
+
FOR EACH ROW EXECUTE FUNCTION bunqueue_assign_event_commit();
|
|
253
|
+
`;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TransactionSQL } from 'bun';
|
|
2
|
+
import type { PostgresContext } from './context';
|
|
3
|
+
export interface PostgresEventPruneWatermarkInput {
|
|
4
|
+
readonly queue: string;
|
|
5
|
+
readonly sourceEventId: number;
|
|
6
|
+
readonly prunedThrough: number;
|
|
7
|
+
readonly prunedCommitSeq?: number;
|
|
8
|
+
readonly prunesCurrentTransaction?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface PostgresEventPruneWatermark extends PostgresEventPruneWatermarkInput {
|
|
11
|
+
readonly commitSeq: number;
|
|
12
|
+
readonly prunedCommitSeq: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function maxPostgresEventId(rows: readonly {
|
|
15
|
+
id: number | string | bigint;
|
|
16
|
+
}[]): number;
|
|
17
|
+
export declare function summarizePostgresPrunedEvents(rows: readonly {
|
|
18
|
+
id: number | string | bigint;
|
|
19
|
+
commit_seq: number | string | bigint | null;
|
|
20
|
+
}[]): Pick<PostgresEventPruneWatermarkInput, 'prunedThrough' | 'prunedCommitSeq' | 'prunesCurrentTransaction'>;
|
|
21
|
+
/** Record durable evidence that queue event history was pruned in this transaction. */
|
|
22
|
+
export declare function recordPostgresEventPruneWatermarks(tx: TransactionSQL, ctx: PostgresContext, inputs: readonly PostgresEventPruneWatermarkInput[]): Promise<void>;
|
|
23
|
+
export declare function loadPostgresEventPruneWatermarks(ctx: PostgresContext): Promise<PostgresEventPruneWatermark[]>;
|
|
24
|
+
export declare function deletePostgresEventPruneWatermark(tx: TransactionSQL, ctx: PostgresContext, queue: string): Promise<void>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { numeric } from './codec';
|
|
2
|
+
export function maxPostgresEventId(rows) {
|
|
3
|
+
return rows.reduce((latest, row) => Math.max(latest, numeric(row.id) ?? 0), 0);
|
|
4
|
+
}
|
|
5
|
+
export function summarizePostgresPrunedEvents(rows) {
|
|
6
|
+
return {
|
|
7
|
+
prunedThrough: maxPostgresEventId(rows),
|
|
8
|
+
prunedCommitSeq: rows.reduce((latest, row) => Math.max(latest, numeric(row.commit_seq) ?? 0), 0),
|
|
9
|
+
prunesCurrentTransaction: rows.some((row) => row.commit_seq === null),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function normalize(watermarks) {
|
|
13
|
+
const byQueue = new Map();
|
|
14
|
+
for (const watermark of watermarks) {
|
|
15
|
+
const current = byQueue.get(watermark.queue);
|
|
16
|
+
byQueue.set(watermark.queue, current
|
|
17
|
+
? {
|
|
18
|
+
queue: watermark.queue,
|
|
19
|
+
sourceEventId: Math.max(current.sourceEventId, watermark.sourceEventId),
|
|
20
|
+
prunedThrough: Math.max(current.prunedThrough, watermark.prunedThrough),
|
|
21
|
+
prunedCommitSeq: Math.max(current.prunedCommitSeq ?? 0, watermark.prunedCommitSeq ?? 0),
|
|
22
|
+
prunesCurrentTransaction: current.prunesCurrentTransaction === true ||
|
|
23
|
+
watermark.prunesCurrentTransaction === true,
|
|
24
|
+
}
|
|
25
|
+
: watermark);
|
|
26
|
+
}
|
|
27
|
+
return [...byQueue.values()].sort((left, right) => left.queue.localeCompare(right.queue));
|
|
28
|
+
}
|
|
29
|
+
/** Record durable evidence that queue event history was pruned in this transaction. */
|
|
30
|
+
export async function recordPostgresEventPruneWatermarks(tx, ctx, inputs) {
|
|
31
|
+
const watermarks = normalize(inputs).filter(({ sourceEventId, prunedThrough }) => sourceEventId > 0 && prunedThrough > 0);
|
|
32
|
+
if (watermarks.length === 0)
|
|
33
|
+
return;
|
|
34
|
+
await tx `
|
|
35
|
+
WITH incoming AS (
|
|
36
|
+
SELECT batch.queue, batch.source_event_id, batch.pruned_through,
|
|
37
|
+
batch.pruned_commit_seq, batch.prunes_current_transaction
|
|
38
|
+
FROM unnest(
|
|
39
|
+
${tx.array(watermarks.map(({ queue }) => queue), 'TEXT')},
|
|
40
|
+
${tx.array(watermarks.map(({ sourceEventId }) => sourceEventId), 'BIGINT')},
|
|
41
|
+
${tx.array(watermarks.map(({ prunedThrough }) => prunedThrough), 'BIGINT')},
|
|
42
|
+
${tx.array(watermarks.map(({ prunedCommitSeq }) => prunedCommitSeq ?? 0), 'BIGINT')},
|
|
43
|
+
${tx.array(watermarks.map(({ prunesCurrentTransaction }) => prunesCurrentTransaction ?? false), 'BOOLEAN')}
|
|
44
|
+
) AS batch(
|
|
45
|
+
queue, source_event_id, pruned_through, pruned_commit_seq,
|
|
46
|
+
prunes_current_transaction
|
|
47
|
+
)
|
|
48
|
+
), inserted AS (
|
|
49
|
+
INSERT INTO bunqueue_event_prune_watermarks
|
|
50
|
+
(namespace, queue, source_event_id, pruned_through, pruned_commit_seq,
|
|
51
|
+
prunes_current_transaction)
|
|
52
|
+
SELECT ${ctx.config.namespace}, queue, source_event_id, pruned_through,
|
|
53
|
+
GREATEST(
|
|
54
|
+
pruned_commit_seq,
|
|
55
|
+
COALESCE((
|
|
56
|
+
SELECT MAX(existing.pruned_commit_seq)
|
|
57
|
+
FROM bunqueue_event_prune_watermarks AS existing
|
|
58
|
+
WHERE existing.namespace = ${ctx.config.namespace}
|
|
59
|
+
AND existing.queue = incoming.queue
|
|
60
|
+
), 0)
|
|
61
|
+
),
|
|
62
|
+
prunes_current_transaction
|
|
63
|
+
FROM incoming
|
|
64
|
+
ON CONFLICT (namespace, queue, source_event_id) DO UPDATE SET
|
|
65
|
+
pruned_through = GREATEST(
|
|
66
|
+
bunqueue_event_prune_watermarks.pruned_through,
|
|
67
|
+
excluded.pruned_through
|
|
68
|
+
),
|
|
69
|
+
pruned_commit_seq = GREATEST(
|
|
70
|
+
COALESCE(bunqueue_event_prune_watermarks.pruned_commit_seq, 0),
|
|
71
|
+
COALESCE(excluded.pruned_commit_seq, 0)
|
|
72
|
+
),
|
|
73
|
+
prunes_current_transaction =
|
|
74
|
+
bunqueue_event_prune_watermarks.prunes_current_transaction
|
|
75
|
+
OR excluded.prunes_current_transaction,
|
|
76
|
+
transaction_id = pg_current_xact_id()::text::bigint,
|
|
77
|
+
commit_seq = NULL
|
|
78
|
+
RETURNING namespace, queue, source_event_id, pruned_through
|
|
79
|
+
)
|
|
80
|
+
DELETE FROM bunqueue_event_prune_watermarks AS previous
|
|
81
|
+
USING inserted AS latest
|
|
82
|
+
WHERE previous.namespace = latest.namespace
|
|
83
|
+
AND previous.queue = latest.queue
|
|
84
|
+
AND previous.source_event_id <> latest.source_event_id
|
|
85
|
+
AND previous.pruned_through <= latest.pruned_through
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
export async function loadPostgresEventPruneWatermarks(ctx) {
|
|
89
|
+
const rows = await ctx.sql `
|
|
90
|
+
SELECT DISTINCT ON (queue)
|
|
91
|
+
queue, source_event_id, pruned_through, commit_seq,
|
|
92
|
+
MAX(pruned_commit_seq) OVER (PARTITION BY queue) AS pruned_commit_seq
|
|
93
|
+
FROM bunqueue_event_prune_watermarks
|
|
94
|
+
WHERE namespace = ${ctx.config.namespace}
|
|
95
|
+
AND commit_seq IS NOT NULL
|
|
96
|
+
ORDER BY queue, commit_seq DESC, source_event_id DESC
|
|
97
|
+
`;
|
|
98
|
+
return rows.map((row) => ({
|
|
99
|
+
queue: row.queue,
|
|
100
|
+
sourceEventId: numeric(row.source_event_id) ?? 0,
|
|
101
|
+
prunedThrough: numeric(row.pruned_through) ?? 0,
|
|
102
|
+
commitSeq: numeric(row.commit_seq) ?? 0,
|
|
103
|
+
prunedCommitSeq: numeric(row.pruned_commit_seq) ?? 0,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
export async function deletePostgresEventPruneWatermark(tx, ctx, queue) {
|
|
107
|
+
await tx `
|
|
108
|
+
DELETE FROM bunqueue_event_prune_watermarks
|
|
109
|
+
WHERE namespace = ${ctx.config.namespace} AND queue = ${queue}
|
|
110
|
+
`;
|
|
111
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TransactionSQL } from 'bun';
|
|
2
|
+
import type { PostgresContext } from './context';
|
|
3
|
+
export interface PostgresPrunedEventRow {
|
|
4
|
+
readonly id: number | string | bigint;
|
|
5
|
+
readonly commit_seq: number | string | bigint | null;
|
|
6
|
+
}
|
|
7
|
+
/** Serialize one autonomous queue-retention sweep without joining job lock domains. */
|
|
8
|
+
export declare function lockPostgresEventRetention(tx: TransactionSQL, ctx: PostgresContext, queue: string): Promise<void>;
|
|
9
|
+
/** Never wait for a late inline retention lock after job locks are already held. */
|
|
10
|
+
export declare function tryLockPostgresEventRetention(tx: TransactionSQL, ctx: PostgresContext, queue: string): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Retain the newest queue events while locking overlapping prune candidates in
|
|
13
|
+
* one deterministic order. The materialized lock step prevents concurrent
|
|
14
|
+
* brokers from deleting the same physical tuples in conflicting scan orders.
|
|
15
|
+
*/
|
|
16
|
+
export declare function prunePostgresQueueEvents(tx: TransactionSQL, ctx: PostgresContext, queue: string, maxLength: number): Promise<PostgresPrunedEventRow[]>;
|
|
17
|
+
/** Remove a queue's old outbox history in the same tuple order used by retention. */
|
|
18
|
+
export declare function deletePostgresQueueEventHistory(tx: TransactionSQL, ctx: PostgresContext, queue: string): Promise<number>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { postgresAdvisoryLockName } from './advisoryLocks';
|
|
2
|
+
/** Serialize one autonomous queue-retention sweep without joining job lock domains. */
|
|
3
|
+
export async function lockPostgresEventRetention(tx, ctx, queue) {
|
|
4
|
+
const lockName = postgresAdvisoryLockName('event-retention', ctx.config.namespace, queue);
|
|
5
|
+
await tx `
|
|
6
|
+
SELECT pg_advisory_xact_lock(hashtextextended(${lockName}, 0))
|
|
7
|
+
`;
|
|
8
|
+
}
|
|
9
|
+
/** Never wait for a late inline retention lock after job locks are already held. */
|
|
10
|
+
export async function tryLockPostgresEventRetention(tx, ctx, queue) {
|
|
11
|
+
const lockName = postgresAdvisoryLockName('event-retention', ctx.config.namespace, queue);
|
|
12
|
+
const [row] = await tx `
|
|
13
|
+
SELECT pg_try_advisory_xact_lock(hashtextextended(${lockName}, 0)) AS acquired
|
|
14
|
+
`;
|
|
15
|
+
return row.acquired;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retain the newest queue events while locking overlapping prune candidates in
|
|
19
|
+
* one deterministic order. The materialized lock step prevents concurrent
|
|
20
|
+
* brokers from deleting the same physical tuples in conflicting scan orders.
|
|
21
|
+
*/
|
|
22
|
+
export async function prunePostgresQueueEvents(tx, ctx, queue, maxLength) {
|
|
23
|
+
return await tx `
|
|
24
|
+
WITH cutoff AS MATERIALIZED (
|
|
25
|
+
SELECT id
|
|
26
|
+
FROM bunqueue_events
|
|
27
|
+
WHERE namespace = ${ctx.config.namespace} AND queue = ${queue}
|
|
28
|
+
ORDER BY id DESC
|
|
29
|
+
OFFSET ${maxLength}
|
|
30
|
+
LIMIT 1
|
|
31
|
+
), candidates AS MATERIALIZED (
|
|
32
|
+
SELECT event.id
|
|
33
|
+
FROM bunqueue_events AS event
|
|
34
|
+
CROSS JOIN cutoff
|
|
35
|
+
WHERE event.namespace = ${ctx.config.namespace} AND event.queue = ${queue}
|
|
36
|
+
AND event.id <= cutoff.id
|
|
37
|
+
ORDER BY event.id
|
|
38
|
+
FOR UPDATE OF event
|
|
39
|
+
), removed AS (
|
|
40
|
+
DELETE FROM bunqueue_events AS event
|
|
41
|
+
USING candidates
|
|
42
|
+
WHERE event.id = candidates.id
|
|
43
|
+
RETURNING event.id, event.namespace, event.transaction_id
|
|
44
|
+
)
|
|
45
|
+
SELECT removed.id, journal.commit_seq
|
|
46
|
+
FROM removed
|
|
47
|
+
LEFT JOIN bunqueue_event_commits AS journal
|
|
48
|
+
ON journal.namespace = removed.namespace
|
|
49
|
+
AND journal.transaction_id = removed.transaction_id
|
|
50
|
+
ORDER BY removed.id
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
/** Remove a queue's old outbox history in the same tuple order used by retention. */
|
|
54
|
+
export async function deletePostgresQueueEventHistory(tx, ctx, queue) {
|
|
55
|
+
const removed = await tx `
|
|
56
|
+
WITH candidates AS MATERIALIZED (
|
|
57
|
+
SELECT event.id
|
|
58
|
+
FROM bunqueue_events AS event
|
|
59
|
+
WHERE event.namespace = ${ctx.config.namespace}
|
|
60
|
+
AND (
|
|
61
|
+
event.queue = ${queue}
|
|
62
|
+
OR (
|
|
63
|
+
event.event_type = 'queue-batch-overflow'
|
|
64
|
+
AND event.job_id = ${`__queue__:${queue}`}
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
ORDER BY event.id
|
|
68
|
+
FOR UPDATE OF event
|
|
69
|
+
)
|
|
70
|
+
DELETE FROM bunqueue_events AS event
|
|
71
|
+
USING candidates
|
|
72
|
+
WHERE event.id = candidates.id
|
|
73
|
+
RETURNING event.id
|
|
74
|
+
`;
|
|
75
|
+
return removed.length;
|
|
76
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PostgresContext } from './context';
|
|
2
|
+
import type { PostgresDeliveredStoreEvent } from './types';
|
|
3
|
+
type EventListener = (event: PostgresDeliveredStoreEvent) => void;
|
|
4
|
+
type InvalidationListener = (queue: string) => void;
|
|
5
|
+
type DrainStatusListener = (error: Error | null) => void;
|
|
6
|
+
export declare function postgresEventDrainBatchSize(maxQueueEvents: number): number;
|
|
7
|
+
/** Commit-ordered journal polling with LISTEN/NOTIFY used only as a wakeup hint. */
|
|
8
|
+
export declare class PostgresEventStream {
|
|
9
|
+
private readonly ctx;
|
|
10
|
+
private subscription;
|
|
11
|
+
private pollTimer;
|
|
12
|
+
private readonly listeners;
|
|
13
|
+
private readonly invalidationListeners;
|
|
14
|
+
private readonly drainStatusListeners;
|
|
15
|
+
private readonly waiters;
|
|
16
|
+
private readonly queueEventCursors;
|
|
17
|
+
private readonly retentionQueues;
|
|
18
|
+
private journalCursor;
|
|
19
|
+
private cursor;
|
|
20
|
+
private baselineCursor;
|
|
21
|
+
private checkpointScanRequested;
|
|
22
|
+
private drainRequested;
|
|
23
|
+
private draining;
|
|
24
|
+
private closed;
|
|
25
|
+
constructor(ctx: PostgresContext);
|
|
26
|
+
start(): Promise<void>;
|
|
27
|
+
subscribe(listener: EventListener): () => void;
|
|
28
|
+
subscribeInvalidation(listener: InvalidationListener): () => void;
|
|
29
|
+
subscribeDrainStatus(listener: DrainStatusListener): () => void;
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
wait(queue: string, timeoutMs: number, signal?: AbortSignal): Promise<void>;
|
|
32
|
+
private handleNotification;
|
|
33
|
+
private wake;
|
|
34
|
+
private wakeAll;
|
|
35
|
+
private removeWaiter;
|
|
36
|
+
private drain;
|
|
37
|
+
private drainLoop;
|
|
38
|
+
private convergeEventRetention;
|
|
39
|
+
private applyEvent;
|
|
40
|
+
private invalidateQueue;
|
|
41
|
+
private applyPruneWatermark;
|
|
42
|
+
private scanPruneWatermarks;
|
|
43
|
+
private reportDrainStatus;
|
|
44
|
+
}
|
|
45
|
+
export {};
|