Garage v0.9 #473

Merged
lx merged 175 commits from next into main 2023-10-10 13:28:29 +00:00
3 changed files with 8 additions and 18 deletions
Showing only changes of commit 53bf2f070c - Show all commits

View file

@ -347,7 +347,7 @@ impl<F: TableSchema, R: TableReplication> TableData<F, R> {
// ---- Utility functions ---- // ---- Utility functions ----
pub fn tree_key(&self, p: &F::P, s: &F::S) -> Vec<u8> { pub fn tree_key(&self, p: &F::P, s: &F::S) -> Vec<u8> {
[p.hash().as_slice(), s.sort_key().as_ref()].concat() [p.hash().as_slice(), s.sort_key()].concat()
} }
pub fn decode_entry(&self, bytes: &[u8]) -> Result<F::E, Error> { pub fn decode_entry(&self, bytes: &[u8]) -> Result<F::E, Error> {

View file

@ -1,5 +1,3 @@
use std::borrow::Cow;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use garage_db as db; use garage_db as db;
@ -38,24 +36,18 @@ impl PartitionKey for FixedBytes32 {
/// Trait for field used to sort data /// Trait for field used to sort data
pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static { pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static {
/// Get the key used to sort /// Get the key used to sort
fn sort_key(&self) -> Cow<'_, [u8]>; fn sort_key(&self) -> &[u8];
} }
impl SortKey for String { impl SortKey for String {
fn sort_key(&self) -> Cow<'_, [u8]> { fn sort_key(&self) -> &[u8] {
Cow::from(self.as_bytes()) self.as_bytes()
} }
} }
impl SortKey for FixedBytes32 { impl SortKey for FixedBytes32 {
fn sort_key(&self) -> Cow<'_, [u8]> { fn sort_key(&self) -> &[u8] {
Cow::from(self.as_slice()) self.as_slice()
}
}
impl SortKey for u32 {
fn sort_key(&self) -> Cow<'_, [u8]> {
Cow::from(u32::to_be_bytes(*self).to_vec())
} }
} }

View file

@ -1,5 +1,3 @@
use std::borrow::Cow;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use garage_util::data::*; use garage_util::data::*;
@ -9,8 +7,8 @@ use crate::schema::*;
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EmptyKey; pub struct EmptyKey;
impl SortKey for EmptyKey { impl SortKey for EmptyKey {
fn sort_key(&self) -> Cow<'_, [u8]> { fn sort_key(&self) -> &[u8] {
Cow::from(&[][..]) &[]
} }
} }
impl PartitionKey for EmptyKey { impl PartitionKey for EmptyKey {