Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion crates/ironclaw_filesystem/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
use async_trait::async_trait;
use ironclaw_host_api::VirtualPath;

use crate::{CasExpectation, Entry, FilesystemError, RecordVersion, SeqNo, VersionedEntry};
use crate::{
CasExpectation, Entry, FilesystemError, FilesystemOperation, RecordVersion, SeqNo,
VersionedEntry,
};

/// Multi-key transactional handle returned by [`RootFilesystem::begin`].
///
Expand All @@ -40,6 +43,13 @@ pub trait StorageTxn: Send {

async fn delete(&mut self, path: &VirtualPath) -> Result<(), FilesystemError>;

async fn reserve_sequence(&mut self, path: &VirtualPath) -> Result<SeqNo, FilesystemError> {
Err(FilesystemError::Unsupported {
path: path.clone(),
operation: FilesystemOperation::ReserveSeq,
})
}

async fn commit(self: Box<Self>) -> Result<(), FilesystemError>;

async fn rollback(self: Box<Self>);
Expand All @@ -60,3 +70,62 @@ impl EventRecord {
Self { seq, payload }
}
}

#[cfg(test)]
mod tests {
use super::*;

struct DummyTxn;

#[async_trait]
impl StorageTxn for DummyTxn {
async fn put(
&mut self,
path: &VirtualPath,
_entry: Entry,
_cas: CasExpectation,
) -> Result<RecordVersion, FilesystemError> {
Err(FilesystemError::Unsupported {
path: path.clone(),
operation: FilesystemOperation::WriteFile,
})
}

async fn get(
&mut self,
path: &VirtualPath,
) -> Result<Option<VersionedEntry>, FilesystemError> {
Err(FilesystemError::Unsupported {
path: path.clone(),
operation: FilesystemOperation::ReadFile,
})
}

async fn delete(&mut self, path: &VirtualPath) -> Result<(), FilesystemError> {
Err(FilesystemError::Unsupported {
path: path.clone(),
operation: FilesystemOperation::Delete,
})
}

async fn commit(self: Box<Self>) -> Result<(), FilesystemError> {
Ok(())
}

async fn rollback(self: Box<Self>) {}
}

#[tokio::test]
async fn storage_txn_reserve_sequence_fails_closed_by_default() {
let path = VirtualPath::new("/events/log").unwrap();
let mut txn = DummyTxn;

let err = txn.reserve_sequence(&path).await.unwrap_err();

assert!(matches!(
err,
FilesystemError::Unsupported { path: actual, operation: FilesystemOperation::ReserveSeq }
if actual == path
));
}
}
Loading
Loading