duron.log module
BaseEntry
Bases: TypedDict
LogStorage
Bases: Protocol
Protocol for persistent storage of operation logs.
The lease mechanism ensures exclusive access for appending entries, preventing concurrent writes from multiple processes.
acquire_lease
async
Acquire an exclusive lease for appending to the log.
Returns:
-
bytes–Opaque lease token to be used in append() and release_lease() calls.
Raises:
-
Exception–if lease cannot be acquired (e.g., already held by another process).
Note
Leases provide concurrency control to ensure only one invoke can append to a log at a time, preventing interleaved writes from multiple processes.
append
async
Append a new entry to the log.
Parameters:
-
lease(bytes) –Valid lease token from acquire_lease().
-
entry(Entry) –Log entry to append (promise/create, promise/complete, stream/emit, etc).
Returns:
-
int–Log index of the appended entry.
Raises:
-
Exception–if lease is invalid or expired.
Note
Appends must be atomic and durable. The returned index must be monotonically increasing and consistent with stream() output.
release_lease
async
Release a previously acquired lease.
Parameters:
-
lease(bytes) –Lease token returned by acquire_lease().
Note
Should be called when invoke completes or encounters an error. Implementations should be idempotent.
stream
Stream log entries from storage.
Yields:
-
AsyncGenerator[tuple[int, BaseEntry], None]–Tuple of (log_index, entry) for each log entry in order.
Note
Log indices are monotonically increasing but may have gaps.