@optimystic/db-p2p 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cluster/cluster-repo.d.ts +35 -12
- package/dist/src/cluster/cluster-repo.d.ts.map +1 -1
- package/dist/src/cluster/cluster-repo.js +47 -15
- package/dist/src/cluster/cluster-repo.js.map +1 -1
- package/dist/src/repo/cluster-coordinator.d.ts +92 -36
- package/dist/src/repo/cluster-coordinator.d.ts.map +1 -1
- package/dist/src/repo/cluster-coordinator.js +266 -198
- package/dist/src/repo/cluster-coordinator.js.map +1 -1
- package/dist/src/repo/coordinator-repo.d.ts.map +1 -1
- package/dist/src/repo/coordinator-repo.js +5 -4
- package/dist/src/repo/coordinator-repo.js.map +1 -1
- package/dist/src/storage/storage-repo.d.ts.map +1 -1
- package/dist/src/storage/storage-repo.js +24 -6
- package/dist/src/storage/storage-repo.js.map +1 -1
- package/package.json +2 -2
- package/src/cluster/cluster-repo.ts +48 -15
- package/src/repo/cluster-coordinator.ts +1409 -1328
- package/src/repo/coordinator-repo.ts +5 -4
- package/src/storage/storage-repo.ts +1781 -1762
|
@@ -179,8 +179,9 @@ export declare class ClusterCoordinator {
|
|
|
179
179
|
resolveCohort(blockId: BlockId): Promise<CohortResolution>;
|
|
180
180
|
/**
|
|
181
181
|
* A node never runs a cluster transaction for a cohort it is not in. Behind members reconcile from the
|
|
182
|
-
* coordinator's own proof-carrying copy (its member applies before the
|
|
183
|
-
*
|
|
182
|
+
* coordinator's own proof-carrying copy (its member applies before the consensus broadcast, and a
|
|
183
|
+
* member that applied earlier, on receipt of the commit round, is sent the record again once it has),
|
|
184
|
+
* and a coordinator outside `record.peers` is not a reconcile target — so a cohort with no holder would stay
|
|
184
185
|
* behind and the commit durability gate would refuse, having first put this node's vote and storage
|
|
185
186
|
* where the cohort does not look. The invariant is held here, at the one place a record's `peers` is
|
|
186
187
|
* chosen, rather than left to the routing convention.
|
|
@@ -213,9 +214,9 @@ export declare class ClusterCoordinator {
|
|
|
213
214
|
* during consensus, when the member retained one. Same availability contract as
|
|
214
215
|
* `localPendResult`. `CoordinatorRepo.commit` uses a retained refusal to detect a rival's
|
|
215
216
|
* win swallowed by the member-side ahead-divergence tolerance, instead of fabricating a
|
|
216
|
-
* success no member durably stored. Read after the
|
|
217
|
-
* verdict already reflects the
|
|
218
|
-
*
|
|
217
|
+
* success no member durably stored. Read after the consensus broadcast, so a behind member's
|
|
218
|
+
* verdict already reflects the reconcile it ran against the remote members that applied in the
|
|
219
|
+
* commit round, and any second one `broadcastMergedRecord` gave it.
|
|
219
220
|
*/
|
|
220
221
|
localCommitResult?: CommitResult;
|
|
221
222
|
/**
|
|
@@ -276,44 +277,99 @@ export declare class ClusterCoordinator {
|
|
|
276
277
|
*/
|
|
277
278
|
private collectPromises;
|
|
278
279
|
/**
|
|
279
|
-
*
|
|
280
|
+
* The commit round, then the consensus delivery. Runs once the promise round reached super-majority.
|
|
281
|
+
*
|
|
282
|
+
* **This node's own member votes to commit first, in process, and its signature rides on the commit
|
|
283
|
+
* round** ({@link presignLocalCommit}). A remote member receiving that record adds its own commit,
|
|
284
|
+
* and in a cohort of two (2 of 2) or three (2 of 3) that is already the strict majority its phase
|
|
285
|
+
* loop needs for consensus, so it applies in the same delivery and answers with its apply report
|
|
286
|
+
* stamped on. What a member accepts does not change: it reaches consensus only on commit signatures
|
|
287
|
+
* it verified, and it signed its own commit only after seeing a super-majority of approved promises.
|
|
288
|
+
* It is the same kind of record the consensus broadcast carries, arriving one round earlier. In a
|
|
289
|
+
* cohort of four or more the coordinator's commit plus one member's is short of a majority, so
|
|
290
|
+
* nobody applies on receipt and the broadcast below works as it always did.
|
|
291
|
+
*
|
|
292
|
+
* Once the merged commits reach the majority, {@link broadcastMergedRecord} delivers the record to
|
|
293
|
+
* this node's member and then only to the remote members still needing it
|
|
294
|
+
* ({@link membersAwaitingConsensus}). With every remote member healthy in a small cohort that list is
|
|
295
|
+
* empty, so a consensus operation costs each remote member two calls (promise, commit) instead of
|
|
296
|
+
* three. When the pre-sign is unavailable the round runs as it did before — every member in
|
|
297
|
+
* parallel, this node's included — and the broadcast then reaches every member.
|
|
280
298
|
*/
|
|
281
299
|
private commitTransaction;
|
|
282
300
|
/**
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
301
|
+
* Have this node's own member vote to commit on the promise-complete record, in process, before the
|
|
302
|
+
* commit round goes out, and merge its signature into `record`. True when the member answered: the
|
|
303
|
+
* round then leaves it out, and the consensus broadcast delivers it the merged record (should it
|
|
304
|
+
* have answered without a commit — its phase was not `OurCommitNeeded` — it is no worse off than
|
|
305
|
+
* in the round, where it would have answered the same). False when there is no local member in the
|
|
306
|
+
* cohort (some test wiring) or the member threw (an expired message, or `validateRecord` refused):
|
|
307
|
+
* the round then runs with it included, as it always did.
|
|
288
308
|
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
309
|
+
* The member cannot reach consensus here: the record carries no commit yet, and its own is a
|
|
310
|
+
* majority only in a cohort of one, which `CoordinatorRepo`'s solo path keeps away from this class.
|
|
311
|
+
* Were one to arrive anyway, the member would apply here and the broadcast would skip it as
|
|
312
|
+
* already executed.
|
|
313
|
+
*/
|
|
314
|
+
private presignLocalCommit;
|
|
315
|
+
/**
|
|
316
|
+
* Send `record` to each of `peerIds` in parallel for its commit vote. No per-peer immediate retry:
|
|
317
|
+
* a failure here is recovered by the consensus broadcast's in-line retry and the scheduled
|
|
318
|
+
* commit-retry timer. (The promise round has no such backstop, which is why `collectPromises` gets
|
|
319
|
+
* the immediate retry instead.)
|
|
320
|
+
*/
|
|
321
|
+
private collectCommits;
|
|
322
|
+
/** Whether `record`'s commit signatures reach the simple majority (>50%) that proves the commit. */
|
|
323
|
+
private hasCommitMajority;
|
|
324
|
+
/** Schedule a commit retry for `missingPeers`, or clear any pending one when nobody is missing. */
|
|
325
|
+
private scheduleOrClearRetry;
|
|
326
|
+
/**
|
|
327
|
+
* One {@link updateMember} call whose failure is logged and returned rather than thrown, so a
|
|
328
|
+
* parallel round can read every member's answer.
|
|
329
|
+
*/
|
|
330
|
+
private deliver;
|
|
331
|
+
/**
|
|
332
|
+
* Deliver the consensus record — carrying a majority of commit signatures — to the members that
|
|
333
|
+
* still have to apply it: this node's own member first, awaited, unless it already applied
|
|
334
|
+
* ({@link deliverToLocalMember}); then `remoteTargets` in parallel. Each remote delivery gets
|
|
335
|
+
* `commitBroadcastImmediateRetries` in-line re-attempts before it counts as failed: the connection
|
|
336
|
+
* the commit round used is usually still warm, so an immediate retry recovers most transient stream
|
|
337
|
+
* errors without falling back to the scheduled retry timer. This node's member is invoked exactly
|
|
338
|
+
* once — a local failure is a real fault, not a transient one.
|
|
339
|
+
*
|
|
340
|
+
* **Delivery order is load-bearing: this node's own member first, then the remote members.** A
|
|
341
|
+
* member that is behind (it never saw the pend, or holds no base for the block) reconciles the
|
|
342
|
+
* committed revision from `record.peers` during its apply. Once the coordinating member has applied
|
|
343
|
+
* it holds the revision, and its copy carries the cohort's commit proof (`buildBlockCommitProof`),
|
|
344
|
+
* which `createReconcileBlock` accepts from a single holder, so a whole cohort of behind members can
|
|
345
|
+
* heal from it. This is also why `remoteTargets` includes members that have ALREADY applied but
|
|
346
|
+
* report a refused commit: in a cohort of three or fewer a remote member applies on receipt of the
|
|
347
|
+
* commit round ({@link commitTransaction}), before this node's member, so a behind one reconciled
|
|
348
|
+
* while nobody held the revision. Sending it the record again now gives it another reconcile
|
|
349
|
+
* (`ClusterMember.handleAlreadyExecuted`), and its answer carries the refreshed verdict. A
|
|
350
|
+
* coordinator outside `record.peers` is not a reconcile target and gains nothing from this order;
|
|
351
|
+
* the durability gate in `CoordinatorRepo.commit` is what makes that shape refuse rather than
|
|
352
|
+
* acknowledge.
|
|
306
353
|
*
|
|
307
|
-
* The mirror case — the coordinating member is ITSELF behind
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
354
|
+
* The mirror case — the coordinating member is ITSELF behind — mostly heals on its own: in a small
|
|
355
|
+
* cohort a remote member applied during the commit round, so this node's member finds a holder on
|
|
356
|
+
* its first reconcile. Where no remote member has applied yet (a cohort of four or more, where
|
|
357
|
+
* nobody applies on receipt), that first reconcile runs before anyone holds the revision and
|
|
358
|
+
* retains a refusal. So once a remote member reports holding the revision, this node's member gets
|
|
359
|
+
* one more reconcile (`reconcileRefusedCommit`). The member skips it unless its retained refusal has
|
|
360
|
+
* the behind shape, so only a behind coordinator pays the extra fetch. It finishes before this
|
|
361
|
+
* method returns, so `executeClusterTransaction` reads the refreshed verdict.
|
|
315
362
|
*/
|
|
316
363
|
private broadcastMergedRecord;
|
|
364
|
+
/**
|
|
365
|
+
* Deliver `record` to this node's own member, awaited. `undefined` — nothing sent — when there is
|
|
366
|
+
* no local member in the cohort, or it has already applied the record.
|
|
367
|
+
*/
|
|
368
|
+
private deliverToLocalMember;
|
|
369
|
+
/** This node's member is in the cohort and has applied the record: just now (`local`), or before. */
|
|
370
|
+
private localMemberHasApplied;
|
|
371
|
+
/** Whether any remote member reports holding the commit, on this delivery or an earlier one. */
|
|
372
|
+
private remoteMemberHolds;
|
|
317
373
|
/**
|
|
318
374
|
* Give this node's own member its second reconcile (see {@link broadcastMergedRecord}). The
|
|
319
375
|
* member contract is never to throw; the catch keeps a broken seam from failing a transaction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cluster-coordinator.d.ts","sourceRoot":"","sources":["../../../src/repo/cluster-coordinator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,E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