From bf6c1b1ef6292925b4be21cc9ed6f2611ee9be91 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 13 Apr 2022 14:02:53 +0200 Subject: [PATCH] skeleton for k2v --- src/api/s3_bucket.rs | 2 +- src/api/s3_copy.rs | 6 +-- src/api/s3_delete.rs | 2 +- src/api/s3_get.rs | 4 +- src/api/s3_list.rs | 4 +- src/api/s3_put.rs | 6 +-- src/garage/admin.rs | 2 +- src/garage/repair.rs | 6 +-- src/model/garage.rs | 7 +-- src/model/k2v/causality.rs | 35 +++++++++++++++ src/model/k2v/item_table.rs | 63 +++++++++++++++++++++++++++ src/model/k2v/mod.rs | 3 ++ src/model/lib.rs | 6 +-- src/model/{ => s3}/block_ref_table.rs | 0 src/model/s3/mod.rs | 3 ++ src/model/{ => s3}/object_table.rs | 2 +- src/model/{ => s3}/version_table.rs | 2 +- 17 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 src/model/k2v/causality.rs create mode 100644 src/model/k2v/item_table.rs create mode 100644 src/model/k2v/mod.rs rename src/model/{ => s3}/block_ref_table.rs (100%) create mode 100644 src/model/s3/mod.rs rename src/model/{ => s3}/object_table.rs (99%) rename src/model/{ => s3}/version_table.rs (99%) diff --git a/src/api/s3_bucket.rs b/src/api/s3_bucket.rs index 8a5407d3..bca41569 100644 --- a/src/api/s3_bucket.rs +++ b/src/api/s3_bucket.rs @@ -7,7 +7,7 @@ use garage_model::bucket_alias_table::*; use garage_model::bucket_table::Bucket; use garage_model::garage::Garage; use garage_model::key_table::Key; -use garage_model::object_table::ObjectFilter; +use garage_model::s3::object_table::ObjectFilter; use garage_model::permission::BucketKeyPerm; use garage_table::util::*; use garage_util::crdt::*; diff --git a/src/api/s3_copy.rs b/src/api/s3_copy.rs index 2d050ff6..19ad84cd 100644 --- a/src/api/s3_copy.rs +++ b/src/api/s3_copy.rs @@ -11,11 +11,11 @@ use garage_table::*; use garage_util::data::*; use garage_util::time::*; -use garage_model::block_ref_table::*; +use garage_model::s3::block_ref_table::*; use garage_model::garage::Garage; use garage_model::key_table::Key; -use garage_model::object_table::*; -use garage_model::version_table::*; +use garage_model::s3::object_table::*; +use garage_model::s3::version_table::*; use crate::api_server::{parse_bucket_key, resolve_bucket}; use crate::error::*; diff --git a/src/api/s3_delete.rs b/src/api/s3_delete.rs index b243d982..2a5b683b 100644 --- a/src/api/s3_delete.rs +++ b/src/api/s3_delete.rs @@ -6,7 +6,7 @@ use garage_util::data::*; use garage_util::time::*; use garage_model::garage::Garage; -use garage_model::object_table::*; +use garage_model::s3::object_table::*; use crate::error::*; use crate::s3_xml; diff --git a/src/api/s3_get.rs b/src/api/s3_get.rs index 7f647e15..3edf22a6 100644 --- a/src/api/s3_get.rs +++ b/src/api/s3_get.rs @@ -14,8 +14,8 @@ use garage_table::EmptyKey; use garage_util::data::*; use garage_model::garage::Garage; -use garage_model::object_table::*; -use garage_model::version_table::*; +use garage_model::s3::object_table::*; +use garage_model::s3::version_table::*; use crate::error::*; diff --git a/src/api/s3_list.rs b/src/api/s3_list.rs index 5852fc1b..3002f782 100644 --- a/src/api/s3_list.rs +++ b/src/api/s3_list.rs @@ -10,8 +10,8 @@ use garage_util::error::Error as GarageError; use garage_util::time::*; use garage_model::garage::Garage; -use garage_model::object_table::*; -use garage_model::version_table::Version; +use garage_model::s3::object_table::*; +use garage_model::s3::version_table::Version; use garage_table::EmptyKey; diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs index ed0bf00b..3b8bfb22 100644 --- a/src/api/s3_put.rs +++ b/src/api/s3_put.rs @@ -14,10 +14,10 @@ use garage_util::error::Error as GarageError; use garage_util::time::*; use garage_block::manager::INLINE_THRESHOLD; -use garage_model::block_ref_table::*; +use garage_model::s3::block_ref_table::*; use garage_model::garage::Garage; -use garage_model::object_table::*; -use garage_model::version_table::*; +use garage_model::s3::object_table::*; +use garage_model::s3::version_table::*; use crate::error::*; use crate::s3_xml; diff --git a/src/garage/admin.rs b/src/garage/admin.rs index 0b20bb20..aecc3ac6 100644 --- a/src/garage/admin.rs +++ b/src/garage/admin.rs @@ -21,7 +21,7 @@ use garage_model::garage::Garage; use garage_model::helper::error::{Error, OkOrBadRequest}; use garage_model::key_table::*; use garage_model::migrate::Migrate; -use garage_model::object_table::ObjectFilter; +use garage_model::s3::object_table::ObjectFilter; use garage_model::permission::*; use crate::cli::*; diff --git a/src/garage/repair.rs b/src/garage/repair.rs index 3666ca8f..bd7e87d2 100644 --- a/src/garage/repair.rs +++ b/src/garage/repair.rs @@ -2,10 +2,10 @@ use std::sync::Arc; use tokio::sync::watch; -use garage_model::block_ref_table::*; +use garage_model::s3::block_ref_table::*; use garage_model::garage::Garage; -use garage_model::object_table::*; -use garage_model::version_table::*; +use garage_model::s3::object_table::*; +use garage_model::s3::version_table::*; use garage_table::*; use garage_util::error::Error; diff --git a/src/model/garage.rs b/src/model/garage.rs index abdb920a..8629f3c8 100644 --- a/src/model/garage.rs +++ b/src/model/garage.rs @@ -13,13 +13,14 @@ use garage_table::replication::TableFullReplication; use garage_table::replication::TableShardedReplication; use garage_table::*; -use crate::block_ref_table::*; +use crate::s3::block_ref_table::*; +use crate::s3::object_table::*; +use crate::s3::version_table::*; + use crate::bucket_alias_table::*; use crate::bucket_table::*; use crate::helper; use crate::key_table::*; -use crate::object_table::*; -use crate::version_table::*; /// An entire Garage full of data pub struct Garage { diff --git a/src/model/k2v/causality.rs b/src/model/k2v/causality.rs new file mode 100644 index 00000000..822134d5 --- /dev/null +++ b/src/model/k2v/causality.rs @@ -0,0 +1,35 @@ +use std::collections::BTreeMap; + +use garage_util::data::*; + +/// Node IDs used in K2V are u64 integers that are the abbreviation +/// of full Garage node IDs which are 256-bit UUIDs. +pub type K2VNodeId = u64; + +pub fn make_node_id(node_id: Uuid) -> K2VNodeId { + let mut tmp = [0u8; 8]; + tmp.copy_from_slice(&node_id.as_slice()[..8]); + u64::from_be_bytes(tmp) +} + + +pub struct CausalityContext { + pub vector_clock: BTreeMap, +} + +impl CausalityContext { + /// Empty causality context + pub fn new_empty() -> Self { + Self { + vector_clock: BTreeMap::new(), + } + } + /// Make binary representation and encode in base64 + pub fn serialize(&self) -> String { + unimplemented!(); //TODO + } + /// Parse from base64-encoded binary representation + pub fn parse(s: &str) -> Self { + unimplemented!(); //TODO + } +} diff --git a/src/model/k2v/item_table.rs b/src/model/k2v/item_table.rs new file mode 100644 index 00000000..f40829cb --- /dev/null +++ b/src/model/k2v/item_table.rs @@ -0,0 +1,63 @@ +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; + +use garage_util::data::*; + +use garage_table::crdt::*; +use garage_table::*; + +use crate::k2v::causality::*; + +#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] +pub struct K2VItem { + pub bucket_id: Uuid, + pub partition_key: String, + pub sort_key: String, + + items: BTreeMap, +} + +#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] +struct DvvsEntry { + t_discard: u64, + values: Vec<(u64, DvvsValue)>, +} + +#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] +pub enum DvvsValue { + Value(#[serde(with = "serde_bytes")] Vec), + Deleted, +} + +impl K2VItem { + /// Creates a new K2VItem when no previous entry existed in the db + pub fn new(this_node: Uuid, value: DvvsValue) -> Self { + unimplemented!(); // TODO + } + /// Updates a K2VItem with a new value or a deletion event + pub fn update(&mut self, this_node: Uuid, context: CausalityContext, new_value: DvvsValue) { + unimplemented!(); // TODO + } + + /// Extract the causality context of a K2V Item + pub fn causality_context(&self) -> CausalityContext { + unimplemented!(); // TODO + } + + /// Extract the list of values + pub fn values(&'_ self) -> Vec<&'_ DvvsValue> { + unimplemented!(); // TODO + } +} + +impl Crdt for K2VItem { + fn merge(&mut self, other: &Self) { + unimplemented!(); // TODO + } +} + +impl Crdt for DvvsEntry { + fn merge(&mut self, other: &Self) { + unimplemented!(); // TODO + } +} diff --git a/src/model/k2v/mod.rs b/src/model/k2v/mod.rs new file mode 100644 index 00000000..4d269624 --- /dev/null +++ b/src/model/k2v/mod.rs @@ -0,0 +1,3 @@ +pub mod item_table; + +pub mod causality; diff --git a/src/model/lib.rs b/src/model/lib.rs index 05a4cdc7..6c69c8e2 100644 --- a/src/model/lib.rs +++ b/src/model/lib.rs @@ -3,12 +3,12 @@ extern crate tracing; pub mod permission; -pub mod block_ref_table; pub mod bucket_alias_table; pub mod bucket_table; pub mod key_table; -pub mod object_table; -pub mod version_table; + +pub mod s3; +pub mod k2v; pub mod garage; pub mod helper; diff --git a/src/model/block_ref_table.rs b/src/model/s3/block_ref_table.rs similarity index 100% rename from src/model/block_ref_table.rs rename to src/model/s3/block_ref_table.rs diff --git a/src/model/s3/mod.rs b/src/model/s3/mod.rs new file mode 100644 index 00000000..4e94337d --- /dev/null +++ b/src/model/s3/mod.rs @@ -0,0 +1,3 @@ +pub mod block_ref_table; +pub mod object_table; +pub mod version_table; diff --git a/src/model/object_table.rs b/src/model/s3/object_table.rs similarity index 99% rename from src/model/object_table.rs rename to src/model/s3/object_table.rs index da53878e..df3e5349 100644 --- a/src/model/object_table.rs +++ b/src/model/s3/object_table.rs @@ -9,7 +9,7 @@ use garage_table::crdt::*; use garage_table::replication::TableShardedReplication; use garage_table::*; -use crate::version_table::*; +use crate::s3::version_table::*; use garage_model_050::object_table as old; diff --git a/src/model/version_table.rs b/src/model/s3/version_table.rs similarity index 99% rename from src/model/version_table.rs rename to src/model/s3/version_table.rs index 839b1f4f..9b46936d 100644 --- a/src/model/version_table.rs +++ b/src/model/s3/version_table.rs @@ -8,7 +8,7 @@ use garage_table::crdt::*; use garage_table::replication::TableShardedReplication; use garage_table::*; -use crate::block_ref_table::*; +use crate::s3::block_ref_table::*; use garage_model_050::version_table as old;