@peerbit/shared-log 13.2.24 → 13.2.26
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/checked-prune.d.ts +12 -0
- package/dist/src/checked-prune.d.ts.map +1 -1
- package/dist/src/checked-prune.js +33 -0
- package/dist/src/checked-prune.js.map +1 -1
- package/dist/src/coordinate-persistence.d.ts +211 -0
- package/dist/src/coordinate-persistence.d.ts.map +1 -0
- package/dist/src/coordinate-persistence.js +1133 -0
- package/dist/src/coordinate-persistence.js.map +1 -0
- package/dist/src/errors.d.ts +1 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +19 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +127 -133
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1400 -4269
- package/dist/src/index.js.map +1 -1
- package/dist/src/instance-lifecycle.d.ts +117 -0
- package/dist/src/instance-lifecycle.d.ts.map +1 -0
- package/dist/src/instance-lifecycle.js +254 -0
- package/dist/src/instance-lifecycle.js.map +1 -0
- package/dist/src/join-warmup.d.ts +86 -0
- package/dist/src/join-warmup.d.ts.map +1 -0
- package/dist/src/join-warmup.js +351 -0
- package/dist/src/join-warmup.js.map +1 -0
- package/dist/src/native-write-through-block-store.d.ts +123 -0
- package/dist/src/native-write-through-block-store.d.ts.map +1 -0
- package/dist/src/native-write-through-block-store.js +989 -0
- package/dist/src/native-write-through-block-store.js.map +1 -0
- package/dist/src/peer-session.d.ts +117 -0
- package/dist/src/peer-session.d.ts.map +1 -0
- package/dist/src/peer-session.js +259 -0
- package/dist/src/peer-session.js.map +1 -0
- package/dist/src/replication-announcement.d.ts +116 -0
- package/dist/src/replication-announcement.d.ts.map +1 -0
- package/dist/src/replication-announcement.js +515 -0
- package/dist/src/replication-announcement.js.map +1 -0
- package/dist/src/replicator-liveness.d.ts +59 -0
- package/dist/src/replicator-liveness.d.ts.map +1 -0
- package/dist/src/replicator-liveness.js +304 -0
- package/dist/src/replicator-liveness.js.map +1 -0
- package/dist/src/sync/dispatch-lifecycle.d.ts +48 -0
- package/dist/src/sync/dispatch-lifecycle.d.ts.map +1 -0
- package/dist/src/sync/dispatch-lifecycle.js +141 -0
- package/dist/src/sync/dispatch-lifecycle.js.map +1 -0
- package/dist/src/sync/factory.d.ts +29 -0
- package/dist/src/sync/factory.d.ts.map +1 -0
- package/dist/src/sync/factory.js +87 -0
- package/dist/src/sync/factory.js.map +1 -0
- package/dist/src/sync/pending-sync-store.d.ts +105 -0
- package/dist/src/sync/pending-sync-store.d.ts.map +1 -0
- package/dist/src/sync/pending-sync-store.js +877 -0
- package/dist/src/sync/pending-sync-store.js.map +1 -0
- package/dist/src/sync/rateless-iblt.d.ts +4 -1
- package/dist/src/sync/rateless-iblt.d.ts.map +1 -1
- package/dist/src/sync/rateless-iblt.js +102 -106
- package/dist/src/sync/rateless-iblt.js.map +1 -1
- package/dist/src/sync/simple.d.ts +10 -41
- package/dist/src/sync/simple.d.ts.map +1 -1
- package/dist/src/sync/simple.js +259 -952
- package/dist/src/sync/simple.js.map +1 -1
- package/dist/src/sync/sync-peer-state.d.ts +16 -0
- package/dist/src/sync/sync-peer-state.d.ts.map +1 -0
- package/dist/src/sync/sync-peer-state.js +82 -0
- package/dist/src/sync/sync-peer-state.js.map +1 -0
- package/package.json +12 -12
- package/src/checked-prune.ts +35 -0
- package/src/coordinate-persistence.ts +1796 -0
- package/src/errors.ts +21 -0
- package/src/index.ts +4014 -7858
- package/src/instance-lifecycle.ts +351 -0
- package/src/join-warmup.ts +507 -0
- package/src/native-write-through-block-store.ts +1170 -0
- package/src/peer-session.ts +336 -0
- package/src/replication-announcement.ts +744 -0
- package/src/replicator-liveness.ts +439 -0
- package/src/sync/dispatch-lifecycle.ts +230 -0
- package/src/sync/factory.ts +154 -0
- package/src/sync/pending-sync-store.ts +1085 -0
- package/src/sync/rateless-iblt.ts +122 -132
- package/src/sync/simple.ts +334 -1144
- package/src/sync/sync-peer-state.ts +107 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Per-peer sync slot state shared by the simple and rateless synchronizers
|
|
2
|
+
// (stage-4 sync unification). One row per peer carries the response/lookup
|
|
3
|
+
// slot accounting whose release closures may settle long after the peer is
|
|
4
|
+
// gone; both synchronizers use the same registry and the same
|
|
5
|
+
// capture-the-row identity pattern.
|
|
6
|
+
//
|
|
7
|
+
// Per-field lifetime policy (review this table when adding fields):
|
|
8
|
+
//
|
|
9
|
+
// | field | created | cleared |
|
|
10
|
+
// |------------------------------|--------------------|----------------------------|
|
|
11
|
+
// | lookups / responses / active | first slot acquire | physical release settles; |
|
|
12
|
+
// | | | row DETACH only removes |
|
|
13
|
+
// | | | current peer-generation |
|
|
14
|
+
// | | | quota (global quota stays |
|
|
15
|
+
// | | | charged until settlement) |
|
|
16
|
+
// | pendingResponseHashes | consume accepts an | lease release settles |
|
|
17
|
+
// | (simple synchronizer only) | authorization | while attached; row |
|
|
18
|
+
// | | (custody moves | DETACHES at peer |
|
|
19
|
+
// | | batch -> row) | disconnect (budget returns |
|
|
20
|
+
// | | | in aggregate) |
|
|
21
|
+
// | activeReleases | active-response or | logical release settles |
|
|
22
|
+
// | | coordinate | (self-removal); detach |
|
|
23
|
+
// | | dispatch starts | invokes outstanding |
|
|
24
|
+
// | | | logical releases so |
|
|
25
|
+
// | | | retained work drains |
|
|
26
|
+
//
|
|
27
|
+
// Global physical-work accounting deliberately SURVIVES both close()/open()
|
|
28
|
+
// generation rotation and peer disconnect: the underlying storage resolvers
|
|
29
|
+
// and transport sends are not universally abortable, so cross-generation
|
|
30
|
+
// work stays charged until it settles. Disconnect only detaches the row from
|
|
31
|
+
// the current peer generation and releases logical lifecycle ownership.
|
|
32
|
+
//
|
|
33
|
+
// Deliberately host-side this stage (stage-5 folds them into the host peer
|
|
34
|
+
// sessions): dispatch epochs and dispatch-target sets (benchmark-gated hot
|
|
35
|
+
// path), pending-claim rows (owned by the pending-sync record store),
|
|
36
|
+
// admission per-peer indexes (owned by the record store's reservation
|
|
37
|
+
// objects) and the recently-sent exchange-head dedupe rows.
|
|
38
|
+
|
|
39
|
+
export type SyncPeerSlotRow = {
|
|
40
|
+
peer: string;
|
|
41
|
+
attached: boolean;
|
|
42
|
+
lookups: number;
|
|
43
|
+
responses: number;
|
|
44
|
+
active: number;
|
|
45
|
+
// Portion of the simple synchronizer's global pending-response hash budget
|
|
46
|
+
// held by this peer's ACTIVE (consumed) authorizations. Batch-resident
|
|
47
|
+
// hashes stay charged against the batch; consume moves custody here so a
|
|
48
|
+
// disconnect can return the budget even when the response ship never
|
|
49
|
+
// settles. Always 0 on rateless rows.
|
|
50
|
+
pendingResponseHashes: number;
|
|
51
|
+
// Outstanding disconnect-time LOGICAL releases. Both synchronizers put
|
|
52
|
+
// active-response lifecycle cleanup here; Simple also puts coordinate
|
|
53
|
+
// dispatch completion here. Detach invokes the remainder so retained work
|
|
54
|
+
// and dispatch listeners drain. Each eventual async completion separately
|
|
55
|
+
// returns its global physical permit exactly once.
|
|
56
|
+
activeReleases: Set<() => void>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export class SyncPeerSlotRegistry {
|
|
60
|
+
readonly rows = new Map<string, SyncPeerSlotRow>();
|
|
61
|
+
|
|
62
|
+
ensure(peer: string): SyncPeerSlotRow {
|
|
63
|
+
let row = this.rows.get(peer);
|
|
64
|
+
if (!row) {
|
|
65
|
+
row = {
|
|
66
|
+
peer,
|
|
67
|
+
attached: true,
|
|
68
|
+
lookups: 0,
|
|
69
|
+
responses: 0,
|
|
70
|
+
active: 0,
|
|
71
|
+
pendingResponseHashes: 0,
|
|
72
|
+
activeReleases: new Set(),
|
|
73
|
+
};
|
|
74
|
+
this.rows.set(peer, row);
|
|
75
|
+
}
|
|
76
|
+
return row;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Detaches and returns the peer's row (or undefined when the peer holds no
|
|
80
|
+
// slots). The caller drops only current-generation/per-peer accounting and
|
|
81
|
+
// logical ownership. Physical release closures retain this row by identity
|
|
82
|
+
// and return global quota only when the underlying work actually settles.
|
|
83
|
+
detach(peer: string): SyncPeerSlotRow | undefined {
|
|
84
|
+
const row = this.rows.get(peer);
|
|
85
|
+
if (!row) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
row.attached = false;
|
|
89
|
+
this.rows.delete(peer);
|
|
90
|
+
return row;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Rows whose slots all settled while attached are dropped eagerly so the
|
|
94
|
+
// registry never accumulates idle peers between disconnects.
|
|
95
|
+
maybeDropIdle(row: SyncPeerSlotRow): void {
|
|
96
|
+
if (
|
|
97
|
+
row.attached &&
|
|
98
|
+
row.lookups === 0 &&
|
|
99
|
+
row.responses === 0 &&
|
|
100
|
+
row.active === 0 &&
|
|
101
|
+
row.pendingResponseHashes === 0 &&
|
|
102
|
+
row.activeReleases.size === 0
|
|
103
|
+
) {
|
|
104
|
+
this.rows.delete(row.peer);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|