Skip to main content

grafeo_engine/transaction/
write_tracker.rs

1//! Bridge between mutation operators and the transaction manager's write tracking.
2
3use std::sync::Arc;
4
5use grafeo_common::types::{EdgeId, NodeId, TransactionId};
6use grafeo_core::execution::operators::{OperatorError, WriteTracker};
7
8use super::TransactionManager;
9
10/// Implements [`WriteTracker`] by forwarding to [`TransactionManager::record_write`].
11///
12/// Created by the planner when a transaction is active, and passed to each
13/// mutation operator so it can record writes for conflict detection.
14pub struct TransactionWriteTracker {
15    manager: Arc<TransactionManager>,
16}
17
18impl TransactionWriteTracker {
19    /// Creates a new write tracker backed by the given transaction manager.
20    pub fn new(manager: Arc<TransactionManager>) -> Self {
21        Self { manager }
22    }
23}
24
25impl WriteTracker for TransactionWriteTracker {
26    fn record_node_write(
27        &self,
28        transaction_id: TransactionId,
29        node_id: NodeId,
30    ) -> Result<(), OperatorError> {
31        self.manager
32            .record_write(transaction_id, node_id)
33            .map_err(|e| OperatorError::WriteConflict(e.to_string()))
34    }
35
36    fn record_edge_write(
37        &self,
38        transaction_id: TransactionId,
39        edge_id: EdgeId,
40    ) -> Result<(), OperatorError> {
41        self.manager
42            .record_write(transaction_id, edge_id)
43            .map_err(|e| OperatorError::WriteConflict(e.to_string()))
44    }
45}