@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.
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 +12 -12
  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,82 @@
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
+ export class SyncPeerSlotRegistry {
39
+ rows = new Map();
40
+ ensure(peer) {
41
+ let row = this.rows.get(peer);
42
+ if (!row) {
43
+ row = {
44
+ peer,
45
+ attached: true,
46
+ lookups: 0,
47
+ responses: 0,
48
+ active: 0,
49
+ pendingResponseHashes: 0,
50
+ activeReleases: new Set(),
51
+ };
52
+ this.rows.set(peer, row);
53
+ }
54
+ return row;
55
+ }
56
+ // Detaches and returns the peer's row (or undefined when the peer holds no
57
+ // slots). The caller drops only current-generation/per-peer accounting and
58
+ // logical ownership. Physical release closures retain this row by identity
59
+ // and return global quota only when the underlying work actually settles.
60
+ detach(peer) {
61
+ const row = this.rows.get(peer);
62
+ if (!row) {
63
+ return undefined;
64
+ }
65
+ row.attached = false;
66
+ this.rows.delete(peer);
67
+ return row;
68
+ }
69
+ // Rows whose slots all settled while attached are dropped eagerly so the
70
+ // registry never accumulates idle peers between disconnects.
71
+ maybeDropIdle(row) {
72
+ if (row.attached &&
73
+ row.lookups === 0 &&
74
+ row.responses === 0 &&
75
+ row.active === 0 &&
76
+ row.pendingResponseHashes === 0 &&
77
+ row.activeReleases.size === 0) {
78
+ this.rows.delete(row.peer);
79
+ }
80
+ }
81
+ }
82
+ //# sourceMappingURL=sync-peer-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-peer-state.js","sourceRoot":"","sources":["../../../src/sync/sync-peer-state.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,8DAA8D;AAC9D,oCAAoC;AACpC,EAAE;AACF,oEAAoE;AACpE,EAAE;AACF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,qFAAqF;AACrF,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S,KAAK,CAAC;YACnB,GAAG,CAAC,MAAM,KAAK,CAAC;YAChB,GAAG,CAAC,qBAAqB,KAAK,CAAC;YAC/B,GAAG,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC,EAC5B,CAAC;YACF,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;IACF,CAAC;CACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/shared-log",
3
- "version": "13.2.24",
3
+ "version": "13.2.26",
4
4
  "description": "Shared log",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -63,35 +63,35 @@
63
63
  "pino": "^9.4.0",
64
64
  "uint8arrays": "^5.1.0",
65
65
  "@peerbit/any-store": "2.2.14",
66
- "@peerbit/blocks-interface": "2.1.5",
67
66
  "@peerbit/cache": "3.1.1",
67
+ "@peerbit/blocks-interface": "2.1.5",
68
68
  "@peerbit/blocks": "4.2.10",
69
69
  "@peerbit/crypto": "3.1.5",
70
- "@peerbit/diagnostics": "0.0.1",
71
70
  "@peerbit/indexer-interface": "3.0.9",
72
- "@peerbit/indexer-sqlite3": "3.0.12",
73
- "@peerbit/log": "6.2.14",
71
+ "@peerbit/diagnostics": "0.0.1",
72
+ "@peerbit/log": "6.2.15",
73
+ "@peerbit/indexer-sqlite3": "3.0.13",
74
74
  "@peerbit/logger": "2.0.1",
75
+ "@peerbit/pubsub": "5.4.0",
75
76
  "@peerbit/program": "6.0.48",
76
77
  "@peerbit/pubsub-interface": "5.2.0",
77
- "@peerbit/riblt": "1.2.0",
78
+ "@peerbit/rpc": "6.1.16",
78
79
  "@peerbit/stream-interface": "6.0.15",
79
80
  "@peerbit/time": "3.0.1",
80
- "@peerbit/pubsub": "5.4.0",
81
- "@peerbit/rpc": "6.1.16"
81
+ "@peerbit/riblt": "1.2.0"
82
82
  },
83
83
  "optionalDependencies": {
84
- "@peerbit/native-backbone": "0.2.5",
85
- "@peerbit/shared-log-rust": "0.1.4"
84
+ "@peerbit/shared-log-rust": "0.1.4",
85
+ "@peerbit/native-backbone": "0.2.5"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/libsodium-wrappers": "^0.7.14",
89
89
  "@types/pidusage": "^2.0.5",
90
90
  "uuid": "^11.1.1",
91
91
  "@peerbit/indexer-rust": "1.0.7",
92
- "@peerbit/test-utils": "3.1.20",
92
+ "@peerbit/test-utils": "3.1.21",
93
93
  "@peerbit/any-store-rust": "0.1.4",
94
- "peerbit": "5.3.20"
94
+ "peerbit": "5.3.21"
95
95
  },
96
96
  "repository": {
97
97
  "type": "git",
@@ -79,6 +79,41 @@ export class CheckedPruneCoordinator<T, R extends "u32" | "u64"> {
79
79
  private readonly peerRemovalFences = new Map<string, number>();
80
80
  private readonly restartReservations = new Map<string, object>();
81
81
  private readonly candidateTokens = new Map<string, object>();
82
+ // Moved from SharedLog (same name — the sanctioned file-to-file ratchet
83
+ // move). Depth of checked-prune removals currently holding the ownership
84
+ // lane across a lower-log `log.remove` whose program onChange callback
85
+ // re-enters this instance: while non-zero, invokeProgramOnChange
86
+ // classifies removal-bearing changes as checked-prune-driven. Reset comes
87
+ // free with the per-open coordinator replacement (index.ts open() creates
88
+ // a fresh coordinator); deliberately NOT touched by close() — the release
89
+ // closures drain it, matching the legacy host counter which was reset
90
+ // only at open.
91
+ private _checkedPruneRemoveBlocksLocalRangeMutationAdmission = 0;
92
+
93
+ /** ≡ the legacy inc / `finally`-dec pair around the admitted lower-log
94
+ * remove (old SharedLog site, one synchronous block from the admission
95
+ * checks). The returned release is idempotent and drains THIS coordinator
96
+ * instance — a release that survives into a later open decrements the
97
+ * retired coordinator, never the fresh one (the legacy global counter
98
+ * could go to −1 in that window; unreachable today because close() awaits
99
+ * the prune-remove terminal fence before open() can begin, but the
100
+ * instance scoping makes the proof unnecessary and future-caller-proof). */
101
+ blockLocalRangeMutation(): () => void {
102
+ this._checkedPruneRemoveBlocksLocalRangeMutationAdmission += 1;
103
+ let released = false;
104
+ return () => {
105
+ if (released) {
106
+ return;
107
+ }
108
+ released = true;
109
+ this._checkedPruneRemoveBlocksLocalRangeMutationAdmission -= 1;
110
+ };
111
+ }
112
+
113
+ /** ≡ the legacy `counter !== 0` read (site: invokeProgramOnChange). */
114
+ isBlockingLocalRangeMutation(): boolean {
115
+ return this._checkedPruneRemoveBlocksLocalRangeMutationAdmission > 0;
116
+ }
82
117
 
83
118
  private getOrCreateSession(hash: string): CheckedPruneSession<T, R> {
84
119
  let session = this.sessions.get(hash);