aerogramme/src/storage/mod.rs

85 lines
1.8 KiB
Rust
Raw Normal View History

/*
*
* This abstraction goal is to leverage all the semantic of Garage K2V+S3,
* to be as tailored as possible to it ; it aims to be a zero-cost abstraction
* compared to when we where directly using the K2V+S3 client.
2023-11-01 14:15:57 +00:00
*
* My idea: we can encapsulate the causality token
* into the object system so it is not exposed.
*/
2023-11-02 09:38:47 +00:00
use futures::future::BoxFuture;
2023-11-01 14:36:06 +00:00
pub mod in_memory;
pub mod garage;
pub enum Selector<'a> {
Range{ begin: &'a str, end: &'a str },
Filter(u64),
}
pub enum Alternative {
Tombstone,
Value(Vec<u8>),
}
type ConcurrentValues = Vec<Alternative>;
2023-11-01 14:15:57 +00:00
#[derive(Debug)]
pub enum Error {
NotFound,
Internal,
}
2023-11-02 08:57:58 +00:00
pub struct Engine {
2023-11-02 08:42:50 +00:00
pub bucket: String,
2023-11-02 08:57:58 +00:00
pub row: RowBuilder,
}
2023-11-02 09:38:47 +00:00
impl Clone for Engine {
fn clone(&self) -> Self {
Engine {
bucket: "test".into(),
row: Box::new(in_memory::MemCreds{})
}
}
}
impl std::fmt::Debug for Engine {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Engine").field("bucket", &self.bucket).finish()
}
}
// A result
pub type AsyncResult<'a, T> = BoxFuture<'a, Result<T, Error>>;
2023-11-01 14:15:57 +00:00
// ------ Row Builder
2023-11-02 08:57:58 +00:00
pub trait IRowBuilder
2023-11-01 14:15:57 +00:00
{
2023-11-02 08:57:58 +00:00
fn row_store(&self) -> RowStore;
2023-10-30 17:07:40 +00:00
}
2023-11-02 09:38:47 +00:00
pub type RowBuilder = Box<dyn IRowBuilder + Send + Sync>;
2023-10-30 17:07:40 +00:00
2023-11-01 14:15:57 +00:00
// ------ Row Store
2023-11-02 08:57:58 +00:00
pub trait IRowStore
2023-11-01 14:15:57 +00:00
{
2023-11-02 08:57:58 +00:00
fn new_row(&self, partition: &str, sort: &str) -> RowRef;
2023-10-30 17:07:40 +00:00
}
2023-11-02 08:57:58 +00:00
type RowStore = Box<dyn IRowStore>;
2023-10-30 17:07:40 +00:00
2023-11-01 14:15:57 +00:00
// ------- Row Item
2023-11-02 08:57:58 +00:00
pub trait IRowRef
2023-11-01 14:15:57 +00:00
{
2023-11-02 08:57:58 +00:00
fn set_value(&self, content: Vec<u8>) -> RowValue;
2023-11-02 09:38:47 +00:00
fn fetch(&self) -> AsyncResult<RowValue>;
fn rm(&self) -> AsyncResult<()>;
fn poll(&self) -> AsyncResult<Option<RowValue>>;
}
2023-11-02 08:57:58 +00:00
type RowRef = Box<dyn IRowRef>;
2023-10-30 17:07:40 +00:00
2023-11-02 08:57:58 +00:00
pub trait IRowValue
2023-11-01 14:15:57 +00:00
{
2023-11-02 08:57:58 +00:00
fn to_ref(&self) -> RowRef;
2023-11-01 14:15:57 +00:00
fn content(&self) -> ConcurrentValues;
2023-11-02 09:38:47 +00:00
fn push(&self) -> AsyncResult<()>;
2023-10-30 17:07:40 +00:00
}
2023-11-02 08:57:58 +00:00
type RowValue = Box<dyn IRowValue>;