@optimystic/db-core 1.19.0 → 1.20.1
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/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 +533 -120
- package/dist/src/collection/collection.d.ts.map +1 -1
- package/dist/src/collection/collection.js +974 -500
- 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 +156 -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 +112 -26
- 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/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 +3 -0
- package/dist/src/network/index.d.ts.map +1 -1
- package/dist/src/network/index.js +3 -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 +148 -2
- package/dist/src/network/struct.d.ts.map +1 -1
- package/dist/src/network/struct.js.map +1 -1
- 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/testing/test-transactor.d.ts +29 -0
- package/dist/src/testing/test-transactor.d.ts.map +1 -1
- package/dist/src/testing/test-transactor.js +50 -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 +165 -41
- package/dist/src/transaction/coordinator.d.ts.map +1 -1
- package/dist/src/transaction/coordinator.js +605 -300
- 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/network-transactor.d.ts +1 -0
- package/dist/src/transactor/network-transactor.d.ts.map +1 -1
- package/dist/src/transactor/network-transactor.js +61 -28
- 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/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/cluster/structs.ts +42 -7
- package/src/collection/action.ts +34 -0
- package/src/collection/collection.ts +1048 -543
- 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 +183 -1
- package/src/collection/write-attempts.ts +506 -0
- package/src/collections/tree/struct.ts +97 -17
- package/src/collections/tree/tree.ts +125 -29
- package/src/index.ts +2 -0
- package/src/network/i-repo.ts +3 -0
- package/src/network/index.ts +3 -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 +154 -2
- 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/testing/test-transactor.ts +53 -0
- package/src/transaction/commit-failure-class.ts +133 -0
- package/src/transaction/coordinator.ts +696 -349
- 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/network-transactor.ts +62 -28
- package/src/transactor/transactor-source.ts +29 -13
- package/src/utility/visit-every.ts +25 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A collection's staged actions, in two parts: the sealed segments, one per queued entry that wrote
|
|
3
|
+
* the collection, oldest first, and the open segment the current transaction is staging into
|
|
4
|
+
* (docs/offline-sync.md §The segment model). The pure list operations live here; everything that
|
|
5
|
+
* touches the tracker or the collection latch stays on `Collection`.
|
|
6
|
+
*/
|
|
7
|
+
export class SegmentList {
|
|
8
|
+
/** Sealed segments in queue order, oldest first (invariant 1). Private so every change goes
|
|
9
|
+
* through a method that bumps `version`; read it through {@link replayable}, {@link find},
|
|
10
|
+
* {@link head} and {@link entryIds}. */
|
|
11
|
+
sealed = [];
|
|
12
|
+
/** The open segment: what the current transaction has staged. */
|
|
13
|
+
open = [];
|
|
14
|
+
/** Bumped on every change to the sealed list — a seal, an unseal, an insert, a drop, a refusal
|
|
15
|
+
* recorded. Captured by a snapshot so a restore can tell whether the sealed segments it was taken
|
|
16
|
+
* over are still the ones in place (ticket `offline-sync-open-segment-snapshot`). Read and written
|
|
17
|
+
* only under the collection latch or from synchronous callers. */
|
|
18
|
+
version = 0;
|
|
19
|
+
/** Close the open segment into a sealed segment owned by `entryId`. Returns `false` and changes
|
|
20
|
+
* nothing — the version included — when the open segment is empty: an entry that staged nothing
|
|
21
|
+
* here owns no segment here. Throws when `entryId` is already sealed. */
|
|
22
|
+
seal(entryId) {
|
|
23
|
+
if (this.find(entryId) !== undefined) {
|
|
24
|
+
throw new Error(`entry ${entryId} is already sealed in this collection`);
|
|
25
|
+
}
|
|
26
|
+
if (this.open.length === 0) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
this.sealed.push({ entryId, actions: this.open });
|
|
30
|
+
this.open = [];
|
|
31
|
+
this.version++;
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
/** The exact inverse of {@link seal}: move the newest sealed segment's actions back into the open
|
|
35
|
+
* segment, for an enqueue whose journal write failed after sealing (`OfflineQueue.enqueue`).
|
|
36
|
+
* Requires the segment to be the NEWEST sealed one and the open segment to be empty — both true at
|
|
37
|
+
* that one call site, which has just sealed and staged nothing since — and throws otherwise, since
|
|
38
|
+
* putting an older segment's actions behind a newer one's would reorder what was staged. Bumps
|
|
39
|
+
* `version`: the sealed list changed, even though the tracker did not (the transforms are already
|
|
40
|
+
* what they were). */
|
|
41
|
+
unseal(entryId) {
|
|
42
|
+
const newest = this.sealed[this.sealed.length - 1];
|
|
43
|
+
if (newest === undefined || newest.entryId !== entryId) {
|
|
44
|
+
throw new Error(`entry ${entryId} is not the newest sealed segment (${newest?.entryId ?? 'nothing is sealed'}); only the newest can be unsealed`);
|
|
45
|
+
}
|
|
46
|
+
if (this.open.length > 0) {
|
|
47
|
+
throw new Error(`entry ${entryId} cannot be unsealed over a non-empty open segment`);
|
|
48
|
+
}
|
|
49
|
+
this.sealed.pop();
|
|
50
|
+
this.open = [...newest.actions];
|
|
51
|
+
this.version++;
|
|
52
|
+
}
|
|
53
|
+
/** Insert a sealed segment owned by `entryId` holding `actions`, ahead of the segment `before`
|
|
54
|
+
* names, or last when `before` is `undefined` — a segment put back from a journal after a restart
|
|
55
|
+
* (`Collection.restoreSealed`), which belongs wherever its entry sits in queue order. Throws when
|
|
56
|
+
* `entryId` is already sealed or `before` names no segment here, before anything changes. */
|
|
57
|
+
insert(entryId, actions, before) {
|
|
58
|
+
if (this.find(entryId) !== undefined) {
|
|
59
|
+
throw new Error(`entry ${entryId} is already sealed in this collection`);
|
|
60
|
+
}
|
|
61
|
+
const index = before === undefined ? this.sealed.length : this.sealed.findIndex(segment => segment.entryId === before);
|
|
62
|
+
if (index < 0) {
|
|
63
|
+
throw new Error(`entry ${before} is not sealed in this collection; cannot insert ${entryId} before it`);
|
|
64
|
+
}
|
|
65
|
+
this.sealed.splice(index, 0, { entryId, actions: [...actions] });
|
|
66
|
+
this.version++;
|
|
67
|
+
}
|
|
68
|
+
/** Remove the segment owned by `entryId`, wherever it sits. Throws for an unknown id. */
|
|
69
|
+
drop(entryId) {
|
|
70
|
+
const index = this.sealed.findIndex(segment => segment.entryId === entryId);
|
|
71
|
+
if (index < 0) {
|
|
72
|
+
throw new Error(`entry ${entryId} is not sealed in this collection`);
|
|
73
|
+
}
|
|
74
|
+
const [dropped] = this.sealed.splice(index, 1);
|
|
75
|
+
this.version++;
|
|
76
|
+
return dropped;
|
|
77
|
+
}
|
|
78
|
+
/** Record that a replay refused the segment owned by `entryId`, excluding it from later replays. */
|
|
79
|
+
refuse(entryId, error) {
|
|
80
|
+
const segment = this.find(entryId);
|
|
81
|
+
if (segment === undefined) {
|
|
82
|
+
throw new Error(`entry ${entryId} is not sealed in this collection`);
|
|
83
|
+
}
|
|
84
|
+
segment.refused = error;
|
|
85
|
+
this.version++;
|
|
86
|
+
}
|
|
87
|
+
find(entryId) {
|
|
88
|
+
return this.sealed.find(segment => segment.entryId === entryId);
|
|
89
|
+
}
|
|
90
|
+
/** The oldest sealed segment, if any. */
|
|
91
|
+
head() {
|
|
92
|
+
return this.sealed[0];
|
|
93
|
+
}
|
|
94
|
+
entryIds() {
|
|
95
|
+
return this.sealed.map(segment => segment.entryId);
|
|
96
|
+
}
|
|
97
|
+
/** Whether any segment is sealed, refused ones included. */
|
|
98
|
+
hasSealed() {
|
|
99
|
+
return this.sealed.length > 0;
|
|
100
|
+
}
|
|
101
|
+
/** The sealed segments a replay re-stages, in order: every one not refused. */
|
|
102
|
+
replayable() {
|
|
103
|
+
return this.sealed.filter(segment => segment.refused === undefined);
|
|
104
|
+
}
|
|
105
|
+
/** How many actions a replay re-stages: the replayable sealed segments' plus the open segment's. */
|
|
106
|
+
replayableCount() {
|
|
107
|
+
return this.replayable().reduce((count, segment) => count + segment.actions.length, this.open.length);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=segments.js.map
|
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AAK,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvG,CAAC;CACD"}
|
|
@@ -1,7 +1,136 @@
|
|
|
1
|
-
import type { IBlock, BlockId, Action, WriteDurability } from "../index.js";
|
|
1
|
+
import type { IBlock, BlockId, Action, ActionId, Transforms, WriteDurability } from "../index.js";
|
|
2
2
|
import type { IChainHeader } from "../chain/chain-nodes.js";
|
|
3
3
|
import type { RandFn } from "../utility/backoff.js";
|
|
4
|
+
import type { EntryId } from "./segments.js";
|
|
5
|
+
import type { AlreadyAppliedTally } from "./action.js";
|
|
6
|
+
import type { BlockBaseRevs, BlockContentDigests } from "../network/struct.js";
|
|
4
7
|
export type CollectionId = BlockId;
|
|
8
|
+
/**
|
|
9
|
+
* A handler's statement that an action cannot be applied over the committed state it is being
|
|
10
|
+
* replayed against — a uniqueness or lost-update check failed. Not a transport failure and never
|
|
11
|
+
* retryable: the action's staged writes are discarded (the handler runs inside an Atomic), and
|
|
12
|
+
* nothing downgrades it to a stale failure. `TreeGuardRefusedError` in
|
|
13
|
+
* `packages/db-core/src/collections/tree/struct.ts` is the tree's subclass, and carries the
|
|
14
|
+
* contract every refusal obeys.
|
|
15
|
+
*
|
|
16
|
+
* Lives here rather than beside the tree so the collection can recognise a refusal without
|
|
17
|
+
* importing the tree module (which imports the collection). Segment-aware replay
|
|
18
|
+
* (`Collection.replayActions`) treats a throw of this class from a SEALED segment as that
|
|
19
|
+
* segment's refusal and keeps going; from the open segment it propagates as it always has.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ActionRefusedError extends Error {
|
|
22
|
+
/** The collection whose handler refused the action. */
|
|
23
|
+
readonly collectionId: CollectionId;
|
|
24
|
+
constructor(
|
|
25
|
+
/** The collection whose handler refused the action. */
|
|
26
|
+
collectionId: CollectionId, message: string);
|
|
27
|
+
}
|
|
28
|
+
/** Why a sealed segment stood in the way of a commit (see {@link SealedSegmentsError}):
|
|
29
|
+
* - `whole-collection` — a whole-collection commit was asked for while a segment is sealed.
|
|
30
|
+
* - `not-head` — `commitHead` named a segment that is not the oldest sealed one.
|
|
31
|
+
* - `refused` — `commitHead` named a segment a replay has refused; the queue drops it instead.
|
|
32
|
+
* - `in-flight` — a head commit is on the network for the named segment, so neither a second
|
|
33
|
+
* `commitHead` nor a `dropSealed` of it can proceed. */
|
|
34
|
+
export type SealedSegmentsReason = 'whole-collection' | 'not-head' | 'refused' | 'in-flight';
|
|
35
|
+
/**
|
|
36
|
+
* Thrown by the whole-collection commit paths — {@link ICollection.sync},
|
|
37
|
+
* {@link ICollection.updateAndSync}, `Collection.actAndSync` and `Collection.getPendingActions`
|
|
38
|
+
* (the coordinator's append) — while the collection holds sealed segments. Those paths commit
|
|
39
|
+
* everything staged as ONE log entry under one action id; over sealed segments that would merge
|
|
40
|
+
* several queue entries into one, which the queue's identity rules forbid
|
|
41
|
+
* (docs/offline-sync.md §Identity across attempts). A sealed segment is committed on its own,
|
|
42
|
+
* through `Collection.commitHead`, whose own preconditions throw this class too, with a
|
|
43
|
+
* {@link reason} other than `whole-collection` (see {@link SealedSegmentsReason}).
|
|
44
|
+
*
|
|
45
|
+
* Nothing is unstaged or changed when this is thrown: every segment, sealed and open, is exactly
|
|
46
|
+
* as it was.
|
|
47
|
+
*/
|
|
48
|
+
export declare class SealedSegmentsError extends Error {
|
|
49
|
+
readonly collectionId: CollectionId;
|
|
50
|
+
/** The sealed segments' entry ids, in order. */
|
|
51
|
+
readonly sealedEntries: EntryId[];
|
|
52
|
+
readonly reason: SealedSegmentsReason;
|
|
53
|
+
/** The entry a `commitHead` or `dropSealed` named, for every reason but `whole-collection`. */
|
|
54
|
+
readonly entryId?: EntryId | undefined;
|
|
55
|
+
constructor(collectionId: CollectionId,
|
|
56
|
+
/** The sealed segments' entry ids, in order. */
|
|
57
|
+
sealedEntries: EntryId[], reason?: SealedSegmentsReason,
|
|
58
|
+
/** The entry a `commitHead` or `dropSealed` named, for every reason but `whole-collection`. */
|
|
59
|
+
entryId?: EntryId | undefined);
|
|
60
|
+
}
|
|
61
|
+
/** Exactly what one write attempt sent to the transactor — enough to send the same thing again.
|
|
62
|
+
* Retained by `Collection.retainInFlightAttempt` so that a refresh which then finds this attempt's
|
|
63
|
+
* own log entry can land the blocks the attempt left behind, at the same action id and revision
|
|
64
|
+
* (see `Collection.completeOwnEntry`).
|
|
65
|
+
*
|
|
66
|
+
* Also the shape a caller RECORDS before an attempt is sent and hands back on a later cycle
|
|
67
|
+
* ({@link HeadCommitOptions.recordAttempt} and {@link HeadCommitOptions.resume};
|
|
68
|
+
* docs/offline-sync.md §Identity across attempts), so it must stay plain data — ids, numbers and the
|
|
69
|
+
* transforms as the wire carries them, nothing with object identity and no functions: the
|
|
70
|
+
* offline-sync journal serialises it as JSON. */
|
|
71
|
+
export type InFlightAttempt = {
|
|
72
|
+
/** The action id the attempt was sent under — the one every attempt of the write reuses, and
|
|
73
|
+
* the one a cycle that resumes from this record must run under. */
|
|
74
|
+
actionId: ActionId;
|
|
75
|
+
/** The revision the attempt's log entry was stamped with, and pended and committed at. */
|
|
76
|
+
rev: number;
|
|
77
|
+
/** Every transform the attempt pended — the log blocks included. The caller hands over a copy
|
|
78
|
+
* it will not mutate; the collection keeps it as given. */
|
|
79
|
+
transforms: Transforms;
|
|
80
|
+
/** The attempt's log tail block, committed first. */
|
|
81
|
+
tailId: BlockId;
|
|
82
|
+
/** The per-block content declarations the attempt's commit carried, if any. */
|
|
83
|
+
blockDigests?: BlockContentDigests;
|
|
84
|
+
/** The per-block bases the attempt's pend carried, if any (see `PendRequest.baseRevs`). Kept
|
|
85
|
+
* with the transforms because they describe them: a re-send of these operations must name the
|
|
86
|
+
* same bases they were computed against. */
|
|
87
|
+
baseRevs?: BlockBaseRevs;
|
|
88
|
+
};
|
|
89
|
+
/** What `Collection.commitHead` commits the head segment under, beside the retry bounds of
|
|
90
|
+
* {@link SyncOptions}. Both fields are the queue's (docs/offline-sync.md §Identity across
|
|
91
|
+
* attempts): the collection mints neither. */
|
|
92
|
+
export type HeadCommitOptions = SyncOptions & {
|
|
93
|
+
/** The action id the attempt cycle runs under. The queue mints it, and re-supplies the SAME id
|
|
94
|
+
* when it re-drives an entry whose earlier attempt may have landed, so the refresh that opens the
|
|
95
|
+
* cycle recognises that attempt's log entry as the write's own and finishes or consumes it
|
|
96
|
+
* instead of committing a second copy. */
|
|
97
|
+
actionId: ActionId;
|
|
98
|
+
/** The entry's local commit time, stamped on the log entry in place of the time
|
|
99
|
+
* `Collection.syncInternal` mints for a sync. Fixed per write, so every attempt appends the same
|
|
100
|
+
* entry (see "A write's log append is a fixed function of the write and the revision it is
|
|
101
|
+
* requesting" in docs/internals.md). */
|
|
102
|
+
timestamp: number;
|
|
103
|
+
/** The write-ahead hook: called with each attempt exactly as it is about to be sent — after it is
|
|
104
|
+
* built and BEFORE the collection latch is released for the network — and awaited under that
|
|
105
|
+
* latch. It is where the queue records the attempt's identity before sending it
|
|
106
|
+
* (docs/offline-sync.md §Identity across attempts) and, later, where the journal writes it. A
|
|
107
|
+
* throw aborts the cycle before anything is sent: it escapes `commitHead` unchanged, the handle
|
|
108
|
+
* closes, and every segment is exactly as it was. */
|
|
109
|
+
recordAttempt?: (attempt: InFlightAttempt) => Promise<void>;
|
|
110
|
+
/** The attempt an earlier cycle under the SAME `actionId` handed to `recordAttempt` and did not
|
|
111
|
+
* resolve — it must carry this `actionId`, and `openHeadCommit` throws before touching anything
|
|
112
|
+
* when it does not. Seeded as the retained attempt right after the action is marked in flight,
|
|
113
|
+
* so the cycle's opening refresh, finding that attempt's log entry with blocks missing, finishes
|
|
114
|
+
* it from these transforms (`Collection.completeOwnEntry`) instead of refusing it as torn with
|
|
115
|
+
* `transforms-not-held`. Without it a re-drive can recognise only an attempt that landed whole.
|
|
116
|
+
* The revision check still applies: an attempt recorded at a revision other than the entry's is
|
|
117
|
+
* refused as before. And when that refresh finds nothing new, this attempt is what the cycle
|
|
118
|
+
* re-sends, verbatim, while the next attempt would request its revision (`resumedAttempt`), since
|
|
119
|
+
* it may have landed on machines the refresh did not hear from. */
|
|
120
|
+
resume?: InFlightAttempt;
|
|
121
|
+
/** Called once, with what the head segment's actions accepted as already applied
|
|
122
|
+
* ({@link AlreadyAppliedTally}, as recorded on the segment by its last staging over the committed
|
|
123
|
+
* state), at the moment the segment is made durable and dropped: when the committed attempt is
|
|
124
|
+
* folded (`HeadCommitHandle.fold`), or when the cycle's refresh finds the entry's own log entry and
|
|
125
|
+
* consumes the head (`Collection.consumeHead`) — so a re-drive that finds its earlier attempt landed
|
|
126
|
+
* reports it too. Runs synchronously under the collection latch, like `onSealedRefused`, so it must
|
|
127
|
+
* not call a latched method of the collection; the queue's closure only records into a map. A throw
|
|
128
|
+
* out of it is logged, never raised: the commit is already durable. A hook rather than a widened
|
|
129
|
+
* return type because the partial-commit path reports the committed half through
|
|
130
|
+
* `CoordinatorPartialCommitError` and the refresh-consumed path through `RefreshReport`; one hook
|
|
131
|
+
* reaches all three. */
|
|
132
|
+
onCommittedHead?: (applied: AlreadyAppliedTally) => void;
|
|
133
|
+
};
|
|
5
134
|
export type CollectionHeaderBlock = IBlock & Partial<IChainHeader>;
|
|
6
135
|
/** A collection's committed tail: the log tail block its header names, and that block's latest
|
|
7
136
|
* committed revision, which is the collection's (every commit touches the log tail). */
|
|
@@ -65,7 +194,33 @@ export interface SyncOptions {
|
|
|
65
194
|
* {@link deadlineMs} is still checked first, so a sync that is both past its deadline and
|
|
66
195
|
* stalled reports the deadline (as {@link SyncRetryExhaustedError}), not the stall. */
|
|
67
196
|
maxStalledAttempts?: number;
|
|
197
|
+
/** Refuse to let this write be committed by a lone node — a coordinator whose cohort for the
|
|
198
|
+
* write is only itself — while that node knows of members of the cohort it could not reach, is
|
|
199
|
+
* still waiting to hear from a peer it was configured to join through, or could not route the
|
|
200
|
+
* write at all. A node that is genuinely alone (no absent member known, nothing awaited, routed to
|
|
201
|
+
* itself) still commits. The refusal is a promise shortfall (`PromiseShortfallError`, with
|
|
202
|
+
* `soloRefused` naming the reason), so the write stops and is classified `cohort-unreachable`.
|
|
203
|
+
* Rides on every send of the write's attempt cycle as `PendRequest.refuseSolo` and
|
|
204
|
+
* `CommitRequest.refuseSolo`. Default off: only the offline queue sets it (docs/offline-sync.md
|
|
205
|
+
* §When to submit: the reachability gate). A coordinator on a build that predates the field
|
|
206
|
+
* ignores it and commits alone as before. */
|
|
207
|
+
refuseSoloCommit?: boolean;
|
|
68
208
|
}
|
|
209
|
+
/** What a write's attempt cycle carries besides its identity, recorded beside the in-flight mark
|
|
210
|
+
* (`Collection.beginInFlightAction`) so that every send of the cycle carries it: each attempt, and
|
|
211
|
+
* the re-send a refresh makes to finish a torn one (`Collection.completeOwnEntry`). */
|
|
212
|
+
export type InFlightCycle = {
|
|
213
|
+
/** {@link SyncOptions.refuseSoloCommit}, for this cycle. */
|
|
214
|
+
readonly refuseSolo?: boolean;
|
|
215
|
+
};
|
|
216
|
+
/** What `Collection.openHeadCommit` opens a head commit with besides its identity: the cycle's
|
|
217
|
+
* {@link InFlightCycle}, the attempt an earlier cycle under the same action id recorded and did not
|
|
218
|
+
* resolve ({@link HeadCommitOptions.resume}), and the committed-head hook
|
|
219
|
+
* ({@link HeadCommitOptions.onCommittedHead}). */
|
|
220
|
+
export type OpenHeadCommitOptions = InFlightCycle & {
|
|
221
|
+
readonly resume?: InFlightAttempt;
|
|
222
|
+
readonly onCommittedHead?: (applied: AlreadyAppliedTally) => void;
|
|
223
|
+
};
|
|
69
224
|
/** Thrown by {@link ICollection.sync} / {@link ICollection.updateAndSync} when the retry budget
|
|
70
225
|
* (attempt count or deadline) is exhausted while the transactor keeps returning stale failures.
|
|
71
226
|
* Catchable so callers can surface a clear "gave up syncing" condition instead of hanging.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct.d.ts","sourceRoot":"","sources":["../../../src/collection/struct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE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O,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC3E,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;CACrE;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG;IACnD,IAAI,EAAE,QAAQ,CAAC;CACf,CAAC"}
|
|
@@ -1,3 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A handler's statement that an action cannot be applied over the committed state it is being
|
|
3
|
+
* replayed against — a uniqueness or lost-update check failed. Not a transport failure and never
|
|
4
|
+
* retryable: the action's staged writes are discarded (the handler runs inside an Atomic), and
|
|
5
|
+
* nothing downgrades it to a stale failure. `TreeGuardRefusedError` in
|
|
6
|
+
* `packages/db-core/src/collections/tree/struct.ts` is the tree's subclass, and carries the
|
|
7
|
+
* contract every refusal obeys.
|
|
8
|
+
*
|
|
9
|
+
* Lives here rather than beside the tree so the collection can recognise a refusal without
|
|
10
|
+
* importing the tree module (which imports the collection). Segment-aware replay
|
|
11
|
+
* (`Collection.replayActions`) treats a throw of this class from a SEALED segment as that
|
|
12
|
+
* segment's refusal and keeps going; from the open segment it propagates as it always has.
|
|
13
|
+
*/
|
|
14
|
+
export class ActionRefusedError extends Error {
|
|
15
|
+
collectionId;
|
|
16
|
+
constructor(
|
|
17
|
+
/** The collection whose handler refused the action. */
|
|
18
|
+
collectionId, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.collectionId = collectionId;
|
|
21
|
+
this.name = 'ActionRefusedError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Thrown by the whole-collection commit paths — {@link ICollection.sync},
|
|
26
|
+
* {@link ICollection.updateAndSync}, `Collection.actAndSync` and `Collection.getPendingActions`
|
|
27
|
+
* (the coordinator's append) — while the collection holds sealed segments. Those paths commit
|
|
28
|
+
* everything staged as ONE log entry under one action id; over sealed segments that would merge
|
|
29
|
+
* several queue entries into one, which the queue's identity rules forbid
|
|
30
|
+
* (docs/offline-sync.md §Identity across attempts). A sealed segment is committed on its own,
|
|
31
|
+
* through `Collection.commitHead`, whose own preconditions throw this class too, with a
|
|
32
|
+
* {@link reason} other than `whole-collection` (see {@link SealedSegmentsReason}).
|
|
33
|
+
*
|
|
34
|
+
* Nothing is unstaged or changed when this is thrown: every segment, sealed and open, is exactly
|
|
35
|
+
* as it was.
|
|
36
|
+
*/
|
|
37
|
+
export class SealedSegmentsError extends Error {
|
|
38
|
+
collectionId;
|
|
39
|
+
sealedEntries;
|
|
40
|
+
reason;
|
|
41
|
+
entryId;
|
|
42
|
+
constructor(collectionId,
|
|
43
|
+
/** The sealed segments' entry ids, in order. */
|
|
44
|
+
sealedEntries, reason = 'whole-collection',
|
|
45
|
+
/** The entry a `commitHead` or `dropSealed` named, for every reason but `whole-collection`. */
|
|
46
|
+
entryId) {
|
|
47
|
+
super(sealedSegmentsMessage(collectionId, sealedEntries, reason, entryId));
|
|
48
|
+
this.collectionId = collectionId;
|
|
49
|
+
this.sealedEntries = sealedEntries;
|
|
50
|
+
this.reason = reason;
|
|
51
|
+
this.entryId = entryId;
|
|
52
|
+
this.name = 'SealedSegmentsError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function sealedSegmentsMessage(collectionId, sealedEntries, reason, entryId) {
|
|
56
|
+
const listed = sealedEntries.length === 0 ? 'nothing' : sealedEntries.join(', ');
|
|
57
|
+
switch (reason) {
|
|
58
|
+
case 'whole-collection':
|
|
59
|
+
return `collection ${collectionId} holds sealed segment(s) ${listed}; `
|
|
60
|
+
+ `a whole-collection commit would merge them into one log entry — commit the head segment instead`;
|
|
61
|
+
case 'not-head':
|
|
62
|
+
return `collection ${collectionId}: entry ${entryId} is not the head sealed segment (sealed: ${listed}); `
|
|
63
|
+
+ `only the oldest sealed segment can be committed`;
|
|
64
|
+
case 'refused':
|
|
65
|
+
return `collection ${collectionId}: entry ${entryId} carries a recorded refusal; `
|
|
66
|
+
+ `a refused segment is dropped, never committed`;
|
|
67
|
+
case 'in-flight':
|
|
68
|
+
return `collection ${collectionId}: a head commit of entry ${entryId} is in flight on this instance`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
1
71
|
/** Thrown by {@link ICollection.sync} / {@link ICollection.updateAndSync} when the retry budget
|
|
2
72
|
* (attempt count or deadline) is exhausted while the transactor keeps returning stale failures.
|
|
3
73
|
* Catchable so callers can surface a clear "gave up syncing" condition instead of hanging.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct.js","sourceRoot":"","sources":["../../../src/collection/struct.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"struct.js","sourceRoot":"","sources":["../../../src/collection/struct.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGlC;IAFV;IACC,uDAAuD;IAC9C,YAA0B,EACnC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,iBAAY,GAAZ,YAAY,CAAc;QAInC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IAClC,CAAC;CACD;AAUD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAEnC;IAEA;IACA;IAEA;IANV,YACU,YAA0B;IACnC,gDAAgD;IACvC,aAAwB,EACxB,SAA+B,kBAAkB;IAC1D,+FAA+F;IACtF,OAAiB;QAE1B,KAAK,CAAC,qBAAqB,CAAC,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAPlE,iBAAY,GAAZ,YAAY,CAAc;QAE1B,kBAAa,GAAb,aAAa,CAAW;QACxB,WAAM,GAAN,MAAM,CAA2C;QAEjD,YAAO,GAAP,OAAO,CAAU;QAG1B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACnC,CAAC;CACD;AAED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