aerogramme/src/storage/mod.rs

83 lines
1.7 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-01 15:45:29 +00:00
pub trait Sto: Sized {
type Builder: RowBuilder<Self>;
2023-11-01 14:15:57 +00:00
type Store: RowStore<Self>;
type Ref: RowRef<Self>;
type Value: RowValue<Self>;
2023-10-30 17:07:40 +00:00
}
pub struct Engine<T: Sto> {
2023-11-02 08:42:50 +00:00
pub bucket: String,
pub row: T::Builder,
}
pub enum AnyEngine {
InMemory(Engine<in_memory::MemTypes>),
Garage(Engine<garage::GrgTypes>),
}
impl AnyEngine {
2023-11-02 08:42:50 +00:00
pub fn engine<X: Sto>(&self) -> &Engine<X> {
match self {
Self::InMemory(x) => x,
Self::Garage(x) => x,
}
}
}
2023-11-01 14:15:57 +00:00
// ------ Row Builder
2023-11-01 15:45:29 +00:00
pub trait RowBuilder<R: Sto>
2023-11-01 14:15:57 +00:00
{
fn row_store(&self) -> R::Store;
2023-10-30 17:07:40 +00:00
}
2023-11-01 14:15:57 +00:00
// ------ Row Store
2023-11-01 15:45:29 +00:00
pub trait RowStore<R: Sto>
2023-11-01 14:15:57 +00:00
{
fn new_row(&self, partition: &str, sort: &str) -> R::Ref;
2023-10-30 17:07:40 +00:00
}
2023-11-01 14:15:57 +00:00
// ------- Row Item
2023-11-01 15:45:29 +00:00
pub trait RowRef<R: Sto>
2023-11-01 14:15:57 +00:00
{
fn set_value(&self, content: Vec<u8>) -> R::Value;
async fn fetch(&self) -> Result<R::Value, Error>;
async fn rm(&self) -> Result<(), Error>;
2023-11-01 14:15:57 +00:00
async fn poll(&self) -> Result<Option<R::Value>, Error>;
}
2023-10-30 17:07:40 +00:00
2023-11-01 15:45:29 +00:00
pub trait RowValue<R: Sto>
2023-11-01 14:15:57 +00:00
{
fn to_ref(&self) -> R::Ref;
fn content(&self) -> ConcurrentValues;
async fn push(&self) -> Result<(), Error>;
2023-10-30 17:07:40 +00:00
}