cuprate_database/
transaction.rs

1//! Database transaction abstraction; `trait TxRo`, `trait TxRw`.
2
3//---------------------------------------------------------------------------------------------------- Import
4use crate::error::DbResult;
5
6//---------------------------------------------------------------------------------------------------- TxRo
7/// Read-only database transaction.
8///
9/// Returned from [`EnvInner::tx_ro`](crate::EnvInner::tx_ro).
10///
11/// # Commit
12/// It's recommended but may not be necessary to call [`TxRo::commit`] in certain cases:
13/// - <https://docs.rs/heed/0.20.0-alpha.9/heed/struct.RoTxn.html#method.commit>
14pub trait TxRo<'tx> {
15    /// Commit the read-only transaction.
16    ///
17    /// # Errors
18    /// This operation will always return `Ok(())` with the `redb` backend.
19    fn commit(self) -> DbResult<()>;
20}
21
22//---------------------------------------------------------------------------------------------------- TxRw
23/// Read/write database transaction.
24///
25/// Returned from [`EnvInner::tx_rw`](crate::EnvInner::tx_rw).
26pub trait TxRw<'tx> {
27    /// Commit the read/write transaction.
28    ///
29    /// Note that this doesn't necessarily sync the database caches to disk.
30    ///
31    /// # Errors
32    /// This operation will always return `Ok(())` with the `redb` backend.
33    ///
34    /// If `Env::MANUAL_RESIZE == true`,
35    /// [`crate::RuntimeError::ResizeNeeded`] may be returned.
36    fn commit(self) -> DbResult<()>;
37
38    /// Abort the transaction, erasing any writes that have occurred.
39    ///
40    /// # Errors
41    /// This operation will always return `Ok(())` with the `heed` backend.
42    fn abort(self) -> DbResult<()>;
43}