diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-09 17:32:28 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-09 17:32:28 +0200 |
commit | 101444abb3967770ec378ee09f24eb2845dc091d (patch) | |
tree | 7bb838659014b47d220b27d95765174f5d0ae2fe /src/object_table.rs | |
parent | 4c1aee42d5032066272a051687ac200e874cc13f (diff) | |
download | garage-101444abb3967770ec378ee09f24eb2845dc091d.tar.gz garage-101444abb3967770ec378ee09f24eb2845dc091d.zip |
Some progress
Diffstat (limited to 'src/object_table.rs')
-rw-r--r-- | src/object_table.rs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/object_table.rs b/src/object_table.rs new file mode 100644 index 00000000..37c02225 --- /dev/null +++ b/src/object_table.rs @@ -0,0 +1,88 @@ +use std::sync::Arc; +use serde::{Serialize, Deserialize}; +use async_trait::async_trait; +use tokio::sync::RwLock; + +use crate::data::*; +use crate::table::*; +use crate::server::Garage; + + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Object { + pub bucket: String, + pub key: String, + + pub versions: Vec<Box<Version>>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Version { + pub uuid: UUID, + pub timestamp: u64, + + pub mime_type: String, + pub size: u64, + pub is_complete: bool, + + pub data: VersionData, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum VersionData { + DeleteMarker, + Inline(#[serde(with="serde_bytes")] Vec<u8>), + FirstBlock(Hash), +} + +pub struct ObjectTable { + pub garage: RwLock<Option<Arc<Garage>>>, +} + +impl Entry<String, String> for Object { + fn partition_key(&self) -> &String { + &self.bucket + } + fn sort_key(&self) -> &String { + &self.key + } + + fn merge(&mut self, other: &Self) { + for other_v in other.versions.iter() { + match self.versions.binary_search_by(|v| (v.timestamp, &v.uuid).cmp(&(other_v.timestamp, &other_v.uuid))) { + Ok(i) => { + let mut v = &mut self.versions[i]; + if other_v.size > v.size { + v.size = other_v.size; + } + if other_v.is_complete { + v.is_complete = true; + } + } + Err(i) => { + self.versions.insert(i, other_v.clone()); + } + } + } + let last_complete = self.versions + .iter().enumerate().rev() + .filter(|(_, v)| v.is_complete) + .next() + .map(|(vi, _)| vi); + + if let Some(last_vi) = last_complete { + self.versions = self.versions.drain(last_vi..).collect::<Vec<_>>(); + } + } +} + +#[async_trait] +impl TableFormat for ObjectTable { + type P = String; + type S = String; + type E = Object; + + async fn updated(&self, old: Option<&Self::E>, new: &Self::E) { + unimplemented!() + } +} |