linkrs_storage/batch_ops.rs
1//! Auto-commit batch window operations.
2//!
3//! Storage engines that support a shared [`AutoCommitBatchWindow`] implement
4//! this trait so batch loaders can acquire the auto-commit write gate and
5//! register MVCC snapshots once for a run of statements.
6
7use crate::engine::graph_storage::AutoCommitBatchWindow;
8use linkrs_core::{StorageError, StorageResult};
9use std::sync::Arc;
10
11/// Operations for running a run of auto-commit DML statements inside a shared
12/// batch window.
13pub trait AutoCommitBatchOps: Send + Sync {
14 fn begin_auto_commit_batch(&self) -> StorageResult<Arc<AutoCommitBatchWindow>>;
15
16 fn bind_auto_commit_statement(
17 &self,
18 window: &Arc<AutoCommitBatchWindow>,
19 ) -> StorageResult<Self>
20 where
21 Self: Sized;
22
23 fn finalize_auto_commit_batch(&self, window: &AutoCommitBatchWindow) -> StorageResult<()>;
24
25 /// Object-safe variant of [`Self::bind_auto_commit_statement`]: returns
26 /// the bound statement storage as a boxed [`crate::StorageWriter`]
27 /// carrying the window's operation context (shared undo log in group
28 /// mode), so writers behind a `dyn QueryStorage` handle can join the
29 /// window. The default implementation is `not_supported`.
30 fn bind_auto_commit_writer(
31 &self,
32 _window: &Arc<AutoCommitBatchWindow>,
33 ) -> StorageResult<Box<dyn crate::StorageWriter + '_>> {
34 Err(StorageError::not_supported(
35 "bind_auto_commit_writer is not supported by this storage implementation",
36 ))
37 }
38}
39
40/// Group-commit operations on top of an [`AutoCommitBatchWindow`].
41/// The window is shared with `AutoCommitBatchOps`; `bind_auto_commit_statement`
42/// is mode-aware: bound inside a group window it reuses the shared write
43/// timestamp and undo log, so no separate bind method is needed.
44pub trait AutoCommitGroupOps: Send + Sync {
45 /// Open a group window (gate + shared snapshots + shared write timestamp).
46 fn begin_auto_commit_group(&self) -> StorageResult<Arc<AutoCommitBatchWindow>>;
47 /// Single group commit point: one fsync, barrier advance, one ts commit.
48 fn finalize_auto_commit_group(&self, window: &AutoCommitBatchWindow) -> StorageResult<()>;
49 /// Roll back every statement bound to this group via its shared undo log,
50 /// then release the window's snapshots and gate. Default: not supported.
51 fn rollback_auto_commit_group(&self, _window: &AutoCommitBatchWindow) -> StorageResult<()> {
52 Err(StorageError::not_supported(
53 "rollback_auto_commit_group is not supported by this storage implementation",
54 ))
55 }
56}