@nodii/outbox-dispatcher 0.14.0 → 0.14.1
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 +12 -2
- package/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/sql-builders.d.ts +11 -1
- package/dist/sql-builders.d.ts.map +1 -1
- package/dist/sql-builders.js +13 -3
- package/dist/sql-builders.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -157,6 +157,16 @@ when there are more pending tenants than `batchSize`, the ones a pass did not
|
|
|
157
157
|
reach go first on the next, however old the others' rows are. The runner keeps
|
|
158
158
|
that position in memory; a restart starts the rotation again.
|
|
159
159
|
|
|
160
|
+
Rows with the same `occurred_at` (rows written in one transaction always share
|
|
161
|
+
it) go in table order (`ctid`), on both claims and in the unpublished sweep. For
|
|
162
|
+
fresh rows that is the order they were written while they fit on the page
|
|
163
|
+
Postgres is filling. Postgres does not promise it: once vacuum has freed space
|
|
164
|
+
in the table, a later row of the same transaction can land on an earlier page
|
|
165
|
+
and go first. A row whose publish failed is
|
|
166
|
+
the exception: recording the failure rewrites the row, which gives it a new
|
|
167
|
+
`ctid`, so on its retry it can go after rows it was written before. A producer
|
|
168
|
+
that needs strict order within one aggregate opts in to `orderPerAggregate`
|
|
169
|
+
(DEC-0428), which orders by version; this tie-break does not promise it.
|
|
160
170
|
|
|
161
171
|
The claim reads the migration's
|
|
162
172
|
`idx_pending_tenant_<table>` index on `(tenant_id, occurred_at, id) WHERE
|
|
@@ -165,8 +175,8 @@ rows per tenant, so its cost follows the number of pending tenants, not the
|
|
|
165
175
|
backlog. On a large live table, build that index first with
|
|
166
176
|
`buildPendingTenantIndexSql(table)` (`CONCURRENTLY`, outside a transaction).
|
|
167
177
|
|
|
168
|
-
An outbox table without a `tenant_id` column is claimed in plain
|
|
169
|
-
order, and the runner logs one warning; run the library migration to add the
|
|
178
|
+
An outbox table without a `tenant_id` column is claimed in plain
|
|
179
|
+
`occurred_at, ctid` order, and the runner logs one warning; run the library migration to add the
|
|
170
180
|
column. The runner checks again each pass until it finds the column, then
|
|
171
181
|
switches to the round-robin claim without a restart.
|
|
172
182
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "0.14.
|
|
1
|
+
export declare const PACKAGE_VERSION = "0.14.1";
|
|
2
2
|
//# sourceMappingURL=package-version.d.ts.map
|
package/dist/sql-builders.d.ts
CHANGED
|
@@ -15,6 +15,15 @@ export declare function quoteIdent(name: string): string;
|
|
|
15
15
|
* of their id, starting after the tenant the last pass ended on, so a pass that
|
|
16
16
|
* cannot reach every tenant leaves them for the next.
|
|
17
17
|
*
|
|
18
|
+
* Ties: rows with the same `occurred_at` (rows written in one transaction
|
|
19
|
+
* always share it) go in table order (`ctid`), on this path and the untenanted
|
|
20
|
+
* one. For fresh rows that is write order while they fit on the page Postgres is
|
|
21
|
+
* filling; once vacuum has freed space, a later row can land on an earlier page
|
|
22
|
+
* and go first. A row whose publish failed is not:
|
|
23
|
+
* recording the failure rewrites the row, so it gets a new `ctid` and can move
|
|
24
|
+
* behind rows it was written before. A producer that needs strict order within
|
|
25
|
+
* one aggregate uses `orderPerAggregate` (DEC-0428), not this tie-break.
|
|
26
|
+
*
|
|
18
27
|
* Cost: the claim lists the tenants that have pending rows with a skip scan
|
|
19
28
|
* of the pending-tenant index (one index probe per tenant), then reads at
|
|
20
29
|
* most `$2` due rows per tenant from that index. A pass costs about T probes
|
|
@@ -23,7 +32,7 @@ export declare function quoteIdent(name: string): string;
|
|
|
23
32
|
* (`buildPendingTenantIndexSql`); without it every probe scans the pending
|
|
24
33
|
* rows.
|
|
25
34
|
*
|
|
26
|
-
* With `opts.untenanted` the claim is the plain `occurred_at` order, for an
|
|
35
|
+
* With `opts.untenanted` the claim is the plain `occurred_at, ctid` order, for an
|
|
27
36
|
* outbox table without a `tenant_id` column, which cannot be ranked by
|
|
28
37
|
* tenant. The runner picks it only after it finds the column missing.
|
|
29
38
|
*
|
|
@@ -92,6 +101,7 @@ export declare function buildRecordFailureSql(outboxTable: string): string;
|
|
|
92
101
|
* to a DLQ — the event stays in the outbox as the source of truth, and liveness
|
|
93
102
|
* is surfaced by this sweep (NOT a `<svc>_outbox_dlq` table, which D401 removed
|
|
94
103
|
* from the publish side). `age_seconds` carries the row's age for the alert.
|
|
104
|
+
* Rows with the same `occurred_at` go in table order (`ctid`), as in the claim.
|
|
95
105
|
*/
|
|
96
106
|
export declare function buildUnpublishedSweepSql(outboxTable: string): string;
|
|
97
107
|
/** Count pending (un-dispatched) rows by topic — `outbox.depth` gauge § 5.6. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-builders.d.ts","sourceRoot":"","sources":["../src/sql-builders.ts"],"names":[],"mappings":"AASA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED
|
|
1
|
+
{"version":3,"file":"sql-builders.d.ts","sourceRoot":"","sources":["../src/sql-builders.ts"],"names":[],"mappings":"AASA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,IAAI,GAAE,eAAoB,GACzB,MAAM,CAsFR;AAED;6CAC6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sEAAsE;IACtE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;oFACgF;IAChF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;4EAI4E;AAC5E,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;;;0CAI0C;AAC1C,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAED,wDAAwD;AACxD,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;;;;;;;;oDAUoD;AACpD,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,IAAI,GAAE;IACJ,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC1B,GACL,MAAM,CAiBR;AAED,+EAA+E;AAC/E,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAGlE;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAOjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CASpE;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAMhE"}
|
package/dist/sql-builders.js
CHANGED
|
@@ -27,6 +27,15 @@ export function quoteIdent(name) {
|
|
|
27
27
|
* of their id, starting after the tenant the last pass ended on, so a pass that
|
|
28
28
|
* cannot reach every tenant leaves them for the next.
|
|
29
29
|
*
|
|
30
|
+
* Ties: rows with the same `occurred_at` (rows written in one transaction
|
|
31
|
+
* always share it) go in table order (`ctid`), on this path and the untenanted
|
|
32
|
+
* one. For fresh rows that is write order while they fit on the page Postgres is
|
|
33
|
+
* filling; once vacuum has freed space, a later row can land on an earlier page
|
|
34
|
+
* and go first. A row whose publish failed is not:
|
|
35
|
+
* recording the failure rewrites the row, so it gets a new `ctid` and can move
|
|
36
|
+
* behind rows it was written before. A producer that needs strict order within
|
|
37
|
+
* one aggregate uses `orderPerAggregate` (DEC-0428), not this tie-break.
|
|
38
|
+
*
|
|
30
39
|
* Cost: the claim lists the tenants that have pending rows with a skip scan
|
|
31
40
|
* of the pending-tenant index (one index probe per tenant), then reads at
|
|
32
41
|
* most `$2` due rows per tenant from that index. A pass costs about T probes
|
|
@@ -35,7 +44,7 @@ export function quoteIdent(name) {
|
|
|
35
44
|
* (`buildPendingTenantIndexSql`); without it every probe scans the pending
|
|
36
45
|
* rows.
|
|
37
46
|
*
|
|
38
|
-
* With `opts.untenanted` the claim is the plain `occurred_at` order, for an
|
|
47
|
+
* With `opts.untenanted` the claim is the plain `occurred_at, ctid` order, for an
|
|
39
48
|
* outbox table without a `tenant_id` column, which cannot be ranked by
|
|
40
49
|
* tenant. The runner picks it only after it finds the column missing.
|
|
41
50
|
*
|
|
@@ -75,7 +84,7 @@ export function buildClaimBatchSql(outboxTable, opts = {}) {
|
|
|
75
84
|
return `${columns}, '' AS tenant_cursor
|
|
76
85
|
FROM ${t}
|
|
77
86
|
WHERE ${due}
|
|
78
|
-
ORDER BY occurred_at ASC
|
|
87
|
+
ORDER BY occurred_at ASC, ctid ASC
|
|
79
88
|
LIMIT $2
|
|
80
89
|
FOR UPDATE SKIP LOCKED`;
|
|
81
90
|
}
|
|
@@ -208,6 +217,7 @@ export function buildRecordFailureSql(outboxTable) {
|
|
|
208
217
|
* to a DLQ — the event stays in the outbox as the source of truth, and liveness
|
|
209
218
|
* is surfaced by this sweep (NOT a `<svc>_outbox_dlq` table, which D401 removed
|
|
210
219
|
* from the publish side). `age_seconds` carries the row's age for the alert.
|
|
220
|
+
* Rows with the same `occurred_at` go in table order (`ctid`), as in the claim.
|
|
211
221
|
*/
|
|
212
222
|
export function buildUnpublishedSweepSql(outboxTable) {
|
|
213
223
|
const t = quoteIdent(outboxTable);
|
|
@@ -216,7 +226,7 @@ export function buildUnpublishedSweepSql(outboxTable) {
|
|
|
216
226
|
FROM ${t}
|
|
217
227
|
WHERE dispatched_at IS NULL
|
|
218
228
|
AND occurred_at < now() - ($1::int * interval '1 second')
|
|
219
|
-
ORDER BY occurred_at ASC
|
|
229
|
+
ORDER BY occurred_at ASC, ctid ASC
|
|
220
230
|
LIMIT $2`;
|
|
221
231
|
}
|
|
222
232
|
/** Count pending (un-dispatched) rows by topic — `outbox.depth` gauge § 5.6. */
|
package/dist/sql-builders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-builders.js","sourceRoot":"","sources":["../src/sql-builders.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,2EAA2E;AAC3E,6DAA6D;AAE7D,MAAM,QAAQ,GAAG,0BAA0B,CAAC;AAE5C,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,IAAI,IAAI,GAAG,CAAC;AACrB,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"sql-builders.js","sourceRoot":"","sources":["../src/sql-builders.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,2EAA2E;AAC3E,6DAA6D;AAE7D,MAAM,QAAQ,GAAG,0BAA0B,CAAC;AAE5C,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,IAAI,IAAI,GAAG,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,kBAAkB,CAChC,WAAmB,EACnB,OAAwB,EAAE;IAE1B,MAAM,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa;QACjC,CAAC,CAAC;;;8CAGwC;QAC1C,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;;SAEA,CAAC;;;;UAIA,CAAC;AACX,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,oBAAoB,CAAC,WAAmB;IACtD,MAAM,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAClC,OAAO;mBACU,CAAC;;uBAEG,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodii/outbox-dispatcher",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Pattern 3 producer-side outbox drainer for the Nodii microservice stack — defineDispatcher + startDispatcher + single-active SET-NX-EX lease (D209) + FOR UPDATE SKIP LOCKED drain + XADD to Redis Streams + currentHwm + 24h-unpublished ops-alert sweep (D401: no publish-side DLQ) + graceful drain + migrate-gen. Symmetric peer of @nodii/replica-consumer (consumer side). Polyglot ship: TS + Python + Go. Spec: planning hub docKey=outbox-dispatcher.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|