@peerbit/shared-log 13.2.24 → 13.2.25

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.
Files changed (81) hide show
  1. package/dist/src/checked-prune.d.ts +12 -0
  2. package/dist/src/checked-prune.d.ts.map +1 -1
  3. package/dist/src/checked-prune.js +33 -0
  4. package/dist/src/checked-prune.js.map +1 -1
  5. package/dist/src/coordinate-persistence.d.ts +211 -0
  6. package/dist/src/coordinate-persistence.d.ts.map +1 -0
  7. package/dist/src/coordinate-persistence.js +1133 -0
  8. package/dist/src/coordinate-persistence.js.map +1 -0
  9. package/dist/src/errors.d.ts +1 -0
  10. package/dist/src/errors.d.ts.map +1 -1
  11. package/dist/src/errors.js +19 -0
  12. package/dist/src/errors.js.map +1 -1
  13. package/dist/src/index.d.ts +127 -133
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/index.js +1400 -4269
  16. package/dist/src/index.js.map +1 -1
  17. package/dist/src/instance-lifecycle.d.ts +117 -0
  18. package/dist/src/instance-lifecycle.d.ts.map +1 -0
  19. package/dist/src/instance-lifecycle.js +254 -0
  20. package/dist/src/instance-lifecycle.js.map +1 -0
  21. package/dist/src/join-warmup.d.ts +86 -0
  22. package/dist/src/join-warmup.d.ts.map +1 -0
  23. package/dist/src/join-warmup.js +351 -0
  24. package/dist/src/join-warmup.js.map +1 -0
  25. package/dist/src/native-write-through-block-store.d.ts +123 -0
  26. package/dist/src/native-write-through-block-store.d.ts.map +1 -0
  27. package/dist/src/native-write-through-block-store.js +989 -0
  28. package/dist/src/native-write-through-block-store.js.map +1 -0
  29. package/dist/src/peer-session.d.ts +117 -0
  30. package/dist/src/peer-session.d.ts.map +1 -0
  31. package/dist/src/peer-session.js +259 -0
  32. package/dist/src/peer-session.js.map +1 -0
  33. package/dist/src/replication-announcement.d.ts +116 -0
  34. package/dist/src/replication-announcement.d.ts.map +1 -0
  35. package/dist/src/replication-announcement.js +515 -0
  36. package/dist/src/replication-announcement.js.map +1 -0
  37. package/dist/src/replicator-liveness.d.ts +59 -0
  38. package/dist/src/replicator-liveness.d.ts.map +1 -0
  39. package/dist/src/replicator-liveness.js +304 -0
  40. package/dist/src/replicator-liveness.js.map +1 -0
  41. package/dist/src/sync/dispatch-lifecycle.d.ts +48 -0
  42. package/dist/src/sync/dispatch-lifecycle.d.ts.map +1 -0
  43. package/dist/src/sync/dispatch-lifecycle.js +141 -0
  44. package/dist/src/sync/dispatch-lifecycle.js.map +1 -0
  45. package/dist/src/sync/factory.d.ts +29 -0
  46. package/dist/src/sync/factory.d.ts.map +1 -0
  47. package/dist/src/sync/factory.js +87 -0
  48. package/dist/src/sync/factory.js.map +1 -0
  49. package/dist/src/sync/pending-sync-store.d.ts +105 -0
  50. package/dist/src/sync/pending-sync-store.d.ts.map +1 -0
  51. package/dist/src/sync/pending-sync-store.js +877 -0
  52. package/dist/src/sync/pending-sync-store.js.map +1 -0
  53. package/dist/src/sync/rateless-iblt.d.ts +4 -1
  54. package/dist/src/sync/rateless-iblt.d.ts.map +1 -1
  55. package/dist/src/sync/rateless-iblt.js +102 -106
  56. package/dist/src/sync/rateless-iblt.js.map +1 -1
  57. package/dist/src/sync/simple.d.ts +10 -41
  58. package/dist/src/sync/simple.d.ts.map +1 -1
  59. package/dist/src/sync/simple.js +259 -952
  60. package/dist/src/sync/simple.js.map +1 -1
  61. package/dist/src/sync/sync-peer-state.d.ts +16 -0
  62. package/dist/src/sync/sync-peer-state.d.ts.map +1 -0
  63. package/dist/src/sync/sync-peer-state.js +82 -0
  64. package/dist/src/sync/sync-peer-state.js.map +1 -0
  65. package/package.json +9 -9
  66. package/src/checked-prune.ts +35 -0
  67. package/src/coordinate-persistence.ts +1796 -0
  68. package/src/errors.ts +21 -0
  69. package/src/index.ts +4014 -7858
  70. package/src/instance-lifecycle.ts +351 -0
  71. package/src/join-warmup.ts +507 -0
  72. package/src/native-write-through-block-store.ts +1170 -0
  73. package/src/peer-session.ts +336 -0
  74. package/src/replication-announcement.ts +744 -0
  75. package/src/replicator-liveness.ts +439 -0
  76. package/src/sync/dispatch-lifecycle.ts +230 -0
  77. package/src/sync/factory.ts +154 -0
  78. package/src/sync/pending-sync-store.ts +1085 -0
  79. package/src/sync/rateless-iblt.ts +122 -132
  80. package/src/sync/simple.ts +334 -1144
  81. 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
+ }