macp_storage/storage/
mod.rs1mod file;
2mod memory;
3mod migration;
4mod recovery;
5
6#[cfg(feature = "rocksdb-backend")]
7pub mod rocksdb;
8#[cfg(feature = "rocksdb-backend")]
9pub use self::rocksdb::RocksDbBackend;
10
11#[cfg(feature = "redis-backend")]
12pub mod redis_backend;
13#[cfg(feature = "redis-backend")]
14pub use redis_backend::RedisBackend;
15
16pub mod compaction;
17
18pub use file::FileBackend;
19pub use memory::MemoryBackend;
20pub use migration::migrate_if_needed;
21pub use recovery::{cleanup_temp_files, recover_session};
22
23use crate::log_store::LogEntry;
24use macp_core::session::Session;
25use std::io;
26
27#[async_trait::async_trait]
32pub trait StorageBackend: Send + Sync {
33 async fn save_session(&self, session: &Session) -> io::Result<()>;
34 async fn load_session(&self, session_id: &str) -> io::Result<Option<Session>>;
35 async fn load_all_sessions(&self) -> io::Result<Vec<Session>>;
36 async fn delete_session(&self, session_id: &str) -> io::Result<()>;
37 async fn list_session_ids(&self) -> io::Result<Vec<String>>;
38 async fn append_log_entry(&self, session_id: &str, entry: &LogEntry) -> io::Result<()>;
39 async fn load_log(&self, session_id: &str) -> io::Result<Vec<LogEntry>>;
40 async fn create_session_storage(&self, session_id: &str) -> io::Result<()>;
41
42 async fn replace_log(&self, _session_id: &str, _entries: &[LogEntry]) -> io::Result<()> {
43 Err(io::Error::new(
44 io::ErrorKind::Unsupported,
45 "compaction not supported by this backend",
46 ))
47 }
48}