@rotorsoft/act-pg 1.17.0 → 1.18.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/dist/.tsbuildinfo +1 -1
- package/dist/@types/postgres-store.d.ts.map +1 -1
- package/dist/index.cjs +51 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -55
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-store.d.ts","sourceRoot":"","sources":["../../src/postgres-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,SAAS,EACT,KAAK,EAEL,OAAO,EACP,cAAc,EACd,KAAK,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,KAAK,EACL,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,WAAW,EACX,cAAc,EACf,MAAM,gBAAgB,CAAC;AAUxB,OAAO,EAEL,KAAK,UAAU,EAGhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;AA0BpB,KAAK,MAAM,GAAG,QAAQ,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,cAAc,CAAC,EAAE,UAAU,CAAC;CAC7B,CAAC,GACA,EAAE,CAAC,UAAU,CAAC;AAqGhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2GG;AACH,qBAAa,aAAc,YAAW,KAAK;IACzC,OAAO,CAAC,KAAK,CAAC;IACd,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;IACrB,0DAA0D;IAC1D,OAAO,CAAC,IAAI,CAAS;IACrB;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;IAC5C;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,8DAA8D;IAC9D,OAAO,CAAC,cAAc,CAA4B;IAClD;;;;;OAKG;IACH,OAAO,CAAC,eAAe,CAA+C;IACtE;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB,CAAqC;IAClE;;;;;;OAMG;IACH,OAAO,CAAC,eAAe,CAET;IACd;;;;OAIG;IACH,OAAO,CAAC,gBAAgB,CAA4C;IACpE;;;;OAIG;IACH,OAAO,CAAC,mBAAmB,CAAK;IAChC;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,CACP,OAAO,EAAE,CAAC,YAAY,EAAE,iBAAiB,KAAK,IAAI,KAC/C,OAAO,CAAC,cAAc,CAAC,CAAC;IAE7B;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAsC;IAEvE;;;OAGG;IACH,YAAY,MAAM,GAAE,OAAO,CAAC,MAAM,CAAM,EAyBvC;IAED;;;;;;;OAOG;YACW,OAAO;IAQrB;;;;OAIG;IACG,OAAO,kBAGZ;IAED;;;;;;;;;;;;OAYG;YACW,gBAAgB;IAwB9B;;;;OAIG;IACG,IAAI,
|
|
1
|
+
{"version":3,"file":"postgres-store.d.ts","sourceRoot":"","sources":["../../src/postgres-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,SAAS,EACT,KAAK,EAEL,OAAO,EACP,cAAc,EACd,KAAK,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,KAAK,EACL,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,WAA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;;;;;;;;;;;;;;;OA2BG;YACW,wBAAwB;IA2BtC;;;;;;;OAOG;YACW,YAAY;IA2F1B;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU;IAiDlB;;;;;;;;OAQG;IACG,QAAQ,CACZ,OAAO,EAAE,KAAK,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,SAAS,CAAC;QACjB,MAAM,CAAC,EAAE,IAAI,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC,GACD,OAAO,CACR,GAAG,CACD,MAAM,EACN;QACE,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC;QAC7C,MAAM,CAAC,EAAE,IAAI,CAAC;KACf,CACF,CACF,CAkFA;IAED;;;;;;;;;;;OAWG;IACG,OAAO,CACX,MAAM,EAAE,CACN,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,KACpE,OAAO,CAAC,IAAI,CAAC,GACjB,OAAO,CAAC,IAAI,CAAC,CA4Cf;IAED;;;;;;;;;;;;;;;OAeG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMhD;CACF"}
|
package/dist/index.cjs
CHANGED
|
@@ -417,6 +417,11 @@ var PostgresStore = class {
|
|
|
417
417
|
ON ${this._fqs} (lane, priority DESC, at)
|
|
418
418
|
WHERE blocked = false AND at < correlated_at;`
|
|
419
419
|
);
|
|
420
|
+
await client.query(
|
|
421
|
+
`CREATE INDEX IF NOT EXISTS "${this.config.table}_streams_at_ix"
|
|
422
|
+
ON ${this._fqs} (at)
|
|
423
|
+
WHERE blocked = false AND at < correlated_at;`
|
|
424
|
+
);
|
|
420
425
|
await client.query("COMMIT");
|
|
421
426
|
logger.info(
|
|
422
427
|
`Seeded schema "${this.config.schema}" with table "${this.config.table}"`
|
|
@@ -685,67 +690,64 @@ var PostgresStore = class {
|
|
|
685
690
|
-- cost O(subscribed streams) per claim per worker no matter how
|
|
686
691
|
-- little work was pending.
|
|
687
692
|
--
|
|
688
|
-
--
|
|
689
|
-
--
|
|
690
|
-
--
|
|
691
|
-
--
|
|
692
|
-
--
|
|
693
|
-
--
|
|
694
|
-
--
|
|
695
|
-
--
|
|
693
|
+
-- The predicate is repeated in each arm below rather than factored
|
|
694
|
+
-- into a shared CTE, and that repetition is load-bearing (#1510). A
|
|
695
|
+
-- CTE referenced more than once is materialized, so LIMIT 8 was
|
|
696
|
+
-- applied to a fully-built 100,000-row result instead of pushing into
|
|
697
|
+
-- the index: measured at 75.6 ms for a claim that returns 8 rows.
|
|
698
|
+
-- Reading the base table in each arm lets the planner stop after the
|
|
699
|
+
-- limit \u2014 19.9 ms with the existing index, 2.0 ms once the
|
|
700
|
+
-- at-ordered partial index below serves the two watermark arms.
|
|
701
|
+
--
|
|
702
|
+
-- A row with no mark compares unknown and is excluded by SQL's own
|
|
703
|
+
-- rules. That is definitional (#1446): a subscription is claimable iff
|
|
704
|
+
-- a mark says so. seed() marks rows that predate the column.
|
|
705
|
+
--
|
|
706
|
+
-- Priority lanes (ACT-102): higher priority first, then
|
|
707
|
+
-- lagging-watermark order. With everyone at priority=0 the ORDER BY
|
|
708
|
+
-- collapses to plain at ASC, so existing workloads see no change.
|
|
696
709
|
--
|
|
697
|
-
-- The
|
|
698
|
-
--
|
|
699
|
-
--
|
|
700
|
-
--
|
|
701
|
-
--
|
|
702
|
-
--
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
SELECT stream, source, at, priority, lane
|
|
710
|
+
-- The lagging frontier is a UNION of two portions (ACT-1223): the
|
|
711
|
+
-- priority portion takes the first (lagging - fair) slots by
|
|
712
|
+
-- priority DESC, at ASC; a fairness reserve then fills fair more
|
|
713
|
+
-- by pure at ASC (priority ignored), excluding the ones already
|
|
714
|
+
-- chosen, so a default-priority lagging stream is never starved out
|
|
715
|
+
-- by sustained higher-priority load.
|
|
716
|
+
prio AS (
|
|
717
|
+
SELECT stream, source, at, lane, TRUE AS lagging
|
|
706
718
|
FROM ${this._fqs} s
|
|
707
719
|
WHERE s.blocked = false
|
|
708
720
|
AND s.at < s.correlated_at
|
|
709
721
|
${lane_clause}
|
|
710
722
|
AND (s.leased_by IS NULL OR s.leased_until <= NOW())
|
|
711
723
|
AND (s.deferred_at IS NULL OR s.deferred_at <= NOW())
|
|
724
|
+
ORDER BY s.priority DESC, s.at ASC
|
|
725
|
+
LIMIT ($1::int - $5::int)
|
|
726
|
+
),
|
|
727
|
+
fair AS (
|
|
728
|
+
SELECT stream, source, at, lane, TRUE AS lagging
|
|
729
|
+
FROM ${this._fqs} s
|
|
730
|
+
WHERE s.blocked = false
|
|
731
|
+
AND s.at < s.correlated_at
|
|
732
|
+
${lane_clause}
|
|
733
|
+
AND (s.leased_by IS NULL OR s.leased_until <= NOW())
|
|
734
|
+
AND (s.deferred_at IS NULL OR s.deferred_at <= NOW())
|
|
735
|
+
AND s.stream NOT IN (SELECT stream FROM prio)
|
|
736
|
+
ORDER BY s.at ASC
|
|
737
|
+
LIMIT $5
|
|
712
738
|
),
|
|
713
|
-
-- Priority lanes (ACT-102): higher priority first, then
|
|
714
|
-
-- lagging-watermark order. With everyone at priority=0 the
|
|
715
|
-
-- ORDER BY collapses to plain at ASC so existing workloads
|
|
716
|
-
-- see no behavior change.
|
|
717
|
-
--
|
|
718
|
-
-- The lagging frontier is a UNION of two portions (ACT-1223): the
|
|
719
|
-
-- priority-ordered portion takes the first (lagging - fair) slots
|
|
720
|
-
-- by priority DESC, at ASC; a fairness reserve then fills fair more
|
|
721
|
-
-- slots by pure at ASC (priority ignored), excluding the ones
|
|
722
|
-
-- already chosen, so a default-priority lagging stream is never
|
|
723
|
-
-- starved out by sustained higher-priority load. With all
|
|
724
|
-
-- priorities equal both portions order by at, a no-op merge.
|
|
725
739
|
lag AS (
|
|
726
|
-
|
|
727
|
-
SELECT stream, source, at, lane, TRUE AS lagging
|
|
728
|
-
FROM available
|
|
729
|
-
ORDER BY priority DESC, at ASC
|
|
730
|
-
LIMIT ($1::int - $5::int)
|
|
731
|
-
)
|
|
732
|
-
UNION
|
|
733
|
-
(
|
|
734
|
-
SELECT stream, source, at, lane, TRUE AS lagging
|
|
735
|
-
FROM available
|
|
736
|
-
WHERE stream NOT IN (
|
|
737
|
-
SELECT stream FROM available
|
|
738
|
-
ORDER BY priority DESC, at ASC
|
|
739
|
-
LIMIT ($1::int - $5::int)
|
|
740
|
-
)
|
|
741
|
-
ORDER BY at ASC
|
|
742
|
-
LIMIT $5
|
|
743
|
-
)
|
|
740
|
+
SELECT * FROM prio UNION SELECT * FROM fair
|
|
744
741
|
),
|
|
745
742
|
lead AS (
|
|
746
743
|
SELECT stream, source, at, lane, FALSE AS lagging
|
|
747
|
-
FROM
|
|
748
|
-
|
|
744
|
+
FROM ${this._fqs} s
|
|
745
|
+
WHERE s.blocked = false
|
|
746
|
+
AND s.at < s.correlated_at
|
|
747
|
+
${lane_clause}
|
|
748
|
+
AND (s.leased_by IS NULL OR s.leased_until <= NOW())
|
|
749
|
+
AND (s.deferred_at IS NULL OR s.deferred_at <= NOW())
|
|
750
|
+
ORDER BY s.at DESC
|
|
749
751
|
LIMIT $2
|
|
750
752
|
),
|
|
751
753
|
combined AS (
|
|
@@ -1527,12 +1529,6 @@ var PostgresStore = class {
|
|
|
1527
1529
|
this._fqt
|
|
1528
1530
|
]);
|
|
1529
1531
|
const result = /* @__PURE__ */ new Map();
|
|
1530
|
-
const retired = full.filter((t) => t.snapshot === void 0).map((t) => t.stream);
|
|
1531
|
-
if (retired.length) {
|
|
1532
|
-
await client.query(`DELETE FROM ${this._fqs} WHERE stream = ANY($1)`, [
|
|
1533
|
-
retired
|
|
1534
|
-
]);
|
|
1535
|
-
}
|
|
1536
1532
|
for (const { stream, snapshot, meta } of full) {
|
|
1537
1533
|
const { rowCount } = await client.query(
|
|
1538
1534
|
`DELETE FROM ${this._fqt} WHERE stream = $1`,
|