@rotorsoft/act-pg 1.13.18 → 1.14.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 +4 -1
- package/dist/@types/postgres-store.d.ts.map +1 -1
- package/dist/index.cjs +36 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -166,6 +166,8 @@ export declare class PostgresStore implements Store {
|
|
|
166
166
|
readonly config: Config;
|
|
167
167
|
private _fqt;
|
|
168
168
|
private _fqs;
|
|
169
|
+
/** Correlate checkpoint table (#1484) — one row, id 0. */
|
|
170
|
+
private _fqc;
|
|
169
171
|
/**
|
|
170
172
|
* Per-instance writer identifier embedded in every NOTIFY payload. The
|
|
171
173
|
* `notify()` LISTEN handler skips payloads where `by === this._by`,
|
|
@@ -329,9 +331,10 @@ export declare class PostgresStore implements Store {
|
|
|
329
331
|
source?: string;
|
|
330
332
|
priority?: number;
|
|
331
333
|
lane?: string;
|
|
332
|
-
}
|
|
334
|
+
}>, correlated_at?: number): Promise<{
|
|
333
335
|
subscribed: number;
|
|
334
336
|
watermark: number;
|
|
337
|
+
correlated_at: number;
|
|
335
338
|
}>;
|
|
336
339
|
/**
|
|
337
340
|
* Acknowledge and release leases after processing, updating stream positions.
|
|
@@ -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,EACZ,MAAM,gBAAgB,CAAC;AAUxB,OAAO,EA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AK,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
|
@@ -108,6 +108,8 @@ var PostgresStore = class {
|
|
|
108
108
|
config;
|
|
109
109
|
_fqt;
|
|
110
110
|
_fqs;
|
|
111
|
+
/** Correlate checkpoint table (#1484) — one row, id 0. */
|
|
112
|
+
_fqc;
|
|
111
113
|
/**
|
|
112
114
|
* Per-instance writer identifier embedded in every NOTIFY payload. The
|
|
113
115
|
* `notify()` LISTEN handler skips payloads where `by === this._by`,
|
|
@@ -194,6 +196,7 @@ var PostgresStore = class {
|
|
|
194
196
|
this._pool = new Pool({ ...poolConfig, types: scopedTypes });
|
|
195
197
|
this._fqt = `"${this.config.schema}"."${this.config.table}"`;
|
|
196
198
|
this._fqs = `"${this.config.schema}"."${this.config.table}_streams"`;
|
|
199
|
+
this._fqc = `"${this.config.schema}"."${this.config.table}_correlated"`;
|
|
197
200
|
this._channel = notify_channel(this.config.schema, this.config.table);
|
|
198
201
|
if (this.config.notify) {
|
|
199
202
|
this.notify = this._subscribe_notifications.bind(this);
|
|
@@ -330,6 +333,16 @@ var PostgresStore = class {
|
|
|
330
333
|
deferred_at timestamptz
|
|
331
334
|
) TABLESPACE pg_default;`
|
|
332
335
|
);
|
|
336
|
+
await client.query(
|
|
337
|
+
`CREATE TABLE IF NOT EXISTS ${this._fqc} (
|
|
338
|
+
id int PRIMARY KEY DEFAULT 0,
|
|
339
|
+
at bigint NOT NULL DEFAULT -1,
|
|
340
|
+
CONSTRAINT ${this.config.table}_correlated_singleton CHECK (id = 0)
|
|
341
|
+
) TABLESPACE pg_default;`
|
|
342
|
+
);
|
|
343
|
+
await client.query(
|
|
344
|
+
`INSERT INTO ${this._fqc} (id) VALUES (0) ON CONFLICT (id) DO NOTHING;`
|
|
345
|
+
);
|
|
333
346
|
await client.query(
|
|
334
347
|
`ALTER TABLE ${this._fqs}
|
|
335
348
|
ADD COLUMN IF NOT EXISTS priority int NOT NULL DEFAULT 0;`
|
|
@@ -415,7 +428,7 @@ var PostgresStore = class {
|
|
|
415
428
|
WHERE schema_name = '${this.config.schema}'
|
|
416
429
|
) THEN
|
|
417
430
|
EXECUTE 'DROP TABLE IF EXISTS ${this._fqt}';
|
|
418
|
-
EXECUTE 'DROP TABLE IF EXISTS ${this._fqs}';
|
|
431
|
+
EXECUTE 'DROP TABLE IF EXISTS ${this._fqc}, ${this._fqs}';
|
|
419
432
|
IF '${this.config.schema}' <> 'public' THEN
|
|
420
433
|
EXECUTE 'DROP SCHEMA "${this.config.schema}" CASCADE';
|
|
421
434
|
END IF;
|
|
@@ -674,13 +687,16 @@ var PostgresStore = class {
|
|
|
674
687
|
AND (deferred_at IS NULL OR deferred_at <= NOW())
|
|
675
688
|
),
|
|
676
689
|
available AS (
|
|
677
|
-
--
|
|
678
|
-
|
|
679
|
-
|
|
690
|
+
-- Every arm below is watermark-agnostic (#1446): a fresh
|
|
691
|
+
-- subscription sits at -1, and e.id > s.at already answers
|
|
692
|
+
-- correctly there, since the first event has a greater id.
|
|
693
|
+
-- There used to be a fourth arm claiming at < 0 unconditionally,
|
|
694
|
+
-- which handed out an empty lease and a no-op ack for every
|
|
695
|
+
-- subscription with no matching events yet.
|
|
680
696
|
-- Source-less subscription: any non-snapshot event past the
|
|
681
697
|
-- watermark counts, so the id index alone answers it.
|
|
682
698
|
SELECT stream, source, at, priority, lane FROM eligible s
|
|
683
|
-
WHERE s.
|
|
699
|
+
WHERE s.source IS NULL
|
|
684
700
|
AND EXISTS (
|
|
685
701
|
SELECT 1 FROM ${this._fqt} e
|
|
686
702
|
WHERE e.id > s.at AND e.name <> '${import_act.SNAP_EVENT}' LIMIT 1
|
|
@@ -689,7 +705,7 @@ var PostgresStore = class {
|
|
|
689
705
|
-- Literal source (no regex metacharacter): exact equality, so
|
|
690
706
|
-- "s1" never claims "s12", and (stream, id) is usable.
|
|
691
707
|
SELECT stream, source, at, priority, lane FROM eligible s
|
|
692
|
-
WHERE s.
|
|
708
|
+
WHERE s.source IS NOT NULL
|
|
693
709
|
AND s.source !~ '${SOURCE_METACHARACTER_CLASS}'
|
|
694
710
|
AND EXISTS (
|
|
695
711
|
SELECT 1 FROM ${this._fqt} e
|
|
@@ -702,7 +718,7 @@ var PostgresStore = class {
|
|
|
702
718
|
-- it anchors. Unavoidably a scan \u2014 but only for the subscriptions
|
|
703
719
|
-- that actually declare a pattern.
|
|
704
720
|
SELECT stream, source, at, priority, lane FROM eligible s
|
|
705
|
-
WHERE s.
|
|
721
|
+
WHERE s.source IS NOT NULL
|
|
706
722
|
AND s.source ~ '${SOURCE_METACHARACTER_CLASS}'
|
|
707
723
|
AND EXISTS (
|
|
708
724
|
SELECT 1 FROM ${this._fqt} e
|
|
@@ -804,7 +820,7 @@ var PostgresStore = class {
|
|
|
804
820
|
* @param streams - Streams to register with optional source.
|
|
805
821
|
* @returns subscribed count and current max watermark.
|
|
806
822
|
*/
|
|
807
|
-
async subscribe(streams) {
|
|
823
|
+
async subscribe(streams, correlated_at) {
|
|
808
824
|
const client = await this._client("subscribe");
|
|
809
825
|
try {
|
|
810
826
|
await client.query("BEGIN");
|
|
@@ -845,11 +861,21 @@ var PostgresStore = class {
|
|
|
845
861
|
[JSON.stringify(streams)]
|
|
846
862
|
);
|
|
847
863
|
}
|
|
864
|
+
if (correlated_at !== void 0)
|
|
865
|
+
await client.query(
|
|
866
|
+
`UPDATE ${this._fqc} SET at = GREATEST(at, $1::bigint) WHERE id = 0`,
|
|
867
|
+
[correlated_at]
|
|
868
|
+
);
|
|
848
869
|
const { rows } = await client.query(
|
|
849
|
-
`SELECT COALESCE(MAX(at), -1)
|
|
870
|
+
`SELECT (SELECT COALESCE(MAX(at), -1) FROM ${this._fqs}) AS max,
|
|
871
|
+
(SELECT at FROM ${this._fqc} WHERE id = 0) AS correlated_at`
|
|
850
872
|
);
|
|
851
873
|
await client.query("COMMIT");
|
|
852
|
-
return {
|
|
874
|
+
return {
|
|
875
|
+
subscribed,
|
|
876
|
+
watermark: rows[0]?.max ?? -1,
|
|
877
|
+
correlated_at: Number(rows[0]?.correlated_at ?? -1)
|
|
878
|
+
};
|
|
853
879
|
} catch (error) {
|
|
854
880
|
await client.query("ROLLBACK").catch(() => {
|
|
855
881
|
});
|