reifydb_transaction/multi/
mod.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use std::time::Duration;
5
6use reifydb_core::CommitVersion;
7
8pub use crate::multi::transaction::{CommandTransaction, QueryTransaction, TransactionMulti};
9
10pub mod conflict;
11pub mod marker;
12pub mod multi;
13pub mod pending;
14pub mod transaction;
15pub mod types;
16pub mod watermark;
17
18/// Backwards-compat type alias
19pub type TransactionMultiVersion = TransactionMulti;
20
21/// Backwards-compat type alias
22pub type StandardQueryTransaction = QueryTransaction;
23
24/// Backwards-compat type alias
25pub type StandardCommandTransaction = CommandTransaction;
26
27/// Error returned when waiting for watermark times out
28#[derive(Debug, Clone)]
29pub struct AwaitWatermarkError {
30	pub version: CommitVersion,
31	pub timeout: Duration,
32}
33
34impl std::fmt::Display for AwaitWatermarkError {
35	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36		write!(f, "Timeout waiting for watermark to reach version {} after {:?}", self.version.0, self.timeout)
37	}
38}
39
40impl std::error::Error for AwaitWatermarkError {}
41
42impl TransactionMulti {
43	/// Wait for the watermark to reach the specified version.
44	/// Returns Ok(()) if the watermark reaches the version within the timeout,
45	/// or Err(AwaitWatermarkError) if the timeout expires.
46	pub async fn try_wait_for_watermark(
47		&self,
48		version: CommitVersion,
49		timeout: Duration,
50	) -> Result<(), AwaitWatermarkError> {
51		self.tm.try_wait_for_watermark(version, timeout).await
52	}
53
54	/// Get the current version from the transaction manager
55	pub async fn current_version(&self) -> crate::Result<CommitVersion> {
56		self.tm.version().await
57	}
58
59	/// Returns the highest version where ALL prior versions have completed.
60	/// This is useful for CDC polling to know the safe upper bound for fetching
61	/// CDC events - all events up to this version are guaranteed to be in storage.
62	pub fn done_until(&self) -> CommitVersion {
63		self.tm.done_until()
64	}
65
66	/// Returns (query_done_until, command_done_until) for debugging watermark state.
67	pub fn watermarks(&self) -> (CommitVersion, CommitVersion) {
68		self.tm.watermarks()
69	}
70}