From 6005491cd8adf569c0b7f88fc6b3af3f166963ea Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 27 Apr 2023 16:14:44 +0200 Subject: Use Cow<[u8]> for sort keys --- src/table/schema.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/table/schema.rs') diff --git a/src/table/schema.rs b/src/table/schema.rs index 5cbf6c95..44b10898 100644 --- a/src/table/schema.rs +++ b/src/table/schema.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use serde::{Deserialize, Serialize}; use garage_db as db; @@ -32,18 +34,18 @@ impl PartitionKey for FixedBytes32 { /// Trait for field used to sort data pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static { /// Get the key used to sort - fn sort_key(&self) -> &[u8]; + fn sort_key(&self) -> Cow<'_, [u8]>; } impl SortKey for String { - fn sort_key(&self) -> &[u8] { - self.as_bytes() + fn sort_key(&self) -> Cow<'_, [u8]> { + Cow::from(self.as_bytes()) } } impl SortKey for FixedBytes32 { - fn sort_key(&self) -> &[u8] { - self.as_slice() + fn sort_key(&self) -> Cow<'_, [u8]> { + Cow::from(self.as_slice()) } } -- cgit v1.2.3 From 38d6ac429506f9f488ac522581b12fa530442a59 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 27 Apr 2023 17:57:54 +0200 Subject: New multipart upload table layout --- src/table/schema.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/table/schema.rs') diff --git a/src/table/schema.rs b/src/table/schema.rs index 44b10898..7daf3000 100644 --- a/src/table/schema.rs +++ b/src/table/schema.rs @@ -8,6 +8,8 @@ use garage_util::migrate::Migrate; use crate::crdt::Crdt; +// =================================== PARTITION KEYS + /// Trait for field used to partition data pub trait PartitionKey: Clone + PartialEq + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static @@ -31,6 +33,8 @@ impl PartitionKey for FixedBytes32 { } } +// =================================== SORT KEYS + /// Trait for field used to sort data pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static { /// Get the key used to sort @@ -49,6 +53,14 @@ impl SortKey for FixedBytes32 { } } +impl SortKey for u32 { + fn sort_key(&self) -> Cow<'_, [u8]> { + Cow::from(u32::to_be_bytes(*self).to_vec()) + } +} + +// =================================== SCHEMA + /// Trait for an entry in a table. It must be sortable and partitionnable. pub trait Entry: Crdt + PartialEq + Clone + Migrate + Send + Sync + 'static -- cgit v1.2.3 From 53bf2f070cd3ef95bbdf78e439dbeb2d8cda8f19 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 9 May 2023 12:38:55 +0200 Subject: undo sort_key() returning Cow --- src/table/schema.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/table/schema.rs') diff --git a/src/table/schema.rs b/src/table/schema.rs index 7daf3000..fc1a465e 100644 --- a/src/table/schema.rs +++ b/src/table/schema.rs @@ -1,5 +1,3 @@ -use std::borrow::Cow; - use serde::{Deserialize, Serialize}; use garage_db as db; @@ -38,24 +36,18 @@ impl PartitionKey for FixedBytes32 { /// Trait for field used to sort data pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static { /// Get the key used to sort - fn sort_key(&self) -> Cow<'_, [u8]>; + fn sort_key(&self) -> &[u8]; } impl SortKey for String { - fn sort_key(&self) -> Cow<'_, [u8]> { - Cow::from(self.as_bytes()) + fn sort_key(&self) -> &[u8] { + self.as_bytes() } } impl SortKey for FixedBytes32 { - fn sort_key(&self) -> Cow<'_, [u8]> { - Cow::from(self.as_slice()) - } -} - -impl SortKey for u32 { - fn sort_key(&self) -> Cow<'_, [u8]> { - Cow::from(u32::to_be_bytes(*self).to_vec()) + fn sort_key(&self) -> &[u8] { + self.as_slice() } } -- cgit v1.2.3