@optimystic/db-core 1.18.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/README.md +2 -1
- package/dist/src/blocks/helpers.d.ts +7 -0
- package/dist/src/blocks/helpers.d.ts.map +1 -1
- package/dist/src/blocks/helpers.js +7 -1
- package/dist/src/blocks/helpers.js.map +1 -1
- package/dist/src/btree/btree.d.ts +100 -4
- package/dist/src/btree/btree.d.ts.map +1 -1
- package/dist/src/btree/btree.js +252 -90
- package/dist/src/btree/btree.js.map +1 -1
- package/dist/src/btree/node-division.d.ts +37 -0
- package/dist/src/btree/node-division.d.ts.map +1 -0
- package/dist/src/btree/node-division.js +133 -0
- package/dist/src/btree/node-division.js.map +1 -0
- package/dist/src/chain/chain.d.ts +23 -0
- package/dist/src/chain/chain.d.ts.map +1 -1
- package/dist/src/chain/chain.js +43 -6
- package/dist/src/chain/chain.js.map +1 -1
- package/dist/src/cluster/structs.d.ts +41 -8
- package/dist/src/cluster/structs.d.ts.map +1 -1
- package/dist/src/cluster/structs.js +18 -7
- package/dist/src/cluster/structs.js.map +1 -1
- package/dist/src/collection/action.d.ts +29 -0
- package/dist/src/collection/action.d.ts.map +1 -1
- package/dist/src/collection/action.js +6 -0
- package/dist/src/collection/action.js.map +1 -1
- package/dist/src/collection/collection.d.ts +566 -120
- package/dist/src/collection/collection.d.ts.map +1 -1
- package/dist/src/collection/collection.js +1084 -495
- package/dist/src/collection/collection.js.map +1 -1
- package/dist/src/collection/head-commit.d.ts +110 -0
- package/dist/src/collection/head-commit.d.ts.map +1 -0
- package/dist/src/collection/head-commit.js +65 -0
- package/dist/src/collection/head-commit.js.map +1 -0
- package/dist/src/collection/index.d.ts +2 -0
- package/dist/src/collection/index.d.ts.map +1 -1
- package/dist/src/collection/index.js +2 -0
- package/dist/src/collection/index.js.map +1 -1
- package/dist/src/collection/segments.d.ts +77 -0
- package/dist/src/collection/segments.d.ts.map +1 -0
- package/dist/src/collection/segments.js +110 -0
- package/dist/src/collection/segments.js.map +1 -0
- package/dist/src/collection/struct.d.ts +176 -1
- package/dist/src/collection/struct.d.ts.map +1 -1
- package/dist/src/collection/struct.js +70 -0
- package/dist/src/collection/struct.js.map +1 -1
- package/dist/src/collection/write-attempts.d.ts +245 -0
- package/dist/src/collection/write-attempts.d.ts.map +1 -0
- package/dist/src/collection/write-attempts.js +439 -0
- package/dist/src/collection/write-attempts.js.map +1 -0
- package/dist/src/collections/tree/struct.d.ts +100 -17
- package/dist/src/collections/tree/struct.d.ts.map +1 -1
- package/dist/src/collections/tree/struct.js +38 -7
- package/dist/src/collections/tree/struct.js.map +1 -1
- package/dist/src/collections/tree/tree.d.ts +17 -5
- package/dist/src/collections/tree/tree.d.ts.map +1 -1
- package/dist/src/collections/tree/tree.js +117 -29
- package/dist/src/collections/tree/tree.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/log/log.d.ts +5 -1
- package/dist/src/log/log.d.ts.map +1 -1
- package/dist/src/log/log.js +7 -1
- package/dist/src/log/log.js.map +1 -1
- package/dist/src/network/block-size.d.ts +67 -0
- package/dist/src/network/block-size.d.ts.map +1 -0
- package/dist/src/network/block-size.js +82 -0
- package/dist/src/network/block-size.js.map +1 -0
- package/dist/src/network/i-repo.d.ts +3 -0
- package/dist/src/network/i-repo.d.ts.map +1 -1
- package/dist/src/network/index.d.ts +5 -0
- package/dist/src/network/index.d.ts.map +1 -1
- package/dist/src/network/index.js +5 -0
- package/dist/src/network/index.js.map +1 -1
- package/dist/src/network/promise-shortfall-error.d.ts +40 -0
- package/dist/src/network/promise-shortfall-error.d.ts.map +1 -0
- package/dist/src/network/promise-shortfall-error.js +67 -0
- package/dist/src/network/promise-shortfall-error.js.map +1 -0
- package/dist/src/network/refuse-solo.d.ts +8 -0
- package/dist/src/network/refuse-solo.d.ts.map +1 -0
- package/dist/src/network/refuse-solo.js +8 -0
- package/dist/src/network/refuse-solo.js.map +1 -0
- package/dist/src/network/stale-failure.d.ts +20 -3
- package/dist/src/network/stale-failure.d.ts.map +1 -1
- package/dist/src/network/stale-failure.js +24 -3
- package/dist/src/network/stale-failure.js.map +1 -1
- package/dist/src/network/struct.d.ts +161 -13
- package/dist/src/network/struct.d.ts.map +1 -1
- package/dist/src/network/struct.js.map +1 -1
- package/dist/src/network/transaction-size.d.ts +59 -0
- package/dist/src/network/transaction-size.d.ts.map +1 -0
- package/dist/src/network/transaction-size.js +74 -0
- package/dist/src/network/transaction-size.js.map +1 -0
- package/dist/src/network/validity-rejected-error.d.ts +28 -0
- package/dist/src/network/validity-rejected-error.d.ts.map +1 -0
- package/dist/src/network/validity-rejected-error.js +51 -0
- package/dist/src/network/validity-rejected-error.js.map +1 -0
- package/dist/src/offline/entry.d.ts +72 -0
- package/dist/src/offline/entry.d.ts.map +1 -0
- package/dist/src/offline/entry.js +73 -0
- package/dist/src/offline/entry.js.map +1 -0
- package/dist/src/offline/index.d.ts +5 -0
- package/dist/src/offline/index.d.ts.map +1 -0
- package/dist/src/offline/index.js +5 -0
- package/dist/src/offline/index.js.map +1 -0
- package/dist/src/offline/journal.d.ts +61 -0
- package/dist/src/offline/journal.d.ts.map +1 -0
- package/dist/src/offline/journal.js +2 -0
- package/dist/src/offline/journal.js.map +1 -0
- package/dist/src/offline/queue.d.ts +484 -0
- package/dist/src/offline/queue.d.ts.map +1 -0
- package/dist/src/offline/queue.js +1236 -0
- package/dist/src/offline/queue.js.map +1 -0
- package/dist/src/offline/reachability.d.ts +25 -0
- package/dist/src/offline/reachability.d.ts.map +1 -0
- package/dist/src/offline/reachability.js +13 -0
- package/dist/src/offline/reachability.js.map +1 -0
- package/dist/src/offline/status.d.ts +148 -0
- package/dist/src/offline/status.d.ts.map +1 -0
- package/dist/src/offline/status.js +63 -0
- package/dist/src/offline/status.js.map +1 -0
- package/dist/src/offline/wake.d.ts +30 -0
- package/dist/src/offline/wake.d.ts.map +1 -0
- package/dist/src/offline/wake.js +68 -0
- package/dist/src/offline/wake.js.map +1 -0
- package/dist/src/reactivity/config.d.ts +8 -4
- package/dist/src/reactivity/config.d.ts.map +1 -1
- package/dist/src/reactivity/config.js +7 -3
- package/dist/src/reactivity/config.js.map +1 -1
- package/dist/src/reactivity/rotation.d.ts +9 -3
- package/dist/src/reactivity/rotation.d.ts.map +1 -1
- package/dist/src/reactivity/rotation.js +8 -2
- package/dist/src/reactivity/rotation.js.map +1 -1
- package/dist/src/testing/test-transactor.d.ts +31 -0
- package/dist/src/testing/test-transactor.d.ts.map +1 -1
- package/dist/src/testing/test-transactor.js +60 -0
- package/dist/src/testing/test-transactor.js.map +1 -1
- package/dist/src/transaction/commit-failure-class.d.ts +103 -0
- package/dist/src/transaction/commit-failure-class.d.ts.map +1 -0
- package/dist/src/transaction/commit-failure-class.js +96 -0
- package/dist/src/transaction/commit-failure-class.js.map +1 -0
- package/dist/src/transaction/coordinator.d.ts +224 -31
- package/dist/src/transaction/coordinator.d.ts.map +1 -1
- package/dist/src/transaction/coordinator.js +841 -362
- package/dist/src/transaction/coordinator.js.map +1 -1
- package/dist/src/transaction/entry-commit.d.ts +139 -0
- package/dist/src/transaction/entry-commit.d.ts.map +1 -0
- package/dist/src/transaction/entry-commit.js +199 -0
- package/dist/src/transaction/entry-commit.js.map +1 -0
- package/dist/src/transaction/index.d.ts +4 -1
- package/dist/src/transaction/index.d.ts.map +1 -1
- package/dist/src/transaction/index.js +1 -0
- package/dist/src/transaction/index.js.map +1 -1
- package/dist/src/transaction/transaction.d.ts +20 -0
- package/dist/src/transaction/transaction.d.ts.map +1 -1
- package/dist/src/transaction/validator.d.ts +7 -0
- package/dist/src/transaction/validator.d.ts.map +1 -1
- package/dist/src/transaction/validator.js +21 -12
- package/dist/src/transaction/validator.js.map +1 -1
- package/dist/src/transactor/change-notifier.d.ts +13 -4
- package/dist/src/transactor/change-notifier.d.ts.map +1 -1
- package/dist/src/transactor/change-notifier.js.map +1 -1
- package/dist/src/transactor/network-transactor.d.ts +58 -8
- package/dist/src/transactor/network-transactor.d.ts.map +1 -1
- package/dist/src/transactor/network-transactor.js +244 -50
- package/dist/src/transactor/network-transactor.js.map +1 -1
- package/dist/src/transactor/transactor-source.d.ts +22 -11
- package/dist/src/transactor/transactor-source.d.ts.map +1 -1
- package/dist/src/transactor/transactor-source.js +9 -13
- package/dist/src/transactor/transactor-source.js.map +1 -1
- package/dist/src/transactor/transactor.d.ts +14 -0
- package/dist/src/transactor/transactor.d.ts.map +1 -1
- package/dist/src/transform/digest.d.ts +20 -0
- package/dist/src/transform/digest.d.ts.map +1 -1
- package/dist/src/transform/digest.js +23 -3
- package/dist/src/transform/digest.js.map +1 -1
- package/dist/src/utility/visit-every.d.ts +14 -0
- package/dist/src/utility/visit-every.d.ts.map +1 -0
- package/dist/src/utility/visit-every.js +27 -0
- package/dist/src/utility/visit-every.js.map +1 -0
- package/package.json +1 -1
- package/src/blocks/helpers.ts +8 -1
- package/src/btree/btree.ts +266 -88
- package/src/btree/node-division.ts +155 -0
- package/src/chain/chain.ts +55 -6
- package/src/cluster/structs.ts +42 -7
- package/src/collection/action.ts +34 -0
- package/src/collection/collection.ts +1167 -540
- package/src/collection/head-commit.ts +148 -0
- package/src/collection/index.ts +2 -0
- package/src/collection/segments.ts +149 -0
- package/src/collection/struct.ts +201 -1
- package/src/collection/write-attempts.ts +506 -0
- package/src/collections/tree/struct.ts +97 -17
- package/src/collections/tree/tree.ts +129 -31
- package/src/index.ts +2 -0
- package/src/log/log.ts +7 -1
- package/src/network/block-size.ts +81 -0
- package/src/network/i-repo.ts +3 -0
- package/src/network/index.ts +5 -0
- package/src/network/promise-shortfall-error.ts +69 -0
- package/src/network/refuse-solo.ts +7 -0
- package/src/network/stale-failure.ts +27 -4
- package/src/network/struct.ts +169 -15
- package/src/network/transaction-size.ts +73 -0
- package/src/network/validity-rejected-error.ts +55 -0
- package/src/offline/entry.ts +127 -0
- package/src/offline/index.ts +4 -0
- package/src/offline/journal.ts +60 -0
- package/src/offline/queue.ts +1342 -0
- package/src/offline/reachability.ts +32 -0
- package/src/offline/status.ts +183 -0
- package/src/offline/wake.ts +67 -0
- package/src/reactivity/config.ts +8 -4
- package/src/reactivity/rotation.ts +9 -3
- package/src/testing/test-transactor.ts +65 -0
- package/src/transaction/commit-failure-class.ts +133 -0
- package/src/transaction/coordinator.ts +969 -393
- package/src/transaction/entry-commit.ts +285 -0
- package/src/transaction/index.ts +4 -0
- package/src/transaction/transaction.ts +21 -0
- package/src/transaction/validator.ts +22 -12
- package/src/transactor/change-notifier.ts +13 -4
- package/src/transactor/network-transactor.ts +252 -55
- package/src/transactor/transactor-source.ts +29 -13
- package/src/transactor/transactor.ts +16 -0
- package/src/transform/digest.ts +36 -3
- package/src/utility/visit-every.ts +25 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import type { Collection } from '../collection/collection.js';
|
|
2
|
+
import type { EntryId } from '../collection/segments.js';
|
|
3
|
+
import { ActionRefusedError } from '../collection/struct.js';
|
|
4
|
+
import type { SyncOptions } from '../collection/struct.js';
|
|
5
|
+
import type { RandFn } from '../utility/backoff.js';
|
|
6
|
+
import type { ICohortReachability } from './reachability.js';
|
|
7
|
+
import type { EntryStatus, OfflineQueueState, QueuedEntry } from './status.js';
|
|
8
|
+
import type { IOfflineJournal, JournalDriveState } from './journal.js';
|
|
9
|
+
export type OfflineQueueOptions = {
|
|
10
|
+
/** The gate of docs/offline-sync.md §When to submit. Default: always reachable. */
|
|
11
|
+
reachability?: ICohortReachability;
|
|
12
|
+
/** An external wake signal — a gate's `ICohortReachability.onChange`, say: subscribe the queue's
|
|
13
|
+
* {@link OfflineQueue.wake} and return the unsubscribe, which {@link OfflineQueue.dispose} calls.
|
|
14
|
+
* The Quereus plugin does not use it: its controller calls `wake` itself, after retrying a deferred
|
|
15
|
+
* restore. */
|
|
16
|
+
wakeOn?: (wake: () => void) => () => void;
|
|
17
|
+
/** Fail an entry that stays unsettled this long, with reason `expired`. Default: no limit. An
|
|
18
|
+
* entry in doubt is never expired; it expires once its doubt resolves without committing. */
|
|
19
|
+
expireAfterMs?: number;
|
|
20
|
+
/** The re-check timer while the cohort is unreachable or after a transient failure: exponential
|
|
21
|
+
* from `baseMs` to `maxMs`, jittered (`jitteredBackoffMs`). Defaults 1 s / 60 s. */
|
|
22
|
+
recheck?: {
|
|
23
|
+
baseMs?: number;
|
|
24
|
+
maxMs?: number;
|
|
25
|
+
rand?: RandFn;
|
|
26
|
+
};
|
|
27
|
+
/** Retry bounds handed to each submission (`Collection.commitHead` / `TransactionCoordinator.commitEntry`). */
|
|
28
|
+
submit?: Pick<SyncOptions, 'maxAttempts' | 'deadlineMs' | 'baseBackoffMs' | 'maxBackoffMs' | 'maxStalledAttempts'>;
|
|
29
|
+
/** Let an entry be committed by a lone node that knows it is not alone. Unless this is `true`,
|
|
30
|
+
* every submission sets `SyncOptions.refuseSoloCommit`, so a coordinator whose cohort is only
|
|
31
|
+
* itself refuses the entry while it knows of absent members, awaits a bootstrap peer or cannot
|
|
32
|
+
* route the write, and the entry waits for its cohort (`waitingFor: 'cohort'`) rather than settling
|
|
33
|
+
* `committed` on a write only this machine holds (docs/offline-sync.md §When to submit: the
|
|
34
|
+
* reachability gate). A node that is genuinely alone commits either way. Default `false`. */
|
|
35
|
+
allowSoloCommit?: boolean;
|
|
36
|
+
/** The durable journal (docs/offline-sync.md §Persistence), called at every moment the design's
|
|
37
|
+
* write ordering names: before `queued` is emitted, before each send, after a partial commit and
|
|
38
|
+
* an identity renewal, and before each terminal status. Absent, nothing is journaled and the queue
|
|
39
|
+
* is in memory only. */
|
|
40
|
+
journal?: IOfflineJournal;
|
|
41
|
+
/** Clock, for tests. Default `Date.now`. */
|
|
42
|
+
now?: () => number;
|
|
43
|
+
};
|
|
44
|
+
/** What {@link OfflineQueue.restore} puts an entry back from: the journal's entry record, the
|
|
45
|
+
* collections the record's segments name (opened by the caller), and the drive record, when one was
|
|
46
|
+
* written. */
|
|
47
|
+
export type RestoreInit = {
|
|
48
|
+
readonly id: EntryId;
|
|
49
|
+
readonly seq: number;
|
|
50
|
+
readonly queuedAt: number;
|
|
51
|
+
readonly expiresAt?: number;
|
|
52
|
+
/** The collections the entry sealed a segment in, in the record's order — `stage` is called for
|
|
53
|
+
* each, in this order. */
|
|
54
|
+
readonly collections: readonly Collection<any>[];
|
|
55
|
+
/** From the drive record, when one was written: the entry is then in doubt and resumes these.
|
|
56
|
+
* Absent: nothing was ever sent; a fresh action id is minted. */
|
|
57
|
+
readonly drive?: JournalDriveState;
|
|
58
|
+
};
|
|
59
|
+
/** Per collection, what {@link OfflineQueue.restore}'s `stage` found: the segment is in place
|
|
60
|
+
* (possibly refused — the refusal is reported here, since the collection cannot report it to a
|
|
61
|
+
* queue that does not yet hold the entry; see `Collection.restoreSealed`), or the collection already
|
|
62
|
+
* holds the entry's recorded attempt as committed (`Collection.holdsCommitted`), so nothing was
|
|
63
|
+
* staged. */
|
|
64
|
+
export type RestoredSegment = {
|
|
65
|
+
kind: 'staged';
|
|
66
|
+
refused?: ActionRefusedError;
|
|
67
|
+
} | {
|
|
68
|
+
kind: 'already-committed';
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The offline-sync queue (docs/offline-sync.md §Draining): an in-memory list of locally committed
|
|
72
|
+
* entries, each the sealed segments one local commit left in the collections it wrote, drained one
|
|
73
|
+
* at a time in queue order once the cohort can be reached.
|
|
74
|
+
*
|
|
75
|
+
* **One drain loop per queue, serialised.** At most one submission is on the network at a time, and
|
|
76
|
+
* the loop is the only thing that removes entries' segments from the collections apart from
|
|
77
|
+
* {@link discard}, whose removal runs on the same removal chain. Each iteration: park while a
|
|
78
|
+
* {@link restore} holds the drain; apply the refusals {@link onSealedRefused} has collected; expire
|
|
79
|
+
* what has outlived `expireAfterMs`; wait for a wake when the queue is empty; fail the head when a
|
|
80
|
+
* collection already records its refusal; ask the reachability gate; submit the head —
|
|
81
|
+
* `Collection.commitHead` for an entry over one collection, `TransactionCoordinator.commitEntry`
|
|
82
|
+
* over several — and apply the outcome by its class (`classifyCommitFailure`). The gate and the
|
|
83
|
+
* transient failures share one re-check timer, whose step a wake or a committed entry resets.
|
|
84
|
+
*
|
|
85
|
+
* **A partly committed entry is finished, not rolled back** (docs/offline-sync.md §Partial commits):
|
|
86
|
+
* the committed collections' segments are consumed, the entry stays at the head in doubt, and each
|
|
87
|
+
* later submission drives only the collections still holding its segment, under the same action id.
|
|
88
|
+
*
|
|
89
|
+
* **Removing an entry cascades** (docs/offline-sync.md §Removing an entry): a failed entry's
|
|
90
|
+
* segments are dropped from its collections, each drop replays what remains, a later entry the
|
|
91
|
+
* replay refuses is reported through {@link onSealedRefused} and failed in turn with `causedBy`
|
|
92
|
+
* set, until nothing is pending. The callback runs under the collection latch, so it only records
|
|
93
|
+
* and wakes; the loop acts.
|
|
94
|
+
*
|
|
95
|
+
* **The journal is written through at every step of an entry's life** (docs/offline-sync.md
|
|
96
|
+
* §Write ordering), when one is given: {@link enqueue} writes the entry record before it admits the
|
|
97
|
+
* entry, every send is preceded by the drive record (`IOfflineJournal.driving`, the write-ahead that
|
|
98
|
+
* makes the identity rule survive a crash), a partial commit and an identity renewal rewrite it, and
|
|
99
|
+
* each terminal status is written before it is emitted. {@link restore} is the inverse, for a journal
|
|
100
|
+
* putting its records back after a restart.
|
|
101
|
+
*
|
|
102
|
+
* Everything an application sees goes through {@link onStatus} and {@link onQueueState}; a listener
|
|
103
|
+
* that throws is logged and never breaks the drain.
|
|
104
|
+
*/
|
|
105
|
+
export declare class OfflineQueue {
|
|
106
|
+
private readonly list;
|
|
107
|
+
private readonly byId;
|
|
108
|
+
private nextSeq;
|
|
109
|
+
private readonly reachability;
|
|
110
|
+
private readonly waker;
|
|
111
|
+
private readonly submitOptions;
|
|
112
|
+
private readonly refuseSoloCommit;
|
|
113
|
+
private readonly expireAfterMs;
|
|
114
|
+
private readonly journal;
|
|
115
|
+
private readonly now;
|
|
116
|
+
private readonly unsubscribeWake;
|
|
117
|
+
private readonly statusListeners;
|
|
118
|
+
private readonly stateListeners;
|
|
119
|
+
private lastState;
|
|
120
|
+
private unclassifiedFailures;
|
|
121
|
+
private readonly pendingRefusals;
|
|
122
|
+
/** The entry whose segments are being dropped, while they are: the attribution of the refusals
|
|
123
|
+
* those drops report (see {@link causeOf}). */
|
|
124
|
+
private removing;
|
|
125
|
+
/** Every removal — the loop's and {@link discard}'s — runs on this chain, one at a time, so two
|
|
126
|
+
* never interleave their drops and {@link causeOf} always names one removal. Never rejects: a
|
|
127
|
+
* removal's throw reaches whoever awaited that removal, or {@link noteDefect} for a discard. */
|
|
128
|
+
private removals;
|
|
129
|
+
/** Removals chained and not yet finished — a `discard`'s runs off the loop's path, and
|
|
130
|
+
* `whenDrained` answers at once only when none is. */
|
|
131
|
+
private pendingRemovals;
|
|
132
|
+
/** Every {@link restore} runs on this chain, one at a time, so two never hold the drain at once.
|
|
133
|
+
* Never rejects: a restore's throw reaches its own caller. */
|
|
134
|
+
private restores;
|
|
135
|
+
/** The hold the restore in progress has on the drain, while it has one (see {@link restore}). */
|
|
136
|
+
private hold;
|
|
137
|
+
/** The entry a {@link restore} has registered and not yet admitted: listed, so the refusals its
|
|
138
|
+
* insertion reports about other entries are attributed and its `stage` can read its position, but
|
|
139
|
+
* not yet discardable.
|
|
140
|
+
* NOTE: a `discard` of ANOTHER entry chained while `stage` runs is not held back; its drops run
|
|
141
|
+
* beside the insertion, serialised per collection only by the collection latch, and a refusal of
|
|
142
|
+
* the restoring entry's already-inserted segment that such a drop's replay reports is attributed
|
|
143
|
+
* by {@link causeOf} to the entry being discarded. Fine while restores run at start-up, before an
|
|
144
|
+
* application discards anything; if that attribution ever misleads, make `discard` wait out the
|
|
145
|
+
* hold too. */
|
|
146
|
+
private restoring;
|
|
147
|
+
private inFlight;
|
|
148
|
+
private loop;
|
|
149
|
+
/** The loop ran and has exited (disposal, or a defect): nothing parks any more. */
|
|
150
|
+
private loopStopped;
|
|
151
|
+
/** The loop is parked on an empty queue (so `whenDrained` can answer at once). */
|
|
152
|
+
private waitingForWork;
|
|
153
|
+
private readonly drainedWaiters;
|
|
154
|
+
private disposed;
|
|
155
|
+
private disposal;
|
|
156
|
+
/** The error that stopped the drain (`SealedSegmentsError` out of a submission, a removal that
|
|
157
|
+
* threw): `whenDrained` rejects with it and `enqueue` refuses. */
|
|
158
|
+
private defect;
|
|
159
|
+
constructor(options?: OfflineQueueOptions);
|
|
160
|
+
/**
|
|
161
|
+
* Seal each collection's open segment under a new entry, write the journal's entry record, and
|
|
162
|
+
* queue it — in that order, so an entry is never admitted that the journal does not hold
|
|
163
|
+
* (docs/offline-sync.md §Write ordering, rule 1). `undefined` when no collection had anything
|
|
164
|
+
* staged — nothing to queue, nothing sealed, nothing written (`Collection.sealPending` answers
|
|
165
|
+
* `false` and changes nothing for an empty open segment, so a sibling with nothing staged is
|
|
166
|
+
* simply not part of the entry). Emits `queued` before resolving, so a caller can attribute it to
|
|
167
|
+
* the commit it is in. Starts the drain on the first call.
|
|
168
|
+
*
|
|
169
|
+
* **A journal write that throws fails the enqueue**: every collection sealed is unsealed again, in
|
|
170
|
+
* reverse sealing order (`Collection.unseal`, which puts each segment's actions back into its open
|
|
171
|
+
* segment), nothing is registered, no status is emitted, and the journal's error is rethrown. The
|
|
172
|
+
* caller then rolls its transaction back as for any failed commit. Without a journal the write is
|
|
173
|
+
* skipped and the enqueue cannot fail this way; it is one path either way.
|
|
174
|
+
*
|
|
175
|
+
* Latch-free like `sealPending`: the caller brackets it (no act or commit of these collections is
|
|
176
|
+
* in flight, and no second enqueue of them runs until this one has resolved — the unseal on
|
|
177
|
+
* failure requires each segment to still be the newest sealed one).
|
|
178
|
+
*
|
|
179
|
+
* @throws QueueDisposedError after {@link dispose}; the drain's defect, as `cause`, once the
|
|
180
|
+
* drain has stopped on one (nothing queued then would ever drain); whatever the journal threw. */
|
|
181
|
+
enqueue(collections: readonly Collection<any>[], init?: {
|
|
182
|
+
id?: EntryId;
|
|
183
|
+
timestamp?: number;
|
|
184
|
+
}): Promise<QueuedEntry | undefined>;
|
|
185
|
+
/**
|
|
186
|
+
* Put an entry back from a journal's records after a restart (docs/offline-sync.md §Restore after
|
|
187
|
+
* a restart): the only way to register an entry whose segments `enqueue` did not seal. The entry
|
|
188
|
+
* is registered first — inserted by `seq`, so a record restored late sits ahead of entries queued
|
|
189
|
+
* since — and `stage` is then called for each of its collections, in `init.collections` order, to
|
|
190
|
+
* put the segment in place (`Collection.restoreSealed`, at the position the caller finds by
|
|
191
|
+
* reading {@link entries}) or to answer that the collection already holds the entry's recorded
|
|
192
|
+
* attempt as committed (`Collection.holdsCommitted`). What `stage` answers decides what follows:
|
|
193
|
+
*
|
|
194
|
+
* - every collection `already-committed`: the entry is settled `committed` at once, with a
|
|
195
|
+
* durability whose every collection has an `undefined` class (the write is saved; who holds it
|
|
196
|
+
* is unknown), the journal's `settled` written as for any commit, and no `queued` status;
|
|
197
|
+
* - some `already-committed`: those are recorded as committed with `undefined` durability and the
|
|
198
|
+
* entry stays queued in doubt, as after a partial commit, the next submission driving the rest;
|
|
199
|
+
* - a `staged` segment `refused`: the refusal is queued for the loop's first step, which fails the
|
|
200
|
+
* entry through the ordinary cascade (with no `causedBy`);
|
|
201
|
+
* - otherwise it is simply queued. In every case but the first, `queued` is emitted and the drain
|
|
202
|
+
* woken, and the result is the entry as {@link entries} lists it.
|
|
203
|
+
*
|
|
204
|
+
* **The drain is held for the whole call.** The call waits until the loop is parked between
|
|
205
|
+
* iterations — not mid-submission, not mid-removal — holds it there, registers the entry, runs
|
|
206
|
+
* `stage`, and releases. A segment inserted ahead of the current head while that head's commit
|
|
207
|
+
* is on the network would fail the commit's own "head still first" assertion when it retakes the
|
|
208
|
+
* latch, and a `commitHead` that finds another segment ahead of the one it was asked for throws
|
|
209
|
+
* `SealedSegmentsError` (`not-head`), which the loop reads as a defect. A loop that is not
|
|
210
|
+
* running, or is parked on an empty queue, counts as parked at once; several restores serialise.
|
|
211
|
+
* `discard` during a restore is refused for the entry being restored (`UnknownEntryError`: it is
|
|
212
|
+
* registered but not yet admitted) and allowed for others, whose removals run on the removal
|
|
213
|
+
* chain the hold waits out before `stage` runs. A removal chained DURING `stage` runs beside it,
|
|
214
|
+
* serialised per collection by the collection latch only.
|
|
215
|
+
*
|
|
216
|
+
* **Identity.** With `init.drive`: the action id, the attempts to resume and the committed
|
|
217
|
+
* collections are taken from it, and the entry is in doubt when either map is non-empty. Without:
|
|
218
|
+
* a fresh action id, nothing retained, not in doubt.
|
|
219
|
+
*
|
|
220
|
+
* **A `stage` that throws** rolls the registration back: the entry leaves the queue, every segment
|
|
221
|
+
* `stage` already put in place is dropped (`Collection.dropSealed`), nothing is emitted, and the
|
|
222
|
+
* error is rethrown.
|
|
223
|
+
*
|
|
224
|
+
* **`dispose` during a restore.** A restore that has not started `stage` when the queue is
|
|
225
|
+
* disposed rejects with `QueueDisposedError` and releases the hold; one that has finishes its
|
|
226
|
+
* registration (the loop is stopping anyway, and an entry registered after disposal is left
|
|
227
|
+
* sealed for the application exactly like one that was queued before it).
|
|
228
|
+
*
|
|
229
|
+
* @throws QueueDisposedError after {@link dispose}; the drain's defect, as `cause`, once the
|
|
230
|
+
* drain has stopped on one; an `Error` for an id or a `seq` already queued; whatever `stage`
|
|
231
|
+
* threw. */
|
|
232
|
+
restore(init: RestoreInit, stage: (collection: Collection<any>) => Promise<RestoredSegment>): Promise<QueuedEntry | undefined>;
|
|
233
|
+
/**
|
|
234
|
+
* The collection callback: pass as `CollectionInitOptions.onSealedRefused` of every collection
|
|
235
|
+
* whose entries this queue drains. Runs synchronously under the collection latch, so it calls no
|
|
236
|
+
* latched method (`dropSealed`, `update`, `commitHead`): it records the refusal and wakes the
|
|
237
|
+
* loop, which acts on it (step one of each iteration). A refusal for an entry this queue does not
|
|
238
|
+
* hold — another queue's, or one already removed — is ignored; for the entry being submitted it
|
|
239
|
+
* is noted and left to that submission, whose cycle re-checks the recorded refusal and throws it.
|
|
240
|
+
*/
|
|
241
|
+
readonly onSealedRefused: (entryId: EntryId, error: ActionRefusedError) => void;
|
|
242
|
+
/**
|
|
243
|
+
* Reserve every sequence number up to and including `seq`: the next {@link enqueue} takes a higher
|
|
244
|
+
* one. For a journal that has read records it cannot put back yet (a table it cannot reach), so a
|
|
245
|
+
* transaction queued meanwhile never takes a journaled record's number — {@link restore} refuses a
|
|
246
|
+
* `seq` another queued entry holds. Never lowers the counter.
|
|
247
|
+
*/
|
|
248
|
+
reserveSeqThrough(seq: number): void;
|
|
249
|
+
/** The queued entries, in queue order. */
|
|
250
|
+
entries(): readonly QueuedEntry[];
|
|
251
|
+
/** The current status of a queued entry, or `undefined` for an id not queued — never queued, or
|
|
252
|
+
* already committed or failed (a settled entry leaves the queue with its terminal status event). */
|
|
253
|
+
status(entryId: EntryId): EntryStatus | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* Withdraw a never-sent entry: it fails with reason `discarded` and cascades like any failure
|
|
256
|
+
* (docs/offline-sync.md §Removing an entry). Removed from the queue at once, so the drain cannot
|
|
257
|
+
* pick it up; its segments are dropped on the removal chain and `failed` is emitted when the drops
|
|
258
|
+
* are done.
|
|
259
|
+
*
|
|
260
|
+
* @throws EntryNotDiscardableError for an entry that is in doubt (sent at least once — the
|
|
261
|
+
* application cannot withdraw a change it cannot rule out having saved) or being submitted;
|
|
262
|
+
* UnknownEntryError for an id not queued, or one a {@link restore} has registered but not yet
|
|
263
|
+
* admitted. */
|
|
264
|
+
discard(entryId: EntryId): void;
|
|
265
|
+
onStatus(listener: (status: EntryStatus) => void): () => void;
|
|
266
|
+
onQueueState(listener: (state: OfflineQueueState) => void): () => void;
|
|
267
|
+
queueState(): OfflineQueueState;
|
|
268
|
+
/** Kick the drain: a new local commit ({@link enqueue} calls it), a connection event, a test. A
|
|
269
|
+
* wake that finds the loop busy is kept for its next wait, and a wake resets the re-check backoff. */
|
|
270
|
+
wake(): void;
|
|
271
|
+
/** Resolves when the queue is empty and every removal has finished; rejects with
|
|
272
|
+
* {@link QueueDisposedError} on {@link dispose}, and with the drain's defect once it has stopped
|
|
273
|
+
* on one.
|
|
274
|
+
* NOTE: a {@link restore} in progress is not waited for: on an empty queue it answers at once
|
|
275
|
+
* while the restore is about to register an entry. Fine while restores run at start-up, before
|
|
276
|
+
* anything awaits a drain; if a host ever awaits both, make this wait out the restore chain. */
|
|
277
|
+
whenDrained(): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* Stop draining. Unsubscribes the wake signal, clears the timer, aborts the submission in flight
|
|
280
|
+
* (its cycle stops after its current network `await`) and resolves once the loop has applied that
|
|
281
|
+
* submission's outcome locally — a committed outcome is still emitted, a failure is recorded on the
|
|
282
|
+
* entry as usual, and no further entry is submitted. Entries left queued stay sealed in their
|
|
283
|
+
* collections (they are the application's; nothing is dropped). `whenDrained` rejects with
|
|
284
|
+
* {@link QueueDisposedError}; a later `enqueue` throws it. Idempotent.
|
|
285
|
+
*/
|
|
286
|
+
dispose(): Promise<void>;
|
|
287
|
+
private disposeOnce;
|
|
288
|
+
/** The refusal every entry point makes after {@link dispose} and once the drain has stopped on a
|
|
289
|
+
* defect: nothing queued then would ever drain. */
|
|
290
|
+
private assertAccepting;
|
|
291
|
+
/** Start the drain on the first entry; wake it for every later one. */
|
|
292
|
+
private startDrain;
|
|
293
|
+
private drain;
|
|
294
|
+
/** Step zero of every iteration: while a {@link restore} holds the drain, say so and wait for its
|
|
295
|
+
* release — between iterations, so no submission and no removal of the loop's is under way. */
|
|
296
|
+
private parkForHold;
|
|
297
|
+
/** Step one of every iteration: fail each entry a replay has refused since the last one, in
|
|
298
|
+
* queue order, each failure through the removal chain and so able to report more. */
|
|
299
|
+
private processPendingRefusals;
|
|
300
|
+
/** The pending refusal whose entry is earliest in queue order, dropping any for an entry no
|
|
301
|
+
* longer queued. The submitting entry's is never met here: the loop runs this step only between
|
|
302
|
+
* submissions, and its submission throws the refusal itself. */
|
|
303
|
+
private nextPendingRefusal;
|
|
304
|
+
/** Step two: expire what has outlived its `expiresAt`, in queue order, head or not. An entry in
|
|
305
|
+
* doubt is kept and logged (`offline:expiry-deferred`): a possibly-landed write is never dropped
|
|
306
|
+
* on a clock; it expires once its doubt resolves without committing. Stops when the queue is
|
|
307
|
+
* disposed mid-step, since disposal leaves every entry as it is.
|
|
308
|
+
* NOTE: checked once per iteration, and a non-empty queue always has a timer or a submission
|
|
309
|
+
* pending, so an expiry is applied at most one re-check delay (`recheck.maxMs`, 60 s by default)
|
|
310
|
+
* late; if an application ever needs it on the minute, arm a timer at the earliest `expiresAt`. */
|
|
311
|
+
private expireDue;
|
|
312
|
+
/** The refusal a collection has recorded for `entry`'s segment, if any has. */
|
|
313
|
+
private recordedRefusal;
|
|
314
|
+
/** The collections in which `entry` is still a sealed segment: every collection it wrote, until a
|
|
315
|
+
* partial commit consumes some. */
|
|
316
|
+
private remainingCollections;
|
|
317
|
+
/** The gate, asked with each of the head's remaining collections' header id and known log tail id.
|
|
318
|
+
* A gate that throws is logged and read as closed: the next re-check asks again. */
|
|
319
|
+
private gateOpen;
|
|
320
|
+
/** Submit the head once and apply the outcome. Answers whether the loop should wait out the
|
|
321
|
+
* re-check timer before its next iteration (a transient failure) rather than go straight on (the
|
|
322
|
+
* entry committed or failed). */
|
|
323
|
+
private submit;
|
|
324
|
+
/** One submission: `commitHead` for an entry over one collection, the coordinator's per-entry
|
|
325
|
+
* slice over several — built on the transactor the remaining collections share, since a queue
|
|
326
|
+
* holds collections of whatever transactor each was opened on — each under the entry's action id
|
|
327
|
+
* and local commit time, resuming from the attempts retained under that id, and — unless the queue
|
|
328
|
+
* allows it — refusing to be committed by a lone node that knows it is not alone. Each committed
|
|
329
|
+
* head segment's tally reaches {@link recordApplied} through the `onCommittedHead` hook. */
|
|
330
|
+
private send;
|
|
331
|
+
/** The `onCommittedHead` hook's closure: record what `collectionId`'s head segment accepted as
|
|
332
|
+
* already applied, for the entry's `effect` (`effectOf`). Runs under the collection latch, so it
|
|
333
|
+
* records and nothing else. One segment per collection per entry is dropped as committed exactly
|
|
334
|
+
* once, so this is a set, not a sum. */
|
|
335
|
+
private recordApplied;
|
|
336
|
+
/** The queue's write-ahead wrapper: the one moment before a send the queue is told about. The
|
|
337
|
+
* journal's drive record goes first, with the attempts about to go beside the ones already
|
|
338
|
+
* retained (docs/offline-sync.md §Write ordering, rule 2); a throw out of it aborts the cycle with
|
|
339
|
+
* nothing sent (both drivers promise that), so an attempt it refused is neither retained nor a
|
|
340
|
+
* reason for doubt — the entry stays discardable, and `resume` on the next drive names only
|
|
341
|
+
* attempts that may have landed. */
|
|
342
|
+
private recordAttempts;
|
|
343
|
+
/** Settle `entry` committed, reporting every collection it wrote: `written`, the last submission's
|
|
344
|
+
* answer, beside what earlier partial commits committed. The journal hears the status first
|
|
345
|
+
* (docs/offline-sync.md §Write ordering, rule 3). */
|
|
346
|
+
private committed;
|
|
347
|
+
/**
|
|
348
|
+
* Apply a failed submission by its class (docs/offline-sync.md §Classifying an attempt's outcome):
|
|
349
|
+
*
|
|
350
|
+
* | class | transition |
|
|
351
|
+
* |---|---|
|
|
352
|
+
* | the journal's write-ahead threw | `queued`, `backoff` — nothing was sent |
|
|
353
|
+
* | `ActionRefusedError` thrown directly (the head's recorded refusal) | `failed`, `refusalReason` |
|
|
354
|
+
* | `cohort-unreachable` | `queued`, `cohort`; the timer re-checks the gate |
|
|
355
|
+
* | `contention`, `expired`, `in-doubt`, `unknown` | `queued`, `backoff`; `unknown` is also logged and counted |
|
|
356
|
+
* | `guard-refused`, `rejected`, `too-large` | `failed`, with the class's reason |
|
|
357
|
+
* | `torn-not-saved` | `queued`, `backoff`; doubt cleared (unless part of the entry is committed), a fresh action id, retained attempts cleared, the drive record rewritten |
|
|
358
|
+
* | `partial` | `partially-committed`, then `queued`, `backoff`, in doubt, under the same id unless its cause is `torn-not-saved` ({@link partiallyCommitted}) |
|
|
359
|
+
*
|
|
360
|
+
* `SealedSegmentsError` out of a submission means the head alignment invariant broke — a queue
|
|
361
|
+
* defect — and is thrown out of the loop, which stops the drain.
|
|
362
|
+
*
|
|
363
|
+
* **One action id for the entry's whole life, with one exception.** Storage treats a re-send of
|
|
364
|
+
* the same action at the same revision as finishing it and at a new revision as a new write, so
|
|
365
|
+
* re-driving under the same id is always safe and keeps the member-side slot hold the write earned
|
|
366
|
+
* by losing. The exception is `torn-not-saved`: a re-drive under that id would find its own
|
|
367
|
+
* stranded log entry on every refresh, re-send it, and be told again that a rival built past it —
|
|
368
|
+
* a loop. A fresh id lets the next refresh treat the stranded entry as a stranger's and move on,
|
|
369
|
+
* which is exactly the proof `final: true` gives. A refused pend does NOT mint a fresh id here: it
|
|
370
|
+
* proves nothing about the cycle's earlier attempts under the same id.
|
|
371
|
+
*
|
|
372
|
+
* @returns whether the entry stays queued (wait out the timer) rather than having settled. */
|
|
373
|
+
private applyFailure;
|
|
374
|
+
/**
|
|
375
|
+
* A submission committed part of the entry (docs/offline-sync.md §Partial commits). The committed
|
|
376
|
+
* collections' segments are already consumed and their attempts resolved, so they are recorded on
|
|
377
|
+
* the entry and leave `retained`; the rest are still sealed and first, their attempts retained, and
|
|
378
|
+
* the next submission drives exactly them, under the same action id (a fresh one when the rest
|
|
379
|
+
* failed `torn-not-saved`). The entry is in doubt from here to its terminal outcome, so it is
|
|
380
|
+
* neither discarded nor expired. The journal's drive record is rewritten once the entry's state is
|
|
381
|
+
* settled — after a renewal too, so one write carries both — and `partially-committed` is emitted
|
|
382
|
+
* in place of the `queued` status this transition would otherwise report.
|
|
383
|
+
*
|
|
384
|
+
* @returns whether the entry stays queued: `false` only when no collection still holds its segment
|
|
385
|
+
* (the failure came after every collection was saved), which settles it committed. */
|
|
386
|
+
private partiallyCommitted;
|
|
387
|
+
/** After a `torn-not-saved` outcome: nothing sent under the entry's action id is saved or will
|
|
388
|
+
* land, so the next submission goes under a fresh one with nothing to resume. A partly committed
|
|
389
|
+
* entry's committed half keeps the old id; only the remainder commits under the new one. The
|
|
390
|
+
* caller writes the journal's drive record afterwards ({@link journalDriving}). */
|
|
391
|
+
private renewIdentity;
|
|
392
|
+
/** Rule 1 of docs/offline-sync.md §Write ordering: the entry record, before the entry is admitted.
|
|
393
|
+
* On a throw every collection sealed is unsealed, in reverse sealing order, and the error
|
|
394
|
+
* rethrown — nothing is queued. */
|
|
395
|
+
private journalQueued;
|
|
396
|
+
/** The drive record after a partial commit or an identity renewal (rules 2 and 4 of
|
|
397
|
+
* docs/offline-sync.md §Write ordering). A throw is logged and the drain goes on: the entry stays
|
|
398
|
+
* at the head in doubt either way, and the next send's write-ahead repeats the state. The write
|
|
399
|
+
* before a send is {@link recordAttempts}', whose throw aborts the send. */
|
|
400
|
+
private journalDriving;
|
|
401
|
+
/** Rule 3 of docs/offline-sync.md §Write ordering: the terminal status, before it is emitted. A
|
|
402
|
+
* throw is logged and swallowed here, never where the outcome was decided: the network has the
|
|
403
|
+
* write, or the segments are gone, and a stale record is what the restore after a restart
|
|
404
|
+
* resolves. */
|
|
405
|
+
private journalSettled;
|
|
406
|
+
/** One {@link restore}, run on the restore chain: take the hold, wait for the loop to park and the
|
|
407
|
+
* removal chain to drain, register, stage, admit, release. */
|
|
408
|
+
private restoreHeld;
|
|
409
|
+
/** Hold the drain: the loop parks at the top of its next iteration. A loop that is not running
|
|
410
|
+
* (never started, or stopped) or is parked on an empty queue is parked already; one waiting out
|
|
411
|
+
* the re-check timer is woken so it reaches the hold without waiting the timer out. */
|
|
412
|
+
private takeHold;
|
|
413
|
+
/** Release the hold and wake the loop, which goes on from the top of the iteration it parked in. */
|
|
414
|
+
private releaseHold;
|
|
415
|
+
/** Register a restored entry: built from the record and the drive state, inserted by `seq`, with
|
|
416
|
+
* `waitingFor` set by position and `nextSeq` raised past it. */
|
|
417
|
+
private registerRestored;
|
|
418
|
+
/** Insert `entry` into the list by `seq` and re-derive every entry's "waiting for an earlier
|
|
419
|
+
* entry" flag from its position: the head waits for no earlier entry, every other entry does. */
|
|
420
|
+
private insertBySeq;
|
|
421
|
+
/** Run `stage` for each of the entry's collections, in order; on a throw, roll the registration
|
|
422
|
+
* back — the entry leaves the queue and every segment already staged is dropped — and rethrow. */
|
|
423
|
+
private stageRestored;
|
|
424
|
+
/** The rollback of a restore whose `stage` threw: the entry leaves the queue, and each segment
|
|
425
|
+
* `stage` put in place is dropped — every one, a drop that throws being logged, since the stage's
|
|
426
|
+
* own error is the one the caller hears. */
|
|
427
|
+
private unregisterRestored;
|
|
428
|
+
/** Admit a registered entry by what `stage` answered (see {@link restore}). */
|
|
429
|
+
private admitRestored;
|
|
430
|
+
/** Fail `entry` and then act on every refusal its removal reported, in queue order, until none is
|
|
431
|
+
* pending (docs/offline-sync.md §Removing an entry). */
|
|
432
|
+
private failAndCascade;
|
|
433
|
+
/** Fail one entry: removed from the queue at once, its segments dropped on the removal chain.
|
|
434
|
+
* Nothing happens for an entry a `discard` has already claimed. */
|
|
435
|
+
private fail;
|
|
436
|
+
/** Take `entry` out of the queue (the synchronous half of every removal, a commit's included), so
|
|
437
|
+
* the drain cannot pick it again. Answers `false` when it was already taken. */
|
|
438
|
+
private claimRemoval;
|
|
439
|
+
/** Queue `entry`'s drops behind every removal already chained; the returned promise is that
|
|
440
|
+
* removal's own, so its throw reaches the caller while the chain itself never rejects. */
|
|
441
|
+
private chainRemoval;
|
|
442
|
+
/** The asynchronous half of a failure: drop the entry's segment from every collection that still
|
|
443
|
+
* holds one (a collection the entry had no segment in, or whose segment a partial commit consumed,
|
|
444
|
+
* is skipped), then emit `failed` naming those collections, and the ones a partial commit
|
|
445
|
+
* committed whatever triggered the failure — the journal hearing the status first. Each drop
|
|
446
|
+
* replays and may report refusals of later entries through {@link onSealedRefused}, which
|
|
447
|
+
* {@link causeOf} attributes while `removing` names this entry. */
|
|
448
|
+
private remove;
|
|
449
|
+
/**
|
|
450
|
+
* Which earlier entry a refusal of `entry` is attributed to: the nearest one, in queue order, that
|
|
451
|
+
* is being removed right now or already has a refusal pending; `undefined` when there is none (a
|
|
452
|
+
* rival's commit refused the entry directly, found by a reader's refresh — or a restore's
|
|
453
|
+
* insertion did, which removes nothing).
|
|
454
|
+
*
|
|
455
|
+
* Nearest rather than the entry being dropped, because one replay refuses every later segment
|
|
456
|
+
* that no longer applies at once: dropping E1 re-stages E2 (refused) and then E3 over state
|
|
457
|
+
* without E2, so E3's refusal is reported during E1's drop even though it is E2's image E3 built on.
|
|
458
|
+
* Naming the nearest failing entry gives the chain E3 ← E2 ← E1 an application can follow, where
|
|
459
|
+
* the literal "the entry whose drop ran the replay" would flatten it to E3 ← E1, E2 ← E1.
|
|
460
|
+
*/
|
|
461
|
+
private causeOf;
|
|
462
|
+
/** The removal chain, once every removal chained so far — including ones chained while waiting —
|
|
463
|
+
* has finished. */
|
|
464
|
+
private settledRemovals;
|
|
465
|
+
private settleDrained;
|
|
466
|
+
/** The drain has met a defect: stop it, reject every `whenDrained`, and leave every entry as it
|
|
467
|
+
* is. Segments stay sealed in their collections, so nothing the application committed is lost.
|
|
468
|
+
* NOTE: a removal that threw is read as a defect too, though `dropSealed`'s replay reads blocks
|
|
469
|
+
* through the collection's source and so can throw for a read that could not be served (a cache
|
|
470
|
+
* miss while the cohort is unreachable). Fine while every replay runs over blocks the staging
|
|
471
|
+
* read into the cache; if `offline:drain-stopped` is ever seen with such an error, a removal
|
|
472
|
+
* needs to be retried on the re-check timer rather than stop the drain. */
|
|
473
|
+
private stopOnDefect;
|
|
474
|
+
/** A removal off the loop's path (a `discard`) threw: the loop meets it on its next iteration. */
|
|
475
|
+
private noteDefect;
|
|
476
|
+
/** Back to `queued` after a gate check or a failed submission; emitted only when something an
|
|
477
|
+
* application can see changed since the last `queued` status. */
|
|
478
|
+
private setQueued;
|
|
479
|
+
private emitQueued;
|
|
480
|
+
private emit;
|
|
481
|
+
/** Publish the queue-wide state when it differs from the last one published. */
|
|
482
|
+
private publishState;
|
|
483
|
+
}
|
|
484
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src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