From 30bec0758b943351d946234329b9a46bd83749a1 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Fri, 26 Mar 2021 19:41:46 +0100 Subject: attempt at documenting table crate --- src/table/schema.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/table/schema.rs') diff --git a/src/table/schema.rs b/src/table/schema.rs index 4d754664..f5fde95f 100644 --- a/src/table/schema.rs +++ b/src/table/schema.rs @@ -4,7 +4,9 @@ use garage_util::data::*; use crate::crdt::CRDT; +/// Trait for partitionnable data pub trait PartitionKey { + /// Get the key used to partition fn hash(&self) -> Hash; } @@ -20,7 +22,9 @@ impl PartitionKey for Hash { } } +/// Trait for sortable data pub trait SortKey { + /// Get the key used to sort fn sort_key(&self) -> &[u8]; } @@ -36,25 +40,34 @@ impl SortKey for Hash { } } +/// Trait for an entry in a table. It must be sortable and partitionnable. pub trait Entry: CRDT + PartialEq + Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync { + /// Get the key used to partition fn partition_key(&self) -> &P; + /// Get the key used to sort fn sort_key(&self) -> &S; + /// Is the entry a tombstone? Default implementation always return false fn is_tombstone(&self) -> bool { false } } +/// Trait for the schema used in a table pub trait TableSchema: Send + Sync { + /// The partition key used in that table type P: PartitionKey + Clone + PartialEq + Serialize + for<'de> Deserialize<'de> + Send + Sync; + /// The sort key used int that table type S: SortKey + Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync; + /// They type for an entry in that table type E: Entry; type Filter: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync; // Action to take if not able to decode current version: // try loading from an older version + /// Try migrating an entry from an older version fn try_migrate(_bytes: &[u8]) -> Option { None } @@ -63,9 +76,7 @@ pub trait TableSchema: Send + Sync { // as the update itself is an unchangeable fact that will never go back // due to CRDT logic. Typically errors in propagation of info should be logged // to stderr. - fn updated(&self, _old: Option, _new: Option) {} + fn updated(&self, old: Option, new: Option); - fn matches_filter(_entry: &Self::E, _filter: &Self::Filter) -> bool { - true - } + fn matches_filter(entry: &Self::E, filter: &Self::Filter) -> bool; } -- cgit v1.2.3 From c8906f200bf907272bf9fba7d183df4332fa085b Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Tue, 6 Apr 2021 05:25:28 +0200 Subject: make most requested changes --- src/table/schema.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/table/schema.rs') diff --git a/src/table/schema.rs b/src/table/schema.rs index f5fde95f..c17ccc15 100644 --- a/src/table/schema.rs +++ b/src/table/schema.rs @@ -4,7 +4,7 @@ use garage_util::data::*; use crate::crdt::CRDT; -/// Trait for partitionnable data +/// Trait for field used to partition data pub trait PartitionKey { /// Get the key used to partition fn hash(&self) -> Hash; @@ -22,7 +22,7 @@ impl PartitionKey for Hash { } } -/// Trait for sortable data +/// Trait for field used to sort data pub trait SortKey { /// Get the key used to sort fn sort_key(&self) -> &[u8]; -- cgit v1.2.3 From 718ae005486baeed358d56cc7cd319fedd1e76eb Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Wed, 7 Apr 2021 13:39:34 +0200 Subject: change some more comments and revert changes on TableSchema --- src/table/schema.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/table/schema.rs') diff --git a/src/table/schema.rs b/src/table/schema.rs index c17ccc15..13517271 100644 --- a/src/table/schema.rs +++ b/src/table/schema.rs @@ -76,7 +76,7 @@ pub trait TableSchema: Send + Sync { // as the update itself is an unchangeable fact that will never go back // due to CRDT logic. Typically errors in propagation of info should be logged // to stderr. - fn updated(&self, old: Option, new: Option); + fn updated(&self, _old: Option, _new: Option) {} fn matches_filter(entry: &Self::E, filter: &Self::Filter) -> bool; } -- cgit v1.2.3