@rljson/fs-agent 0.1.0 → 0.2.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/README.api.md +374 -187
- package/README.architecture.md +422 -1372
- package/README.md +8 -7
- package/README.public.md +160 -149
- package/README.tests.md +175 -127
- package/dist/README.api.md +374 -187
- package/dist/README.architecture.md +422 -1372
- package/dist/README.md +8 -7
- package/dist/README.public.md +160 -149
- package/dist/README.tests.md +175 -127
- package/dist/fs-agent.d.ts +436 -1199
- package/dist/fs-agent.js +4952 -6578
- package/dist/fs-atomic-write.d.ts +11 -0
- package/dist/fs-edit-chain.d.ts +53 -267
- package/dist/fs-history.d.ts +83 -0
- package/dist/fs-merge.d.ts +109 -0
- package/dist/fs-receive.d.ts +83 -0
- package/dist/fs-scanner.d.ts +70 -23
- package/dist/fs-send.d.ts +53 -0
- package/dist/fs-signals.d.ts +212 -0
- package/dist/fs-stamps.d.ts +102 -0
- package/dist/fs_agent_version.d.ts +2 -0
- package/dist/index.d.ts +7 -7
- package/package.json +31 -45
- package/dist/fs-anti-entropy.d.ts +0 -404
- package/dist/fs-bucket-sync.d.ts +0 -172
- package/dist/fs-conflict-resolver.d.ts +0 -385
- package/dist/fs-manifest.d.ts +0 -159
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rljson/fs-agent",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Rljson fs-agent description",
|
|
5
5
|
"homepage": "https://github.com/rljson/fs-agent",
|
|
6
6
|
"bugs": "https://github.com/rljson/fs-agent/issues",
|
|
@@ -19,59 +19,45 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"type": "module",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "pnpm exec vite build && tsc && node scripts/copy-readme-to-dist.js",
|
|
24
|
-
"test": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pnpm exec vitest run --coverage --no-file-parallelism && pnpm run lint",
|
|
25
|
-
"prebuild": "npm run test",
|
|
26
|
-
"prepublishOnly": "npm run build",
|
|
27
|
-
"lint": "pnpm exec eslint .",
|
|
28
|
-
"updateGoldens": "cross-env UPDATE_GOLDENS=true pnpm test"
|
|
29
|
-
},
|
|
30
22
|
"devDependencies": {
|
|
31
|
-
"@rljson/
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
23
|
+
"@rljson/dna-rljson": "0.2.0",
|
|
24
|
+
"@rljson/server": "0.0.77",
|
|
25
|
+
"@tssuite/helix-js": "0.4.1",
|
|
26
|
+
"@types/node": "^26.6.5",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^8.71.2",
|
|
28
|
+
"@typescript-eslint/parser": "^8.71.2",
|
|
29
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
36
30
|
"cross-env": "^10.1.0",
|
|
37
|
-
"eslint": "~
|
|
38
|
-
"eslint-plugin-jsdoc": "^
|
|
39
|
-
"eslint-plugin-tsdoc": "^0.5.
|
|
40
|
-
"globals": "^17.
|
|
31
|
+
"eslint": "~10.13.0",
|
|
32
|
+
"eslint-plugin-jsdoc": "^65.3.15",
|
|
33
|
+
"eslint-plugin-tsdoc": "^0.5.4",
|
|
34
|
+
"globals": "^17.13.0",
|
|
41
35
|
"jsdoc": "^4.0.5",
|
|
42
36
|
"read-pkg": "^10.1.0",
|
|
43
|
-
"typescript": "~
|
|
44
|
-
"typescript-eslint": "^8.
|
|
45
|
-
"vite": "^
|
|
46
|
-
"vite-node": "^
|
|
47
|
-
"vite-plugin-dts": "^
|
|
37
|
+
"typescript": "~6.0.3",
|
|
38
|
+
"typescript-eslint": "^8.71.2",
|
|
39
|
+
"vite": "^8.3.4",
|
|
40
|
+
"vite-node": "^6.0.0",
|
|
41
|
+
"vite-plugin-dts": "^5.1.2",
|
|
48
42
|
"vite-tsconfig-paths": "^6.1.1",
|
|
49
|
-
"vitest": "^
|
|
43
|
+
"vitest": "^5.0.5",
|
|
50
44
|
"vitest-dom": "^0.1.1"
|
|
51
45
|
},
|
|
52
46
|
"dependencies": {
|
|
53
47
|
"@rljson/bs": "0.0.29",
|
|
54
|
-
"@rljson/db": "0.
|
|
48
|
+
"@rljson/db": "0.1.1",
|
|
55
49
|
"@rljson/hash": "0.0.19",
|
|
56
|
-
"@rljson/io": "0.0.
|
|
50
|
+
"@rljson/io": "0.0.85",
|
|
57
51
|
"@rljson/json": "0.0.23",
|
|
58
|
-
"@rljson/rljson": "0.0.
|
|
59
|
-
"socket.io": "^4.8.
|
|
60
|
-
"socket.io-client": "^4.8.
|
|
52
|
+
"@rljson/rljson": "0.0.86",
|
|
53
|
+
"socket.io": "^4.8.4",
|
|
54
|
+
"socket.io-client": "^4.8.4"
|
|
61
55
|
},
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"@rljson/io": "0.0.84",
|
|
71
|
-
"@rljson/json": "0.0.23",
|
|
72
|
-
"@rljson/rljson": "0.0.83",
|
|
73
|
-
"@rljson/server": "0.0.74"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
"packageManager": "pnpm@10.11.0"
|
|
77
|
-
}
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "pnpm exec vite build && tsc && node scripts/copy-readme-to-dist.js",
|
|
58
|
+
"test": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pnpm exec vitest run --coverage --no-file-parallelism && pnpm run lint",
|
|
59
|
+
"prebuild": "npm run test",
|
|
60
|
+
"lint": "pnpm exec eslint .",
|
|
61
|
+
"updateGoldens": "cross-env UPDATE_GOLDENS=true pnpm test"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/** Tuning for {@link FsAntiEntropy}. */
|
|
2
|
-
export interface AntiEntropyOptions {
|
|
3
|
-
/** Whether divergence is repaired at all. Default: true. */
|
|
4
|
-
enabled?: boolean;
|
|
5
|
-
/**
|
|
6
|
-
* How long one divergence must persist before it is repaired, in ms.
|
|
7
|
-
*
|
|
8
|
-
* Live traffic produces short divergences constantly — a push in flight is
|
|
9
|
-
* one. Only a divergence that outlives it is a lost message. Default: 10 000.
|
|
10
|
-
*/
|
|
11
|
-
graceMs?: number;
|
|
12
|
-
/**
|
|
13
|
-
* Upper bound of the backoff between repeated repairs of the SAME
|
|
14
|
-
* divergence, in ms. Each attempt doubles the wait from `graceMs`, so a
|
|
15
|
-
* repair that cannot succeed (a refusal, an unreachable blob) costs a
|
|
16
|
-
* message every few minutes rather than one per heartbeat. Default: 300 000.
|
|
17
|
-
*/
|
|
18
|
-
maxBackoffMs?: number;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* How many content-equivalence verdicts one agent remembers.
|
|
22
|
-
*
|
|
23
|
-
* Keyed on refs a PEER chooses, so it is bounded: a hub whose state changes
|
|
24
|
-
* constantly must not grow this without limit. Large enough that a rollout
|
|
25
|
-
* window's worth of old-build refs all fit.
|
|
26
|
-
*/
|
|
27
|
-
export declare const CONTENT_AGREED_MAX = 256;
|
|
28
|
-
/** Defaults for {@link AntiEntropyOptions}. */
|
|
29
|
-
export declare const DEFAULT_ANTI_ENTROPY: Required<AntiEntropyOptions>;
|
|
30
|
-
/** What a repair does. See the header of this file. */
|
|
31
|
-
export type AntiEntropyAction = 'pull' | 'push' | 'merge';
|
|
32
|
-
/**
|
|
33
|
-
* What {@link antiEntropyDecision} concluded.
|
|
34
|
-
*
|
|
35
|
-
* `blocked` means the ancestry could not be resolved far enough to decide.
|
|
36
|
-
* Nothing is applied, nothing is latched, and the divergence is retried — the
|
|
37
|
-
* one answer the old signature could not give, because it had nothing to be
|
|
38
|
-
* unsure about.
|
|
39
|
-
*/
|
|
40
|
-
export type AntiEntropyDecision = 'in-sync' | 'unknown' | 'blocked' | AntiEntropyAction;
|
|
41
|
-
/**
|
|
42
|
-
* Where this node's history stands against the hub's, when the chain can say.
|
|
43
|
-
*
|
|
44
|
-
* `behind` — the hub's head descends from ours; we are missing its work.
|
|
45
|
-
* `ahead` — ours descends from the hub's; IT is missing ours.
|
|
46
|
-
* `fork` — neither descends from the other. Both sides have work to keep.
|
|
47
|
-
* `incomplete` — a walk was truncated, so nothing may be concluded.
|
|
48
|
-
*/
|
|
49
|
-
export type Reachability = 'behind' | 'ahead' | 'fork' | 'incomplete';
|
|
50
|
-
/** The part of an agent's state the decision reads. */
|
|
51
|
-
export interface AntiEntropyView {
|
|
52
|
-
/** The origin this agent's connector announces under. */
|
|
53
|
-
origin: string;
|
|
54
|
-
/** The state the folder is in. */
|
|
55
|
-
currentRef: string | undefined;
|
|
56
|
-
/** The incoming state most recently applied. */
|
|
57
|
-
lastAppliedRef: string | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* The state this agent last pushed as its OWN work.
|
|
60
|
-
*
|
|
61
|
-
* Only such a state may be re-announced. An apply can leave the folder
|
|
62
|
-
* short of the tree it applied — a node still catching up — and announcing
|
|
63
|
-
* that is how a burst turns into a rollback.
|
|
64
|
-
*/
|
|
65
|
-
lastPushedRef: string | undefined;
|
|
66
|
-
}
|
|
67
|
-
/** A hub announcement, as the heartbeat carries it. */
|
|
68
|
-
export interface HubAnnouncement {
|
|
69
|
-
/** The state the hub holds. */
|
|
70
|
-
ref: string;
|
|
71
|
-
/** Who produced that state. */
|
|
72
|
-
origin?: string;
|
|
73
|
-
/** What that state declares it descends from. */
|
|
74
|
-
predecessors?: readonly string[];
|
|
75
|
-
/**
|
|
76
|
-
* What the edit chain says about the two histories, when it can say.
|
|
77
|
-
*
|
|
78
|
-
* **This is the field the whole protocol change exists to provide.** Without
|
|
79
|
-
* it the decision has a ref and ONE generation of ancestry, and §2.2's two
|
|
80
|
-
* situations — "a peer deleted what we added" and "a peer forked from an
|
|
81
|
-
* ancestor we share" — arrive at this signature as the SAME VALUE. No rule
|
|
82
|
-
* can separate them, which is why narrowing one was tried twice and cost a
|
|
83
|
-
* discarded folder the first time and a livelock the second.
|
|
84
|
-
*
|
|
85
|
-
* Absent means the chain could not be consulted — an older peer, a node
|
|
86
|
-
* whose chain failed to initialise — and the decision falls back to the
|
|
87
|
-
* heuristics below, which are what shipped before. Absence must never read
|
|
88
|
-
* as `fork`.
|
|
89
|
-
*/
|
|
90
|
-
reachability?: Reachability;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Decides who is behind, from the hub's announcement and our own state.
|
|
94
|
-
* @param hub - What the hub announced.
|
|
95
|
-
* @param view - This agent's state.
|
|
96
|
-
* @param attempt - 1 for the first repair of this divergence, then 2, 3, …
|
|
97
|
-
* A single push is not a livelock; a repeated one is, and only the repeat
|
|
98
|
-
* concedes. Default 1, which is what every existing caller had.
|
|
99
|
-
* @returns What to do about it.
|
|
100
|
-
*/
|
|
101
|
-
export declare function antiEntropyDecision(hub: HubAnnouncement, view: AntiEntropyView, attempt?: number): AntiEntropyDecision;
|
|
102
|
-
/** What {@link FsAntiEntropy} can report about itself. */
|
|
103
|
-
export interface AntiEntropyStatus {
|
|
104
|
-
/** Whether the last announcement differed from our state. */
|
|
105
|
-
diverged: boolean;
|
|
106
|
-
/** Since when the current divergence has lasted, epoch ms. */
|
|
107
|
-
divergedSince: number | null;
|
|
108
|
-
/** The state the hub last announced. */
|
|
109
|
-
hubRef: string | null;
|
|
110
|
-
/**
|
|
111
|
-
* The state this node is in **now**, not the one it was in when it last
|
|
112
|
-
* compared.
|
|
113
|
-
*
|
|
114
|
-
* It used to be the latter, and the two read identically in a quiet fleet and
|
|
115
|
-
* differently in exactly the case somebody is debugging. A node that moves
|
|
116
|
-
* after the last announcement it processed kept reporting the ref it had then,
|
|
117
|
-
* so `hubRef === localRef` with {@link diverged} false was indistinguishable
|
|
118
|
-
* from genuinely being in sync — and a churn run on CI showed four nodes
|
|
119
|
-
* reporting precisely that while two of them held different bytes for one
|
|
120
|
-
* path. Read live, the pair says what it is: the hub announced X, I am at Y,
|
|
121
|
-
* and {@link diverged} is the verdict of the last comparison rather than of
|
|
122
|
-
* this instant.
|
|
123
|
-
*/
|
|
124
|
-
localRef: string | null;
|
|
125
|
-
/**
|
|
126
|
-
* The paths this node and the hub actually disagree about, when that has
|
|
127
|
-
* been established.
|
|
128
|
-
*
|
|
129
|
-
* The register: *"als Statusinfo bleibt: die Prüfsummen sind
|
|
130
|
-
* verschieden"* — which tells
|
|
131
|
-
* an operator nothing they can act on, and tells a user nothing at all. The
|
|
132
|
-
* content comparison that decides {@link diverged} already knows the answer
|
|
133
|
-
* per PATH, so the answer is kept rather than reduced to a boolean.
|
|
134
|
-
*
|
|
135
|
-
* Empty when the two agree, and empty when nothing has compared them yet —
|
|
136
|
-
* which {@link diverged} distinguishes.
|
|
137
|
-
*/
|
|
138
|
-
differingPaths: readonly string[];
|
|
139
|
-
/** How many repairs were started over this agent's lifetime. */
|
|
140
|
-
repairs: number;
|
|
141
|
-
/**
|
|
142
|
-
* The most recent repair, or the most recent refusal to attempt one.
|
|
143
|
-
*
|
|
144
|
-
* `action: 'blocked'` means the ancestry could not be resolved far enough to
|
|
145
|
-
* decide; nothing was done and nothing was latched. It is not counted in
|
|
146
|
-
* {@link repairs}, because nothing was repaired.
|
|
147
|
-
*/
|
|
148
|
-
lastRepair: {
|
|
149
|
-
action: AntiEntropyAction | 'blocked';
|
|
150
|
-
at: number;
|
|
151
|
-
hubRef: string;
|
|
152
|
-
localRef: string;
|
|
153
|
-
attempt: number;
|
|
154
|
-
} | null;
|
|
155
|
-
}
|
|
156
|
-
/** What {@link FsAntiEntropy} needs from the agent it runs in. */
|
|
157
|
-
/** What a content comparison concluded. See {@link AntiEntropyDeps.sameContent}. */
|
|
158
|
-
export interface ContentComparison {
|
|
159
|
-
/** Whether the two folders hold the same content. */
|
|
160
|
-
same: boolean;
|
|
161
|
-
/**
|
|
162
|
-
* The paths they disagree about — on either side, so a path only one of them
|
|
163
|
-
* holds is listed too.
|
|
164
|
-
*
|
|
165
|
-
* Reported even when {@link same} is true, in which case it is empty.
|
|
166
|
-
*/
|
|
167
|
-
differing: readonly string[];
|
|
168
|
-
}
|
|
169
|
-
export interface AntiEntropyDeps {
|
|
170
|
-
/** This agent's state, read fresh at every announcement. */
|
|
171
|
-
view: () => AntiEntropyView;
|
|
172
|
-
/**
|
|
173
|
-
* Whether anything is already applying or queued — a repair then waits.
|
|
174
|
-
* @param hubRef - The state the hub is announcing right now.
|
|
175
|
-
*/
|
|
176
|
-
busy: (hubRef: string) => boolean;
|
|
177
|
-
/**
|
|
178
|
-
* Starts a repair.
|
|
179
|
-
* @param action - What to do.
|
|
180
|
-
* @param hubRef - The state the hub announced.
|
|
181
|
-
* @param hubPredecessors - What that state descends from.
|
|
182
|
-
* @param attempt - 1 for the first repair of this divergence, then 2, 3, …
|
|
183
|
-
*/
|
|
184
|
-
repair: (action: AntiEntropyAction, hubRef: string, hubPredecessors: string[], attempt: number) => void;
|
|
185
|
-
/**
|
|
186
|
-
* Whether a hub ref describes the same CONTENT as this folder.
|
|
187
|
-
*
|
|
188
|
-
* **This is what stops a divergence being reported on a difference of
|
|
189
|
-
* fingerprints alone.** The decision above compares refs, which is all a
|
|
190
|
-
* state beacon carries — and a beacon, unlike a ref event, triggers no
|
|
191
|
-
* apply, so nothing else in the agent ever fetches that tree and nothing
|
|
192
|
-
* ever discovers that the two folders are identical. measured on a real fleet:
|
|
193
|
-
* `diverged: true` for over EIGHT MINUTES on a node holding exactly the
|
|
194
|
-
* hub's 38 files.
|
|
195
|
-
*
|
|
196
|
-
* Costs one tree fetch per hub ref first seen as a divergence, and the
|
|
197
|
-
* verdict is cached in {@link _contentAgreed}, so a repeating beacon costs
|
|
198
|
-
* nothing. Optional, because a host that cannot answer is no worse off than
|
|
199
|
-
* before: the repair still runs and a bucket round still settles it.
|
|
200
|
-
* @param ref - The hub's ref.
|
|
201
|
-
*/
|
|
202
|
-
sameContent?: (ref: string) => Promise<ContentComparison>;
|
|
203
|
-
/** Clock, for tests. */
|
|
204
|
-
now?: () => number;
|
|
205
|
-
/** Log sink. */
|
|
206
|
-
log?: (message: string) => void;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Notices a divergence between this agent and the hub, and repairs it.
|
|
210
|
-
*
|
|
211
|
-
* Fed with every hub announcement; decides nothing while this node's own state
|
|
212
|
-
* is still moving, only once it has sat still and out of step with the hub for
|
|
213
|
-
* {@link AntiEntropyOptions.graceMs} — however often the hub's state changed
|
|
214
|
-
* meanwhile.
|
|
215
|
-
*/
|
|
216
|
-
export declare class FsAntiEntropy {
|
|
217
|
-
private readonly _deps;
|
|
218
|
-
private readonly _options;
|
|
219
|
-
private readonly _now;
|
|
220
|
-
private readonly _log;
|
|
221
|
-
/**
|
|
222
|
-
* Identifies the divergence being watched: OUR state, and only ours.
|
|
223
|
-
*
|
|
224
|
-
* It used to include the hub's state, so every change on the hub restarted
|
|
225
|
-
* the grace period — and a node that missed every forward while another
|
|
226
|
-
* machine wrote every few seconds never got a repair at all, showing "weicht
|
|
227
|
-
* ab, noch kein Reparaturversuch" for good (review, an earlier change). What makes a
|
|
228
|
-
* divergence a lost message is that THIS node is not moving: a node keeping
|
|
229
|
-
* up with the traffic changes its own state with every forward it applies.
|
|
230
|
-
* Which hub state the repair answers is read from the latest announcement.
|
|
231
|
-
*/
|
|
232
|
-
private _key;
|
|
233
|
-
private _divergedSince;
|
|
234
|
-
/** Earliest moment the next repair of {@link _key} may start. */
|
|
235
|
-
private _nextRepairAt;
|
|
236
|
-
/** Repairs started for {@link _key}. */
|
|
237
|
-
private _attempts;
|
|
238
|
-
/**
|
|
239
|
-
* Hub refs proven to describe the same CONTENT as this folder.
|
|
240
|
-
*
|
|
241
|
-
* A tree ref is a hash of the whole tree, and two nodes can derive different
|
|
242
|
-
* ones for byte-identical content — the order a filesystem lists a directory
|
|
243
|
-
* in used to be enough, and during a rollout a node on an older build still
|
|
244
|
-
* derives the old ref. measured on a real fleet: both machines held 38 identical
|
|
245
|
-
* files with identical hashes and one reported `diverged: true` for over
|
|
246
|
-
* EIGHT MINUTES across six merge repairs, logging "equivalent content,
|
|
247
|
-
* skipping restore" every time. The apply path correctly saw nothing to
|
|
248
|
-
* transfer; the anti-entropy correctly saw two refs; neither was wrong.
|
|
249
|
-
*
|
|
250
|
-
* A bucket round settles it: if the per-bucket roots agree, the two folders
|
|
251
|
-
* ARE the same, whatever either calls itself. That verdict is recorded here
|
|
252
|
-
* so the divergence stops being reported instead of being rediscovered every
|
|
253
|
-
* beacon — and so a mixed-version fleet does not spend its rollout window
|
|
254
|
-
* showing red.
|
|
255
|
-
*
|
|
256
|
-
* **KNOWN UNSOUND, AND THE PAIR KEY HAS NOW BEEN TRIED TWICE.** Do not fix
|
|
257
|
-
* this in isolation; read the whole note first.
|
|
258
|
-
*
|
|
259
|
-
* What a bucket round proves is "the hub's ref X describes the same content
|
|
260
|
-
* as the state I am in" — a statement about TWO sides, true only while
|
|
261
|
-
* neither moves. Keyed on X alone it survives this node changing underneath
|
|
262
|
-
* it, so a later announcement of X clears the divergence with no content
|
|
263
|
-
* check at all, for ever.
|
|
264
|
-
*
|
|
265
|
-
* Measured twice, and the second measurement is the one that matters.
|
|
266
|
-
* First as contradictory health signals: all four nodes of a churn run
|
|
267
|
-
* reporting `diverged=false` while their own `differingPaths` named
|
|
268
|
-
* `two.txt`. Then as what that costs, in the churn fuzzer at seed 2:
|
|
269
|
-
*
|
|
270
|
-
* A: 11 files diverged=false hub=goDX1oLq local=kderYtfA differing=[]
|
|
271
|
-
* B: 10 files diverged=false hub=goDX1oLq local=goDX1oLq differing=[sub/three.txt]
|
|
272
|
-
*
|
|
273
|
-
* B had deleted `sub/three.txt`, nobody re-created it, and A, C and D all
|
|
274
|
-
* held it while reporting no divergence — so none of them ever repaired. The
|
|
275
|
-
* fleet does not merely MISREPORT under this memo; the repair is gated on
|
|
276
|
-
* the signal it falsifies, so **the fleet does not heal.** That is worse
|
|
277
|
-
* than the note here used to claim, and it is why this will have to be
|
|
278
|
-
* fixed rather than tolerated.
|
|
279
|
-
*
|
|
280
|
-
* WHY THE PAIR KEY STILL DOES NOT WORK. The note here used to say it must
|
|
281
|
-
* wait "until the repair can tell 'I am ahead' from 'I am behind' without a
|
|
282
|
-
* chain verdict", and that reads as though a chain verdict were the only
|
|
283
|
-
* missing piece. It is not sufficient. `antiEntropyDecision` does switch on
|
|
284
|
-
* `hub.reachability` before any heuristic — `ahead` answers `push` — and the
|
|
285
|
-
* second attempt still took `I7b` to 0 of 8.
|
|
286
|
-
*
|
|
287
|
-
* Two inputs were found and fixed on the way, and NEITHER was enough:
|
|
288
|
-
*
|
|
289
|
-
* - bucket-sync envelopes were reaching `observe` as if they were states
|
|
290
|
-
* (`hub=~BR~{"r"…`), so the folder looked permanently diverged and the
|
|
291
|
-
* decision came from heuristics on a JSON envelope. Fixed in
|
|
292
|
-
* `fs-agent.ts` — the note here had already claimed this was fixed
|
|
293
|
-
* elsewhere, which was wrong;
|
|
294
|
-
* - a bare hub beacon was observed with no reachability at all, so the
|
|
295
|
-
* heuristics decided `pull` for a node that was ahead
|
|
296
|
-
* (`hub=hd3PHz1r… local=_esQ4A0L… — pull`). Now resolved through the
|
|
297
|
-
* chain and offered as a second observation.
|
|
298
|
-
*
|
|
299
|
-
* THE DEFECT UNDERNEATH IS A LIVELOCK, AND IT HAS ONE ROOT CAUSE. Traced by
|
|
300
|
-
* removing the masks one at a time and then logging the decision inputs:
|
|
301
|
-
*
|
|
302
|
-
* anti-entropy: hub=_esQ4A0L… local=hd3PHz1r… diverged for 89s — pull (attempt 44)
|
|
303
|
-
*
|
|
304
|
-
* Forty-four attempts over eighty-nine seconds, and every one of them with
|
|
305
|
-
* `reachability` UNDEFINED. With no verdict the switch above falls through
|
|
306
|
-
* and the heuristic answers `pull` for a divergence it cannot close, for
|
|
307
|
-
* ever — the same unbounded retry `@rljson/mongo-agent` bounded in 0.0.52.
|
|
308
|
-
*
|
|
309
|
-
* So the chain never decides here, not because the decision ignores it but
|
|
310
|
-
* because the verdict does not arrive: resolving the announced state is a
|
|
311
|
-
* read, and on this path it still takes the full ten seconds
|
|
312
|
-
* (`Timeout after 10000ms: … resolveAnnouncement`). A verdict that arrives
|
|
313
|
-
* late is indistinguishable from no verdict.
|
|
314
|
-
*
|
|
315
|
-
* THE ORDER THAT FOLLOWS, and it is not "fix the memo":
|
|
316
|
-
*
|
|
317
|
-
* 1. make the reachability read return on the anti-entropy path;
|
|
318
|
-
* 2. then the switch above answers from the chain and the livelock stops;
|
|
319
|
-
* 3. then both masks come off together — this key, and the envelope filter;
|
|
320
|
-
* 4. the memo is one line at the end of that, exactly as the convergence
|
|
321
|
-
* contract has said all along.
|
|
322
|
-
*
|
|
323
|
-
* The masks, found while attempting step 4 first:
|
|
324
|
-
*
|
|
325
|
-
* memo pair key applied, both fixes in I7b 0 of 8
|
|
326
|
-
* memo reverted, both fixes in I7b 0 of 6
|
|
327
|
-
* memo reverted, second observe removed I7b 0 of 3
|
|
328
|
-
* memo reverted, envelope filter removed I7b 3 of 3
|
|
329
|
-
*
|
|
330
|
-
* Dropping bucket envelopes from `observe` is correct in principle — an
|
|
331
|
-
* envelope names no tree — and it BREAKS `I7b` on its own, because the
|
|
332
|
-
* spurious divergence those envelopes produce is what keeps the tracked hub
|
|
333
|
-
* state moving so the livelock above never persists long enough to run.
|
|
334
|
-
*
|
|
335
|
-
* Both masks are therefore load-bearing today, and neither may be removed
|
|
336
|
-
* before step 1. That is why the pair key failed twice with a different
|
|
337
|
-
* explanation each time.
|
|
338
|
-
*
|
|
339
|
-
* The code already knew the rule and applied it to one side only: a `no` is
|
|
340
|
-
* deliberately never cached, because *"caching a `no` would have to be
|
|
341
|
-
* invalidated the moment either side changes"*. A `yes` needs exactly the
|
|
342
|
-
* same invalidation, and the pair key is what provides it — once the repair
|
|
343
|
-
* behind it is safe.
|
|
344
|
-
*
|
|
345
|
-
* Bounded, because it is keyed on refs a peer chooses: a hub that changes
|
|
346
|
-
* state constantly must not grow this without limit.
|
|
347
|
-
*/
|
|
348
|
-
private readonly _contentAgreed;
|
|
349
|
-
/**
|
|
350
|
-
* The memo key: what the hub announced AND the state this node was in.
|
|
351
|
-
* @param hubRef - The ref the hub announced.
|
|
352
|
-
* @param localRef - The state this node is in, read fresh from `view`.
|
|
353
|
-
* @returns A key no other pair can spell.
|
|
354
|
-
*/
|
|
355
|
-
private static _agreementKey;
|
|
356
|
-
/**
|
|
357
|
-
* Hub refs a content check is already running for.
|
|
358
|
-
*
|
|
359
|
-
* A beacon repeats, and a second fetch of a tree the first fetch is already
|
|
360
|
-
* reading answers the same question at twice the cost.
|
|
361
|
-
*/
|
|
362
|
-
private readonly _contentChecking;
|
|
363
|
-
/** See {@link AntiEntropyStatus.differingPaths}. */
|
|
364
|
-
private _differingPaths;
|
|
365
|
-
private _hubRef;
|
|
366
|
-
private _repairs;
|
|
367
|
-
private _lastRepair;
|
|
368
|
-
constructor(options: AntiEntropyOptions | undefined, _deps: AntiEntropyDeps);
|
|
369
|
-
/**
|
|
370
|
-
* Asks whether a hub ref describes this folder's content, and records a
|
|
371
|
-
* `yes`.
|
|
372
|
-
*
|
|
373
|
-
* Fire and forget: the answer arrives after this announcement is done with,
|
|
374
|
-
* and clears the divergence then. A `no` is not recorded — content really
|
|
375
|
-
* differing is what the repair is for, and caching a `no` would have to be
|
|
376
|
-
* invalidated the moment either side changes.
|
|
377
|
-
* @param ref - The hub ref under consideration.
|
|
378
|
-
*/
|
|
379
|
-
private _checkContent;
|
|
380
|
-
/**
|
|
381
|
-
* Records that a hub ref describes the same content as this folder.
|
|
382
|
-
*
|
|
383
|
-
* Called when a bucket round finds the per-bucket roots identical. See
|
|
384
|
-
* {@link _contentAgreed}.
|
|
385
|
-
* @param ref - The hub ref that was compared.
|
|
386
|
-
*/
|
|
387
|
-
agreedOn(ref: string): void;
|
|
388
|
-
/** Whether repairs are switched on. */
|
|
389
|
-
get enabled(): boolean;
|
|
390
|
-
/**
|
|
391
|
-
* A snapshot of what this instance has seen and done.
|
|
392
|
-
*
|
|
393
|
-
* `localRef` is read from `view` here rather than from a remembered field,
|
|
394
|
-
* because this node's own state is the one fact that is always available and
|
|
395
|
-
* never needs remembering — see {@link AntiEntropyStatus.localRef}. The field
|
|
396
|
-
* that held it is gone rather than left unread.
|
|
397
|
-
*/
|
|
398
|
-
get status(): AntiEntropyStatus;
|
|
399
|
-
/**
|
|
400
|
-
* Takes one hub announcement into account.
|
|
401
|
-
* @param hub - What the hub announced.
|
|
402
|
-
*/
|
|
403
|
-
observe(hub: HubAnnouncement): void;
|
|
404
|
-
}
|
package/dist/fs-bucket-sync.d.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { BucketRoots, ManifestEntry, ReconcilePlan } from './fs-manifest.ts';
|
|
2
|
-
/** Ask for the peer's bucket roots. Body: nothing. */
|
|
3
|
-
export declare const BQ = "~BQ~";
|
|
4
|
-
/** The roots. Body: `bucket:root` pairs. */
|
|
5
|
-
export declare const BR = "~BR~";
|
|
6
|
-
/** Ask for the entries of listed buckets. Body: bucket indices. */
|
|
7
|
-
export declare const BG = "~BG~";
|
|
8
|
-
/** The entries. Body: `path:blobId` pairs. */
|
|
9
|
-
export declare const BE = "~BE~";
|
|
10
|
-
/** Every prefix this protocol owns. */
|
|
11
|
-
export declare const BUCKET_SYNC_PREFIXES: readonly ["~BQ~", "~BR~", "~BG~", "~BE~"];
|
|
12
|
-
/**
|
|
13
|
-
* Whether a ref belongs to this protocol.
|
|
14
|
-
* @param ref - The ref as it arrived.
|
|
15
|
-
* @returns `true` when it is a bucket-sync message.
|
|
16
|
-
*/
|
|
17
|
-
export declare const isBucketSync: (ref: string) => boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Encodes bucket roots for the wire.
|
|
20
|
-
* @param round - The round this answers.
|
|
21
|
-
* @param roots - The roots to send.
|
|
22
|
-
* @returns A ref carrying them.
|
|
23
|
-
*/
|
|
24
|
-
export declare const encodeRoots: (round: number, roots: BucketRoots) => string;
|
|
25
|
-
/**
|
|
26
|
-
* Decodes bucket roots.
|
|
27
|
-
* @param ref - A `~BR~` ref.
|
|
28
|
-
* @returns The round and roots, or `undefined` for an unreadable body. An
|
|
29
|
-
* EMPTY roots object is a real state — a node with nothing in its folder —
|
|
30
|
-
* and is not the same as an unreadable one.
|
|
31
|
-
*/
|
|
32
|
-
export declare const decodeRoots: (ref: string) => {
|
|
33
|
-
round: number;
|
|
34
|
-
roots: BucketRoots;
|
|
35
|
-
} | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Encodes a request for the peer's roots.
|
|
38
|
-
* @param round - The round being started.
|
|
39
|
-
* @returns A ref.
|
|
40
|
-
*/
|
|
41
|
-
export declare const encodeQuery: (round: number) => string;
|
|
42
|
-
/**
|
|
43
|
-
* Decodes a request for roots.
|
|
44
|
-
* @param ref - A `~BQ~` ref.
|
|
45
|
-
* @returns The round, or `undefined` for an unreadable body.
|
|
46
|
-
*/
|
|
47
|
-
export declare const decodeQuery: (ref: string) => number | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Encodes a request for the entries of some buckets.
|
|
50
|
-
* @param round - The round.
|
|
51
|
-
* @param buckets - The bucket indices wanted.
|
|
52
|
-
* @returns A ref carrying them.
|
|
53
|
-
*/
|
|
54
|
-
export declare const encodeWanted: (round: number, buckets: readonly number[]) => string;
|
|
55
|
-
/**
|
|
56
|
-
* Decodes a request for bucket entries.
|
|
57
|
-
* @param ref - A `~BG~` ref.
|
|
58
|
-
* @returns The round and bucket indices, or `undefined`.
|
|
59
|
-
*/
|
|
60
|
-
export declare const decodeWanted: (ref: string) => {
|
|
61
|
-
round: number;
|
|
62
|
-
buckets: number[];
|
|
63
|
-
} | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* Encodes manifest entries for the wire.
|
|
66
|
-
* @param round - The round.
|
|
67
|
-
* @param entries - The entries to send.
|
|
68
|
-
* @returns A ref carrying them.
|
|
69
|
-
*/
|
|
70
|
-
export declare const encodeEntries: (round: number, entries: readonly ManifestEntry[]) => string;
|
|
71
|
-
/**
|
|
72
|
-
* Decodes manifest entries.
|
|
73
|
-
* @param ref - A `~BE~` ref.
|
|
74
|
-
* @returns The round and entries, or `undefined`. A tombstone arrives as a
|
|
75
|
-
* path with an empty blob id, which is the whole point of carrying deletions
|
|
76
|
-
* this way.
|
|
77
|
-
*/
|
|
78
|
-
export declare const decodeEntries: (ref: string) => {
|
|
79
|
-
round: number;
|
|
80
|
-
entries: ManifestEntry[];
|
|
81
|
-
} | undefined;
|
|
82
|
-
/** What {@link FsBucketSync} needs from the agent it runs in. */
|
|
83
|
-
export interface BucketSyncHost {
|
|
84
|
-
/**
|
|
85
|
-
* This folder's manifest: `path → blobId`, with every tombstoned path
|
|
86
|
-
* included at {@link TOMBSTONE_BLOB}.
|
|
87
|
-
*
|
|
88
|
-
* A tombstone must be in here or the delete-wins half cannot work: a peer
|
|
89
|
-
* would see the path simply absent, which is the ambiguity the whole design
|
|
90
|
-
* removes.
|
|
91
|
-
*/
|
|
92
|
-
manifest(): ReadonlyMap<string, string>;
|
|
93
|
-
/**
|
|
94
|
-
* Paths this node's own history says it EDITED.
|
|
95
|
-
*
|
|
96
|
-
* Travels with each entry so a same-path conflict is settled by who wrote
|
|
97
|
-
* the file rather than by which content hash sorts higher. Optional: a host
|
|
98
|
-
* without a chain claims nothing, and the hash rule still converges.
|
|
99
|
-
*/
|
|
100
|
-
claimed?(): ReadonlySet<string>;
|
|
101
|
-
/**
|
|
102
|
-
* `path → timeId` of the newest edit this node has heard of for each path.
|
|
103
|
-
*
|
|
104
|
-
* Optional for the same reason {@link claimed} is: a host that cannot answer
|
|
105
|
-
* leaves the entries without times, and `reconcile` falls back to the rules
|
|
106
|
-
* that shipped before the field existed.
|
|
107
|
-
*/
|
|
108
|
-
editTimes?(): ReadonlyMap<string, string>;
|
|
109
|
-
/** Puts a protocol ref on the wire. */
|
|
110
|
-
send(ref: string): void;
|
|
111
|
-
/**
|
|
112
|
-
* Performs a plan.
|
|
113
|
-
*
|
|
114
|
-
* Only the host may touch the folder. `drop` is destructive and must go
|
|
115
|
-
* through the same mass-delete guard an ordinary prune does — the protocol
|
|
116
|
-
* deliberately has no way to delete anything itself.
|
|
117
|
-
*/
|
|
118
|
-
apply(plan: ReconcilePlan): Promise<void>;
|
|
119
|
-
/**
|
|
120
|
-
* Whether this node's manifest is complete enough to compare.
|
|
121
|
-
*
|
|
122
|
-
* Mongo calls this `ready()`, and its header says why: until a baseline is
|
|
123
|
-
* complete the bucket roots are partial *"and would make a peer see spurious
|
|
124
|
-
* differences"*. A node mid-cold-start must neither answer nor ask.
|
|
125
|
-
*/
|
|
126
|
-
ready(): boolean;
|
|
127
|
-
/**
|
|
128
|
-
* The roots were identical: the two folders hold the same content.
|
|
129
|
-
*
|
|
130
|
-
* Worth telling the host, because a ref comparison cannot reach this
|
|
131
|
-
* conclusion. Two nodes derive different tree refs for byte-identical
|
|
132
|
-
* content whenever anything outside the content map differs — and during a
|
|
133
|
-
* rollout, a node on an older build always does. Measured as eight minutes
|
|
134
|
-
* of `diverged: true` on 38 identical files.
|
|
135
|
-
*/
|
|
136
|
-
agreed?(): void;
|
|
137
|
-
/** Log sink. */
|
|
138
|
-
log?: (message: string) => void;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* One side of the bucket-sync conversation.
|
|
142
|
-
*
|
|
143
|
-
* Stateless between rounds except for the buckets it is waiting on, so a round
|
|
144
|
-
* that is interrupted — a peer that goes away mid-exchange — costs nothing and
|
|
145
|
-
* is simply started again.
|
|
146
|
-
*/
|
|
147
|
-
export declare class FsBucketSync {
|
|
148
|
-
private readonly _host;
|
|
149
|
-
private readonly _log;
|
|
150
|
-
/** Buckets we asked for entries of, and the round we asked in. */
|
|
151
|
-
private _awaiting;
|
|
152
|
-
/** Monotonic round ids, so no two messages from this node are identical. */
|
|
153
|
-
private _round;
|
|
154
|
-
constructor(_host: BucketSyncHost);
|
|
155
|
-
/** Whether a round is in flight. */
|
|
156
|
-
get busy(): boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Starts a round by asking a peer for its roots.
|
|
159
|
-
*
|
|
160
|
-
* Refused while this node is not {@link BucketSyncHost.ready}: comparing a
|
|
161
|
-
* partial manifest makes a peer see differences that are not there, and the
|
|
162
|
-
* cheapest outcome of that is a pointless exchange.
|
|
163
|
-
* @returns Whether a round was started.
|
|
164
|
-
*/
|
|
165
|
-
start(): boolean;
|
|
166
|
-
/**
|
|
167
|
-
* Takes one protocol message.
|
|
168
|
-
* @param ref - The message.
|
|
169
|
-
* @returns Whether it was a bucket-sync message this node acted on.
|
|
170
|
-
*/
|
|
171
|
-
receive(ref: string): Promise<boolean>;
|
|
172
|
-
}
|