Next-depth pass: network-stack, CRDTs, gossip, scheduling, experimental
Expand introspection helpers and getStats(protocol) across six categories after the storage/trust giant pass. network-stack (10): listPeerIds, hasPeer, bestPeer, listCircuitIds, queueDepth, listPendingIds, and related helpers; protocol in getStats. state-crdts: crdt-map has/size/entries; conflict-set size/isEmpty; reactive-state size/keys; richer getStats on map and conflict-set. messaging-gossip: gossip-mesh seenCount/clearSeen; dedup size/clear; event-bus getStats merges metrics/topics/peers. scheduling-queues: topic-lease listShards/isHeld; peer-scheduler listJobs; activity-queue pending/claimed stats. measurement-rate-control: bucket-rate listPeerIds/peerCount. experimental (16): protocol-rich getStats; mycelium listPeerIds/totalCredits; pheromone listPathIds. Docs: API Methods for link-probe, crdt-map, gossip-mesh; expanded category READMEs for state-crdts, messaging-gossip, scheduling, measurement. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -1,11 +1,25 @@
|
||||
# Scheduling & queues
|
||||
|
||||
**Path:** `modules/scheduling-queues/` · **Modules:** 5 (5 production, 0 scaffold)
|
||||
**Path:** `modules/scheduling-queues/` · **Modules:** 5 (all production)
|
||||
|
||||
See [MODULE_CATEGORIES.md](../MODULE_CATEGORIES.md#scheduling-queues).
|
||||
Leader leases, peer cron, activity queues, and deadline ordering. Hub: [`../../docs/scheduling-queues/README.md`](../../docs/scheduling-queues/README.md).
|
||||
|
||||
- [hyper-p2p-activity-queue](./hyper-p2p-activity-queue/) — production
|
||||
- [hyper-p2p-cron-gossip](./hyper-p2p-cron-gossip/) — production
|
||||
- [hyper-p2p-deadline-queue](./hyper-p2p-deadline-queue/) — production
|
||||
- [hyper-p2p-peer-scheduler](./hyper-p2p-peer-scheduler/) — production
|
||||
- [hyper-p2p-topic-lease](./hyper-p2p-topic-lease/) — production
|
||||
## Modules
|
||||
|
||||
| Module | Protocol | Summary |
|
||||
|--------|----------|---------|
|
||||
| [hyper-p2p-topic-lease](./hyper-p2p-topic-lease/) | `topic-lease/v1` | Shard leader election (`listShards`, `isHeld`) |
|
||||
| [hyper-p2p-peer-scheduler](./hyper-p2p-peer-scheduler/) | `peer-scheduler/v1` | Cron-like jobs with lease-aware leader (`listJobs`) |
|
||||
| [hyper-p2p-cron-gossip](./hyper-p2p-cron-gossip/) | `cron-gossip/v1` | Gossiped schedule registry |
|
||||
| [hyper-p2p-activity-queue](./hyper-p2p-activity-queue/) | `activity-queue/v1` | Priority queue + vector-clock ordering |
|
||||
| [hyper-p2p-deadline-queue](./hyper-p2p-deadline-queue/) | `deadline-queue/v1` | Time-ordered deadline heap |
|
||||
|
||||
## Composition
|
||||
|
||||
`peer-scheduler` accepts `topicLease` — only the lease holder runs `tick` for a shard.
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
cd hyper-p2p-topic-lease && npm test
|
||||
```
|
||||
|
||||
@@ -176,7 +176,14 @@ class HyperP2PActivityQueue extends EventEmitter {
|
||||
|
||||
|
||||
getStats () {
|
||||
return { ...this._stats }
|
||||
return {
|
||||
...this._stats,
|
||||
pending: this.getQueueDepth(),
|
||||
total: this._queue.length,
|
||||
claimed: this._claimed.size,
|
||||
deadLetter: this._deadLetter.length,
|
||||
protocol: PROTOCOL
|
||||
}
|
||||
}
|
||||
|
||||
async close () {
|
||||
|
||||
@@ -42,6 +42,12 @@ class HyperP2PPeerScheduler extends EventEmitter {
|
||||
return id
|
||||
}
|
||||
|
||||
listJobs () { return [...this._jobs.values()] }
|
||||
|
||||
hasJob (jobId) { return this._jobs.has(jobId) }
|
||||
|
||||
jobCount () { return this._jobs.size }
|
||||
|
||||
cancel (jobId) {
|
||||
const ok = this._jobs.delete(jobId)
|
||||
if (ok) this.emit('cancelled', { jobId })
|
||||
@@ -94,7 +100,7 @@ class HyperP2PPeerScheduler extends EventEmitter {
|
||||
|
||||
|
||||
getStats () {
|
||||
return { ...this._stats }
|
||||
return { ...this._stats, jobs: this._jobs.size, protocol: PROTOCOL }
|
||||
}
|
||||
|
||||
async close () {
|
||||
|
||||
@@ -64,6 +64,18 @@ class HyperP2PTopicLease extends EventEmitter {
|
||||
return this.holder(topicShard)
|
||||
}
|
||||
|
||||
listShards () { return [...this._leases.keys()] }
|
||||
|
||||
isHeld (topicShard) {
|
||||
const h = this.holder(topicShard)
|
||||
return h != null
|
||||
}
|
||||
|
||||
leaseCount () {
|
||||
const now = Date.now()
|
||||
return [...this._leases.values()].filter((l) => l.expiresAt > now).length
|
||||
}
|
||||
|
||||
_expireSweep () {
|
||||
const now = Date.now()
|
||||
for (const [shard, lease] of this._leases) {
|
||||
@@ -100,7 +112,7 @@ class HyperP2PTopicLease extends EventEmitter {
|
||||
|
||||
|
||||
getStats () {
|
||||
return { ...this._stats }
|
||||
return { ...this._stats, leases: this.leaseCount(), shards: this._leases.size, protocol: PROTOCOL }
|
||||
}
|
||||
|
||||
async close () {
|
||||
|
||||
Reference in New Issue
Block a user