@peerbit/shared-log 14.0.0 → 15.0.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/index.d.ts +4 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -16
- package/dist/src/index.js.map +1 -1
- package/dist/src/replication-announcement.d.ts +3 -4
- package/dist/src/replication-announcement.d.ts.map +1 -1
- package/dist/src/replication-announcement.js +22 -3
- package/dist/src/replication-announcement.js.map +1 -1
- package/dist/src/replication-info-mutation.d.ts +34 -0
- package/dist/src/replication-info-mutation.d.ts.map +1 -0
- package/dist/src/replication-info-mutation.js +2 -0
- package/dist/src/replication-info-mutation.js.map +1 -0
- package/dist/src/replication-info-v2-send.d.ts +5 -5
- package/dist/src/replication-info-v2-send.d.ts.map +1 -1
- package/dist/src/replication-info-v2-send.js +9 -8
- package/dist/src/replication-info-v2-send.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +28 -22
- package/src/replication-announcement.ts +27 -6
- package/src/replication-info-mutation.ts +34 -0
- package/src/replication-info-v2-send.ts +10 -16
|
@@ -10,6 +10,7 @@ import { TimeoutError, debounceFixedInterval } from "@peerbit/time";
|
|
|
10
10
|
import { isNotStartedError } from "./errors.js";
|
|
11
11
|
import type { TransportMessage } from "./message.js";
|
|
12
12
|
import type { ReplicationRangeIndexable } from "./ranges.js";
|
|
13
|
+
import type { ReplicationInfoMutation } from "./replication-info-mutation.js";
|
|
13
14
|
import {
|
|
14
15
|
AddedReplicationSegmentMessage,
|
|
15
16
|
AllReplicatingSegmentsMessage,
|
|
@@ -206,14 +207,34 @@ export type ReplicationAnnouncementDeps<R extends "u32" | "u64"> = {
|
|
|
206
207
|
queueCurrentReplicationStateAnnouncementRetry: (error: unknown) => boolean;
|
|
207
208
|
// V2 is always current. Legacy publication is enabled only for an explicit
|
|
208
209
|
// compatibility open and retains its exact rejection/retry semantics there.
|
|
209
|
-
enqueueReplicationInfoV2: (
|
|
210
|
+
enqueueReplicationInfoV2: (mutation: ReplicationInfoMutation) => void;
|
|
210
211
|
isLegacyReplicationInfoEnabled: () => boolean;
|
|
211
212
|
};
|
|
212
213
|
|
|
213
|
-
|
|
214
|
+
/**
|
|
215
|
+
* The dormant legacy tail still broadcasts the retired wire classes when an
|
|
216
|
+
* explicit compatibility open enabled it (impossible since B12 stage 1; the
|
|
217
|
+
* tail is deleted in stage 3). Materialize the frame from the neutral
|
|
218
|
+
* mutation locally so the tail keeps its exact byte semantics until then.
|
|
219
|
+
*/
|
|
220
|
+
const toLegacyReplicationInfoFrame = (
|
|
221
|
+
mutation: ReplicationInfoMutation,
|
|
222
|
+
):
|
|
214
223
|
| AllReplicatingSegmentsMessage
|
|
215
224
|
| AddedReplicationSegmentMessage
|
|
216
|
-
| StoppedReplicating
|
|
225
|
+
| StoppedReplicating => {
|
|
226
|
+
if ("full" in mutation) {
|
|
227
|
+
return new AllReplicatingSegmentsMessage({
|
|
228
|
+
segments: mutation.full.segments,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if ("added" in mutation) {
|
|
232
|
+
return new AddedReplicationSegmentMessage({
|
|
233
|
+
segments: mutation.added.segments,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return new StoppedReplicating({ segmentIds: mutation.stopped.segmentIds });
|
|
237
|
+
};
|
|
217
238
|
|
|
218
239
|
export class ReplicationAnnouncementCoordinator<R extends "u32" | "u64"> {
|
|
219
240
|
replicationAnnouncementRetryDebounced:
|
|
@@ -627,7 +648,7 @@ export class ReplicationAnnouncementCoordinator<R extends "u32" | "u64"> {
|
|
|
627
648
|
}
|
|
628
649
|
|
|
629
650
|
async sendReplicationAnnouncement(
|
|
630
|
-
|
|
651
|
+
mutation: ReplicationInfoMutation,
|
|
631
652
|
ownershipLifecycleController = this.deps.captureReplicationOwnershipLifecycle(),
|
|
632
653
|
options?: { shouldSend?: () => boolean },
|
|
633
654
|
): Promise<void> {
|
|
@@ -652,12 +673,12 @@ export class ReplicationAnnouncementCoordinator<R extends "u32" | "u64"> {
|
|
|
652
673
|
// after that stale send settles.
|
|
653
674
|
this.rotateAnnouncementSession();
|
|
654
675
|
this.advanceCurrentReplicationStateAnnouncementRepairGeneration();
|
|
655
|
-
this.deps.enqueueReplicationInfoV2(
|
|
676
|
+
this.deps.enqueueReplicationInfoV2(mutation);
|
|
656
677
|
if (!this.deps.isLegacyReplicationInfoEnabled()) {
|
|
657
678
|
return;
|
|
658
679
|
}
|
|
659
680
|
try {
|
|
660
|
-
await this.deps.getRpc().send(
|
|
681
|
+
await this.deps.getRpc().send(toLegacyReplicationInfoFrame(mutation), {
|
|
661
682
|
priority: CONVERGENCE_MESSAGE_PRIORITY,
|
|
662
683
|
signal: ownershipLifecycleController.signal,
|
|
663
684
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReplicationRangeMessage } from "./ranges.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Neutral internal representation of a local replication-state mutation.
|
|
5
|
+
*
|
|
6
|
+
* Producers (replicate/unreplicate/join and their corrective snapshot paths)
|
|
7
|
+
* hand these plain tagged objects to the announcement coordinator, which maps
|
|
8
|
+
* them onto the directed V2 wire messages:
|
|
9
|
+
*
|
|
10
|
+
* - `full` -> FullReplicationInfoV2Message (authoritative snapshot)
|
|
11
|
+
* - `added` -> AddedReplicationInfoV2Message (incremental delta)
|
|
12
|
+
* - `stopped` -> StoppedReplicationInfoV2Message (retired segment ids)
|
|
13
|
+
*
|
|
14
|
+
* The retired legacy announcement classes (AllReplicatingSegmentsMessage,
|
|
15
|
+
* AddedReplicationSegmentMessage, StoppedReplicating) remain registered
|
|
16
|
+
* decode tombstones on the wire surface but are no longer the internal
|
|
17
|
+
* currency between mutation producers and the V2 sender.
|
|
18
|
+
*/
|
|
19
|
+
export type FullReplicationInfoMutation = {
|
|
20
|
+
full: { segments: ReplicationRangeMessage<any>[] };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type AddedReplicationInfoMutation = {
|
|
24
|
+
added: { segments: ReplicationRangeMessage<any>[] };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type StoppedReplicationInfoMutation = {
|
|
28
|
+
stopped: { segmentIds: Uint8Array[] };
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ReplicationInfoMutation =
|
|
32
|
+
| FullReplicationInfoMutation
|
|
33
|
+
| AddedReplicationInfoMutation
|
|
34
|
+
| StoppedReplicationInfoMutation;
|
|
@@ -8,13 +8,11 @@ import {
|
|
|
8
8
|
import type { TransportMessage } from "./message.js";
|
|
9
9
|
import type { ReplicationRangeIndexable } from "./ranges.js";
|
|
10
10
|
import { deriveReplicationInfoV2ReceiverBinding } from "./replication-info-v2-binding.js";
|
|
11
|
+
import type { ReplicationInfoMutation } from "./replication-info-mutation.js";
|
|
11
12
|
import {
|
|
12
13
|
AddedReplicationInfoV2Message,
|
|
13
|
-
AddedReplicationSegmentMessage,
|
|
14
|
-
AllReplicatingSegmentsMessage,
|
|
15
14
|
FullReplicationInfoV2Message,
|
|
16
15
|
RequestReplicationInfoV2Message,
|
|
17
|
-
StoppedReplicating,
|
|
18
16
|
StoppedReplicationInfoV2Message,
|
|
19
17
|
} from "./replication.js";
|
|
20
18
|
|
|
@@ -27,14 +25,9 @@ const MAX_BACKOFF_EXPONENT = 20;
|
|
|
27
25
|
|
|
28
26
|
export { deriveReplicationInfoV2ReceiverBinding } from "./replication-info-v2-binding.js";
|
|
29
27
|
|
|
30
|
-
export type LegacyReplicationInfoMessage =
|
|
31
|
-
| AllReplicatingSegmentsMessage
|
|
32
|
-
| AddedReplicationSegmentMessage
|
|
33
|
-
| StoppedReplicating;
|
|
34
|
-
|
|
35
28
|
type SendRequest =
|
|
36
29
|
| { kind: "snapshot" }
|
|
37
|
-
| { kind: "
|
|
30
|
+
| { kind: "mutation"; mutation: ReplicationInfoMutation };
|
|
38
31
|
|
|
39
32
|
export type ReplicationInfoV2SendState = {
|
|
40
33
|
peerHash: string;
|
|
@@ -393,9 +386,9 @@ export class ReplicationInfoV2SendCoordinator<R extends "u32" | "u64"> {
|
|
|
393
386
|
return true;
|
|
394
387
|
}
|
|
395
388
|
|
|
396
|
-
enqueue(
|
|
389
|
+
enqueue(mutation: ReplicationInfoMutation): void {
|
|
397
390
|
for (const state of [...this._sendStates.values()]) {
|
|
398
|
-
this.enqueueState(state, { kind: "
|
|
391
|
+
this.enqueueState(state, { kind: "mutation", mutation });
|
|
399
392
|
}
|
|
400
393
|
}
|
|
401
394
|
|
|
@@ -538,20 +531,21 @@ export class ReplicationInfoV2SendCoordinator<R extends "u32" | "u64"> {
|
|
|
538
531
|
this.deps.validatePersistedReplicationRangeSnapshot(segments);
|
|
539
532
|
return new FullReplicationInfoV2Message({ ...common, segments });
|
|
540
533
|
}
|
|
541
|
-
|
|
542
|
-
|
|
534
|
+
const { mutation } = request;
|
|
535
|
+
if ("full" in mutation) {
|
|
536
|
+
const segments = mutation.full.segments;
|
|
543
537
|
this.deps.validatePersistedReplicationRangeSnapshot(segments);
|
|
544
538
|
return new FullReplicationInfoV2Message({ ...common, segments });
|
|
545
539
|
}
|
|
546
|
-
if (
|
|
540
|
+
if ("added" in mutation) {
|
|
547
541
|
return new AddedReplicationInfoV2Message({
|
|
548
542
|
...common,
|
|
549
|
-
segments:
|
|
543
|
+
segments: mutation.added.segments,
|
|
550
544
|
});
|
|
551
545
|
}
|
|
552
546
|
return new StoppedReplicationInfoV2Message({
|
|
553
547
|
...common,
|
|
554
|
-
segmentIds:
|
|
548
|
+
segmentIds: mutation.stopped.segmentIds,
|
|
555
549
|
});
|
|
556
550
|
}
|
|
557
551
|
|