aboutsummaryrefslogtreecommitdiff
path: root/src/table/schema.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-04-27 17:57:54 +0200
committerAlex Auvolat <alex@adnab.me>2023-06-09 16:23:37 +0200
commit38d6ac429506f9f488ac522581b12fa530442a59 (patch)
treeac3d2b81f50c9b91038019649c3b096afeeb9a3d /src/table/schema.rs
parent6005491cd8adf569c0b7f88fc6b3af3f166963ea (diff)
downloadgarage-38d6ac429506f9f488ac522581b12fa530442a59.tar.gz
garage-38d6ac429506f9f488ac522581b12fa530442a59.zip
New multipart upload table layout
Diffstat (limited to 'src/table/schema.rs')
-rw-r--r--src/table/schema.rs12
1 files changed, 12 insertions, 0 deletions
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<P: PartitionKey, S: SortKey>:
Crdt + PartialEq + Clone + Migrate + Send + Sync + 'static