pub struct RedbBackend { /* private fields */ }Expand description
On-disk EventStore backed by a per-run [redb] file.
One backend instance owns at most one open run at a time. Opening a fresh run creates
<base>/<instance_id>/<run_id>.redb and writes the manifest with status
RunStatus::Running before returning. Reopening a path whose manifest is still
RunStatus::Running returns EventStoreError::CrashedPredecessor; the caller seals
it as RunStatus::CrashedRecovered (or RunStatus::Quarantined) and then opens a new
run, mirroring the in-memory backend’s contract.
Implementations§
Source§impl RedbBackend
impl RedbBackend
Sourcepub fn new(base_dir: impl Into<PathBuf>) -> Self
pub fn new(base_dir: impl Into<PathBuf>) -> Self
Creates a new RedbBackend rooted at base_dir.
The backend creates <base_dir>/<instance_id>/ lazily on the first
EventStore::open_run call.
Sourcepub fn run_dir(&self, instance_id: &str) -> PathBuf
pub fn run_dir(&self, instance_id: &str) -> PathBuf
Returns the directory the backend writes run files to for instance_id.
Sourcepub fn run_path(&self, instance_id: &str, run_id: &str) -> PathBuf
pub fn run_path(&self, instance_id: &str, run_id: &str) -> PathBuf
Returns the on-disk path the backend uses for (instance_id, run_id).
Sourcepub fn current_path(&self) -> Result<&Path, EventStoreError>
pub fn current_path(&self) -> Result<&Path, EventStoreError>
Returns the path of the currently open run file.
§Errors
Returns EventStoreError::Backend when no run is open.
Sourcepub fn open_sealed(
base_dir: impl Into<PathBuf>,
instance_id: &str,
run_id: &str,
) -> Result<Self, EventStoreError>
pub fn open_sealed( base_dir: impl Into<PathBuf>, instance_id: &str, run_id: &str, ) -> Result<Self, EventStoreError>
Opens the sealed run file at <base>/<instance_id>/<run_id>.redb for read-only replay.
§Design
The standard EventStore::open_run path rejects sealed files: that is the
crash-recovery guard, a successor must not silently reopen a predecessor’s log
without going through seal. Event-store replay is the legitimate case for touching
a sealed file, so the reader uses this constructor instead.
The shared EventStore trait is held intentionally narrow and is locked by
design; adding a sealed-open method to it would force the in-memory backend
(whose sealed runs stay readable in place without a reopen step) to carry a
useless second entry point, and would conflate the writer’s open-or-recover
lifecycle with the reader’s pure read-only path. The sealed-open path therefore
lives as a backend-specific constructor: each backend adds the entry points it
actually needs. The resulting RedbBackend still implements EventStore,
so the reader composes over the locked trait without pulling in writer-only
methods. crate::backend::MemoryBackend has no equivalent constructor: a
sealed in-memory run keeps its state accessible to any reader holding the
backend instance, and the reader receives that instance directly.
The returned backend holds a read-only database handle, rejects
EventStore::append_batch with EventStoreError::Closed (the manifest is
already sealed), and exposes every read path: EventStore::scan_range,
EventStore::scan_seq, EventStore::lookup, and EventStore::manifest.
§Errors
Returns EventStoreError::Backend when the run file does not exist or its
status is not a sealed terminal state (use EventStore::open_run for that
path); EventStoreError::Corrupted when the run file lacks a manifest or
fails to decode.
Sourcepub fn open_sealed_file(
path: impl Into<PathBuf>,
) -> Result<Self, EventStoreError>
pub fn open_sealed_file( path: impl Into<PathBuf>, ) -> Result<Self, EventStoreError>
Opens a sealed redb run file directly by path for read-only replay or verification.
§Errors
Returns EventStoreError::Backend when the run file does not exist or its
status is not a sealed terminal state (use EventStore::open_run for that
path); EventStoreError::Corrupted when the run file lacks a manifest or
fails to decode.
Sourcepub fn list_runs(
base_dir: &Path,
instance_id: &str,
) -> Result<Vec<RunManifest>, EventStoreError>
pub fn list_runs( base_dir: &Path, instance_id: &str, ) -> Result<Vec<RunManifest>, EventStoreError>
Lists the manifests of every run file under <base_dir>/<instance_id>/*.redb.
Used by the reader for forensics navigation across runs without requiring an
active backend instance per run. The result is sorted by start_ts_init so
chronologically-newer runs appear last.
Opens each run file with a read-only database handle. A run file whose process died hard (kill, OOM, power loss) lacks redb’s allocator-state table and refuses the read-only open; the listing falls back to a writable open, which performs redb’s repair pass and leaves the file readable again. Files that still cannot be opened or that lack a manifest are skipped with a logged error so one current-format damaged file cannot block recovery or retention over the healthy runs; such files never become recovery parents or reclaim candidates and are left in place for manual inspection. Unsupported store formats are returned as errors rather than skipped because they require operator action.
§Errors
Returns EventStoreError::Backend when the directory iterator fails, or
EventStoreError::Corrupted when a run file uses an unsupported store format.
Trait Implementations§
Source§impl Debug for RedbBackend
impl Debug for RedbBackend
Source§impl EventStore for RedbBackend
impl EventStore for RedbBackend
Source§fn open_run(&mut self, manifest: RunManifest) -> Result<(), EventStoreError>
fn open_run(&mut self, manifest: RunManifest) -> Result<(), EventStoreError>
Source§fn append_batch(
&mut self,
entries: &[AppendEntry],
) -> Result<u64, EventStoreError>
fn append_batch( &mut self, entries: &[AppendEntry], ) -> Result<u64, EventStoreError>
(entry, index_keys) pairs in a single backend transaction. Read moreSource§fn scan_range(
&self,
from: u64,
to: u64,
direction: ScanDirection,
) -> Result<Vec<EventStoreEntry>, EventStoreError>
fn scan_range( &self, from: u64, to: u64, direction: ScanDirection, ) -> Result<Vec<EventStoreEntry>, EventStoreError>
Source§fn scan_seq(&self, seq: u64) -> Result<Option<EventStoreEntry>, EventStoreError>
fn scan_seq(&self, seq: u64) -> Result<Option<EventStoreEntry>, EventStoreError>
seq. Read moreSource§fn lookup(
&self,
kind: IndexKind,
key: &str,
) -> Result<Option<u64>, EventStoreError>
fn lookup( &self, kind: IndexKind, key: &str, ) -> Result<Option<u64>, EventStoreError>
seq recorded under the given index key. Read moreSource§fn iter_index_keys(
&self,
kind: IndexKind,
) -> Result<Vec<(String, u64)>, EventStoreError>
fn iter_index_keys( &self, kind: IndexKind, ) -> Result<Vec<(String, u64)>, EventStoreError>
(key, seq) pair stored under the given secondary index. Read moreSource§fn record_snapshot_anchor(
&mut self,
anchor: SnapshotAnchor,
) -> Result<(), EventStoreError>
fn record_snapshot_anchor( &mut self, anchor: SnapshotAnchor, ) -> Result<(), EventStoreError>
Source§fn latest_snapshot_anchor(
&self,
) -> Result<Option<SnapshotAnchor>, EventStoreError>
fn latest_snapshot_anchor( &self, ) -> Result<Option<SnapshotAnchor>, EventStoreError>
Source§fn seal(&mut self, status: RunStatus) -> Result<(), EventStoreError>
fn seal(&mut self, status: RunStatus) -> Result<(), EventStoreError>
Source§fn manifest(&self) -> Result<RunManifest, EventStoreError>
fn manifest(&self) -> Result<RunManifest, EventStoreError>
Source§fn high_watermark(&self) -> Result<u64, EventStoreError>
fn high_watermark(&self) -> Result<u64, EventStoreError>
seq durably acknowledged for the open run. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for RedbBackend
impl !UnwindSafe for RedbBackend
impl Freeze for RedbBackend
impl Send for RedbBackend
impl Sync for RedbBackend
impl Unpin for RedbBackend
impl UnsafeUnpin for RedbBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more