skeleton for k2v

This commit is contained in:
Alex 2022-04-13 14:02:53 +02:00
parent 30f0cab22c
commit bf6c1b1ef6
Signed by: lx
GPG key ID: 0E496D15096376BE
17 changed files with 129 additions and 24 deletions

View file

@ -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::*;

View file

@ -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::*;

View file

@ -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;

View file

@ -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::*;

View file

@ -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;

View file

@ -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;

View file

@ -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::*;

View file

@ -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;

View file

@ -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 {

View file

@ -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<K2VNodeId, u64>,
}
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
}
}

View file

@ -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<K2VNodeId, DvvsEntry>,
}
#[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<u8>),
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
}
}

3
src/model/k2v/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod item_table;
pub mod causality;

View file

@ -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;

3
src/model/s3/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod block_ref_table;
pub mod object_table;
pub mod version_table;

View file

@ -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;

View file

@ -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;