@serfab/cadre-core 1.19.0 → 1.20.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/cadre-node.d.ts +118 -16
- package/dist/cadre-node.js +210 -31
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-database.d.ts +2 -1
- package/dist/control-database.js +128 -126
- package/dist/control-database.js.map +1 -1
- package/dist/control-protocol-guard.js +3 -2
- package/dist/control-protocol-guard.js.map +1 -1
- package/dist/control-read-retry.d.ts +19 -16
- package/dist/control-read-retry.js +22 -54
- package/dist/control-read-retry.js.map +1 -1
- package/dist/control-retry.d.ts +50 -6
- package/dist/control-retry.js +53 -6
- package/dist/control-retry.js.map +1 -1
- package/dist/control-stream.js +2 -1
- package/dist/control-stream.js.map +1 -1
- package/dist/control-write-retry.d.ts +24 -16
- package/dist/control-write-retry.js +58 -30
- package/dist/control-write-retry.js.map +1 -1
- package/dist/describe-thrown.d.ts +12 -0
- package/dist/describe-thrown.js +59 -0
- package/dist/describe-thrown.js.map +1 -0
- package/dist/edge-node/config.d.ts +8 -2
- package/dist/edge-node/config.js +5 -1
- package/dist/edge-node/config.js.map +1 -1
- package/dist/edge-node/dissolve.d.ts +1 -1
- package/dist/edge-node/dissolve.js +1 -1
- package/dist/edge-node/dissolve.js.map +1 -1
- package/dist/edge-node/edge-join.js +4 -1
- package/dist/edge-node/edge-join.js.map +1 -1
- package/dist/edge-node/edge-node.d.ts +10 -0
- package/dist/edge-node/edge-node.js +54 -9
- package/dist/edge-node/edge-node.js.map +1 -1
- package/dist/edge-node/options.d.ts +11 -2
- package/dist/edge-node/options.js +11 -4
- package/dist/edge-node/options.js.map +1 -1
- package/dist/edge-node/platform.d.ts +15 -3
- package/dist/edge-node/strand-move.d.ts +0 -2
- package/dist/edge-node/strand-move.js +1 -4
- package/dist/edge-node/strand-move.js.map +1 -1
- package/dist/edge-node/strands.js +5 -3
- package/dist/edge-node/strands.js.map +1 -1
- package/dist/enrollment.js +2 -1
- package/dist/enrollment.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/member-redemption.js +3 -9
- package/dist/member-redemption.js.map +1 -1
- package/dist/node-local-snapshot.js +2 -1
- package/dist/node-local-snapshot.js.map +1 -1
- package/dist/peer-dial.js +3 -2
- package/dist/peer-dial.js.map +1 -1
- package/dist/pending-join-runner.d.ts +29 -2
- package/dist/pending-join-runner.js +60 -20
- package/dist/pending-join-runner.js.map +1 -1
- package/dist/push-notifier-apns.js +8 -7
- package/dist/push-notifier-apns.js.map +1 -1
- package/dist/push-notifier-fcm.js +6 -5
- package/dist/push-notifier-fcm.js.map +1 -1
- package/dist/push-notifier-shared.d.ts +0 -2
- package/dist/push-notifier-shared.js +4 -4
- package/dist/push-notifier-shared.js.map +1 -1
- package/dist/relay-reservation.js +4 -3
- package/dist/relay-reservation.js.map +1 -1
- package/dist/strand-addr-protocol.js +2 -1
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-app-schema-report.d.ts +53 -0
- package/dist/strand-app-schema-report.js +77 -0
- package/dist/strand-app-schema-report.js.map +1 -0
- package/dist/strand-database.d.ts +60 -0
- package/dist/strand-database.js +93 -0
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.js +4 -3
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-protocol.js +4 -3
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +73 -2
- package/dist/strand-instance-manager.js +112 -9
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.d.ts +13 -1
- package/dist/strand-membership-reconciler.js +25 -16
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +16 -2
- package/dist/strand-membership-writer.js +54 -8
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-move.js +4 -6
- package/dist/strand-move.js.map +1 -1
- package/dist/strand-offline.d.ts +102 -0
- package/dist/strand-offline.js +97 -0
- package/dist/strand-offline.js.map +1 -0
- package/dist/types.d.ts +37 -0
- package/dist/types.js.map +1 -1
- package/package.json +8 -8
- package/src/cadre-node.ts +230 -31
- package/src/control-database.ts +5594 -5592
- package/src/control-protocol-guard.ts +3 -2
- package/src/control-read-retry.ts +22 -58
- package/src/control-retry.ts +54 -6
- package/src/control-stream.ts +2 -1
- package/src/control-write-retry.ts +58 -30
- package/src/describe-thrown.ts +60 -0
- package/src/edge-node/config.ts +11 -2
- package/src/edge-node/dissolve.ts +2 -1
- package/src/edge-node/edge-join.ts +2 -1
- package/src/edge-node/edge-node.ts +57 -7
- package/src/edge-node/options.ts +20 -4
- package/src/edge-node/platform.ts +15 -3
- package/src/edge-node/strand-move.ts +1 -5
- package/src/edge-node/strands.ts +74 -72
- package/src/enrollment.ts +2 -1
- package/src/index.ts +27 -1
- package/src/member-redemption.ts +3 -9
- package/src/node-local-snapshot.ts +2 -1
- package/src/peer-dial.ts +605 -604
- package/src/pending-join-runner.ts +68 -22
- package/src/push-notifier-apns.ts +8 -7
- package/src/push-notifier-fcm.ts +6 -5
- package/src/push-notifier-shared.ts +5 -5
- package/src/relay-reservation.ts +1212 -1211
- package/src/strand-addr-protocol.ts +2 -1
- package/src/strand-app-schema-report.ts +115 -0
- package/src/strand-database.ts +123 -1
- package/src/strand-first-sync-gate.ts +600 -599
- package/src/strand-formation-protocol.ts +4 -3
- package/src/strand-instance-manager.ts +137 -10
- package/src/strand-membership-reconciler.ts +942 -928
- package/src/strand-membership-writer.ts +61 -14
- package/src/strand-move.ts +594 -597
- package/src/strand-offline.ts +178 -0
- package/src/types.ts +36 -0
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
type FormationRejectionCode
|
|
43
43
|
} from './strand-formation-rejection.js';
|
|
44
44
|
import type { FormationTokenCheck, FormationTokenRead } from './formation-token.js';
|
|
45
|
+
import { describeThrown, toError } from './describe-thrown.js';
|
|
45
46
|
|
|
46
47
|
const log = debug('sereus:cadre:formation-proto');
|
|
47
48
|
|
|
@@ -918,7 +919,7 @@ async function releaseFormationConnection(connection: Connection): Promise<void>
|
|
|
918
919
|
await connection.close();
|
|
919
920
|
} catch (error) {
|
|
920
921
|
log('closing the formation connection to %s failed; aborting it: %o', connection.remotePeer.toString(), error);
|
|
921
|
-
connection.abort(
|
|
922
|
+
connection.abort(toError(error));
|
|
922
923
|
}
|
|
923
924
|
}
|
|
924
925
|
|
|
@@ -1011,7 +1012,7 @@ function noMachineReached(failures: Array<{ peerId: string; error: FormationUnre
|
|
|
1011
1012
|
*/
|
|
1012
1013
|
function describeAllAddressesFailed(error: unknown): unknown {
|
|
1013
1014
|
if (!(error instanceof AggregateError)) return error;
|
|
1014
|
-
const reasons = error.errors.map(
|
|
1015
|
+
const reasons = error.errors.map(describeThrown);
|
|
1015
1016
|
return new FormationUnreachableError(
|
|
1016
1017
|
`Formation could not reach the inviter at any of the ${reasons.length} addresses tried: ${reasons.join('; ')}`,
|
|
1017
1018
|
{ cause: error }
|
|
@@ -1021,7 +1022,7 @@ function describeAllAddressesFailed(error: unknown): unknown {
|
|
|
1021
1022
|
/** Report a failure that came before any answer as {@link FormationUnreachableError}, keeping its message. */
|
|
1022
1023
|
function asUnreachable(error: unknown): FormationUnreachableError {
|
|
1023
1024
|
if (error instanceof FormationUnreachableError) return error;
|
|
1024
|
-
return new FormationUnreachableError(
|
|
1025
|
+
return new FormationUnreachableError(describeThrown(error), { cause: error });
|
|
1025
1026
|
}
|
|
1026
1027
|
|
|
1027
1028
|
/**
|
|
@@ -2,8 +2,10 @@ import debug from 'debug';
|
|
|
2
2
|
import type { Libp2p, PrivateKey } from '@libp2p/interface';
|
|
3
3
|
import { createLibp2pNode, type IRawStorage } from '@optimystic/db-p2p';
|
|
4
4
|
import { wrapStorageWithCache, disposeStorageCache } from '@serfab/quereus-plugin-sereus';
|
|
5
|
-
import { StrandDatabase } from './strand-database.js';
|
|
5
|
+
import { StrandDatabase, type StrandDatabaseOffline } from './strand-database.js';
|
|
6
6
|
import type { StrandCommitDurability, StrandCommitHeld } from './strand-commit-durability.js';
|
|
7
|
+
import type { StrandOfflineConfig, StrandOfflineListeners, StrandOfflineMode } from './strand-offline.js';
|
|
8
|
+
import type { StrandAppSchemaListeners } from './strand-app-schema-report.js';
|
|
7
9
|
import { PeerJoinBackfill, type PeerJoinBackfillConfig } from './peer-join-backfill.js';
|
|
8
10
|
import { strandNetworkStatePersistence, type StrandNetworkStateStore } from './strand-network-state.js';
|
|
9
11
|
import {
|
|
@@ -49,6 +51,7 @@ import { strandRedialTimings, superviseStrandPeerRedial, type StrandPeerRedial }
|
|
|
49
51
|
import { groupAddrsByPeerId } from './peer-addr-book.js';
|
|
50
52
|
import { isCohortUnreachableRead } from './control-read-retry.js';
|
|
51
53
|
import { declaredCohortReadDeadlineMs, optimysticDialLimits, peerJoinPushBudget, relayReservationBudgetMs, resolveLinkRoundTripMs } from './link-budget.js';
|
|
54
|
+
import { describeThrown } from './describe-thrown.js';
|
|
52
55
|
|
|
53
56
|
const log = debug('sereus:cadre:strand-manager');
|
|
54
57
|
|
|
@@ -304,6 +307,20 @@ export interface StartStrandConfig {
|
|
|
304
307
|
*/
|
|
305
308
|
onCommitHeld?: (event: StrandCommitHeld) => void;
|
|
306
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Offline mode for this strand (docs/strands.md → "Offline mode"), forwarded from
|
|
312
|
+
* `CadreNodeConfig.strandOffline`, with where each database built for the launch reports its
|
|
313
|
+
* queue (`CadreNode` emits them as events). Absent: no database gets an offline queue. The mode
|
|
314
|
+
* itself is the manager's, per strand ({@link StrandInstanceManager.setOfflineMode}).
|
|
315
|
+
*/
|
|
316
|
+
offline?: StrandOfflineConfig & StrandOfflineListeners;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Where each database built for the launch reports an `App` schema apply it held back
|
|
320
|
+
* (`CadreNode` emits them as events). Retained and isolated like {@link onCommitDurability}.
|
|
321
|
+
*/
|
|
322
|
+
appSchema?: StrandAppSchemaListeners;
|
|
323
|
+
|
|
307
324
|
/**
|
|
308
325
|
* Re-announce this strand's delegate peer id (`delegatePeerId` — the strand
|
|
309
326
|
* node's own transport peer id) to ONE relay (`relayAddr`, a direct dial addr
|
|
@@ -561,6 +578,20 @@ export class StrandInstanceManager {
|
|
|
561
578
|
* {@link releaseRuntime}, so a stop or a quiesce cancels it.
|
|
562
579
|
*/
|
|
563
580
|
private unreachableJoinRetries: Map<string, unknown> = new Map();
|
|
581
|
+
/**
|
|
582
|
+
* The offline mode set per strand id ({@link setOfflineMode}); a strand absent here runs in its
|
|
583
|
+
* launch's `initialMode`. Never cleared: the mode belongs to the strand, not to one database, so
|
|
584
|
+
* it outlives hibernation, every rebuild and a stop, for as long as the process runs.
|
|
585
|
+
*/
|
|
586
|
+
private offlineModes: Map<string, StrandOfflineMode> = new Map();
|
|
587
|
+
/**
|
|
588
|
+
* The transaction ids each strand's offline queue listed when its database last closed
|
|
589
|
+
* ({@link releaseRuntime}), for a leave from a hibernating strand, whose queue is then only in
|
|
590
|
+
* its journal ({@link queuedTransactionIds}). Exact while the strand hibernates: nothing drains
|
|
591
|
+
* a journal without a database. Deleted with the instance: on {@link stopStrand}, and when a
|
|
592
|
+
* {@link startStrand} fails.
|
|
593
|
+
*/
|
|
594
|
+
private closedQueues: Map<string, readonly string[]> = new Map();
|
|
564
595
|
private stopping = false;
|
|
565
596
|
|
|
566
597
|
constructor() {
|
|
@@ -675,13 +706,15 @@ export class StrandInstanceManager {
|
|
|
675
706
|
} catch (error) {
|
|
676
707
|
// Status/error first — the (now discarded) record is still what `log` reports on.
|
|
677
708
|
instance.status = 'error';
|
|
678
|
-
instance.error =
|
|
709
|
+
instance.error = describeThrown(error);
|
|
679
710
|
log('Failed to start strand %s: %s', strandId, instance.error);
|
|
680
711
|
// Drop the dead record so this strand id can be launched again. Keep the
|
|
681
712
|
// `launchConfigs` has an entry iff `instances` does invariant — resumeStrand
|
|
682
713
|
// reads both, and a config without an instance would strand the config.
|
|
683
714
|
this.instances.delete(strandId);
|
|
684
715
|
this.launchConfigs.delete(strandId);
|
|
716
|
+
// The cleanup above remembered the half-built database's queue; an untracked strand keeps none.
|
|
717
|
+
this.closedQueues.delete(strandId);
|
|
685
718
|
// The store this launch resolved goes with it: nothing owns it any more, and a
|
|
686
719
|
// retained cache wrapper would be handed back (already retired) on a retry.
|
|
687
720
|
await this.disposeStrandStorage(strandId);
|
|
@@ -1127,7 +1160,9 @@ export class StrandInstanceManager {
|
|
|
1127
1160
|
// reconciler that would otherwise write it is disarmed (see buildStrandRuntime).
|
|
1128
1161
|
bindFounderPeer: config.membershipReconciliation?.enabled !== false,
|
|
1129
1162
|
onCommitDurability: config.onCommitDurability,
|
|
1130
|
-
onCommitHeld: config.onCommitHeld
|
|
1163
|
+
onCommitHeld: config.onCommitHeld,
|
|
1164
|
+
offline: this.offlineDatabaseConfig(strandId, config.offline),
|
|
1165
|
+
appSchema: config.appSchema
|
|
1131
1166
|
});
|
|
1132
1167
|
const storageRepo = node.storageRepo;
|
|
1133
1168
|
const gate = new StrandFirstSyncGate({
|
|
@@ -1155,7 +1190,7 @@ export class StrandInstanceManager {
|
|
|
1155
1190
|
await this.discardDatabaseAttempt(strandId, gate);
|
|
1156
1191
|
log('Strand %s: no seed peer has answered yet, so this joiner cannot build its database (%s); ' +
|
|
1157
1192
|
'its runtime stays up and the build is retried every %dms',
|
|
1158
|
-
strandId,
|
|
1193
|
+
strandId, describeThrown(error), UNREACHABLE_JOIN_RETRY_MS);
|
|
1159
1194
|
return 'awaiting-seed';
|
|
1160
1195
|
}
|
|
1161
1196
|
timing('[buildStrandRuntime:%s] strandDatabase.initialize: %dms', strandId, Math.round(performance.now() - t0));
|
|
@@ -1201,6 +1236,23 @@ export class StrandInstanceManager {
|
|
|
1201
1236
|
return 'built';
|
|
1202
1237
|
}
|
|
1203
1238
|
|
|
1239
|
+
/**
|
|
1240
|
+
* One build's {@link StrandDatabaseOffline}: the strand's journal, which the database resolves as
|
|
1241
|
+
* it initializes (a throw or rejection fails the build), and the strand's mode, which it reads each
|
|
1242
|
+
* time it applies it.
|
|
1243
|
+
*/
|
|
1244
|
+
private offlineDatabaseConfig(strandId: string, offline: StartStrandConfig['offline']): StrandDatabaseOffline | undefined {
|
|
1245
|
+
if (!offline) {
|
|
1246
|
+
return undefined;
|
|
1247
|
+
}
|
|
1248
|
+
const { journal, initialMode: _initialMode, ...listeners } = offline;
|
|
1249
|
+
return {
|
|
1250
|
+
...listeners,
|
|
1251
|
+
journal: () => journal(strandId),
|
|
1252
|
+
mode: () => this.currentOfflineMode(strandId, offline)
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1204
1256
|
/**
|
|
1205
1257
|
* Whether this strand's raw store holds no block. False for a store that cannot list its
|
|
1206
1258
|
* blocks, or whose listing fails, so such a launch probes at once.
|
|
@@ -1288,7 +1340,7 @@ export class StrandInstanceManager {
|
|
|
1288
1340
|
log('Strand %s: releasing the runtime after a failed database retry also failed: %o', strandId, cleanupErr);
|
|
1289
1341
|
});
|
|
1290
1342
|
instance.status = 'error';
|
|
1291
|
-
instance.error =
|
|
1343
|
+
instance.error = describeThrown(error);
|
|
1292
1344
|
log('Strand %s: building the database of a joiner that was waiting for a seed peer failed: %s', strandId, instance.error);
|
|
1293
1345
|
return;
|
|
1294
1346
|
}
|
|
@@ -1361,9 +1413,11 @@ export class StrandInstanceManager {
|
|
|
1361
1413
|
if (gate) {
|
|
1362
1414
|
gate.stop();
|
|
1363
1415
|
this.firstSyncGates.delete(instance.strandId);
|
|
1416
|
+
this.rememberQueue(instance.strandId, gate.database);
|
|
1364
1417
|
await gate.database.close();
|
|
1365
1418
|
}
|
|
1366
1419
|
if (instance.database) {
|
|
1420
|
+
this.rememberQueue(instance.strandId, instance.database);
|
|
1367
1421
|
await instance.database.close();
|
|
1368
1422
|
instance.database = undefined;
|
|
1369
1423
|
}
|
|
@@ -1504,8 +1558,9 @@ export class StrandInstanceManager {
|
|
|
1504
1558
|
* this removal again — the in-memory retained key is the last chance.
|
|
1505
1559
|
*
|
|
1506
1560
|
* Never throws. Quiet no-op for a strand that is untracked, open, or launched
|
|
1507
|
-
* without a party key; a quiesced (hibernating) strand,
|
|
1508
|
-
*
|
|
1561
|
+
* without a party key; a quiesced (hibernating) strand, a strand whose offline queue
|
|
1562
|
+
* still holds transactions (the writer refuses with `StrandOfflineQueueBusyError`), or a
|
|
1563
|
+
* strand whose write quorum is already unreachable, leaves the stale binding behind with a log —
|
|
1509
1564
|
* it grants nothing today (admission is not allowlist-gated) and only
|
|
1510
1565
|
* mis-credits diversity. The strand's own membership reconciler is stopped —
|
|
1511
1566
|
* and its in-flight pass awaited — FIRST, so a pass that was already past its
|
|
@@ -1537,7 +1592,8 @@ export class StrandInstanceManager {
|
|
|
1537
1592
|
return;
|
|
1538
1593
|
}
|
|
1539
1594
|
try {
|
|
1540
|
-
// Background write on the app's database: never join a transaction the app has open
|
|
1595
|
+
// Background write on the app's database: never join a transaction the app has open, and
|
|
1596
|
+
// never wait behind its offline queue (the writer refuses both; the catch below logs it).
|
|
1541
1597
|
await removeMemberPeer(db, {
|
|
1542
1598
|
memberKeyPair: strandMemberKeyPair(config.partyMemberPrivateKey),
|
|
1543
1599
|
peerId
|
|
@@ -1711,7 +1767,7 @@ export class StrandInstanceManager {
|
|
|
1711
1767
|
return instance;
|
|
1712
1768
|
} catch (error) {
|
|
1713
1769
|
instance.status = 'error';
|
|
1714
|
-
instance.error =
|
|
1770
|
+
instance.error = describeThrown(error);
|
|
1715
1771
|
log('Failed to resume strand %s: %s', strandId, instance.error);
|
|
1716
1772
|
throw error;
|
|
1717
1773
|
}
|
|
@@ -1966,6 +2022,7 @@ export class StrandInstanceManager {
|
|
|
1966
2022
|
if (wasGated) {
|
|
1967
2023
|
this.launchConfigs.get(strandId)?.onWritable?.(strandId);
|
|
1968
2024
|
}
|
|
2025
|
+
database.reportPublished();
|
|
1969
2026
|
// Neither throws nor awaits: publishing must stay synchronous. `start()` is a no-op on an
|
|
1970
2027
|
// enforcer already started or stopped, and the reconciler pass chains on the loop's own
|
|
1971
2028
|
// tail, so it cannot overlap a pass already in flight.
|
|
@@ -1973,6 +2030,75 @@ export class StrandInstanceManager {
|
|
|
1973
2030
|
void this.membershipReconcilers.get(strandId)?.reconcile();
|
|
1974
2031
|
}
|
|
1975
2032
|
|
|
2033
|
+
/**
|
|
2034
|
+
* A tracked strand's offline mode: the one last set ({@link setOfflineMode}), else its launch's
|
|
2035
|
+
* `initialMode`, else `'online'`.
|
|
2036
|
+
*
|
|
2037
|
+
* @throws when the strand is not tracked.
|
|
2038
|
+
*/
|
|
2039
|
+
offlineMode(strandId: string): StrandOfflineMode {
|
|
2040
|
+
const config = this.launchConfigs.get(strandId);
|
|
2041
|
+
if (!config) {
|
|
2042
|
+
throw new Error(`Cannot read the offline mode of strand ${strandId}: not tracked`);
|
|
2043
|
+
}
|
|
2044
|
+
return this.currentOfflineMode(strandId, config.offline);
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
private currentOfflineMode(strandId: string, offline: StrandOfflineConfig | undefined): StrandOfflineMode {
|
|
2048
|
+
return this.offlineModes.get(strandId) ?? offline?.initialMode ?? 'online';
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
/**
|
|
2052
|
+
* Set a tracked strand's offline mode, for the rest of the process (see {@link offlineModes}).
|
|
2053
|
+
* A live database takes it now, published or still behind the first-sync gate, for transactions
|
|
2054
|
+
* begun from then on; a build in progress reads it when it applies the mode, and a hibernating
|
|
2055
|
+
* strand gets it at its next build.
|
|
2056
|
+
*
|
|
2057
|
+
* @throws when the strand is not tracked.
|
|
2058
|
+
*/
|
|
2059
|
+
setOfflineMode(strandId: string, mode: StrandOfflineMode): void {
|
|
2060
|
+
const instance = this.instances.get(strandId);
|
|
2061
|
+
if (!instance) {
|
|
2062
|
+
throw new Error(`Cannot set the offline mode of strand ${strandId}: not tracked`);
|
|
2063
|
+
}
|
|
2064
|
+
this.offlineModes.set(strandId, mode);
|
|
2065
|
+
this.liveDatabase(strandId)?.applyOfflineMode();
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
/**
|
|
2069
|
+
* The transaction ids a strand's offline queue holds: its live database's, else what its
|
|
2070
|
+
* database listed when it last closed (a hibernating strand, see {@link closedQueues}), else none.
|
|
2071
|
+
*
|
|
2072
|
+
* NOTE: a strand this process has built no database for reads as empty, though its journal may
|
|
2073
|
+
* hold transactions from an earlier run, which come back if the strand is ever attached again.
|
|
2074
|
+
* If apps are found leaving strands with transactions journaled that way, read the journal here.
|
|
2075
|
+
*/
|
|
2076
|
+
queuedTransactionIds(strandId: string): readonly string[] {
|
|
2077
|
+
return this.liveDatabase(strandId)?.queuedTransactionIds() ?? this.closedQueues.get(strandId) ?? [];
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
/**
|
|
2081
|
+
* Withdraw what the live database's offline queue never sent (`StrandDatabase.discardQueuedTransactions`),
|
|
2082
|
+
* returning the ids it kept; `undefined` when no live database has a queue (a hibernating
|
|
2083
|
+
* strand, whose queue is back once a build restores it from the journal).
|
|
2084
|
+
*/
|
|
2085
|
+
discardQueuedTransactions(strandId: string): readonly string[] | undefined {
|
|
2086
|
+
return this.liveDatabase(strandId)?.discardQueuedTransactions();
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
/** A strand's database: the published one, else the one still behind the first-sync gate. */
|
|
2090
|
+
private liveDatabase(strandId: string): StrandDatabase | undefined {
|
|
2091
|
+
return this.instances.get(strandId)?.database ?? this.firstSyncGates.get(strandId)?.database;
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
/** Keep what a closing database's queue lists, for {@link queuedTransactionIds}; one with no queue changes nothing. */
|
|
2095
|
+
private rememberQueue(strandId: string, database: StrandDatabase): void {
|
|
2096
|
+
const queued = database.queuedTransactionIds();
|
|
2097
|
+
if (queued !== undefined) {
|
|
2098
|
+
this.closedQueues.set(strandId, queued);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
|
|
1976
2102
|
/** Reject every {@link whenWritable} waiter for a strand that is going away. */
|
|
1977
2103
|
private rejectWritableWaiters(strandId: string, reason: string): void {
|
|
1978
2104
|
const waiters = this.writableWaiters.get(strandId);
|
|
@@ -2060,12 +2186,13 @@ export class StrandInstanceManager {
|
|
|
2060
2186
|
instance.status = 'stopped';
|
|
2061
2187
|
this.instances.delete(strandId);
|
|
2062
2188
|
this.launchConfigs.delete(strandId);
|
|
2189
|
+
this.closedQueues.delete(strandId);
|
|
2063
2190
|
// Storage is released only here — NOT in releaseRuntime, which a quiesce shares.
|
|
2064
2191
|
await this.disposeStrandStorage(strandId);
|
|
2065
2192
|
log('Strand %s stopped successfully', strandId);
|
|
2066
2193
|
} catch (error) {
|
|
2067
2194
|
instance.status = 'error';
|
|
2068
|
-
instance.error =
|
|
2195
|
+
instance.error = describeThrown(error);
|
|
2069
2196
|
log('Error stopping strand %s: %s', strandId, instance.error);
|
|
2070
2197
|
throw error;
|
|
2071
2198
|
}
|