aerogramme/src/storage/mod.rs

67 lines
1.4 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-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-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 08:57:58 +00:00
pub type RowBuilder = Box<dyn IRowBuilder>;
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;
async fn fetch(&self) -> Result<RowValue, Error>;
async fn rm(&self) -> Result<(), Error>;
2023-11-02 08:57:58 +00:00
async fn poll(&self) -> Result<Option<RowValue>, Error>;
}
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;
async fn push(&self) -> Result<(), Error>;
2023-10-30 17:07:40 +00:00
}
2023-11-02 08:57:58 +00:00
type RowValue = Box<dyn IRowValue>;