From 95685ba9a75df0f00458b8260fb87bae82e0dfa3 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 1 Nov 2023 09:20:36 +0100 Subject: a first naive version of the storage interface --- src/main.rs | 4 +++ src/storage/garage.rs | 0 src/storage/in_memory.rs | 0 src/storage/mod.rs | 85 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 src/storage/garage.rs create mode 100644 src/storage/in_memory.rs diff --git a/src/main.rs b/src/main.rs index 2f6d512..7e1626d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ +#![feature(async_fn_in_trait)] +#![feature(return_position_impl_trait_in_trait)] +// should be stabilized soon https://github.com/rust-lang/rust/pull/115822 + mod bayou; mod config; mod cryptoblob; diff --git a/src/storage/garage.rs b/src/storage/garage.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/storage/in_memory.rs b/src/storage/in_memory.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 399a416..1a77a55 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -1,32 +1,83 @@ -pub trait RowStore { - fn new_row_ref(partition: &str, sort: &str) -> K; +/* + * T1 : Filter + * T2 : Range + * T3 : Atom + */ + +/* + * My idea: we can encapsulate the causality token + * into the object system so it is not exposed. + * + * 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. + */ + + +mod garage; + +pub enum Selector<'a> { + Range{ begin: &'a str, end: &'a str }, + Filter(u64), +} + +pub enum Alternative { + Tombstone, + Value(Vec), +} +type ConcurrentValues = Vec; + +pub enum Error { + NotFound, + Internal, +} + +// ------ Rows +pub trait RowStore { + fn new_ref(partition: &str, sort: &str) -> impl RowRef; + fn new_ref_batch(partition: &str, filter: Selector) -> impl RowRefBatch; } pub trait RowRef { - fn set_value(&self, content: &[u8]) -> RowValue; - async fn get(&self) -> Result; - async fn rm(&self) -> Result<(), E>; - async fn obs(&self) -> Result, ()>; + fn to_value(&self, content: &[u8]) -> impl RowValue; + async fn get(&self) -> Result; + async fn rm(&self) -> Result<(), Error>; + async fn poll(&self) -> Result, Error>; } pub trait RowValue { - fn row_ref(&self) -> RowRef; - fn content(&self) -> Vec; - async fn put(&self) -> Result<(), E>; + fn row_ref(&self) -> impl RowRef; + fn content(&self) -> ConcurrentValues; + async fn persist(&self) -> Result<(), Error>; } -/* - async fn get_many_keys(&self, keys: &[K]) -> Result, ()>; - async fn put_many_keys(&self, values: &[V]) -> Result<(), ()>; -}*/ +// ------ Row batch +pub trait RowRefBatch { + fn to_values(&self, content: Vec<&[u8]>) -> impl RowValueBatch; + fn into_independant(&self) -> Vec; + async fn get(&self) -> Result; + async fn rm(&self) -> Result<(), Error>; +} +pub trait RowValueBatch { + fn into_independant(&self) -> Vec; + fn content(&self) -> Vec; + async fn persist(&self) -> Result<(), Error>; +} + +// ----- Blobs pub trait BlobStore { - fn new_blob_ref(key: &str) -> BlobRef; + fn new_ref(key: &str) -> impl BlobRef; async fn list(&self) -> (); } pub trait BlobRef { - async fn put(&self, key: &str, body: &[u8]) -> (); - async fn copy(&self, dst: &BlobRef) -> (); - async fn rm(&self, key: &str); + fn set_value(&self, content: &[u8]) -> impl BlobValue; + async fn get(&self) -> impl BlobValue; + async fn copy(&self, dst: &impl BlobRef) -> (); + async fn rm(&self, key: &str) -> (); +} + +pub trait BlobValue { + async fn persist(); } -- cgit v1.2.3