Storage API Reference¶
Pluggable storage backends for persistent and in-memory state management.
Durability ledger: the storage protocol every backend implements.
Claim
dataclass
¶
ClaimState
¶
Bases: str, Enum
Outcome of :meth:StoragePlugin.claim_processed.
- CLAIMED: this caller owns the key and must execute the work.
- IN_FLIGHT: another caller owns it and has not finished — do not execute.
- DONE: the work already ran; :attr:
Claim.resultis what it returned.
Source code in src/istos/consistency/storage.py
Durability
¶
Bases: str, Enum
Delivery semantics for handler execution.
- AT_MOST_ONCE: Fire-and-forget. No logging, no dedup. Fastest.
- AT_LEAST_ONCE: Logs every call to event_log. Retries may cause duplicates.
- EXACTLY_ONCE: Logs + idempotency. The key is claimed before the handler runs, so a concurrent duplicate cannot execute alongside it; once the work finishes, later duplicates return the cached result.
Source code in src/istos/consistency/storage.py
InMemoryStoragePlugin
¶
Thread-safe in-memory storage with full durability support. Data is lost on restart — use for testing and development.
Source code in src/istos/consistency/storage.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
StoragePlugin
¶
Bases: Protocol
Unified interface for storage backends.
Every storage must support all operations — the handler's durability
parameter decides which ones are actually called.
Source code in src/istos/consistency/storage.py
check_processed(idempotency_key)
async
¶
Cached result if the work finished, else None.
A key that is only claimed reads as None. This cannot tell "never ran"
from "ran and returned None" — use :meth:claim_processed when that
difference matters.
Source code in src/istos/consistency/storage.py
claim_processed(idempotency_key, *, lease_s=DEFAULT_CLAIM_LEASE_S)
async
¶
Atomically claim idempotency_key for execution, or report its state.
Decides in one indivisible step whether this caller is the one that
executes. :meth:check_processed before the handler plus
:meth:mark_processed after it is not equivalent: every concurrent
duplicate passes the check and executes.
The claim carries a lease, so a process that dies mid-handler does not block the key forever. DONE is terminal — a lease never expires a finished result.
Source code in src/istos/consistency/storage.py
delete(key)
async
¶
get(key)
async
¶
get_log(key, limit=100)
async
¶
log(key, value, idempotency_key=None)
async
¶
Append an event to the durable log. Skips duplicates by idempotency_key.
mark_processed(idempotency_key, result)
async
¶
Complete a claim: mark the key DONE and cache result.
First result wins — a key that is already DONE is left untouched.
put(key, value)
async
¶
release_claim(idempotency_key)
async
¶
Give up a claim that did not finish, so the work can be retried.
A no-op if the key is already DONE — a completed result is never undone.