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::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(&self, transaction_id: TransactionId, node_id: NodeId) {
27        // Silently ignore errors: the transaction may have been aborted concurrently,
28        // and the mutation will fail at commit time anyway.
29        let _ = self.manager.record_write(transaction_id, node_id);
30    }
31
32    fn record_edge_write(&self, transaction_id: TransactionId, edge_id: EdgeId) {
33        let _ = self.manager.record_write(transaction_id, edge_id);
34    }
35}