1- import chronos
1+ import chronos, results
22import ./ sds_message_id
33import ./ sds_message
44import ./ unacknowledged_message
55import ./ incoming_message
66import ./ repair_entry
77export
8- sds_message_id, sds_message, unacknowledged_message, incoming_message, repair_entry
8+ results, sds_message_id, sds_message, unacknowledged_message, incoming_message,
9+ repair_entry
910
1011# # SDS state persistence interface (issue #64).
1112# #
@@ -18,6 +19,14 @@ export
1819# # All proc fields are async (return `Future`) so backends can do real I/O
1920# # without blocking the Chronos event loop the manager runs on.
2021# #
22+ # # Every field returns a `Result` so backend failures are propagated to nim-sds
23+ # # rather than swallowed by the backend. Mutating ops return
24+ # # `Result[void, string]`; the getter (`loadAllForChannel`) returns
25+ # # `Result[ChannelSnapshot, string]`. The error is a backend-supplied message;
26+ # # nim-sds maps it to `ReliabilityError.rePersistenceError` and surfaces it on
27+ # # the corresponding public API call. The contract still forbids raising
28+ # # (`raises: []`): failure must travel through the `Result`, not an exception.
29+ # #
2130# # Bloom filter is intentionally not persisted: it is rebuilt from the local
2231# # history log on bootstrap. Async timers are likewise recomputed from the
2332# # absolute timestamps stored in the repair buffer entries.
@@ -44,120 +53,125 @@ type
4453 # # in-memory state in lockstep without blocking the event loop.
4554
4655 # Per-channel lamport clock
47- saveLamport* : proc (channelId: SdsChannelID , lamport: int64 ): Future [ void ] {.
48- async : (raises: []), gcsafe
49- .}
56+ saveLamport* : proc (
57+ channelId: SdsChannelID , lamport: int64
58+ ): Future [ Result [ void , string ]] {. async : (raises: []), gcsafe .}
5059
5160 # Local log (delivered messages)
52- appendLogEntry* : proc (channelId: SdsChannelID , msg: SdsMessage ): Future [ void ] {.
53- async : (raises: []), gcsafe
54- .}
55- removeLogEntry* : proc (channelId: SdsChannelID , msgId: SdsMessageID ): Future [ void ] {.
56- async : (raises: []), gcsafe
57- .}
58- setRetrievalHint* : proc (msgId: SdsMessageID , hint: seq [ byte ]): Future [ void ] {.
59- async : (raises: []), gcsafe
60- .}
61+ appendLogEntry* : proc (
62+ channelId: SdsChannelID , msg: SdsMessage
63+ ): Future [ Result [ void , string ]] {. async : (raises: []), gcsafe .}
64+ removeLogEntry* : proc (
65+ channelId: SdsChannelID , msgId: SdsMessageID
66+ ): Future [ Result [ void , string ]] {. async : (raises: []), gcsafe .}
67+ setRetrievalHint* : proc (
68+ msgId: SdsMessageID , hint: seq [ byte ]
69+ ): Future [ Result [ void , string ]] {. async : (raises: []), gcsafe .}
6170
6271 # Outgoing unacknowledged buffer
6372 saveOutgoing* : proc (
6473 channelId: SdsChannelID , msg: UnacknowledgedMessage
65- ): Future [void ] {.async : (raises: []), gcsafe .}
66- removeOutgoing* : proc (channelId: SdsChannelID , msgId: SdsMessageID ): Future [ void ] {.
67- async : (raises: []), gcsafe
68- .}
74+ ): Future [Result [ void , string ] ] {.async : (raises: []), gcsafe .}
75+ removeOutgoing* : proc (
76+ channelId: SdsChannelID , msgId: SdsMessageID
77+ ): Future [ Result [ void , string ]] {. async : (raises: []), gcsafe .}
6978
7079 # Incoming dependency-waiting buffer
71- saveIncoming* : proc (channelId: SdsChannelID , msg: IncomingMessage ): Future [ void ] {.
72- async : (raises: []), gcsafe
73- .}
74- removeIncoming* : proc (channelId: SdsChannelID , msgId: SdsMessageID ): Future [ void ] {.
75- async : (raises: []), gcsafe
76- .}
80+ saveIncoming* : proc (
81+ channelId: SdsChannelID , msg: IncomingMessage
82+ ): Future [ Result [ void , string ]] {. async : (raises: []), gcsafe .}
83+ removeIncoming* : proc (
84+ channelId: SdsChannelID , msgId: SdsMessageID
85+ ): Future [ Result [ void , string ]] {. async : (raises: []), gcsafe .}
7786
7887 # SDS-R outgoing repair buffer
7988 saveOutgoingRepair* : proc (
8089 channelId: SdsChannelID , msgId: SdsMessageID , entry: OutgoingRepairEntry
81- ) {.async : (raises: []).}
90+ ): Future [ Result [ void , string ]] {.async : (raises: []), gcsafe .}
8291 removeOutgoingRepair* : proc (
8392 channelId: SdsChannelID , msgId: SdsMessageID
84- ): Future [void ] {.async : (raises: []), gcsafe .}
93+ ): Future [Result [ void , string ] ] {.async : (raises: []), gcsafe .}
8594
8695 # SDS-R incoming repair buffer
8796 saveIncomingRepair* : proc (
8897 channelId: SdsChannelID , msgId: SdsMessageID , entry: IncomingRepairEntry
89- ) {.async : (raises: []).}
98+ ): Future [ Result [ void , string ]] {.async : (raises: []), gcsafe .}
9099 removeIncomingRepair* : proc (
91100 channelId: SdsChannelID , msgId: SdsMessageID
92- ): Future [void ] {.async : (raises: []), gcsafe .}
101+ ): Future [Result [ void , string ] ] {.async : (raises: []), gcsafe .}
93102
94103 # Wipe all persisted state for a channel in one transactional call.
95104 # Called by removeChannel / resetReliabilityManager. Backends should
96105 # implement this atomically (e.g. one BEGIN/COMMIT) — a per-row loop on
97106 # the nim-sds side would mean N fsyncs per drop.
98- dropChannel* :
99- proc (channelId: SdsChannelID ): Future [void ] {.async : (raises: []), gcsafe .}
100-
101- # Bootstrap on `addChannel` / `getOrCreateChannel`.
102- loadAllForChannel* : proc (channelId: SdsChannelID ): Future [ChannelSnapshot ] {.
107+ dropChannel* : proc (channelId: SdsChannelID ): Future [Result [void , string ]] {.
103108 async : (raises: []), gcsafe
104109 .}
105110
111+ # Bootstrap on `addChannel` / `getOrCreateChannel`.
112+ loadAllForChannel* : proc (
113+ channelId: SdsChannelID
114+ ): Future [Result [ChannelSnapshot , string ]] {.async : (raises: []), gcsafe .}
115+
106116proc noOpPersistence * (): Persistence =
107117 # # Default backend that discards every write and returns an empty snapshot.
108118 # # Used so existing callers (and tests) that don't care about durability
109119 # # keep working without supplying a real backend.
110120 Persistence (
111- saveLamport: proc (channelId: SdsChannelID , lamport: int64 ) {.async : (raises: []).} =
112- discard ,
121+ saveLamport: proc (
122+ channelId: SdsChannelID , lamport: int64
123+ ): Future [Result [void , string ]] {.async : (raises: []).} =
124+ ok (),
113125 appendLogEntry: proc (
114126 channelId: SdsChannelID , msg: SdsMessage
115- ) {.async : (raises: []).} =
116- discard ,
127+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
128+ ok () ,
117129 removeLogEntry: proc (
118130 channelId: SdsChannelID , msgId: SdsMessageID
119- ) {.async : (raises: []).} =
120- discard ,
131+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
132+ ok () ,
121133 setRetrievalHint: proc (
122134 msgId: SdsMessageID , hint: seq [byte ]
123- ) {.async : (raises: []).} =
124- discard ,
135+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
136+ ok () ,
125137 saveOutgoing: proc (
126138 channelId: SdsChannelID , msg: UnacknowledgedMessage
127- ) {.async : (raises: []).} =
128- discard ,
139+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
140+ ok () ,
129141 removeOutgoing: proc (
130142 channelId: SdsChannelID , msgId: SdsMessageID
131- ) {.async : (raises: []).} =
132- discard ,
143+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
144+ ok () ,
133145 saveIncoming: proc (
134146 channelId: SdsChannelID , msg: IncomingMessage
135- ) {.async : (raises: []).} =
136- discard ,
147+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
148+ ok () ,
137149 removeIncoming: proc (
138150 channelId: SdsChannelID , msgId: SdsMessageID
139- ) {.async : (raises: []).} =
140- discard ,
151+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
152+ ok () ,
141153 saveOutgoingRepair: proc (
142154 channelId: SdsChannelID , msgId: SdsMessageID , entry: OutgoingRepairEntry
143- ) {.async : (raises: []).} =
144- discard ,
155+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
156+ ok () ,
145157 removeOutgoingRepair: proc (
146158 channelId: SdsChannelID , msgId: SdsMessageID
147- ) {.async : (raises: []).} =
148- discard ,
159+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
160+ ok () ,
149161 saveIncomingRepair: proc (
150162 channelId: SdsChannelID , msgId: SdsMessageID , entry: IncomingRepairEntry
151- ) {.async : (raises: []).} =
152- discard ,
163+ ): Future [ Result [ void , string ]] {.async : (raises: []).} =
164+ ok () ,
153165 removeIncomingRepair: proc (
154166 channelId: SdsChannelID , msgId: SdsMessageID
155- ) {.async : (raises: []).} =
156- discard ,
157- dropChannel: proc (channelId: SdsChannelID ) {.async : (raises: []).} =
158- discard ,
167+ ): Future [Result [void , string ]] {.async : (raises: []).} =
168+ ok (),
169+ dropChannel: proc (
170+ channelId: SdsChannelID
171+ ): Future [Result [void , string ]] {.async : (raises: []).} =
172+ ok (),
159173 loadAllForChannel: proc (
160174 channelId: SdsChannelID
161- ): Future [ChannelSnapshot ] {.async : (raises: []).} =
162- return ChannelSnapshot (),
175+ ): Future [Result [ ChannelSnapshot , string ] ] {.async : (raises: []).} =
176+ ok ( ChannelSnapshot () ),
163177 )
0 commit comments