diff options
author | Quentin <quentin@deuxfleurs.fr> | 2020-11-21 10:52:27 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2020-11-21 10:52:27 +0100 |
commit | 2f6eca4ef36b662be841454774af55fe84f42d6a (patch) | |
tree | c6d7b5e5b0bedd66a4c2afacebb32760b5ed924b /src/table | |
parent | 5b363626f4803b3e43cdb450fd6ee04ac9429c4d (diff) | |
parent | 5dc304ac41c2ae0699fbdd56117b60c517a1ad39 (diff) | |
download | garage-2f6eca4ef36b662be841454774af55fe84f42d6a.tar.gz garage-2f6eca4ef36b662be841454774af55fe84f42d6a.zip |
Merge remote-tracking branch 'origin/master' into feature/website
Diffstat (limited to 'src/table')
-rw-r--r-- | src/table/lib.rs | 3 | ||||
-rw-r--r-- | src/table/schema.rs | 51 | ||||
-rw-r--r-- | src/table/util.rs | 35 |
3 files changed, 60 insertions, 29 deletions
diff --git a/src/table/lib.rs b/src/table/lib.rs index ac129146..7684fe9d 100644 --- a/src/table/lib.rs +++ b/src/table/lib.rs @@ -4,10 +4,13 @@ extern crate log; pub mod schema; +pub mod util; + pub mod table; pub mod table_fullcopy; pub mod table_sharded; pub mod table_sync; pub use schema::*; +pub use util::*; pub use table::*; diff --git a/src/table/schema.rs b/src/table/schema.rs index 1914320e..49cede0a 100644 --- a/src/table/schema.rs +++ b/src/table/schema.rs @@ -8,54 +8,46 @@ pub trait PartitionKey { fn hash(&self) -> Hash; } -pub trait SortKey { - fn sort_key(&self) -> &[u8]; -} - -pub trait Entry<P: PartitionKey, S: SortKey>: - PartialEq + Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync -{ - fn partition_key(&self) -> &P; - fn sort_key(&self) -> &S; - - fn merge(&mut self, other: &Self); -} - -#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct EmptyKey; -impl SortKey for EmptyKey { - fn sort_key(&self) -> &[u8] { - &[] - } -} -impl PartitionKey for EmptyKey { +impl PartitionKey for String { fn hash(&self) -> Hash { - [0u8; 32].into() + hash(self.as_bytes()) } } -impl PartitionKey for String { +impl PartitionKey for Hash { fn hash(&self) -> Hash { - hash(self.as_bytes()) + self.clone() } } + + +pub trait SortKey { + fn sort_key(&self) -> &[u8]; +} + impl SortKey for String { fn sort_key(&self) -> &[u8] { self.as_bytes() } } -impl PartitionKey for Hash { - fn hash(&self) -> Hash { - self.clone() - } -} impl SortKey for Hash { fn sort_key(&self) -> &[u8] { self.as_slice() } } + +pub trait Entry<P: PartitionKey, S: SortKey>: + PartialEq + Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync +{ + fn partition_key(&self) -> &P; + fn sort_key(&self) -> &S; + + fn merge(&mut self, other: &Self); +} + + #[async_trait] pub trait TableSchema: Send + Sync { type P: PartitionKey + Clone + PartialEq + Serialize + for<'de> Deserialize<'de> + Send + Sync; @@ -74,3 +66,4 @@ pub trait TableSchema: Send + Sync { true } } + diff --git a/src/table/util.rs b/src/table/util.rs new file mode 100644 index 00000000..043a457c --- /dev/null +++ b/src/table/util.rs @@ -0,0 +1,35 @@ +use serde::{Deserialize, Serialize}; + +use garage_util::data::*; + +use crate::schema::*; + +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct EmptyKey; +impl SortKey for EmptyKey { + fn sort_key(&self) -> &[u8] { + &[] + } +} +impl PartitionKey for EmptyKey { + fn hash(&self) -> Hash { + [0u8; 32].into() + } +} + +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum DeletedFilter { + All, + Deleted, + NotDeleted, +} + +impl DeletedFilter { + pub fn apply(&self, deleted: bool) -> bool { + match self { + DeletedFilter::All => true, + DeletedFilter::Deleted => deleted, + DeletedFilter::NotDeleted => !deleted, + } + } +} |