Skip to main content

reddb_server/storage/transaction/
mod.rs

1//! Live transaction snapshot and visibility support.
2//!
3//! The live engine is optimistic MVCC: `SnapshotManager` allocates xids,
4//! `visibility` decides snapshot reads, and commit-time first-committer-wins
5//! checks live in the runtime.
6//!
7//! # Isolation Levels
8//!
9//! - **Read Committed**: See committed changes from other transactions
10//! - **Snapshot Isolation**: See consistent snapshot from transaction start
11//! - **Serializable**: Full serializability (not yet implemented)
12
13// ADR 0065 retires these dormant transaction-coordinator scaffolding modules
14// from the normal build. The live engine chose optimistic FCW; it does not
15// promote the lock/deadlock/savepoint/log coordinator stack.
16#[cfg(any())]
17pub mod coordinator;
18#[cfg(any())]
19pub mod lock;
20#[cfg(any())]
21pub mod log;
22#[cfg(any())]
23pub mod savepoint;
24pub mod snapshot;
25pub mod visibility;
26
27/// Isolation level requested by `BEGIN ISOLATION LEVEL ...`.
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
29pub enum IsolationLevel {
30    /// `READ UNCOMMITTED`
31    ReadUncommitted,
32    /// `READ COMMITTED`
33    ReadCommitted,
34    /// `REPEATABLE READ` / `SNAPSHOT`
35    #[default]
36    SnapshotIsolation,
37    /// `SERIALIZABLE`
38    Serializable,
39}
40
41impl From<crate::storage::query::ast::IsolationLevel> for IsolationLevel {
42    fn from(level: crate::storage::query::ast::IsolationLevel) -> Self {
43        match level {
44            crate::storage::query::ast::IsolationLevel::ReadUncommitted => Self::ReadUncommitted,
45            crate::storage::query::ast::IsolationLevel::ReadCommitted => Self::ReadCommitted,
46            crate::storage::query::ast::IsolationLevel::SnapshotIsolation => {
47                Self::SnapshotIsolation
48            }
49            crate::storage::query::ast::IsolationLevel::Serializable => Self::Serializable,
50        }
51    }
52}
53
54#[cfg(any())]
55pub use coordinator::{Transaction, TransactionManager, TxnConfig, TxnError, TxnHandle, TxnState};
56#[cfg(any())]
57pub use lock::{LockManager, LockMode, LockResult, LockWaiter};
58#[cfg(any())]
59pub use log::{LogEntry, LogEntryType, TransactionLog, WalConfig};
60#[cfg(any())]
61pub use savepoint::{Savepoint, SavepointManager};
62pub use snapshot::{Snapshot, SnapshotManager, TxnContext, Xid, XID_NONE};
63pub use visibility::is_visible;