mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-11 06:46:53 +00:00
Slight refactoring to make things clearer with DeletedFilter
This commit is contained in:
@@ -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::*;
|
||||
|
||||
+27
-34
@@ -8,10 +8,36 @@ pub trait PartitionKey {
|
||||
fn hash(&self) -> Hash;
|
||||
}
|
||||
|
||||
impl PartitionKey for String {
|
||||
fn hash(&self) -> Hash {
|
||||
hash(self.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartitionKey for Hash {
|
||||
fn hash(&self) -> Hash {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub trait SortKey {
|
||||
fn sort_key(&self) -> &[u8];
|
||||
}
|
||||
|
||||
impl SortKey for String {
|
||||
fn sort_key(&self) -> &[u8] {
|
||||
self.as_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
@@ -21,40 +47,6 @@ pub trait Entry<P: PartitionKey, S: SortKey>:
|
||||
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 {
|
||||
fn hash(&self) -> Hash {
|
||||
[0u8; 32].into()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartitionKey for String {
|
||||
fn hash(&self) -> Hash {
|
||||
hash(self.as_bytes())
|
||||
}
|
||||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait TableSchema: Send + Sync {
|
||||
@@ -74,3 +66,4 @@ pub trait TableSchema: Send + Sync {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user