Skip to main content

lora_wal/recorder/
errors.rs

1//! Error types and the [`WroteCommit`] flag returned from
2//! [`super::WalRecorder::commit`].
3
4use thiserror::Error;
5
6use crate::errors::WalError;
7
8/// Whether [`super::WalRecorder::commit`] actually wrote a `TxCommit` to the
9/// log. Read-only queries — those that never trigger
10/// `MutationRecorder::record` — return [`WroteCommit::No`] so the host
11/// can skip the surrounding `flush()` and avoid a per-query `fsync`
12/// just to record an empty transaction.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum WroteCommit {
15    /// A `TxBegin` had been lazily allocated and was paired with a
16    /// matching `TxCommit`. Caller should `flush()` (under PerCommit).
17    Yes,
18    /// No mutation events fired during the query, so neither `TxBegin`
19    /// nor `TxCommit` was appended. Caller can skip `flush()` entirely.
20    No,
21}
22
23impl WroteCommit {
24    pub fn wrote(self) -> bool {
25        matches!(self, Self::Yes)
26    }
27}
28
29#[derive(Debug, Error)]
30pub enum WalCommitError {
31    #[error("WAL commit failed: {0}")]
32    Commit(#[source] WalError),
33    #[error("WAL flush failed: {0}")]
34    Flush(#[source] WalError),
35}
36
37#[derive(Debug, Error)]
38#[error("WAL poisoned: {reason}")]
39pub struct WalPoisonError {
40    pub(super) reason: String,
41}
42
43impl WalPoisonError {
44    pub fn reason(&self) -> &str {
45        &self.reason
46    }
47}
48
49#[derive(Debug, Error)]
50pub enum WalBufferedCommitError {
51    #[error("WAL arm failed: {0}")]
52    Arm(#[source] WalError),
53    #[error("WAL poisoned: {0}")]
54    Poisoned(String),
55    #[error("WAL poisoned during commit replay: {0}")]
56    ReplayPoisoned(String),
57    #[error(transparent)]
58    Commit(#[from] WalCommitError),
59}