From a88fd49f71844f04013970a678201a65ab89fb19 Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 21 Nov 2020 17:50:19 +0100 Subject: Use handle_get --- src/model/block.rs | 2 +- src/model/bucket_table.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src/model') diff --git a/src/model/block.rs b/src/model/block.rs index 6a5d9c5b..8a513a3c 100644 --- a/src/model/block.rs +++ b/src/model/block.rs @@ -20,7 +20,7 @@ use garage_rpc::rpc_client::*; use garage_rpc::rpc_server::*; use garage_table::table_sharded::TableShardedReplication; -use garage_table::{TableReplication, DeletedFilter}; +use garage_table::{DeletedFilter, TableReplication}; use crate::block_ref_table::*; diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index 35c0cc27..11f853f9 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -104,7 +104,6 @@ impl Entry for Bucket { pub struct BucketTable; - #[async_trait] impl TableSchema for BucketTable { type P = EmptyKey; -- cgit v1.2.3 From e1ce2b228aaacd5984bf4e1b73a0a6c1276f78e5 Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 12 Dec 2020 17:00:31 +0100 Subject: WIP table migration --- src/model/bucket_table.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/model') diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index b7f24d71..b6b0fceb 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -21,27 +21,43 @@ pub struct Bucket { #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub enum BucketState { Deleted, - Present(crdt::LWWMap), + Present(BucketParams), } impl CRDT for BucketState { fn merge(&mut self, o: &Self) { match o { BucketState::Deleted => *self = BucketState::Deleted, - BucketState::Present(other_ak) => { - if let BucketState::Present(ak) = self { - ak.merge(other_ak); + BucketState::Present(other_params) => { + if let BucketState::Present(params) = self { + params.merge(other_params); } } } } } +#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] +pub struct BucketParams { + pub authorized_keys: crdt::LWWMap, + pub website: crdt::LWW +} + +impl CRDT for BucketParams { + fn merge(&mut self, o: &Self) { + self.authorized_keys.merge(&o.authorized_keys); + self.website.merge(&o.website); + } +} + impl Bucket { pub fn new(name: String) -> Self { Bucket { name, - state: crdt::LWW::new(BucketState::Present(crdt::LWWMap::new())), + state: crdt::LWW::new(BucketState::Present(BucketParams { + authorized_keys: crdt::LWWMap::new(), + website: crdt::LWW::new(false) + })), } } pub fn is_deleted(&self) -> bool { @@ -50,7 +66,7 @@ impl Bucket { pub fn authorized_keys(&self) -> &[(String, u64, PermissionSet)] { match self.state.get() { BucketState::Deleted => &[], - BucketState::Present(ak) => ak.items(), + BucketState::Present(state) => state.authorized_keys.items(), } } } -- cgit v1.2.3 From 96388acf230d48877a037b21931f61e2c63d2574 Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 12 Dec 2020 21:35:29 +0100 Subject: Implement migration --- src/model/bucket_table.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/model') diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index b6b0fceb..08d0d168 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -10,6 +10,11 @@ use crate::key_table::PermissionSet; use model010::bucket_table as prev; +/// A bucket is a collection of objects +/// +/// Its parameters are not directly accessible as: +/// - It must be possible to merge paramaters, hence the use of a LWW CRDT. +/// - A bucket has 2 states, Present or Deleted and parameters make sense only if present. #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub struct Bucket { // Primary key @@ -123,9 +128,15 @@ impl TableSchema for BucketTable { }, )); } + + let params = BucketParams { + authorized_keys: keys, + website: crdt::LWW::new(false) + }; + Some(Bucket { name: old.name, - state: crdt::LWW::migrate_from_raw(old.timestamp, BucketState::Present(keys)), + state: crdt::LWW::migrate_from_raw(old.timestamp, BucketState::Present(params)), }) } } -- cgit v1.2.3 From d0eb6a457f6f83c8f49d262adf6150964a1249b2 Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 14 Dec 2020 21:46:49 +0100 Subject: Migrate RPC to new schema --- src/model/bucket_table.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/model') diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index 08d0d168..609490cb 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -55,14 +55,20 @@ impl CRDT for BucketParams { } } +impl BucketParams { + pub fn new() -> Self { + BucketParams { + authorized_keys: crdt::LWWMap::new(), + website: crdt::LWW::new(false) + } + } +} + impl Bucket { pub fn new(name: String) -> Self { Bucket { name, - state: crdt::LWW::new(BucketState::Present(BucketParams { - authorized_keys: crdt::LWWMap::new(), - website: crdt::LWW::new(false) - })), + state: crdt::LWW::new(BucketState::Present(BucketParams::new())), } } pub fn is_deleted(&self) -> bool { -- cgit v1.2.3 From 3bc4d57a0f4a600c788a3c7ff51d633d1b7e6f09 Mon Sep 17 00:00:00 2001 From: Quentin Date: Tue, 15 Dec 2020 12:48:24 +0100 Subject: First implementation of the CLI --- src/model/bucket_table.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/model') diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index 609490cb..78b0416f 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -45,7 +45,7 @@ impl CRDT for BucketState { #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub struct BucketParams { pub authorized_keys: crdt::LWWMap, - pub website: crdt::LWW + pub website: crdt::LWW, } impl CRDT for BucketParams { @@ -59,7 +59,7 @@ impl BucketParams { pub fn new() -> Self { BucketParams { authorized_keys: crdt::LWWMap::new(), - website: crdt::LWW::new(false) + website: crdt::LWW::new(false), } } } @@ -134,10 +134,10 @@ impl TableSchema for BucketTable { }, )); } - + let params = BucketParams { authorized_keys: keys, - website: crdt::LWW::new(false) + website: crdt::LWW::new(false), }; Some(Bucket { -- cgit v1.2.3