@hoshinotatsuya/pg-replica-sync 0.2.2 → 0.3.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/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/dist/compare-lsn.d.mts +3 -3
- package/dist/compare-lsn.d.ts +3 -3
- package/dist/compare-lsn.js +3 -3
- package/dist/constants/exclusion-reason.constant.d.mts +12 -12
- package/dist/constants/exclusion-reason.constant.d.ts +12 -12
- package/dist/constants/exclusion-reason.constant.d.ts.map +1 -1
- package/dist/constants/exclusion-reason.constant.js +12 -12
- package/dist/constants/exclusion-reason.constant.js.map +1 -1
- package/dist/constants/node-role.constant.d.mts +1 -1
- package/dist/constants/node-role.constant.d.ts +1 -1
- package/dist/constants/node-role.constant.d.ts.map +1 -1
- package/dist/constants/node-role.constant.js +1 -1
- package/dist/constants/node-role.constant.js.map +1 -1
- package/dist/constants/probe-sql.constant.d.mts +25 -25
- package/dist/constants/probe-sql.constant.d.ts +25 -25
- package/dist/constants/probe-sql.constant.js +25 -25
- package/dist/constants/replica-sync-defaults.constant.d.mts +26 -26
- package/dist/constants/replica-sync-defaults.constant.d.ts +26 -26
- package/dist/constants/replica-sync-defaults.constant.d.ts.map +1 -1
- package/dist/constants/replica-sync-defaults.constant.js +26 -26
- package/dist/constants/replica-sync-defaults.constant.js.map +1 -1
- package/dist/constants/route-reason.constant.d.mts +13 -13
- package/dist/constants/route-reason.constant.d.ts +13 -13
- package/dist/constants/route-reason.constant.d.ts.map +1 -1
- package/dist/constants/route-reason.constant.js +13 -13
- package/dist/constants/route-reason.constant.js.map +1 -1
- package/dist/constants/token-format.constant.d.mts +11 -11
- package/dist/constants/token-format.constant.d.ts +11 -11
- package/dist/constants/token-format.constant.d.ts.map +1 -1
- package/dist/constants/token-format.constant.js +11 -11
- package/dist/constants/token-format.constant.js.map +1 -1
- package/dist/constants/wal-format.constant.d.mts +6 -6
- package/dist/constants/wal-format.constant.d.ts +6 -6
- package/dist/constants/wal-format.constant.d.ts.map +1 -1
- package/dist/constants/wal-format.constant.js +6 -6
- package/dist/constants/wal-format.constant.js.map +1 -1
- package/dist/decode-canonical-base64url.d.mts +1 -1
- package/dist/decode-canonical-base64url.d.ts +1 -1
- package/dist/decode-canonical-base64url.d.ts.map +1 -1
- package/dist/decode-canonical-base64url.js +1 -1
- package/dist/decode-canonical-base64url.js.map +1 -1
- package/dist/deep-freeze.d.mts +7 -7
- package/dist/deep-freeze.d.ts +7 -7
- package/dist/deep-freeze.js +9 -9
- package/dist/deep-freeze.js.map +1 -1
- package/dist/destroy-client.d.mts +3 -3
- package/dist/destroy-client.d.ts +3 -3
- package/dist/destroy-client.js +3 -3
- package/dist/evaluate-replica.d.mts +3 -3
- package/dist/evaluate-replica.d.ts +3 -3
- package/dist/evaluate-replica.js +3 -3
- package/dist/format-lsn.d.mts +1 -1
- package/dist/format-lsn.d.ts +1 -1
- package/dist/format-lsn.d.ts.map +1 -1
- package/dist/format-lsn.js +2 -2
- package/dist/format-lsn.js.map +1 -1
- package/dist/invalid-lsn.error.d.mts +1 -1
- package/dist/invalid-lsn.error.d.ts +1 -1
- package/dist/invalid-lsn.error.d.ts.map +1 -1
- package/dist/invalid-lsn.error.js +2 -2
- package/dist/invalid-lsn.error.js.map +1 -1
- package/dist/invalid-replica-sync-options.error.d.mts +1 -1
- package/dist/invalid-replica-sync-options.error.d.ts +1 -1
- package/dist/invalid-replica-sync-options.error.d.ts.map +1 -1
- package/dist/invalid-replica-sync-options.error.js +1 -1
- package/dist/invalid-replica-sync-options.error.js.map +1 -1
- package/dist/lag-bytes.d.mts +3 -3
- package/dist/lag-bytes.d.ts +3 -3
- package/dist/lag-bytes.js +3 -3
- package/dist/lsn-or-null.d.mts +1 -1
- package/dist/lsn-or-null.d.ts +1 -1
- package/dist/lsn-or-null.d.ts.map +1 -1
- package/dist/lsn-or-null.js +1 -1
- package/dist/lsn-or-null.js.map +1 -1
- package/dist/notify.d.mts +7 -7
- package/dist/notify.d.ts +7 -7
- package/dist/notify.js +8 -8
- package/dist/notify.js.map +1 -1
- package/dist/parse-lsn.d.mts +3 -3
- package/dist/parse-lsn.d.ts +3 -3
- package/dist/parse-lsn.js +3 -3
- package/dist/probe-connection-closed.error.d.mts +1 -1
- package/dist/probe-connection-closed.error.d.ts +1 -1
- package/dist/probe-connection-closed.error.d.ts.map +1 -1
- package/dist/probe-connection-closed.error.js +2 -2
- package/dist/probe-connection-closed.error.js.map +1 -1
- package/dist/probe-connection.d.mts +20 -20
- package/dist/probe-connection.d.ts +20 -20
- package/dist/probe-connection.d.ts.map +1 -1
- package/dist/probe-connection.js +25 -25
- package/dist/probe-connection.js.map +1 -1
- package/dist/probe-timeout.error.d.mts +1 -1
- package/dist/probe-timeout.error.d.ts +1 -1
- package/dist/probe-timeout.error.d.ts.map +1 -1
- package/dist/probe-timeout.error.js +2 -2
- package/dist/probe-timeout.error.js.map +1 -1
- package/dist/read-node-state.d.mts +3 -3
- package/dist/read-node-state.d.ts +3 -3
- package/dist/read-node-state.js +4 -4
- package/dist/read-node-state.js.map +1 -1
- package/dist/replica-router.d.mts +133 -133
- package/dist/replica-router.d.ts +133 -133
- package/dist/replica-router.d.ts.map +1 -1
- package/dist/replica-router.js +162 -162
- package/dist/replica-router.js.map +1 -1
- package/dist/require-integer.d.mts +1 -1
- package/dist/require-integer.d.ts +1 -1
- package/dist/require-integer.d.ts.map +1 -1
- package/dist/require-integer.js +3 -3
- package/dist/require-integer.js.map +1 -1
- package/dist/secret-weakness.d.mts +13 -13
- package/dist/secret-weakness.d.ts +13 -13
- package/dist/secret-weakness.js +16 -16
- package/dist/secret-weakness.js.map +1 -1
- package/dist/smallest-period.d.mts +4 -4
- package/dist/smallest-period.d.ts +4 -4
- package/dist/smallest-period.js +4 -4
- package/dist/sql-state-of.d.mts +6 -6
- package/dist/sql-state-of.d.ts +6 -6
- package/dist/sql-state-of.js +6 -6
- package/dist/state-cache.d.mts +14 -14
- package/dist/state-cache.d.ts +14 -14
- package/dist/state-cache.d.ts.map +1 -1
- package/dist/state-cache.js +15 -15
- package/dist/state-cache.js.map +1 -1
- package/dist/timeline-of.d.mts +2 -2
- package/dist/timeline-of.d.ts +2 -2
- package/dist/timeline-of.js +2 -2
- package/dist/to-error.d.mts +1 -1
- package/dist/to-error.d.ts +1 -1
- package/dist/to-error.d.ts.map +1 -1
- package/dist/to-error.js +1 -1
- package/dist/to-error.js.map +1 -1
- package/dist/token-codec.d.mts +10 -10
- package/dist/token-codec.d.ts +10 -10
- package/dist/token-codec.js +31 -31
- package/dist/token-codec.js.map +1 -1
- package/dist/token-lsn.d.mts +13 -13
- package/dist/token-lsn.d.ts +13 -13
- package/dist/token-lsn.js +13 -13
- package/dist/transaction-not-committed.error.d.mts +2 -2
- package/dist/transaction-not-committed.error.d.ts +2 -2
- package/dist/transaction-not-committed.error.d.ts.map +1 -1
- package/dist/transaction-not-committed.error.js +3 -3
- package/dist/transaction-not-committed.error.js.map +1 -1
- package/dist/transaction-not-open.error.d.mts +5 -5
- package/dist/transaction-not-open.error.d.ts +5 -5
- package/dist/transaction-not-open.error.js +6 -6
- package/dist/transaction-not-open.error.js.map +1 -1
- package/dist/types/cache-entry.type.d.mts +4 -4
- package/dist/types/cache-entry.type.d.ts +4 -4
- package/dist/types/clock.type.d.mts +3 -3
- package/dist/types/clock.type.d.ts +3 -3
- package/dist/types/confirm-event.type.d.mts +3 -3
- package/dist/types/confirm-event.type.d.ts +3 -3
- package/dist/types/decoded-token.type.d.mts +2 -2
- package/dist/types/decoded-token.type.d.ts +2 -2
- package/dist/types/evaluated.type.d.mts +1 -1
- package/dist/types/evaluated.type.d.ts +1 -1
- package/dist/types/evaluated.type.d.ts.map +1 -1
- package/dist/types/exclusion.type.d.mts +1 -1
- package/dist/types/exclusion.type.d.ts +1 -1
- package/dist/types/exclusion.type.d.ts.map +1 -1
- package/dist/types/node-state.type.d.mts +13 -13
- package/dist/types/node-state.type.d.ts +13 -13
- package/dist/types/node-state.type.d.ts.map +1 -1
- package/dist/types/not-a-pool.type.d.mts +5 -5
- package/dist/types/not-a-pool.type.d.ts +5 -5
- package/dist/types/probe-event.type.d.mts +1 -1
- package/dist/types/probe-event.type.d.ts +1 -1
- package/dist/types/probe-event.type.d.ts.map +1 -1
- package/dist/types/probe-outcome.type.d.mts +1 -1
- package/dist/types/probe-outcome.type.d.ts +1 -1
- package/dist/types/probe-outcome.type.d.ts.map +1 -1
- package/dist/types/probe-sample.type.d.mts +1 -1
- package/dist/types/probe-sample.type.d.ts +1 -1
- package/dist/types/probe-sample.type.d.ts.map +1 -1
- package/dist/types/replica-node.type.d.mts +7 -7
- package/dist/types/replica-node.type.d.ts +7 -7
- package/dist/types/replica-requirement.type.d.mts +2 -2
- package/dist/types/replica-requirement.type.d.ts +2 -2
- package/dist/types/replica-router-options.type.d.mts +25 -25
- package/dist/types/replica-router-options.type.d.ts +25 -25
- package/dist/types/replica-router-options.type.d.ts.map +1 -1
- package/dist/types/route-decision.type.d.mts +5 -5
- package/dist/types/route-decision.type.d.ts +5 -5
- package/dist/types/route-decision.type.d.ts.map +1 -1
- package/dist/types/router-observer.type.d.mts +5 -5
- package/dist/types/router-observer.type.d.ts +5 -5
- package/dist/types/router-observer.type.d.ts.map +1 -1
- package/dist/types/router-stats.type.d.mts +8 -8
- package/dist/types/router-stats.type.d.ts +8 -8
- package/dist/types/router-stats.type.d.ts.map +1 -1
- package/dist/types/sql-command-executor.type.d.mts +4 -4
- package/dist/types/sql-command-executor.type.d.ts +4 -4
- package/dist/types/sql-query-executor.type.d.mts +3 -3
- package/dist/types/sql-query-executor.type.d.ts +3 -3
- package/dist/types/wal-layout.type.d.mts +1 -1
- package/dist/types/wal-layout.type.d.ts +1 -1
- package/dist/types/wal-layout.type.d.ts.map +1 -1
- package/dist/types/wal-position.type.d.mts +5 -5
- package/dist/types/wal-position.type.d.ts +5 -5
- package/dist/types/wal-position.type.d.ts.map +1 -1
- package/dist/value-text.d.mts +5 -5
- package/dist/value-text.d.ts +5 -5
- package/dist/value-text.js +6 -6
- package/dist/value-text.js.map +1 -1
- package/dist/wal-layout-of.d.mts +1 -1
- package/dist/wal-layout-of.d.ts +1 -1
- package/dist/wal-layout-of.d.ts.map +1 -1
- package/dist/wal-layout-of.js +1 -1
- package/dist/wal-layout-of.js.map +1 -1
- package/package.json +11 -9
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this package are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/) (before 1.0 a breaking change bumps the minor version).
|
|
6
6
|
|
|
7
|
+
## 0.3.0 — 2026-11-29
|
|
8
|
+
|
|
9
|
+
- **Breaking for anyone matching message text:** all error messages (`InvalidReplicaSyncOptionsError`,
|
|
10
|
+
`ProbeTimeoutError`, `TransactionNotOpenError`, `TransactionNotCommittedError`, `InvalidLsnError` and
|
|
11
|
+
the router's own errors), the `detail` of an `invalid` decoded token, log lines of the scripts, code
|
|
12
|
+
comments and test names are now in English. Error classes, `ROUTE_REASON` and `EXCLUSION_REASON`
|
|
13
|
+
values are unchanged — match on them instead of text.
|
|
14
|
+
|
|
7
15
|
## 0.2.2 — 2026-11-21
|
|
8
16
|
|
|
9
17
|
First public release as `@hoshinotatsuya/pg-replica-sync`, MIT; documentation in English and Russian; no
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@hoshinotatsuya/pg-replica-sync)
|
|
4
4
|
[](https://github.com/HoshinoTatsuya/pg-replica-sync/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
|
-
[
|
|
6
|
+
[Russian version](README.ru.md) · [Changelog](CHANGELOG.md)
|
|
7
7
|
|
|
8
8
|
Reads from PostgreSQL replicas with a **read-your-writes** guarantee, by WAL position. After a write the client
|
|
9
9
|
gets a signed position token. A read carrying the token goes to a replica only when it is **proven** that the
|
package/dist/compare-lsn.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* `X/Y` (
|
|
4
|
-
*
|
|
2
|
+
* Comparison of WAL positions as 64-bit numbers: -1, 0 or 1. Accepts the text
|
|
3
|
+
* `X/Y` (parsed strictly) or an already parsed position. The single point of
|
|
4
|
+
* position comparison in the package.
|
|
5
5
|
*/
|
|
6
6
|
export declare function compareLsn(left: string | bigint, right: string | bigint): -1 | 0 | 1;
|
package/dist/compare-lsn.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* `X/Y` (
|
|
4
|
-
*
|
|
2
|
+
* Comparison of WAL positions as 64-bit numbers: -1, 0 or 1. Accepts the text
|
|
3
|
+
* `X/Y` (parsed strictly) or an already parsed position. The single point of
|
|
4
|
+
* position comparison in the package.
|
|
5
5
|
*/
|
|
6
6
|
export declare function compareLsn(left: string | bigint, right: string | bigint): -1 | 0 | 1;
|
|
7
7
|
//# sourceMappingURL=compare-lsn.d.ts.map
|
package/dist/compare-lsn.js
CHANGED
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.compareLsn = compareLsn;
|
|
4
4
|
const parse_lsn_1 = require("./parse-lsn");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* `X/Y` (
|
|
8
|
-
*
|
|
6
|
+
* Comparison of WAL positions as 64-bit numbers: -1, 0 or 1. Accepts the text
|
|
7
|
+
* `X/Y` (parsed strictly) or an already parsed position. The single point of
|
|
8
|
+
* position comparison in the package.
|
|
9
9
|
*/
|
|
10
10
|
function compareLsn(left, right) {
|
|
11
11
|
const a = typeof left === 'bigint' ? left : (0, parse_lsn_1.parseLsn)(left);
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Why a replica did not fit this read. Every "could not determine"
|
|
3
|
+
* is a separate value and an exclusion, not "fits".
|
|
4
4
|
*/
|
|
5
5
|
export declare const EXCLUSION_REASON: {
|
|
6
|
-
/**
|
|
6
|
+
/** The probe did not answer: a connection refusal, an error or the time ceiling. */
|
|
7
7
|
readonly unavailable: "unavailable";
|
|
8
|
-
/** `pg_is_in_recovery() = false`:
|
|
8
|
+
/** `pg_is_in_recovery() = false`: the node became the primary. */
|
|
9
9
|
readonly promoted: "promoted";
|
|
10
|
-
/**
|
|
10
|
+
/** WAL replay is paused (`pg_wal_replay_pause`). */
|
|
11
11
|
readonly paused: "paused";
|
|
12
|
-
/**
|
|
12
|
+
/** The probe role does not see `pg_stat_wal_receiver` (pg_read_all_stats / pg_monitor is needed). */
|
|
13
13
|
readonly noStatsPrivilege: "no-stats-privilege";
|
|
14
|
-
/**
|
|
14
|
+
/** The timeline could not be determined (the WAL receiver does not work). */
|
|
15
15
|
readonly timelineUnknown: "timeline-unknown";
|
|
16
|
-
/**
|
|
16
|
+
/** The replica timeline is not the one of the token (or of the primary). */
|
|
17
17
|
readonly timelineMismatch: "timeline-mismatch";
|
|
18
|
-
/**
|
|
18
|
+
/** A replica from another cluster (system identifier). */
|
|
19
19
|
readonly otherCluster: "other-cluster";
|
|
20
|
-
/**
|
|
20
|
+
/** The state came but does not parse (the WAL position is empty or not in the `X/Y` form). */
|
|
21
21
|
readonly stateUnknown: "state-unknown";
|
|
22
|
-
/**
|
|
22
|
+
/** The replay position is smaller than the token position. */
|
|
23
23
|
readonly behind: "behind";
|
|
24
|
-
/**
|
|
24
|
+
/** Without a token: the lag is above the ceiling. */
|
|
25
25
|
readonly lagExceeded: "lag-exceeded";
|
|
26
26
|
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Why a replica did not fit this read. Every "could not determine"
|
|
3
|
+
* is a separate value and an exclusion, not "fits".
|
|
4
4
|
*/
|
|
5
5
|
export declare const EXCLUSION_REASON: {
|
|
6
|
-
/**
|
|
6
|
+
/** The probe did not answer: a connection refusal, an error or the time ceiling. */
|
|
7
7
|
readonly unavailable: "unavailable";
|
|
8
|
-
/** `pg_is_in_recovery() = false`:
|
|
8
|
+
/** `pg_is_in_recovery() = false`: the node became the primary. */
|
|
9
9
|
readonly promoted: "promoted";
|
|
10
|
-
/**
|
|
10
|
+
/** WAL replay is paused (`pg_wal_replay_pause`). */
|
|
11
11
|
readonly paused: "paused";
|
|
12
|
-
/**
|
|
12
|
+
/** The probe role does not see `pg_stat_wal_receiver` (pg_read_all_stats / pg_monitor is needed). */
|
|
13
13
|
readonly noStatsPrivilege: "no-stats-privilege";
|
|
14
|
-
/**
|
|
14
|
+
/** The timeline could not be determined (the WAL receiver does not work). */
|
|
15
15
|
readonly timelineUnknown: "timeline-unknown";
|
|
16
|
-
/**
|
|
16
|
+
/** The replica timeline is not the one of the token (or of the primary). */
|
|
17
17
|
readonly timelineMismatch: "timeline-mismatch";
|
|
18
|
-
/**
|
|
18
|
+
/** A replica from another cluster (system identifier). */
|
|
19
19
|
readonly otherCluster: "other-cluster";
|
|
20
|
-
/**
|
|
20
|
+
/** The state came but does not parse (the WAL position is empty or not in the `X/Y` form). */
|
|
21
21
|
readonly stateUnknown: "state-unknown";
|
|
22
|
-
/**
|
|
22
|
+
/** The replay position is smaller than the token position. */
|
|
23
23
|
readonly behind: "behind";
|
|
24
|
-
/**
|
|
24
|
+
/** Without a token: the lag is above the ceiling. */
|
|
25
25
|
readonly lagExceeded: "lag-exceeded";
|
|
26
26
|
};
|
|
27
27
|
//# sourceMappingURL=exclusion-reason.constant.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclusion-reason.constant.d.ts","sourceRoot":"","sources":["../../src/constants/exclusion-reason.constant.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;IAC3B,
|
|
1
|
+
{"version":3,"file":"exclusion-reason.constant.d.ts","sourceRoot":"","sources":["../../src/constants/exclusion-reason.constant.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;IAC3B,oFAAoF;;IAEpF,kEAAkE;;IAElE,oDAAoD;;IAEpD,qGAAqG;;IAErG,6EAA6E;;IAE7E,4EAA4E;;IAE5E,0DAA0D;;IAE1D,8FAA8F;;IAE9F,8DAA8D;;IAE9D,qDAAqD;;CAE7C,CAAC"}
|
|
@@ -3,29 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EXCLUSION_REASON = void 0;
|
|
4
4
|
const deep_freeze_1 = require("../deep-freeze");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Why a replica did not fit this read. Every "could not determine"
|
|
7
|
+
* is a separate value and an exclusion, not "fits".
|
|
8
8
|
*/
|
|
9
9
|
exports.EXCLUSION_REASON = {
|
|
10
|
-
/**
|
|
10
|
+
/** The probe did not answer: a connection refusal, an error or the time ceiling. */
|
|
11
11
|
unavailable: 'unavailable',
|
|
12
|
-
/** `pg_is_in_recovery() = false`:
|
|
12
|
+
/** `pg_is_in_recovery() = false`: the node became the primary. */
|
|
13
13
|
promoted: 'promoted',
|
|
14
|
-
/**
|
|
14
|
+
/** WAL replay is paused (`pg_wal_replay_pause`). */
|
|
15
15
|
paused: 'paused',
|
|
16
|
-
/**
|
|
16
|
+
/** The probe role does not see `pg_stat_wal_receiver` (pg_read_all_stats / pg_monitor is needed). */
|
|
17
17
|
noStatsPrivilege: 'no-stats-privilege',
|
|
18
|
-
/**
|
|
18
|
+
/** The timeline could not be determined (the WAL receiver does not work). */
|
|
19
19
|
timelineUnknown: 'timeline-unknown',
|
|
20
|
-
/**
|
|
20
|
+
/** The replica timeline is not the one of the token (or of the primary). */
|
|
21
21
|
timelineMismatch: 'timeline-mismatch',
|
|
22
|
-
/**
|
|
22
|
+
/** A replica from another cluster (system identifier). */
|
|
23
23
|
otherCluster: 'other-cluster',
|
|
24
|
-
/**
|
|
24
|
+
/** The state came but does not parse (the WAL position is empty or not in the `X/Y` form). */
|
|
25
25
|
stateUnknown: 'state-unknown',
|
|
26
|
-
/**
|
|
26
|
+
/** The replay position is smaller than the token position. */
|
|
27
27
|
behind: 'behind',
|
|
28
|
-
/**
|
|
28
|
+
/** Without a token: the lag is above the ceiling. */
|
|
29
29
|
lagExceeded: 'lag-exceeded',
|
|
30
30
|
};
|
|
31
31
|
(0, deep_freeze_1.deepFreeze)(exports.EXCLUSION_REASON);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclusion-reason.constant.js","sourceRoot":"","sources":["../../src/constants/exclusion-reason.constant.ts"],"names":[],"mappings":";;;AAAA,gDAA4C;AAE5C;;;GAGG;AACU,QAAA,gBAAgB,GAAG;IAC9B,
|
|
1
|
+
{"version":3,"file":"exclusion-reason.constant.js","sourceRoot":"","sources":["../../src/constants/exclusion-reason.constant.ts"],"names":[],"mappings":";;;AAAA,gDAA4C;AAE5C;;;GAGG;AACU,QAAA,gBAAgB,GAAG;IAC9B,oFAAoF;IACpF,WAAW,EAAE,aAAa;IAC1B,kEAAkE;IAClE,QAAQ,EAAE,UAAU;IACpB,oDAAoD;IACpD,MAAM,EAAE,QAAQ;IAChB,qGAAqG;IACrG,gBAAgB,EAAE,oBAAoB;IACtC,6EAA6E;IAC7E,eAAe,EAAE,kBAAkB;IACnC,4EAA4E;IAC5E,gBAAgB,EAAE,mBAAmB;IACrC,0DAA0D;IAC1D,YAAY,EAAE,eAAe;IAC7B,8FAA8F;IAC9F,YAAY,EAAE,eAAe;IAC7B,8DAA8D;IAC9D,MAAM,EAAE,QAAQ;IAChB,qDAAqD;IACrD,WAAW,EAAE,cAAc;CACnB,CAAC;AACX,IAAA,wBAAU,EAAC,wBAAgB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-role.constant.d.ts","sourceRoot":"","sources":["../../src/constants/node-role.constant.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"node-role.constant.d.ts","sourceRoot":"","sources":["../../src/constants/node-role.constant.ts"],"names":[],"mappings":"AAEA,6CAA6C;AAC7C,eAAO,MAAM,SAAS;;;CAGZ,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NODE_ROLE = void 0;
|
|
4
4
|
const deep_freeze_1 = require("../deep-freeze");
|
|
5
|
-
/**
|
|
5
|
+
/** The role of the node the read went to. */
|
|
6
6
|
exports.NODE_ROLE = {
|
|
7
7
|
primary: 'primary',
|
|
8
8
|
replica: 'replica',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-role.constant.js","sourceRoot":"","sources":["../../src/constants/node-role.constant.ts"],"names":[],"mappings":";;;AAAA,gDAA4C;AAE5C,
|
|
1
|
+
{"version":3,"file":"node-role.constant.js","sourceRoot":"","sources":["../../src/constants/node-role.constant.ts"],"names":[],"mappings":";;;AAAA,gDAA4C;AAE5C,6CAA6C;AAChC,QAAA,SAAS,GAAG;IACvB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;CACV,CAAC;AACX,IAAA,wBAAU,EAAC,iBAAS,CAAC,CAAC"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* recovery, `pg_walfile_name`
|
|
5
|
-
*
|
|
2
|
+
* The node state probe is one query, the same for the primary and a replica.
|
|
3
|
+
* Functions that fail in the "wrong" mode (`pg_get_wal_replay_pause_state` outside
|
|
4
|
+
* recovery, `pg_walfile_name` in recovery) are under CASE: Postgres evaluates
|
|
5
|
+
* a branch only when its condition holds (checked on 17).
|
|
6
6
|
*
|
|
7
|
-
* -
|
|
8
|
-
* `pg_control_checkpoint().timeline_id`
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* pg_read_all_stats
|
|
12
|
-
*
|
|
13
|
-
* -
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `write_pending
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* - `started_at`
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* `system_identifier`
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* - `wal_layout`
|
|
26
|
-
* (`pg_control_init()`):
|
|
27
|
-
*
|
|
7
|
+
* - The primary timeline comes from the WAL file name of the current insert position:
|
|
8
|
+
* `pg_control_checkpoint().timeline_id` after a promotion stays old until
|
|
9
|
+
* the next checkpoint (measured: promotion → 2 by WAL, 1 by checkpoint).
|
|
10
|
+
* - The replica timeline is `pg_stat_wal_receiver.received_tli`; without
|
|
11
|
+
* pg_read_all_stats the column is empty (measured under a role without privileges), so the privilege
|
|
12
|
+
* is requested by the same query: "no privileges" and "the receiver is stopped" are different reasons.
|
|
13
|
+
* - The primary position is `pg_current_wal_insert_lsn()`, not `pg_current_wal_lsn()`:
|
|
14
|
+
* with `synchronous_commit = off` the commit record may not be written yet,
|
|
15
|
+
* and the write position would be SMALLER than the end of the commit. The insert position is not.
|
|
16
|
+
* - `write_pending`: the connection has the number of an unfinished transaction: a token
|
|
17
|
+
* issued before COMMIT would be smaller than the commit position, and a replica would "catch up with"
|
|
18
|
+
* it without this write. Such a token is not issued.
|
|
19
|
+
* - `started_at` is the postmaster start moment in epoch seconds (not the `::text`
|
|
20
|
+
* of a timestamp: its form depends on the DateStyle and TimeZone of the session, and one and the
|
|
21
|
+
* same read and probe connection would give different instances): together with
|
|
22
|
+
* `system_identifier` this is the server instance. After a replica restart the replay position
|
|
23
|
+
* rolls back to minRecoveryPoint (measured: by 69–94 MB), and everything taken before
|
|
24
|
+
* the restart no longer applies to it.
|
|
25
|
+
* - `wal_layout` is the alignment, the page size and the WAL segment size of the primary
|
|
26
|
+
* (`pg_control_init()`): by them an insert position right after a page header
|
|
27
|
+
* is reduced to the page boundary (`tokenLsn`).
|
|
28
28
|
*/
|
|
29
29
|
export declare const PROBE_SQL: {
|
|
30
30
|
readonly STATE: "SELECT pg_is_in_recovery() AS in_recovery,\n (SELECT system_identifier::text FROM pg_control_system()) AS system_id,\n extract(epoch FROM pg_postmaster_start_time())::text AS started_at,\n CASE WHEN pg_is_in_recovery() THEN pg_last_wal_replay_lsn()::text END AS replay_lsn,\n CASE WHEN pg_is_in_recovery() THEN pg_get_wal_replay_pause_state() END AS pause_state,\n CASE WHEN pg_is_in_recovery() THEN (SELECT received_tli FROM pg_stat_wal_receiver LIMIT 1) END AS received_tli,\n pg_has_role(current_user, 'pg_read_all_stats', 'USAGE') AS has_stats,\n CASE WHEN NOT pg_is_in_recovery() THEN pg_current_wal_insert_lsn()::text END AS insert_lsn,\n CASE WHEN NOT pg_is_in_recovery() THEN pg_walfile_name(pg_current_wal_insert_lsn()) END AS wal_file,\n CASE WHEN NOT pg_is_in_recovery() THEN pg_current_xact_id_if_assigned() IS NOT NULL END AS write_pending,\n CASE WHEN NOT pg_is_in_recovery() THEN (SELECT ARRAY[max_data_alignment, wal_block_size, bytes_per_wal_segment] FROM pg_control_init()) END AS wal_layout";
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* recovery, `pg_walfile_name`
|
|
5
|
-
*
|
|
2
|
+
* The node state probe is one query, the same for the primary and a replica.
|
|
3
|
+
* Functions that fail in the "wrong" mode (`pg_get_wal_replay_pause_state` outside
|
|
4
|
+
* recovery, `pg_walfile_name` in recovery) are under CASE: Postgres evaluates
|
|
5
|
+
* a branch only when its condition holds (checked on 17).
|
|
6
6
|
*
|
|
7
|
-
* -
|
|
8
|
-
* `pg_control_checkpoint().timeline_id`
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* pg_read_all_stats
|
|
12
|
-
*
|
|
13
|
-
* -
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `write_pending
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* - `started_at`
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* `system_identifier`
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* - `wal_layout`
|
|
26
|
-
* (`pg_control_init()`):
|
|
27
|
-
*
|
|
7
|
+
* - The primary timeline comes from the WAL file name of the current insert position:
|
|
8
|
+
* `pg_control_checkpoint().timeline_id` after a promotion stays old until
|
|
9
|
+
* the next checkpoint (measured: promotion → 2 by WAL, 1 by checkpoint).
|
|
10
|
+
* - The replica timeline is `pg_stat_wal_receiver.received_tli`; without
|
|
11
|
+
* pg_read_all_stats the column is empty (measured under a role without privileges), so the privilege
|
|
12
|
+
* is requested by the same query: "no privileges" and "the receiver is stopped" are different reasons.
|
|
13
|
+
* - The primary position is `pg_current_wal_insert_lsn()`, not `pg_current_wal_lsn()`:
|
|
14
|
+
* with `synchronous_commit = off` the commit record may not be written yet,
|
|
15
|
+
* and the write position would be SMALLER than the end of the commit. The insert position is not.
|
|
16
|
+
* - `write_pending`: the connection has the number of an unfinished transaction: a token
|
|
17
|
+
* issued before COMMIT would be smaller than the commit position, and a replica would "catch up with"
|
|
18
|
+
* it without this write. Such a token is not issued.
|
|
19
|
+
* - `started_at` is the postmaster start moment in epoch seconds (not the `::text`
|
|
20
|
+
* of a timestamp: its form depends on the DateStyle and TimeZone of the session, and one and the
|
|
21
|
+
* same read and probe connection would give different instances): together with
|
|
22
|
+
* `system_identifier` this is the server instance. After a replica restart the replay position
|
|
23
|
+
* rolls back to minRecoveryPoint (measured: by 69–94 MB), and everything taken before
|
|
24
|
+
* the restart no longer applies to it.
|
|
25
|
+
* - `wal_layout` is the alignment, the page size and the WAL segment size of the primary
|
|
26
|
+
* (`pg_control_init()`): by them an insert position right after a page header
|
|
27
|
+
* is reduced to the page boundary (`tokenLsn`).
|
|
28
28
|
*/
|
|
29
29
|
export declare const PROBE_SQL: {
|
|
30
30
|
readonly STATE: "SELECT pg_is_in_recovery() AS in_recovery,\n (SELECT system_identifier::text FROM pg_control_system()) AS system_id,\n extract(epoch FROM pg_postmaster_start_time())::text AS started_at,\n CASE WHEN pg_is_in_recovery() THEN pg_last_wal_replay_lsn()::text END AS replay_lsn,\n CASE WHEN pg_is_in_recovery() THEN pg_get_wal_replay_pause_state() END AS pause_state,\n CASE WHEN pg_is_in_recovery() THEN (SELECT received_tli FROM pg_stat_wal_receiver LIMIT 1) END AS received_tli,\n pg_has_role(current_user, 'pg_read_all_stats', 'USAGE') AS has_stats,\n CASE WHEN NOT pg_is_in_recovery() THEN pg_current_wal_insert_lsn()::text END AS insert_lsn,\n CASE WHEN NOT pg_is_in_recovery() THEN pg_walfile_name(pg_current_wal_insert_lsn()) END AS wal_file,\n CASE WHEN NOT pg_is_in_recovery() THEN pg_current_xact_id_if_assigned() IS NOT NULL END AS write_pending,\n CASE WHEN NOT pg_is_in_recovery() THEN (SELECT ARRAY[max_data_alignment, wal_block_size, bytes_per_wal_segment] FROM pg_control_init()) END AS wal_layout";
|
|
@@ -3,32 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PROBE_SQL = void 0;
|
|
4
4
|
const deep_freeze_1 = require("../deep-freeze");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* recovery, `pg_walfile_name`
|
|
9
|
-
*
|
|
6
|
+
* The node state probe is one query, the same for the primary and a replica.
|
|
7
|
+
* Functions that fail in the "wrong" mode (`pg_get_wal_replay_pause_state` outside
|
|
8
|
+
* recovery, `pg_walfile_name` in recovery) are under CASE: Postgres evaluates
|
|
9
|
+
* a branch only when its condition holds (checked on 17).
|
|
10
10
|
*
|
|
11
|
-
* -
|
|
12
|
-
* `pg_control_checkpoint().timeline_id`
|
|
13
|
-
*
|
|
14
|
-
* -
|
|
15
|
-
* pg_read_all_stats
|
|
16
|
-
*
|
|
17
|
-
* -
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* - `write_pending
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* - `started_at`
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* `system_identifier`
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* - `wal_layout`
|
|
30
|
-
* (`pg_control_init()`):
|
|
31
|
-
*
|
|
11
|
+
* - The primary timeline comes from the WAL file name of the current insert position:
|
|
12
|
+
* `pg_control_checkpoint().timeline_id` after a promotion stays old until
|
|
13
|
+
* the next checkpoint (measured: promotion → 2 by WAL, 1 by checkpoint).
|
|
14
|
+
* - The replica timeline is `pg_stat_wal_receiver.received_tli`; without
|
|
15
|
+
* pg_read_all_stats the column is empty (measured under a role without privileges), so the privilege
|
|
16
|
+
* is requested by the same query: "no privileges" and "the receiver is stopped" are different reasons.
|
|
17
|
+
* - The primary position is `pg_current_wal_insert_lsn()`, not `pg_current_wal_lsn()`:
|
|
18
|
+
* with `synchronous_commit = off` the commit record may not be written yet,
|
|
19
|
+
* and the write position would be SMALLER than the end of the commit. The insert position is not.
|
|
20
|
+
* - `write_pending`: the connection has the number of an unfinished transaction: a token
|
|
21
|
+
* issued before COMMIT would be smaller than the commit position, and a replica would "catch up with"
|
|
22
|
+
* it without this write. Such a token is not issued.
|
|
23
|
+
* - `started_at` is the postmaster start moment in epoch seconds (not the `::text`
|
|
24
|
+
* of a timestamp: its form depends on the DateStyle and TimeZone of the session, and one and the
|
|
25
|
+
* same read and probe connection would give different instances): together with
|
|
26
|
+
* `system_identifier` this is the server instance. After a replica restart the replay position
|
|
27
|
+
* rolls back to minRecoveryPoint (measured: by 69–94 MB), and everything taken before
|
|
28
|
+
* the restart no longer applies to it.
|
|
29
|
+
* - `wal_layout` is the alignment, the page size and the WAL segment size of the primary
|
|
30
|
+
* (`pg_control_init()`): by them an insert position right after a page header
|
|
31
|
+
* is reduced to the page boundary (`tokenLsn`).
|
|
32
32
|
*/
|
|
33
33
|
exports.PROBE_SQL = {
|
|
34
34
|
STATE: `SELECT pg_is_in_recovery() AS in_recovery,
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** The router defaults; each one is overridden by an option with the same meaning. */
|
|
2
2
|
export declare const REPLICA_SYNC_DEFAULTS: {
|
|
3
|
-
/**
|
|
3
|
+
/** How long a node state lives in the cache, ms. */
|
|
4
4
|
readonly STATE_TTL_MS: 250;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The ceiling of `stateTtlMs`, ms: the window in which a replica restart (the replay
|
|
7
|
+
* position after it is SMALLER — a rollback to minRecoveryPoint) may stay
|
|
8
|
+
* unnoticed if the loss of the probe connection did not reach the client.
|
|
9
9
|
*/
|
|
10
10
|
readonly MAX_STATE_TTL_MS: 1000;
|
|
11
|
-
/**
|
|
11
|
+
/** The ceiling of one probe (connection establishment + query), ms. */
|
|
12
12
|
readonly PROBE_TIMEOUT_MS: 1000;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `PROBE_TIMEOUT_MS
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* The lifetime ceiling of a probe connection that did not get established or on which a query
|
|
15
|
+
* did not answer, ms (from the start of the establishment or the query). A probe that did not fit into
|
|
16
|
+
* `PROBE_TIMEOUT_MS` is a refusal of this probe, but the connection is not torn until this
|
|
17
|
+
* ceiling: a slow but alive replica (establishment longer than the probe ceiling) gets
|
|
18
|
+
* a ready connection for the next probe, and a frozen one stays unavailable.
|
|
19
19
|
*/
|
|
20
20
|
readonly CONNECT_TIMEOUT_MS: 10000;
|
|
21
|
-
/**
|
|
21
|
+
/** How long a node that did not answer a probe is not polled again, ms. */
|
|
22
22
|
readonly UNAVAILABLE_RETRY_MS: 2000;
|
|
23
|
-
/**
|
|
23
|
+
/** Without a token: the ceiling of a replica lag behind the primary, bytes of WAL. */
|
|
24
24
|
readonly MAX_LAG_BYTES: 1048576;
|
|
25
|
-
/**
|
|
25
|
+
/** Waiting for catch-up before going to the primary, ms (0 — do not wait). */
|
|
26
26
|
readonly WAIT_FOR_CATCH_UP_MS: 0;
|
|
27
|
-
/**
|
|
27
|
+
/** The interval of polling the replicas during the wait, ms. */
|
|
28
28
|
readonly CATCH_UP_POLL_MS: 10;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* No more than one new probe of a node per this many ms, with any number of reads:
|
|
31
|
+
* a token ahead of a replica requires a fresh probe, and without a ceiling lagging replicas
|
|
32
|
+
* would be polled on every read.
|
|
33
33
|
*/
|
|
34
34
|
readonly MIN_PROBE_INTERVAL_MS: 10;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* (
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* How long a token that after a failover no replica can satisfy
|
|
37
|
+
* (another timeline, another cluster, ahead of the primary) holds reads on the
|
|
38
|
+
* primary, ms; an older one is read as without a token. A token "without a position" does not
|
|
39
|
+
* age: its position is unknown.
|
|
40
40
|
*/
|
|
41
41
|
readonly TOKEN_TTL_MS: 60000;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* How many token positions the router remembers (the moment of the first encounter — for
|
|
44
|
+
* the probe frequency ceiling and expiry); the one not seen for the longest time is evicted (LRU).
|
|
45
45
|
*/
|
|
46
46
|
readonly POSITION_MEMORY: 1024;
|
|
47
|
-
/**
|
|
47
|
+
/** The ceiling of values that go into timers (`setTimeout` above 2³¹−1 ms fires after 1 ms). */
|
|
48
48
|
readonly MAX_TIMER_MS: 2147483647;
|
|
49
|
-
/** `application_name`
|
|
49
|
+
/** The `application_name` of the probe connections if the address does not set it: visible in pg_stat_activity. */
|
|
50
50
|
readonly APPLICATION_NAME: "pg-replica-sync";
|
|
51
51
|
};
|