@@ -15,22 +15,7 @@ export
1515proc defaultConfig * (): ReliabilityConfig =
1616 return ReliabilityConfig .init ()
1717
18- proc reliabilityErr * (detail: string ): ReliabilityError {.gcsafe , raises : [].} =
19- # # Maps a backend-supplied persistence error string onto the
20- # # `rePersistenceError` enum value. The enum carries no payload, so the
21- # # original detail is logged here — this is the single point where a
22- # # persistence failure is recorded, while the enum value travels up the
23- # # `Result` chain to the public API caller, who decides what to do.
24- # #
25- # # With the snapshot-based Persistence interface, most protocol ops no
26- # # longer propagate persistence errors at all — they log and continue
27- # # (see PLAN_SNAPSHOT_PERSISTENCE.md §8). This helper is still used by
28- # # the durability-intent ops (removeChannel, resetReliabilityManager,
29- # # getOrCreateChannel) that retain err-on-failure semantics.
30- warn " persistence operation failed" , detail = detail
31- ReliabilityError .rePersistenceError
32-
33- proc snapshotMeta * (channel: ChannelContext ): ChannelMeta {.gcsafe , raises : [].} =
18+ proc snapshotMeta (channel: ChannelContext ): ChannelMeta {.gcsafe , raises : [].} =
3419 # # Captures the current in-memory state of a `ChannelContext` as a
3520 # # `ChannelMeta` blob, suitable for `Persistence.saveChannelMeta`.
3621 # #
@@ -39,16 +24,17 @@ proc snapshotMeta*(channel: ChannelContext): ChannelMeta {.gcsafe, raises: [].}
3924 # # (see PLAN §6). The bloom filter and message history are intentionally
4025 # # excluded — the former is rebuilt from the latter on bootstrap, and
4126 # # the latter is persisted separately via `updateHistory`.
42- result = ChannelMeta .init ()
43- result .lamportTimestamp = channel.lamportTimestamp
27+ var meta = ChannelMeta .init ()
28+ meta .lamportTimestamp = channel.lamportTimestamp
4429 for u in channel.outgoingBuffer:
45- result .outgoingBuffer.add (u)
30+ meta .outgoingBuffer.add (u)
4631 for _, m in channel.incomingBuffer.pairs:
47- result .incomingBuffer.add (m)
32+ meta .incomingBuffer.add (m)
4833 for id, e in channel.outgoingRepairBuffer.pairs:
49- result .outgoingRepairBuffer.add (OutgoingRepairKV (messageId: id, entry: e))
34+ meta .outgoingRepairBuffer.add (OutgoingRepairKV (messageId: id, entry: e))
5035 for id, e in channel.incomingRepairBuffer.pairs:
51- result .incomingRepairBuffer.add (IncomingRepairKV (messageId: id, entry: e))
36+ meta.incomingRepairBuffer.add (IncomingRepairKV (messageId: id, entry: e))
37+ return meta
5238
5339proc trySaveMeta * (
5440 rm: ReliabilityManager , channelId: SdsChannelID , channel: ChannelContext
@@ -59,12 +45,11 @@ proc trySaveMeta*(
5945 # #
6046 # # This helper is the single point where snapshot-save failures are
6147 # # logged; callers do not need to handle the Result.
62- let res = await rm.persistence.saveChannelMeta (channelId, snapshotMeta (channel))
63- if res.isErr:
48+ (await rm.persistence.saveChannelMeta (channelId, snapshotMeta (channel))).isOkOr:
6449 warn " snapshot save failed; in-memory state authoritative, next op will retry" ,
65- channelId = channelId, detail = res. error
50+ channelId = channelId, detail = error
6651
67- proc queueHistoryAppend * (channel: ChannelContext , msgId: SdsMessageID ) =
52+ proc queueHistoryAppend (channel: ChannelContext , msgId: SdsMessageID ) =
6853 # # Push an append onto the pending history queue. Only the id is
6954 # # stored — the full SdsMessage is looked up from `messageHistory` at
7055 # # flush time (invariant: every queued id is present in messageHistory).
@@ -76,7 +61,7 @@ proc queueHistoryAppend*(channel: ChannelContext, msgId: SdsMessageID) =
7661 channel.pendingHistoryEvicts.excl (msgId)
7762 channel.pendingHistoryAppends.incl (msgId)
7863
79- proc queueHistoryEvict * (channel: ChannelContext , msgId: SdsMessageID ) =
64+ proc queueHistoryEvict (channel: ChannelContext , msgId: SdsMessageID ) =
8065 # # Push an evict onto the pending history queue. Merge rule symmetric
8166 # # with `queueHistoryAppend`: cancels any pending append for the same
8267 # # id (the just-evicted message no longer needs to be persisted as an
@@ -119,8 +104,7 @@ proc tryUpdateHistory*(
119104 except KeyError :
120105 return # checked `in` above; unreachable, but tables can raise per spec
121106
122- if channel.pendingHistoryAppends.len == 0 and
123- channel.pendingHistoryEvicts.len == 0 :
107+ if channel.pendingHistoryAppends.len == 0 and channel.pendingHistoryEvicts.len == 0 :
124108 return # nothing to flush — no round-trip cost
125109
126110 var batch = HistoryUpdate .init ()
@@ -151,8 +135,7 @@ proc tryUpdateHistory*(
151135 detail = res.error
152136 if channel.pendingHistoryAppends.len > rm.config.maxMessageHistory:
153137 warn " pending history queue exceeds maxMessageHistory; backend may be stuck" ,
154- channelId = channelId,
155- pendingAppends = channel.pendingHistoryAppends.len
138+ channelId = channelId, pendingAppends = channel.pendingHistoryAppends.len
156139
157140proc dropChannelFromPersistence * (
158141 rm: ReliabilityManager , channelId: SdsChannelID
@@ -165,7 +148,8 @@ proc dropChannelFromPersistence*(
165148 # # err on failure (durability is the semantic intent — the caller asked
166149 # # us to confirm a disk wipe; we cannot silently lie). See PLAN §8.
167150 (await rm.persistence.dropChannel (channelId)).isOkOr:
168- return err (reliabilityErr (error))
151+ warn " persistence operation failed" , cause = error
152+ return err (ReliabilityError .rePersistenceError)
169153 ok ()
170154
171155proc cleanup * (rm: ReliabilityManager ) {.async : (raises: []).} =
@@ -344,16 +328,6 @@ proc getRecentHistoryEntries*(
344328 if not rm.onRetrievalHint.isNil ():
345329 {.cast (raises: []).}:
346330 entry.retrievalHint = rm.onRetrievalHint (msgId)
347- if entry.retrievalHint.len > 0 :
348- # Phase 2B: best-effort hint persistence via V2. Non-fatal —
349- # hints are an optimisation; a missing hint just means the
350- # peer falls back to slower retrieval.
351- let hintRes = await rm.persistence.setRetrievalHint (
352- msgId, entry.retrievalHint
353- )
354- if hintRes.isErr:
355- warn " retrieval hint save failed; continuing" ,
356- msgId = msgId, detail = hintRes.error
357331 entry.senderId = channel.messageHistory[msgId].senderId
358332 entries.add (entry)
359333 ok (entries)
@@ -456,7 +430,9 @@ proc getOrCreateChannel*(
456430 )
457431 )
458432 let data = (await rm.persistence.loadChannel (channelId)).valueOr:
459- return err (reliabilityErr (error))
433+ warn " persistence operation failed" , cause = error
434+ return err (ReliabilityError .rePersistenceError)
435+
460436 channel.lamportTimestamp = data.meta.lamportTimestamp
461437 # Backend contract: messageHistory MUST be ordered oldest-first.
462438 # If a backend violates this, FIFO eviction breaks across restarts.
0 commit comments