@rocicorp/zero 1.12.0 → 1.13.0-canary.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/out/shared/src/bigint-json.d.ts +6 -0
- package/out/shared/src/bigint-json.d.ts.map +1 -1
- package/out/shared/src/bigint-json.js +14 -1
- package/out/shared/src/bigint-json.js.map +1 -1
- package/out/shared/src/objects.d.ts +7 -0
- package/out/shared/src/objects.d.ts.map +1 -1
- package/out/shared/src/objects.js +10 -1
- package/out/shared/src/objects.js.map +1 -1
- package/out/shared/src/resolver.d.ts.map +1 -1
- package/out/shared/src/resolver.js +12 -1
- package/out/shared/src/resolver.js.map +1 -1
- package/out/zero/package.js +1 -1
- package/out/zero/package.js.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js +4 -3
- package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/normalize.d.ts.map +1 -1
- package/out/zero-cache/src/config/normalize.js +3 -23
- package/out/zero-cache/src/config/normalize.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +1 -27
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +19 -47
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/custom/fetch.js +17 -2
- package/out/zero-cache/src/custom/fetch.js.map +1 -1
- package/out/zero-cache/src/db/create.js +45 -1
- package/out/zero-cache/src/db/create.js.map +1 -1
- package/out/zero-cache/src/db/lite-tables.d.ts.map +1 -1
- package/out/zero-cache/src/db/lite-tables.js +4 -3
- package/out/zero-cache/src/db/lite-tables.js.map +1 -1
- package/out/zero-cache/src/db/pg-copy-binary.js +61 -25
- package/out/zero-cache/src/db/pg-copy-binary.js.map +1 -1
- package/out/zero-cache/src/db/pg-to-lite.d.ts +17 -0
- package/out/zero-cache/src/db/pg-to-lite.d.ts.map +1 -1
- package/out/zero-cache/src/db/pg-to-lite.js +84 -1
- package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +21 -30
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/main.js +0 -1
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/replicator.js +1 -1
- package/out/zero-cache/src/server/replicator.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +6 -5
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js +49 -11
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js +64 -21
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/replication-slots.js +11 -6
- package/out/zero-cache/src/services/change-source/pg/replication-slots.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +13 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +16 -3
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js +59 -3
- package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts +1 -0
- package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/published.js +56 -12
- package/out/zero-cache/src/services/change-source/pg/schema/published.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +1 -0
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js +35 -12
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/validation.d.ts +6 -1
- package/out/zero-cache/src/services/change-source/pg/schema/validation.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/validation.js +25 -1
- package/out/zero-cache/src/services/change-source/pg/schema/validation.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/backfill-progress.js +6 -5
- package/out/zero-cache/src/services/change-source/protocol/backfill-progress.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backfill-state.js +7 -6
- package/out/zero-cache/src/services/change-streamer/backfill-state.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-log-codec.js +2 -2
- package/out/zero-cache/src/services/change-streamer/change-log-codec.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-log-initializer.js +16 -199
- package/out/zero-cache/src/services/change-streamer/change-log-initializer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +76 -127
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/snapshot-reservations.js +1 -1
- package/out/zero-cache/src/services/change-streamer/snapshot-reservations.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-catchup.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-purge-scheduler.js +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-read-router.js +15 -49
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-read-router.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-reader.js +8 -2
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-reader.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.js +20 -36
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +32 -20
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js +4 -2
- package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-log-cookies.d.ts +0 -16
- package/out/zero-cache/src/services/replicator/change-log-cookies.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/change-log-cookies.js +3 -95
- package/out/zero-cache/src/services/replicator/change-log-cookies.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-log-db.js +2 -2
- package/out/zero-cache/src/services/replicator/change-log-db.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.js +1 -30
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-processor.js +82 -9
- package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.js +7 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
- package/out/zero-cache/src/services/replicator/reporter/report-schema.d.ts +1 -0
- package/out/zero-cache/src/services/replicator/reporter/report-schema.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/reporter/report-schema.js +4 -1
- package/out/zero-cache/src/services/replicator/reporter/report-schema.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/change-log.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/change-log.js +2 -1
- package/out/zero-cache/src/services/replicator/schema/change-log.js.map +1 -1
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.js +6 -102
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.js.map +1 -1
- package/out/zero-cache/src/services/statz.d.ts.map +1 -1
- package/out/zero-cache/src/services/statz.js +1 -1
- package/out/zero-cache/src/services/statz.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/schema/init.js +3 -0
- package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.js +47 -3
- package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +51 -6
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/lite.d.ts +7 -0
- package/out/zero-cache/src/types/lite.d.ts.map +1 -1
- package/out/zero-cache/src/types/lite.js +12 -2
- package/out/zero-cache/src/types/lite.js.map +1 -1
- package/out/zero-cache/src/types/pg-types.d.ts +2 -1
- package/out/zero-cache/src/types/pg-types.d.ts.map +1 -1
- package/out/zero-cache/src/types/pg-types.js +2 -1
- package/out/zero-cache/src/types/pg-types.js.map +1 -1
- package/out/zero-cache/src/types/pg.d.ts +20 -0
- package/out/zero-cache/src/types/pg.d.ts.map +1 -1
- package/out/zero-cache/src/types/pg.js +64 -27
- package/out/zero-cache/src/types/pg.js.map +1 -1
- package/out/zero-cache/src/types/streams.d.ts +2 -0
- package/out/zero-cache/src/types/streams.d.ts.map +1 -1
- package/out/zero-cache/src/types/streams.js +2 -1
- package/out/zero-cache/src/types/streams.js.map +1 -1
- package/out/zero-cache/src/workers/replicator.js +7 -6
- package/out/zero-cache/src/workers/replicator.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +18 -1
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zqlite/src/db.js +4 -1
- package/out/zqlite/src/db.js.map +1 -1
- package/package.json +1 -1
- package/out/zero-cache/src/services/change-streamer/change-log-compare-digest.js +0 -67
- package/out/zero-cache/src/services/change-streamer/change-log-compare-digest.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/change-log-transaction-hash.js +0 -39
- package/out/zero-cache/src/services/change-streamer/change-log-transaction-hash.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/shard-sampling.js +0 -19
- package/out/zero-cache/src/services/change-streamer/shard-sampling.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-comparator.js +0 -417
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-comparator.js.map +0 -1
|
@@ -14,14 +14,13 @@ import { publishReplicationError, replicationStatusError } from "../replicator/r
|
|
|
14
14
|
import "./change-streamer.js";
|
|
15
15
|
import { BackfillStateTracker } from "./backfill-state-tracker.js";
|
|
16
16
|
import { serializeChangeStreamDataWithChange } from "./change-log-codec.js";
|
|
17
|
-
import { SQLiteChangeLogReader } from "./sqlite-change-log-reader.js";
|
|
18
17
|
import { ChangeLogInitializer, replicaInitializationSource } from "./change-log-initializer.js";
|
|
19
18
|
import { DrainTracker } from "./drain-tracker.js";
|
|
20
19
|
import { Forwarder } from "./forwarder.js";
|
|
21
20
|
import { RestoreAdmission } from "./restore-admission.js";
|
|
22
21
|
import { SnapshotReservations } from "./snapshot-reservations.js";
|
|
23
22
|
import { SQLiteChangeLogCatchup } from "./sqlite-change-log-catchup.js";
|
|
24
|
-
import {
|
|
23
|
+
import { SQLiteChangeLogReader } from "./sqlite-change-log-reader.js";
|
|
25
24
|
import { SQLiteChangeLogPurgeScheduler } from "./sqlite-change-log-purge-scheduler.js";
|
|
26
25
|
import { SQLiteChangeLogReadRouter, inspectSQLiteChangeLog } from "./sqlite-change-log-read-router.js";
|
|
27
26
|
import { SQLiteChangeLogWriter } from "./sqlite-change-log-writer.js";
|
|
@@ -200,7 +199,6 @@ var ChangeStreamerImpl = class {
|
|
|
200
199
|
#sqliteCatchupOptions;
|
|
201
200
|
#changeLogWriter;
|
|
202
201
|
#purgeScheduler;
|
|
203
|
-
#comparator;
|
|
204
202
|
#acker;
|
|
205
203
|
#backupMonitor;
|
|
206
204
|
#initializer;
|
|
@@ -214,8 +212,7 @@ var ChangeStreamerImpl = class {
|
|
|
214
212
|
#changeCounter = getOrCreateCounter("replication", "changes", "Count of replicated changes (DML or DDL statements)");
|
|
215
213
|
#transactionForwardDuration = getOrCreateLatencyHistogram("replication", "transaction_forward_duration", "Time from receiving a transaction's `begin` to forwarding its `commit`, i.e. the change-streamer half of forward-to-subscriber latency.");
|
|
216
214
|
#catchupRoutes = getOrCreateCounter("replication", "sqlite_change_log.catchup_routes", "Catchup subscriptions by selected source and low-cardinality reason.");
|
|
217
|
-
#
|
|
218
|
-
#reservationConfirmDelays = getOrCreateCounter("replication", "sqlite_change_log.reservation_confirm_delays", "Snapshot reservations whose confirmation was deferred because the selected source's change-log minimum was later than the backup watermark. Counted once per reservation, by that source.");
|
|
215
|
+
#reservationConfirmDelays = getOrCreateCounter("replication", "sqlite_change_log.reservation_confirm_delays", "Snapshot reservations whose confirmation was deferred because the change log's minimum was later than the backup watermark. Counted once per reservation.");
|
|
219
216
|
#latestLagReportCommitTimeMs = 0;
|
|
220
217
|
#lagReports = resolver();
|
|
221
218
|
#backupWatermark;
|
|
@@ -250,26 +247,21 @@ var ChangeStreamerImpl = class {
|
|
|
250
247
|
this.#source = source;
|
|
251
248
|
this.#pgChangeLogBehindSlot = opts.pgChangeLogBehindSlot;
|
|
252
249
|
this.#storer = changeDBProvider ? new Storer(lc, shard, taskID, discoveryAddress, discoveryProtocol, changeDBProvider, subscriptionState, (consumed) => this.#acker.trackPgChangeLog(consumed[2].watermark), (err) => this.stop(err), opts) : null;
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
assert(opts.sqliteChangeLogCompare === void 0, "SQLite change-log comparison requires the PG change log");
|
|
256
|
-
}
|
|
250
|
+
if (this.#pgChangeLogEnabled) assert(!opts.sqliteChangeLogWriter && !opts.sqliteChangeLogPurge && !opts.sqliteCatchup, "the SQLite change log is only used when the PG change log is disabled");
|
|
251
|
+
else assert(opts.sqliteChangeLogWriter && opts.sqliteChangeLogPurge && opts.sqliteCatchup, "disabling the PG change log requires the SQLite change log");
|
|
257
252
|
assert(!(this.#pgChangeLogEnabled && opts.pgChangeLogBehindSlot && !backupConfig?.replicaFile), "the PG change log is behind the replication slot, but there is no restored replica to re-initialize it from");
|
|
258
253
|
this.#forwarder = new Forwarder(lc, {
|
|
259
254
|
flowControlConsensusTimeoutProportion: opts.flowControlConsensusTimeoutProportion,
|
|
260
255
|
flowControlSlowSubscriberGracePeriodMs: opts.flowControlSlowSubscriberGracePeriodMs
|
|
261
256
|
});
|
|
262
|
-
const serveOptions = opts.sqliteChangeLogServe;
|
|
263
257
|
const writerOptions = opts.sqliteChangeLogWriter;
|
|
258
|
+
const purgeOptions = opts.sqliteChangeLogPurge;
|
|
264
259
|
const catchupOptions = opts.sqliteCatchup;
|
|
265
|
-
this.#readRouter =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
failureCooldownMs: serveOptions.failureCooldownMs,
|
|
271
|
-
now: serveOptions.now,
|
|
272
|
-
inspect: serveOptions.inspect ?? (() => inspectSQLiteChangeLog(lc, catchupOptions.changeLogFile, writerOptions.identity))
|
|
260
|
+
this.#readRouter = writerOptions && purgeOptions && catchupOptions ? new SQLiteChangeLogReadRouter({
|
|
261
|
+
retentionMs: purgeOptions.retentionMs,
|
|
262
|
+
failureCooldownMs: catchupOptions.failureCooldownMs,
|
|
263
|
+
now: catchupOptions.now,
|
|
264
|
+
inspect: catchupOptions.inspect ?? (() => inspectSQLiteChangeLog(lc, catchupOptions.changeLogFile, writerOptions.identity))
|
|
273
265
|
}) : void 0;
|
|
274
266
|
this.#reservations = backupConfig ? new SnapshotReservations(lc, backupConfig, {
|
|
275
267
|
onClose: (taskID) => {
|
|
@@ -294,40 +286,28 @@ var ChangeStreamerImpl = class {
|
|
|
294
286
|
onDisabled: () => {
|
|
295
287
|
this.#readRouter?.trip(true);
|
|
296
288
|
this.#closeSQLiteCatchup();
|
|
297
|
-
this.#comparator?.stop();
|
|
298
289
|
},
|
|
299
|
-
onRebuilt: () =>
|
|
300
|
-
this.#closeSQLiteCatchup();
|
|
301
|
-
this.#comparator?.invalidate();
|
|
302
|
-
}
|
|
290
|
+
onRebuilt: () => this.#closeSQLiteCatchup()
|
|
303
291
|
}) : void 0;
|
|
304
292
|
this.#purgeScheduler = opts.sqliteChangeLogPurge && this.#changeLogWriter ? new SQLiteChangeLogPurgeScheduler(lc, () => this.#changeLogWriter?.connection, () => this.#forwarder.getAcks(), opts.sqliteChangeLogPurge) : void 0;
|
|
305
293
|
this.#acker = new UpstreamAcker({
|
|
306
294
|
trackPgChangeLog: this.#pgChangeLogEnabled,
|
|
307
295
|
trackBackup: backupConfig ? backupConfig.litestreamVersion === "v5" : !this.#pgChangeLogEnabled
|
|
308
296
|
});
|
|
309
|
-
const replicaFileForInitialization = opts.
|
|
297
|
+
const replicaFileForInitialization = opts.sqliteChangeLogWriter?.replicaFile;
|
|
310
298
|
const replicaFileForReinitialization = this.#pgChangeLogEnabled && opts.pgChangeLogBehindSlot ? backupConfig?.replicaFile : void 0;
|
|
311
299
|
const replicaFile = replicaFileForInitialization ?? replicaFileForReinitialization;
|
|
312
300
|
const replicaSource = replicaFile ? replicaInitializationSource(lc, replicaFile) : void 0;
|
|
313
|
-
this.#initializer = new ChangeLogInitializer(lc, {
|
|
314
|
-
initFromPgChangeLog: this.#pgChangeLogEnabled,
|
|
315
|
-
initFromReplica: replicaFileForInitialization !== void 0
|
|
316
|
-
}, {
|
|
301
|
+
this.#initializer = new ChangeLogInitializer(lc, this.#pgChangeLogEnabled, {
|
|
317
302
|
pgChangeLog: () => must(this.#storer).getStartStreamInitializationParameters(),
|
|
318
303
|
replica: () => must(replicaSource)(),
|
|
319
|
-
reconcileChangeLog: (
|
|
320
|
-
changeLog: () => this.#changeLogWriter?.connection,
|
|
304
|
+
reconcileChangeLog: (seed) => this.#changeLogWriter?.reconcileFromLog(seed),
|
|
321
305
|
reinitializePgChangeLog: replicaFileForReinitialization ? (params) => must(this.#storer).reinitializeFromReplica(params) : void 0
|
|
322
306
|
});
|
|
323
307
|
this.#sqliteCatchupOptions = opts.sqliteCatchup ? {
|
|
324
308
|
...opts.sqliteCatchup,
|
|
325
309
|
cleanupGuard: opts.sqliteCatchup.cleanupGuard ?? this.#purgeScheduler?.cleanupGuard
|
|
326
310
|
} : void 0;
|
|
327
|
-
this.#comparator = this.#storer && opts.sqliteChangeLogCompare && opts.sqliteChangeLogWriter && opts.sqliteCatchup ? new SQLiteChangeLogComparator(lc, shard, opts.sqliteCatchup.changeLogFile, opts.sqliteChangeLogWriter.identity, this.#storer, {
|
|
328
|
-
setTimeoutFn,
|
|
329
|
-
...opts.sqliteChangeLogCompare
|
|
330
|
-
}) : void 0;
|
|
331
311
|
this.#purgeLock = initialPurgeLock;
|
|
332
312
|
this.#autoReset = autoReset;
|
|
333
313
|
this.#state = new RunningState(this.id, void 0, setTimeoutFn);
|
|
@@ -537,29 +517,27 @@ var ChangeStreamerImpl = class {
|
|
|
537
517
|
return downstream;
|
|
538
518
|
}
|
|
539
519
|
/**
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
520
|
+
* Starts the catchup of an accepted `subscriber` from the change log in use
|
|
521
|
+
* (or rejects it), and returns the function that removes the subscriber from
|
|
522
|
+
* wherever it was registered. If this fails partway, any partial
|
|
543
523
|
* registration is removed before the error is rethrown.
|
|
544
524
|
*/
|
|
545
525
|
async #startCatchup(lc, ctx, subscriber) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
const storer = must(this.#storer, "cannot catch up from a disabled PG change log");
|
|
526
|
+
if (this.#storer) {
|
|
527
|
+
const removeFromForwarder = () => {
|
|
528
|
+
lc.info?.(`removing subscriber ${subscriber.id}`);
|
|
529
|
+
this.#forwarder.remove(subscriber);
|
|
530
|
+
};
|
|
552
531
|
try {
|
|
553
532
|
this.#forwarder.add(subscriber);
|
|
554
|
-
storer.catchup(subscriber, ctx.mode);
|
|
533
|
+
this.#storer.catchup(subscriber, ctx.mode);
|
|
555
534
|
} catch (e) {
|
|
556
535
|
removeFromForwarder();
|
|
557
536
|
throw e;
|
|
558
537
|
}
|
|
559
538
|
return removeFromForwarder;
|
|
560
|
-
}
|
|
539
|
+
}
|
|
561
540
|
const sqliteDecision = this.#selectSQLiteCatchup(lc, ctx);
|
|
562
|
-
if (!sqliteDecision) return catchupFromPG();
|
|
563
541
|
if (sqliteDecision.kind === "rejected") {
|
|
564
542
|
lc.warn?.(`${sqliteDecision.terminal ? "rejecting" : "ending"} subscription for ${ctx.id}: ${sqliteDecision.message}`);
|
|
565
543
|
if (sqliteDecision.terminal) subscriber.close(2, sqliteDecision.message);
|
|
@@ -577,30 +555,21 @@ var ChangeStreamerImpl = class {
|
|
|
577
555
|
}
|
|
578
556
|
switch (registration.kind) {
|
|
579
557
|
case "registered":
|
|
580
|
-
lc.debug?.(`serving ${ctx.id} from SQLite catchup`,
|
|
558
|
+
lc.debug?.(`serving ${ctx.id} from SQLite catchup`, { sqliteChangeLogCoverage: coverage });
|
|
581
559
|
this.#recordCatchupRoute("sqlite", reason);
|
|
582
560
|
return removeFromSQLite;
|
|
583
|
-
case "uncovered":
|
|
584
|
-
lc.info?.(`serving ${ctx.id} from PG catchup: subscriber watermark ${ctx.watermark} is below the SQLite change-log minimum ` + registration.minWatermark);
|
|
585
|
-
this.#recordCatchupRoute("pg", "watermark-uncovered");
|
|
586
|
-
return catchupFromPG();
|
|
587
|
-
} else {
|
|
561
|
+
case "uncovered": {
|
|
588
562
|
const message = `earliest supported watermark is ${registration.minWatermark} (requested ${ctx.watermark})`;
|
|
589
|
-
lc.warn?.(`rejecting subscriber at watermark ${ctx.watermark}: the SQLite change log starts at ${registration.minWatermark}
|
|
563
|
+
lc.warn?.(`rejecting subscriber at watermark ${ctx.watermark}: the SQLite change log starts at ${registration.minWatermark}`);
|
|
590
564
|
this.#recordCatchupRoute("none", "watermark-uncovered");
|
|
591
565
|
subscriber.close(2, message);
|
|
592
566
|
return removeFromSQLite;
|
|
593
567
|
}
|
|
594
|
-
case "declined":
|
|
595
|
-
lc.error?.(`
|
|
596
|
-
this.#recordCatchupRoute("pg", "registration-failed");
|
|
597
|
-
return catchupFromPG();
|
|
598
|
-
} else {
|
|
599
|
-
lc.error?.(`ending subscription for ${ctx.id} to retry SQLite catchup: registration failed and the PG change log is disabled`, registration.error);
|
|
568
|
+
case "declined":
|
|
569
|
+
lc.error?.(`ending subscription for ${ctx.id} to retry SQLite catchup: registration failed`, registration.error);
|
|
600
570
|
this.#recordCatchupRoute("none", "registration-failed");
|
|
601
571
|
subscriber.fail(registration.error);
|
|
602
572
|
return removeFromSQLite;
|
|
603
|
-
}
|
|
604
573
|
case "handled":
|
|
605
574
|
this.#recordCatchupRoute("sqlite", "registration-handled");
|
|
606
575
|
return removeFromSQLite;
|
|
@@ -647,38 +616,34 @@ var ChangeStreamerImpl = class {
|
|
|
647
616
|
const backupWatermark = this.#backupWatermark;
|
|
648
617
|
const reservations = this.#reservations;
|
|
649
618
|
if (backupWatermark === void 0 || !reservations?.confirmationsRequired()) return;
|
|
650
|
-
|
|
619
|
+
if (this.#storer) {
|
|
620
|
+
const { minWatermark } = await this.#getChangeLogState();
|
|
621
|
+
for (const taskID of reservations.unconfirmedTaskIDs()) this.#confirmReservation(reservations, taskID, "pg", minWatermark, backupWatermark);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
const router = must(this.#readRouter);
|
|
651
625
|
for (const taskID of reservations.unconfirmedTaskIDs()) {
|
|
652
|
-
let route =
|
|
653
|
-
if (
|
|
654
|
-
if (!
|
|
655
|
-
|
|
656
|
-
route =
|
|
657
|
-
if (route
|
|
626
|
+
let route = router.peek(taskID);
|
|
627
|
+
if (route === void 0) continue;
|
|
628
|
+
if (!route.available) {
|
|
629
|
+
router.release(taskID);
|
|
630
|
+
route = router.pin(taskID);
|
|
631
|
+
if (!route.available) {
|
|
658
632
|
if (reservations.noteConfirmationDelayed(taskID)) this.#reservationConfirmDelays.add(1);
|
|
659
|
-
this.#lc.warn?.(`delaying snapshot reservation for ${taskID}: SQLite change log is unavailable
|
|
633
|
+
this.#lc.warn?.(`delaying snapshot reservation for ${taskID}: SQLite change log is unavailable`);
|
|
660
634
|
continue;
|
|
661
635
|
}
|
|
662
636
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
if (route?.source === "sqlite") minWatermark = must(route.coverage, "a pinned SQLite route must carry its covered range").minWatermark;
|
|
674
|
-
else minWatermark = must(pgState, "a PG reservation route requires the PG change log").minWatermark;
|
|
675
|
-
if (minWatermark <= backupWatermark) {
|
|
676
|
-
reservations.confirmFor(taskID, this.#replicaVersion, backupWatermark, source);
|
|
677
|
-
this.#restoreAdmission?.reservationConfirmed(taskID, backupWatermark);
|
|
678
|
-
} else {
|
|
679
|
-
if (reservations.noteConfirmationDelayed(taskID)) this.#reservationConfirmDelays.add(1);
|
|
680
|
-
this.#lc.error?.(`${source} change-log minWatermark ${minWatermark} is later than backupWatermark ${backupWatermark}. Delaying confirmation of snapshot reservation until next backup.`);
|
|
681
|
-
}
|
|
637
|
+
this.#confirmReservation(reservations, taskID, "sqlite", route.coverage.minWatermark, backupWatermark);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
#confirmReservation(reservations, taskID, source, minWatermark, backupWatermark) {
|
|
641
|
+
if (minWatermark <= backupWatermark) {
|
|
642
|
+
reservations.confirmFor(taskID, this.#replicaVersion, backupWatermark, source);
|
|
643
|
+
this.#restoreAdmission?.reservationConfirmed(taskID, backupWatermark);
|
|
644
|
+
} else {
|
|
645
|
+
if (reservations.noteConfirmationDelayed(taskID)) this.#reservationConfirmDelays.add(1);
|
|
646
|
+
this.#lc.error?.(`${source} change-log minWatermark ${minWatermark} is later than backupWatermark ${backupWatermark}. Delaying confirmation of snapshot reservation until next backup.`);
|
|
682
647
|
}
|
|
683
648
|
}
|
|
684
649
|
#maybeSchedulePGPurge() {
|
|
@@ -781,7 +746,6 @@ var ChangeStreamerImpl = class {
|
|
|
781
746
|
this.#lagReports.resolve({ request: () => {} });
|
|
782
747
|
this.#stream?.changes.cancel();
|
|
783
748
|
this.#purgeScheduler?.stop();
|
|
784
|
-
this.#comparator?.stop();
|
|
785
749
|
this.#sqliteCatchup?.close();
|
|
786
750
|
this.#changeLogWriter?.close();
|
|
787
751
|
await Promise.allSettled([this.#storer?.stop(), this.#source.stop()]);
|
|
@@ -840,43 +804,31 @@ var ChangeStreamerImpl = class {
|
|
|
840
804
|
return this.#currentTransactionCompletion?.promise.then((completion) => completion.watermark) ?? committed;
|
|
841
805
|
}
|
|
842
806
|
#selectSQLiteCatchup(lc, ctx) {
|
|
843
|
-
const opts = this.#sqliteCatchupOptions;
|
|
844
|
-
if (this.#lastForwardedCommitWatermark === void 0
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
807
|
+
const opts = must(this.#sqliteCatchupOptions);
|
|
808
|
+
if (this.#lastForwardedCommitWatermark === void 0) return this.#rejectSQLiteCatchup("not-ready", "SQLite catchup is not ready");
|
|
809
|
+
const route = must(this.#readRouter).consume(ctx.taskID);
|
|
810
|
+
if (!route.available) {
|
|
811
|
+
if (route.reason === "log-unavailable") this.#declineSQLiteCatchup(lc, ctx, opts, `${opts.changeLogFile} is unavailable or incompatible`);
|
|
812
|
+
return this.#rejectSQLiteCatchup(route.reason, `SQLite catchup is unavailable (${route.reason})`);
|
|
848
813
|
}
|
|
849
|
-
|
|
850
|
-
if (
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
if (route.reason === "cold-log") lc.info?.(`serving ${ctx.id} from PG catchup: SQLite change log is still warming`, { sqliteChangeLogCoverage: route.coverage });
|
|
854
|
-
else if (route.reason === "log-unavailable") this.#declineSQLiteCatchup(lc, ctx, opts, `${opts.changeLogFile} is unavailable or incompatible`);
|
|
855
|
-
else lc.debug?.(`serving ${ctx.id} from PG catchup: SQLite route ${route.reason}`, ...route.coverage ? [{ sqliteChangeLogCoverage: route.coverage }] : []);
|
|
856
|
-
return this.#fallbackOrReject(route.reason, `SQLite catchup route ${route.reason} is unavailable and the PG change log is disabled`);
|
|
857
|
-
}
|
|
858
|
-
const coverage = route.coverage;
|
|
859
|
-
assert(coverage, "a SQLite route must carry its covered range");
|
|
860
|
-
if (ctx.watermark < coverage.minWatermark) {
|
|
861
|
-
lc.info?.(`serving ${ctx.id} from PG catchup: subscriber watermark ${ctx.watermark} is below the SQLite change-log minimum ` + coverage.minWatermark, { sqliteChangeLogCoverage: coverage });
|
|
862
|
-
return this.#fallbackOrReject("watermark-uncovered", `earliest supported watermark is ${coverage.minWatermark} (requested ${ctx.watermark})`, true);
|
|
863
|
-
}
|
|
814
|
+
const { coverage } = route;
|
|
815
|
+
if (ctx.watermark < coverage.minWatermark) {
|
|
816
|
+
lc.info?.(`subscriber watermark ${ctx.watermark} is below the SQLite change-log minimum ${coverage.minWatermark}`, { sqliteChangeLogCoverage: coverage });
|
|
817
|
+
return this.#rejectSQLiteCatchup("watermark-uncovered", `earliest supported watermark is ${coverage.minWatermark} (requested ${ctx.watermark})`, true);
|
|
864
818
|
}
|
|
865
|
-
if (!this.#readRouter && !opts.shouldUse?.(ctx)) return this.#fallbackOrReject("selector", "SQLite catchup was not selected and the PG change log is disabled");
|
|
866
|
-
if (this.#readRouter && opts.shouldUse && !opts.shouldUse(ctx)) return this.#fallbackOrReject("selector", "SQLite catchup was not selected and the PG change log is disabled");
|
|
867
819
|
const catchup = this.#sqliteCatchup ?? this.#openSQLiteCatchup(lc, opts, ctx);
|
|
868
|
-
if (catchup) return
|
|
820
|
+
if (!catchup) return this.#rejectSQLiteCatchup("log-unavailable", "SQLite change log is unavailable");
|
|
821
|
+
return {
|
|
869
822
|
kind: "selected",
|
|
870
823
|
catchup,
|
|
871
|
-
reason: route
|
|
872
|
-
coverage
|
|
873
|
-
logWarm: route
|
|
824
|
+
reason: route.reason,
|
|
825
|
+
coverage,
|
|
826
|
+
logWarm: route.reason !== "selected-cold"
|
|
874
827
|
};
|
|
875
|
-
else return this.#fallbackOrReject("log-unavailable", "SQLite change log is unavailable and the PG change log is disabled");
|
|
876
828
|
}
|
|
877
|
-
#
|
|
878
|
-
this.#recordCatchupRoute(
|
|
879
|
-
return
|
|
829
|
+
#rejectSQLiteCatchup(reason, message, terminal = false) {
|
|
830
|
+
this.#recordCatchupRoute("none", reason);
|
|
831
|
+
return {
|
|
880
832
|
kind: "rejected",
|
|
881
833
|
message,
|
|
882
834
|
terminal
|
|
@@ -894,13 +846,10 @@ var ChangeStreamerImpl = class {
|
|
|
894
846
|
*
|
|
895
847
|
* The log may not exist yet -- the writer creates it at the stream loop's
|
|
896
848
|
* first reconcile, and deletes it when it fails soft -- or may exist without
|
|
897
|
-
* content, or may be unreadable.
|
|
898
|
-
* subscription
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
* so each declines here instead. With PG disabled, the caller ends the
|
|
902
|
-
* subscription so that it retries. Neither the failure nor the reader is
|
|
903
|
-
* retained, so a later subscription retries from scratch.
|
|
849
|
+
* content, or may be unreadable. Each declines here -- before `Forwarder.add()`
|
|
850
|
+
* commits the subscriber to SQLite -- and the caller ends the subscription
|
|
851
|
+
* so that it retries. Neither the failure nor the reader is retained, so a
|
|
852
|
+
* later subscription retries from scratch.
|
|
904
853
|
*/
|
|
905
854
|
#openSQLiteCatchup(lc, opts, ctx) {
|
|
906
855
|
let reader;
|
|
@@ -930,7 +879,7 @@ var ChangeStreamerImpl = class {
|
|
|
930
879
|
return this.#sqliteCatchup;
|
|
931
880
|
}
|
|
932
881
|
/**
|
|
933
|
-
* Reports
|
|
882
|
+
* Reports declining SQLite catchup, tracking how long the log has been
|
|
934
883
|
* unavailable so that a subscription that merely arrived before the writer's
|
|
935
884
|
* first reconcile does not look like an incident.
|
|
936
885
|
*/
|
|
@@ -938,7 +887,7 @@ var ChangeStreamerImpl = class {
|
|
|
938
887
|
const now = Date.now();
|
|
939
888
|
this.#changeLogUnavailableSince ??= now;
|
|
940
889
|
const unavailableMs = now - this.#changeLogUnavailableSince;
|
|
941
|
-
lc[unavailableMs >= (opts.notReadyWarnThresholdMs ?? DEFAULT_CHANGE_LOG_UNAVAILABLE_WARN_THRESHOLD_MS) ? "warn" : "debug"]?.(
|
|
890
|
+
lc[unavailableMs >= (opts.notReadyWarnThresholdMs ?? DEFAULT_CHANGE_LOG_UNAVAILABLE_WARN_THRESHOLD_MS) ? "warn" : "debug"]?.(`cannot serve ${ctx.id} from SQLite catchup: ${reason} (unavailable for ${unavailableMs} ms)`, ...error === void 0 ? [] : [error]);
|
|
942
891
|
}
|
|
943
892
|
};
|
|
944
893
|
var CLEANUP_DELAY_MS = DEFAULT_MAX_RETRY_DELAY_MS * 3;
|