2023-11-01 08:20:36 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* 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 08:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2023-11-01 14:36:06 +00:00
|
|
|
pub mod in_memory;
|
|
|
|
pub mod garage;
|
2023-11-01 08:20:36 +00:00
|
|
|
|
|
|
|
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)]
|
2023-11-01 08:20:36 +00:00
|
|
|
pub enum Error {
|
|
|
|
NotFound,
|
|
|
|
Internal,
|
|
|
|
}
|
|
|
|
|
2023-11-01 15:45:29 +00:00
|
|
|
pub trait Sto: Sized {
|
2023-11-01 16:18:58 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-11-01 16:18:58 +00:00
|
|
|
pub struct Engine<T: Sto> {
|
2023-11-02 08:42:50 +00:00
|
|
|
pub bucket: String,
|
|
|
|
pub row: T::Builder,
|
2023-11-01 16:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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> {
|
2023-11-01 16:18:58 +00:00
|
|
|
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>;
|
2023-11-01 08:20:36 +00:00
|
|
|
async fn rm(&self) -> Result<(), Error>;
|
2023-11-01 14:15:57 +00:00
|
|
|
async fn poll(&self) -> Result<Option<R::Value>, Error>;
|
2023-11-01 08:20:36 +00:00
|
|
|
}
|
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
|
|
|
}
|